From b81d758c41a8debe883538a512412dfb22e62a89 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 8 Nov 2021 11:57:17 +0100 Subject: [PATCH] option_parser: Expect commas instead of colons for lists The elements of a list should be using commas as the correct delimiter now that it is supported. Deprecate use of colons as delimiter. Signed-off-by: Sebastien Boeuf --- docs/memory.md | 32 ++++++++++++++++++++++---------- option_parser/src/lib.rs | 19 ++++++++++++++++--- tests/integration.rs | 14 +++++++------- vmm/src/config.rs | 4 ++-- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/docs/memory.md b/docs/memory.md index 6e5011805..8ea9554a5 100644 --- a/docs/memory.md +++ b/docs/memory.md @@ -446,17 +446,20 @@ integer of 8 bits. For instance, if one needs to attach all CPUs from 0 to 4 to a specific node, the syntax using `-` will help define a contiguous range with `cpus=0-4`. The -same example could also be described with `cpus=0:1:2:3:4`. +same example could also be described with `cpus=[0,1,2,3,4]`. -A combination of both `-` and `:` separators is useful when one might need to +A combination of both `-` and `,` separators is useful when one might need to describe a list containing all CPUs from 0 to 99 and the CPU 255, as it could -simply be described with `cpus=0-99:255`. +simply be described with `cpus=[0-99,255]`. + +As soon as one tries to describe a list of values, `[` and `]` must be used to +demarcate the list. _Example_ ``` --cpus boot=8 ---numa guest_numa_id=0,cpus=1-3:7 guest_numa_id=1,cpus=0:4-6 +--numa guest_numa_id=0,cpus=[1-3,7] guest_numa_id=1,cpus=[0,4-6] ``` ### `distances` @@ -473,7 +476,10 @@ node. The second value is an unsigned integer of 8 bits as it represents the distance between the current NUMA node and the destination NUMA node. The two values are separated by `@` (`value1@value2`), meaning the destination NUMA node `value1` is located at a distance of `value2`. Each tuple is separated -from the others with `:` separator. +from the others with `,` separator. + +As soon as one tries to describe a list of values, `[` and `]` must be used to +demarcate the list. For instance, if one wants to define 3 NUMA nodes, with each node located at different distances, it can be described with the following example. @@ -481,7 +487,7 @@ different distances, it can be described with the following example. _Example_ ``` ---numa guest_numa_id=0,distances=1@15:2@25 guest_numa_id=1,distances=0@15:2@20 guest_numa_id=2,distances=0@25:1@20 +--numa guest_numa_id=0,distances=[1@15,2@25] guest_numa_id=1,distances=[0@15,2@20] guest_numa_id=2,distances=[0@25,1@20] ``` ### `memory_zones` @@ -498,7 +504,10 @@ workload run more efficiently. Multiple values can be provided to define the list. Each value is a string referring to an existing memory zone identifier. Values are separated from -each other with the `:` separator. +each other with the `,` separator. + +As soon as one tries to describe a list of values, `[` and `]` must be used to +demarcate the list. Note that a memory zone must belong to a single NUMA node. The following configuration is incorrect, therefore not allowed: @@ -509,7 +518,7 @@ _Example_ ``` --memory size=0 --memory-zone id=mem0,size=1G id=mem1,size=1G id=mem2,size=1G ---numa guest_numa_id=0,memory_zones=mem0:mem2 guest_numa_id=1,memory_zones=mem1 +--numa guest_numa_id=0,memory_zones=[mem0,mem2] guest_numa_id=1,memory_zones=mem1 ``` ### `sgx_epc_sections` @@ -520,13 +529,16 @@ which must be seen by the guest as belonging to the NUMA node `guest_numa_id`. Multiple values can be provided to define the list. Each value is a string referring to an existing SGX EPC section identifier. Values are separated from -each other with the `:` separator. +each other with the `,` separator. + +As soon as one tries to describe a list of values, `[` and `]` must be used to +demarcate the list. _Example_ ``` --sgx-epc id=epc0,size=32M id=epc1,size=64M id=epc2,size=32M ---numa guest_numa_id=0,sgx_epc_sections=epc1 guest_numa_id=1,sgx_epc_sections=epc0:epc2 +--numa guest_numa_id=0,sgx_epc_sections=epc1 guest_numa_id=1,sgx_epc_sections=[epc0,epc2] ``` ### PCI bus diff --git a/option_parser/src/lib.rs b/option_parser/src/lib.rs index 844cbdd82..ebbb5787b 100644 --- a/option_parser/src/lib.rs +++ b/option_parser/src/lib.rs @@ -202,7 +202,11 @@ impl FromStr for IntegerList { fn from_str(s: &str) -> std::result::Result { let mut integer_list = Vec::new(); - let ranges_list: Vec<&str> = s.trim().split(':').collect(); + let ranges_list: Vec<&str> = s + .trim() + .trim_matches(|c| c == '[' || c == ']') + .split(',') + .collect(); for range in ranges_list.iter() { let items: Vec<&str> = range.split('-').collect(); @@ -246,7 +250,11 @@ impl FromStr for TupleTwoIntegers { fn from_str(s: &str) -> std::result::Result { let mut list = Vec::new(); - let tuples_list: Vec<&str> = s.trim().split(':').collect(); + let tuples_list: Vec<&str> = s + .trim() + .trim_matches(|c| c == '[' || c == ']') + .split(',') + .collect(); for tuple in tuples_list.iter() { let items: Vec<&str> = tuple.split('@').collect(); @@ -281,7 +289,12 @@ impl FromStr for StringList { type Err = StringListParseError; fn from_str(s: &str) -> std::result::Result { - let string_list: Vec = s.trim().split(':').map(|e| e.to_owned()).collect(); + let string_list: Vec = s + .trim() + .trim_matches(|c| c == '[' || c == ']') + .split(',') + .map(|e| e.to_owned()) + .collect(); Ok(StringList(string_list)) } diff --git a/tests/integration.rs b/tests/integration.rs index 1b23fd0c7..7320d4870 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1136,9 +1136,9 @@ mod tests { ]) .args(&[ "--numa", - "guest_numa_id=0,cpus=0-2:9,distances=1@15:2@20,memory_zones=mem0", - "guest_numa_id=1,cpus=3-4:6-8,distances=0@20:2@25,memory_zones=mem1", - "guest_numa_id=2,cpus=5:10-11,distances=0@25:1@30,memory_zones=mem2", + "guest_numa_id=0,cpus=[0-2,9],distances=[1@15,2@20],memory_zones=mem0", + "guest_numa_id=1,cpus=[3-4,6-8],distances=[0@20,2@25],memory_zones=mem1", + "guest_numa_id=2,cpus=[5,10-11],distances=[0@25,1@30],memory_zones=mem2", ]) .args(&["--kernel", kernel_path.to_str().unwrap()]) .args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) @@ -5580,7 +5580,7 @@ mod tests { .args(&[ "--net", &format!( - "fd={}:{},mac={},num_queues={}", + "fd=[{},{}],mac={},num_queues={}", taps[0].as_raw_fd(), taps[1].as_raw_fd(), guest.network.guest_mac, @@ -7114,9 +7114,9 @@ mod tests { "id=mem1,size=1G,hotplug_size=32G", "id=mem2,size=1G,hotplug_size=32G", "--numa", - "guest_numa_id=0,cpus=0-2:9,distances=1@15:2@20,memory_zones=mem0", - "guest_numa_id=1,cpus=3-4:6-8,distances=0@20:2@25,memory_zones=mem1", - "guest_numa_id=2,cpus=5:10-11,distances=0@25:1@30,memory_zones=mem2", + "guest_numa_id=0,cpus=[0-2,9],distances=[1@15,2@20],memory_zones=mem0", + "guest_numa_id=1,cpus=[3-4,6-8],distances=[0@20,2@25],memory_zones=mem1", + "guest_numa_id=2,cpus=[5,10-11],distances=[0@25,1@30],memory_zones=mem2", ] } else { &["--memory", "size=4G"] diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 8cca3d060..667e8fd53 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -1136,7 +1136,7 @@ impl Default for NetConfig { impl NetConfig { pub const SYNTAX: &'static str = "Network parameters \ - \"tap=,ip=,mask=,mac=,fd=,iommu=on|off,\ + \"tap=,ip=,mask=,mac=,fd=,iommu=on|off,\ num_queues=,queue_size=,id=,\ vhost_user=,socket=,vhost_mode=client|server,\ bw_size=,bw_one_time_burst=,bw_refill_time=,\ @@ -2653,7 +2653,7 @@ mod tests { ); assert_eq!( - NetConfig::parse("mac=de:ad:be:ef:12:34,fd=3:7,num_queues=4")?, + NetConfig::parse("mac=de:ad:be:ef:12:34,fd=[3,7],num_queues=4")?, NetConfig { mac: MacAddr::parse_str("de:ad:be:ef:12:34").unwrap(), fds: Some(vec![3, 7]),