mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
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:
parent
5bf7113768
commit
c58dd761f4
13
src/main.rs
13
src/main.rs
@ -526,7 +526,6 @@ mod unit_tests {
|
|||||||
},
|
},
|
||||||
memory: MemoryConfig {
|
memory: MemoryConfig {
|
||||||
size: 536_870_912,
|
size: 536_870_912,
|
||||||
file: None,
|
|
||||||
mergeable: false,
|
mergeable: false,
|
||||||
hotplug_method: HotplugMethod::Acpi,
|
hotplug_method: HotplugMethod::Acpi,
|
||||||
hotplug_size: None,
|
hotplug_size: None,
|
||||||
@ -644,18 +643,6 @@ mod unit_tests {
|
|||||||
}"#,
|
}"#,
|
||||||
true,
|
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"],
|
vec!["cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "size=1G,mergeable=on"],
|
||||||
r#"{
|
r#"{
|
||||||
|
@ -38,4 +38,4 @@ write_files:
|
|||||||
# 1G ram requires 512 pages
|
# 1G ram requires 512 pages
|
||||||
echo 512 | sudo tee /proc/sys/vm/nr_hugepages
|
echo 512 | sudo tee /proc/sys/vm/nr_hugepages
|
||||||
sudo chmod a+rwX /dev/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
|
||||||
|
@ -481,8 +481,6 @@ components:
|
|||||||
hotplug_size:
|
hotplug_size:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
file:
|
|
||||||
type: string
|
|
||||||
mergeable:
|
mergeable:
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
@ -360,8 +360,6 @@ pub struct MemoryZoneConfig {
|
|||||||
pub struct MemoryConfig {
|
pub struct MemoryConfig {
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub file: Option<PathBuf>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub mergeable: bool,
|
pub mergeable: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub hotplug_method: HotplugMethod,
|
pub hotplug_method: HotplugMethod,
|
||||||
@ -398,7 +396,6 @@ impl MemoryConfig {
|
|||||||
.map_err(Error::ParseMemory)?
|
.map_err(Error::ParseMemory)?
|
||||||
.unwrap_or(ByteSized(DEFAULT_MEMORY_MB << 20))
|
.unwrap_or(ByteSized(DEFAULT_MEMORY_MB << 20))
|
||||||
.0;
|
.0;
|
||||||
let file = parser.get("file").map(PathBuf::from);
|
|
||||||
let mergeable = parser
|
let mergeable = parser
|
||||||
.convert::<Toggle>("mergeable")
|
.convert::<Toggle>("mergeable")
|
||||||
.map_err(Error::ParseMemory)?
|
.map_err(Error::ParseMemory)?
|
||||||
@ -477,7 +474,6 @@ impl MemoryConfig {
|
|||||||
|
|
||||||
Ok(MemoryConfig {
|
Ok(MemoryConfig {
|
||||||
size,
|
size,
|
||||||
file,
|
|
||||||
mergeable,
|
mergeable,
|
||||||
hotplug_method,
|
hotplug_method,
|
||||||
hotplug_size,
|
hotplug_size,
|
||||||
@ -494,7 +490,6 @@ impl Default for MemoryConfig {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
MemoryConfig {
|
MemoryConfig {
|
||||||
size: DEFAULT_MEMORY_MB << 20,
|
size: DEFAULT_MEMORY_MB << 20,
|
||||||
file: None,
|
|
||||||
mergeable: false,
|
mergeable: false,
|
||||||
hotplug_method: HotplugMethod::Acpi,
|
hotplug_method: HotplugMethod::Acpi,
|
||||||
hotplug_size: None,
|
hotplug_size: None,
|
||||||
@ -1288,10 +1283,6 @@ impl VmConfig {
|
|||||||
return Err(ValidationError::CpusMaxLowerThanBoot);
|
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 {
|
if let Some(disks) = &self.disks {
|
||||||
for disk in disks {
|
for disk in disks {
|
||||||
if disk.vhost_socket.as_ref().and(disk.path.as_ref()).is_some() {
|
if disk.vhost_socket.as_ref().and(disk.path.as_ref()).is_some() {
|
||||||
@ -1489,21 +1480,16 @@ mod tests {
|
|||||||
let mut parser = OptionParser::new();
|
let mut parser = OptionParser::new();
|
||||||
parser
|
parser
|
||||||
.add("size")
|
.add("size")
|
||||||
.add("file")
|
|
||||||
.add("mergeable")
|
.add("mergeable")
|
||||||
.add("hotplug_method")
|
.add("hotplug_method")
|
||||||
.add("hotplug_size");
|
.add("hotplug_size");
|
||||||
|
|
||||||
assert!(parser
|
assert!(parser.parse("size=128M,hanging_param").is_err());
|
||||||
.parse("size=128M,file=/dev/shm,hanging_param")
|
assert!(parser.parse("size=128M,too_many_equals=foo=bar").is_err());
|
||||||
.is_err());
|
assert!(parser.parse("size=128M,file=/dev/shm").is_err());
|
||||||
assert!(parser
|
assert!(parser.parse("size=128M").is_ok());
|
||||||
.parse("size=128M,file=/dev/shm,too_many_equals=foo=bar")
|
|
||||||
.is_err());
|
|
||||||
assert!(parser.parse("size=128M,file=/dev/shm").is_ok());
|
|
||||||
|
|
||||||
assert_eq!(parser.get("size"), Some("128M".to_owned()));
|
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("mergeable"));
|
||||||
assert!(parser.is_set("size"));
|
assert!(parser.is_set("size"));
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1557,14 +1543,6 @@ mod tests {
|
|||||||
MemoryConfig::parse("size=512M", None)?,
|
MemoryConfig::parse("size=512M", None)?,
|
||||||
MemoryConfig::default()
|
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!(
|
assert_eq!(
|
||||||
MemoryConfig::parse("size=512M,mergeable=on", None)?,
|
MemoryConfig::parse("size=512M,mergeable=on", None)?,
|
||||||
MemoryConfig {
|
MemoryConfig {
|
||||||
@ -2016,7 +1994,6 @@ mod tests {
|
|||||||
},
|
},
|
||||||
memory: MemoryConfig {
|
memory: MemoryConfig {
|
||||||
size: 536_870_912,
|
size: 536_870_912,
|
||||||
file: None,
|
|
||||||
mergeable: false,
|
mergeable: false,
|
||||||
hotplug_method: HotplugMethod::Acpi,
|
hotplug_method: HotplugMethod::Acpi,
|
||||||
hotplug_size: None,
|
hotplug_size: None,
|
||||||
|
@ -64,7 +64,6 @@ pub struct MemoryManager {
|
|||||||
pub vm: Arc<dyn hypervisor::Vm>,
|
pub vm: Arc<dyn hypervisor::Vm>,
|
||||||
hotplug_slots: Vec<HotPlugState>,
|
hotplug_slots: Vec<HotPlugState>,
|
||||||
selected_slot: usize,
|
selected_slot: usize,
|
||||||
backing_file: Option<PathBuf>,
|
|
||||||
mergeable: bool,
|
mergeable: bool,
|
||||||
allocator: Arc<Mutex<SystemAllocator>>,
|
allocator: Arc<Mutex<SystemAllocator>>,
|
||||||
hotplug_method: HotplugMethod,
|
hotplug_method: HotplugMethod,
|
||||||
@ -371,7 +370,7 @@ impl MemoryManager {
|
|||||||
|
|
||||||
for region in ram_regions.iter() {
|
for region in ram_regions.iter() {
|
||||||
mem_regions.push(MemoryManager::create_ram_region(
|
mem_regions.push(MemoryManager::create_ram_region(
|
||||||
&config.file,
|
&None,
|
||||||
0,
|
0,
|
||||||
region.0,
|
region.0,
|
||||||
region.1,
|
region.1,
|
||||||
@ -438,7 +437,7 @@ impl MemoryManager {
|
|||||||
|
|
||||||
if !use_zones {
|
if !use_zones {
|
||||||
virtiomem_region = Some(MemoryManager::create_ram_region(
|
virtiomem_region = Some(MemoryManager::create_ram_region(
|
||||||
&config.file,
|
&None,
|
||||||
0,
|
0,
|
||||||
start_addr,
|
start_addr,
|
||||||
size as usize,
|
size as usize,
|
||||||
@ -490,7 +489,6 @@ impl MemoryManager {
|
|||||||
vm,
|
vm,
|
||||||
hotplug_slots,
|
hotplug_slots,
|
||||||
selected_slot: 0,
|
selected_slot: 0,
|
||||||
backing_file: config.file.clone(),
|
|
||||||
mergeable: config.mergeable,
|
mergeable: config.mergeable,
|
||||||
allocator: allocator.clone(),
|
allocator: allocator.clone(),
|
||||||
hotplug_method: config.hotplug_method.clone(),
|
hotplug_method: config.hotplug_method.clone(),
|
||||||
@ -791,7 +789,7 @@ impl MemoryManager {
|
|||||||
|
|
||||||
// Allocate memory for the region
|
// Allocate memory for the region
|
||||||
let region = MemoryManager::create_ram_region(
|
let region = MemoryManager::create_ram_region(
|
||||||
&self.backing_file,
|
&None,
|
||||||
0,
|
0,
|
||||||
start_addr,
|
start_addr,
|
||||||
size,
|
size,
|
||||||
|
Loading…
Reference in New Issue
Block a user