vmm: Remove 'file' option from MemoryConfig

After the introduction of user defined memory zones, we can now remove
the deprecated 'file' option from --memory parameter. This makes this
parameter simpler, letting more advanced users define their own custom
memory zones through the dedicated parameter.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-08-24 11:09:01 +02:00 committed by Samuel Ortiz
parent 5bf7113768
commit c58dd761f4
5 changed files with 8 additions and 48 deletions

View File

@ -526,7 +526,6 @@ mod unit_tests {
},
memory: MemoryConfig {
size: 536_870_912,
file: None,
mergeable: false,
hotplug_method: HotplugMethod::Acpi,
hotplug_size: None,
@ -644,18 +643,6 @@ mod unit_tests {
}"#,
true,
),
(
vec![
"cloud-hypervisor", "--kernel", "/path/to/kernel",
"--memory",
"size=1G,file=/path/to/shared/file",
],
r#"{
"kernel": {"path": "/path/to/kernel"},
"memory": {"size": 1073741824, "file": "/path/to/shared/file"}
}"#,
true,
),
(
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "size=1G,mergeable=on"],
r#"{

View File

@ -38,4 +38,4 @@ write_files:
# 1G ram requires 512 pages
echo 512 | sudo tee /proc/sys/vm/nr_hugepages
sudo chmod a+rwX /dev/hugepages
/mnt/cloud-hypervisor --kernel /mnt/vmlinux --cmdline "console=hvc0 reboot=k panic=1 nomodules i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd root=/dev/vda1 VFIOTAG" --disk path=/mnt/focal-server-cloudimg-amd64-custom.qcow2 path=/mnt/cloudinit.img --cpus boot=1 --memory size=512M,hotplug_size=1G,file=/dev/hugepages --device path=/sys/bus/pci/devices/0000:00:06.0/ path=/sys/bus/pci/devices/0000:00:07.0/ --api-socket /tmp/ch_api.sock
/mnt/cloud-hypervisor --kernel /mnt/vmlinux --cmdline "console=hvc0 reboot=k panic=1 nomodules i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd root=/dev/vda1 VFIOTAG" --disk path=/mnt/focal-server-cloudimg-amd64-custom.qcow2 path=/mnt/cloudinit.img --cpus boot=1 --memory size=512M,hotplug_size=1G,hugepages=on --device path=/sys/bus/pci/devices/0000:00:06.0/ path=/sys/bus/pci/devices/0000:00:07.0/ --api-socket /tmp/ch_api.sock

View File

@ -481,8 +481,6 @@ components:
hotplug_size:
type: integer
format: int64
file:
type: string
mergeable:
type: boolean
default: false

View File

@ -360,8 +360,6 @@ pub struct MemoryZoneConfig {
pub struct MemoryConfig {
pub size: u64,
#[serde(default)]
pub file: Option<PathBuf>,
#[serde(default)]
pub mergeable: bool,
#[serde(default)]
pub hotplug_method: HotplugMethod,
@ -398,7 +396,6 @@ impl MemoryConfig {
.map_err(Error::ParseMemory)?
.unwrap_or(ByteSized(DEFAULT_MEMORY_MB << 20))
.0;
let file = parser.get("file").map(PathBuf::from);
let mergeable = parser
.convert::<Toggle>("mergeable")
.map_err(Error::ParseMemory)?
@ -477,7 +474,6 @@ impl MemoryConfig {
Ok(MemoryConfig {
size,
file,
mergeable,
hotplug_method,
hotplug_size,
@ -494,7 +490,6 @@ impl Default for MemoryConfig {
fn default() -> Self {
MemoryConfig {
size: DEFAULT_MEMORY_MB << 20,
file: None,
mergeable: false,
hotplug_method: HotplugMethod::Acpi,
hotplug_size: None,
@ -1288,10 +1283,6 @@ impl VmConfig {
return Err(ValidationError::CpusMaxLowerThanBoot);
}
if self.memory.file.is_some() {
error!("Use of backing file ('--memory file=') is deprecated. Use the 'shared' and 'hugepages' controls.");
}
if let Some(disks) = &self.disks {
for disk in disks {
if disk.vhost_socket.as_ref().and(disk.path.as_ref()).is_some() {
@ -1489,21 +1480,16 @@ mod tests {
let mut parser = OptionParser::new();
parser
.add("size")
.add("file")
.add("mergeable")
.add("hotplug_method")
.add("hotplug_size");
assert!(parser
.parse("size=128M,file=/dev/shm,hanging_param")
.is_err());
assert!(parser
.parse("size=128M,file=/dev/shm,too_many_equals=foo=bar")
.is_err());
assert!(parser.parse("size=128M,file=/dev/shm").is_ok());
assert!(parser.parse("size=128M,hanging_param").is_err());
assert!(parser.parse("size=128M,too_many_equals=foo=bar").is_err());
assert!(parser.parse("size=128M,file=/dev/shm").is_err());
assert!(parser.parse("size=128M").is_ok());
assert_eq!(parser.get("size"), Some("128M".to_owned()));
assert_eq!(parser.get("file"), Some("/dev/shm".to_owned()));
assert!(!parser.is_set("mergeable"));
assert!(parser.is_set("size"));
Ok(())
@ -1557,14 +1543,6 @@ mod tests {
MemoryConfig::parse("size=512M", None)?,
MemoryConfig::default()
);
assert_eq!(
MemoryConfig::parse("size=512M,file=/some/file", None)?,
MemoryConfig {
size: 512 << 20,
file: Some(PathBuf::from("/some/file")),
..Default::default()
}
);
assert_eq!(
MemoryConfig::parse("size=512M,mergeable=on", None)?,
MemoryConfig {
@ -2016,7 +1994,6 @@ mod tests {
},
memory: MemoryConfig {
size: 536_870_912,
file: None,
mergeable: false,
hotplug_method: HotplugMethod::Acpi,
hotplug_size: None,

View File

@ -64,7 +64,6 @@ pub struct MemoryManager {
pub vm: Arc<dyn hypervisor::Vm>,
hotplug_slots: Vec<HotPlugState>,
selected_slot: usize,
backing_file: Option<PathBuf>,
mergeable: bool,
allocator: Arc<Mutex<SystemAllocator>>,
hotplug_method: HotplugMethod,
@ -371,7 +370,7 @@ impl MemoryManager {
for region in ram_regions.iter() {
mem_regions.push(MemoryManager::create_ram_region(
&config.file,
&None,
0,
region.0,
region.1,
@ -438,7 +437,7 @@ impl MemoryManager {
if !use_zones {
virtiomem_region = Some(MemoryManager::create_ram_region(
&config.file,
&None,
0,
start_addr,
size as usize,
@ -490,7 +489,6 @@ impl MemoryManager {
vm,
hotplug_slots,
selected_slot: 0,
backing_file: config.file.clone(),
mergeable: config.mergeable,
allocator: allocator.clone(),
hotplug_method: config.hotplug_method.clone(),
@ -791,7 +789,7 @@ impl MemoryManager {
// Allocate memory for the region
let region = MemoryManager::create_ram_region(
&self.backing_file,
&None,
0,
start_addr,
size,