From 6d27ac9dfc52031019efdaf569644e4a298bb2e0 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 11 Sep 2019 16:22:00 +0100 Subject: [PATCH] vmm: Allow the DeviceManager to inject extra kernel commandline entries This is useful for virtio-mmio to be able to provide the commandline entries for the devices. Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 10 ++++++++++ vmm/src/vm.rs | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 8f1272c32..ad7f3a6b3 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -277,6 +277,9 @@ pub struct DeviceManager { // mmap()ed region to unmap on drop mmap_regions: Vec<(*mut libc::c_void, usize)>, + + // Things to be added to the commandline (i.e. for virtio-mmio) + cmdline_additions: Vec, } impl DeviceManager { @@ -392,6 +395,8 @@ impl DeviceManager { &mut mmap_regions, )?); + let mut cmdline_additions = Vec::new(); + let pci_root = PciRoot::new(None); let mut pci = PciConfigIo::new(pci_root); @@ -421,6 +426,7 @@ impl DeviceManager { ioapic, pci, mmap_regions, + cmdline_additions, }; dm.register_devices()?; @@ -963,6 +969,10 @@ impl DeviceManager { pub fn console(&self) -> &Arc { &self.console } + + pub fn cmdline_additions(&self) -> &[String] { + self.cmdline_additions.as_slice() + } } impl Drop for DeviceManager { diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index df1a855e8..c62336fbe 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -752,8 +752,12 @@ impl<'a> Vm<'a> { } pub fn load_kernel(&mut self) -> Result { - let cmdline_cstring = - CString::new(self.config.cmdline.args.clone()).map_err(|_| Error::CmdLine)?; + let mut cmdline = self.config.cmdline.args.clone(); + for entry in self.devices.cmdline_additions() { + cmdline.insert_str(entry).map_err(|_| Error::CmdLine)?; + } + + let cmdline_cstring = CString::new(cmdline).map_err(|_| Error::CmdLine)?; let mem = self.memory.read().unwrap(); let entry_addr = match linux_loader::loader::Elf::load( mem.deref(),