Skip to content

Commit 924eab5

Browse files
committed
Added '--use-extended-yaml' option
1 parent 2e4c903 commit 924eab5

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed

docs/shadow_config_overview.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ Acceptable unit *prefixes* are:
7777

7878
Examples: `20 B`, `100 MB`, `100 megabyte`, `10 kibibytes`, `30 MiB`, `1024 Mbytes`
7979

80-
## YAML Extensions
80+
## YAML Extensions (Experimental)
81+
82+
Shadow has experimental support for extended YAML conventions. These can be
83+
enabled using the `--use-extended-yaml true` command line option.
8184

8285
### Merge/Override Mappings
8386

docs/shadow_config_spec.md

+9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ hosts:
8484
- [`experimental.use_cpu_pinning`](#experimentaluse_cpu_pinning)
8585
- [`experimental.use_dynamic_runahead`](#experimentaluse_dynamic_runahead)
8686
- [`experimental.use_explicit_block_message`](#experimentaluse_explicit_block_message)
87+
- [`experimental.use_extended_yaml`](#experimentaluse_extended_yaml)
8788
- [`experimental.use_legacy_working_dir`](#experimentaluse_legacy_working_dir)
8889
- [`experimental.use_libc_preload`](#experimentaluse_libc_preload)
8990
- [`experimental.use_memory_manager`](#experimentaluse_memory_manager)
@@ -480,6 +481,14 @@ Type: Bool
480481
Send message to managed process telling it to stop spinning when a syscall
481482
blocks.
482483

484+
#### `experimental.use_extended_yaml`
485+
486+
Default: false
487+
Type: Bool
488+
489+
Enable extended YAML conventions (merge keys and extension fields). Can only be
490+
enabled on the command line (enabling in the configuration file is a no-op).
491+
483492
#### `experimental.use_legacy_working_dir`
484493

485494
Default: false

src/main/core/main.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ pub fn run_shadow<'a>(args: Vec<&'a OsStr>) -> anyhow::Result<()> {
6161
}
6262
.into();
6363

64+
// this option is weird since it's a configuration option but we need to read it before merging
65+
// with the configuration file
66+
let use_extended_yaml = options.experimental.use_extended_yaml.unwrap_or_default();
67+
6468
// load the configuration yaml
65-
let config_file = load_config_file(&config_filename)
69+
let config_file = load_config_file(&config_filename, use_extended_yaml)
6670
.with_context(|| format!("Failed to load configuration file {}", config_filename))?;
6771

6872
// generate the final shadow configuration from the config file and cli options
@@ -179,7 +183,10 @@ pub fn run_shadow<'a>(args: Vec<&'a OsStr>) -> anyhow::Result<()> {
179183
Ok(())
180184
}
181185

182-
fn load_config_file(filename: impl AsRef<std::path::Path>) -> anyhow::Result<ConfigFileOptions> {
186+
fn load_config_file(
187+
filename: impl AsRef<std::path::Path>,
188+
extended_yaml: bool,
189+
) -> anyhow::Result<ConfigFileOptions> {
183190
let file = std::fs::File::open(filename).context("Could not open config file")?;
184191

185192
// serde's default behaviour is to silently ignore duplicate keys during deserialization so we
@@ -191,23 +198,25 @@ fn load_config_file(filename: impl AsRef<std::path::Path>) -> anyhow::Result<Con
191198
let mut config_file: serde_yaml::Value =
192199
serde_yaml::from_reader(file).context("Could not parse configuration file as yaml")?;
193200

194-
// apply the merge before removing extension fields
195-
config_file
196-
.apply_merge()
197-
.context("Could not merge '<<' keys")?;
198-
199-
// remove top-level extension fields
200-
if let serde_yaml::Value::Mapping(ref mut mapping) = &mut config_file {
201-
// remove entries having a key beginning with "x-" (follows docker's convention:
202-
// https://docs.docker.com/compose/compose-file/#extension)
203-
mapping.retain(|key, _value| {
204-
if let serde_yaml::Value::String(key) = key {
205-
if key.starts_with("x-") {
206-
return false;
201+
if extended_yaml {
202+
// apply the merge before removing extension fields
203+
config_file
204+
.apply_merge()
205+
.context("Could not merge '<<' keys")?;
206+
207+
// remove top-level extension fields
208+
if let serde_yaml::Value::Mapping(ref mut mapping) = &mut config_file {
209+
// remove entries having a key beginning with "x-" (follows docker's convention:
210+
// https://docs.docker.com/compose/compose-file/#extension)
211+
mapping.retain(|key, _value| {
212+
if let serde_yaml::Value::String(key) = key {
213+
if key.starts_with("x-") {
214+
return false;
215+
}
207216
}
208-
}
209-
true
210-
});
217+
true
218+
});
219+
}
211220
}
212221

213222
Ok(serde_yaml::from_value(config_file).context("Could not parse configuration file")?)

src/main/core/support/configuration.rs

+8
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@ pub struct ExperimentalOptions {
449449
#[clap(long, value_name = "seconds")]
450450
#[clap(help = EXP_HELP.get("unblocked_vdso_latency").unwrap().as_str())]
451451
pub unblocked_vdso_latency: Option<units::Time<units::TimePrefix>>,
452+
453+
/// Enable extended YAML conventions (merge keys and extension fields). Can only be enabled on
454+
/// the command line (enabling in the configuration file is a no-op).
455+
#[clap(hide_short_help = true)]
456+
#[clap(long, value_name = "bool")]
457+
#[clap(help = EXP_HELP.get("use_extended_yaml").unwrap().as_str())]
458+
pub use_extended_yaml: Option<bool>,
452459
}
453460

454461
impl ExperimentalOptions {
@@ -500,6 +507,7 @@ impl Default for ExperimentalOptions {
500507
host_heartbeat_log_info: Some(IntoIterator::into_iter([LogInfoFlag::Node]).collect()),
501508
host_heartbeat_interval: None,
502509
strace_logging_mode: Some(StraceLoggingMode::Off),
510+
use_extended_yaml: Some(false),
503511
}
504512
}
505513
}

0 commit comments

Comments
 (0)