runtime-rs: Enable memory backend option for Machine for s390x

For s390x, it requires an additional option `memory-backend` for `-machine`.
Otherwise, virtiofsd exits with HandleRequest(InvalidParam).

This commit is to add a field `memory_backend` to `struct Machine`
and turn it on for s390x.

Signed-off-by: Hyounggyu Choi <Hyounggyu.Choi@ibm.com>
This commit is contained in:
Hyounggyu Choi 2024-03-22 14:54:45 +01:00
parent 9bcfaad625
commit 2cfe745efb

View File

@ -285,6 +285,7 @@ struct Machine {
nvdimm: bool,
is_nvdimm_supported: bool,
memory_backend: Option<String>,
}
impl Machine {
@ -310,6 +311,7 @@ impl Machine {
options: config.machine_info.machine_accelerators.clone(),
nvdimm: false,
is_nvdimm_supported,
memory_backend: None,
}
}
@ -320,6 +322,11 @@ impl Machine {
self.nvdimm = is_on && self.is_nvdimm_supported;
self
}
fn set_memory_backend(&mut self, mem_backend: &str) -> &mut Self {
self.memory_backend = Some(mem_backend.to_owned());
self
}
}
#[async_trait]
@ -334,6 +341,9 @@ impl ToQemuParams for Machine {
if self.nvdimm {
params.push("nvdimm=on".to_owned());
}
if let Some(mem_backend) = &self.memory_backend {
params.push(format!("memory-backend={}", mem_backend));
}
Ok(vec!["-machine".to_owned(), params.join(",")])
}
}
@ -983,8 +993,15 @@ impl<'a> QemuCmdLine<'a> {
//self.devices.push(Box::new(mem_file));
self.memory.set_memory_backend_file(&mem_file);
self.machine.set_nvdimm(true);
self.devices.push(Box::new(NumaNode::new(&mem_file.id)));
match self.bus_type() {
VirtioBusType::Pci => {
self.machine.set_nvdimm(true);
self.devices.push(Box::new(NumaNode::new(&mem_file.id)));
}
VirtioBusType::Ccw => {
self.machine.set_memory_backend(&mem_file.id);
}
}
}
pub fn add_vsock(&mut self, vhostfd: RawFd, guest_cid: u32) -> Result<()> {