diff --git a/src/main.rs b/src/main.rs index c114ba9dc..92f966bbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,12 @@ fn main() { .help("Path to kernel image (vmlinux)") .takes_value(true), ) + .arg( + Arg::with_name("disk") + .long("disk") + .help("Path to VM disk image") + .takes_value(true), + ) .arg( Arg::with_name("cpus") .long("cpus") @@ -43,9 +49,14 @@ fn main() { .value_of("kernel") .map(PathBuf::from) .expect("Missing argument: kernel"); - let kernel_path = kernel_arg.as_path(); + let disk_arg = cmd_arguments + .value_of("disk") + .map(PathBuf::from) + .expect("Missing argument: disk"); + let disk_path = disk_arg.as_path(); + let mut vcpus = DEFAULT_VCPUS; if let Some(cpus) = cmd_arguments.value_of("cpus") { vcpus = cpus.parse::().unwrap(); @@ -59,7 +70,7 @@ fn main() { println!("VM [{} vCPUS {} MB of memory]", vcpus, memory); println!("Booting {:?}...", kernel_path); - let vm_config = VmConfig::new(kernel_path, vcpus, memory).unwrap(); + let vm_config = VmConfig::new(kernel_path, disk_path, vcpus, memory).unwrap(); vmm::boot_kernel(vm_config).unwrap(); } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index a3e3cc5c9..54ae20889 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -206,6 +206,7 @@ impl Vcpu { pub struct VmConfig<'a> { kernel_path: &'a Path, + disk_path: &'a Path, cmdline: Option, cmdline_addr: GuestAddress, @@ -214,9 +215,15 @@ pub struct VmConfig<'a> { } impl<'a> VmConfig<'a> { - pub fn new(kernel_path: &'a Path, vcpus: u8, memory_size: GuestUsize) -> Result { + pub fn new( + kernel_path: &'a Path, + disk_path: &'a Path, + vcpus: u8, + memory_size: GuestUsize, + ) -> Result { Ok(VmConfig { kernel_path, + disk_path, memory_size, vcpu_count: vcpus, ..Default::default() @@ -232,6 +239,7 @@ impl<'a> Default for VmConfig<'a> { VmConfig { kernel_path: Path::new(""), + disk_path: Path::new(""), cmdline: Some(cmdline), cmdline_addr: CMDLINE_OFFSET, memory_size: DEFAULT_MEMORY, @@ -257,7 +265,12 @@ struct DeviceManager { } impl DeviceManager { - fn new(memory: GuestMemoryMmap, allocator: &mut SystemAllocator, vm_fd: &VmFd) -> Result { + fn new( + memory: GuestMemoryMmap, + allocator: &mut SystemAllocator, + vm_fd: &VmFd, + vm_cfg: &VmConfig, + ) -> Result { let io_bus = devices::Bus::new(); let mut mmio_bus = devices::Bus::new(); let serial_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFd)?; @@ -277,7 +290,7 @@ impl DeviceManager { let raw_img: File = OpenOptions::new() .read(true) .write(true) - .open("/foo/bar/rootfs.img") + .open(&vm_cfg.disk_path) .map_err(Error::Disk)?; let virtio_block_device = @@ -478,7 +491,7 @@ impl<'a> Vm<'a> { ) .ok_or(Error::CreateSystemAllocator)?; - let device_manager = DeviceManager::new(guest_memory.clone(), &mut allocator, &fd) + let device_manager = DeviceManager::new(guest_memory.clone(), &mut allocator, &fd, &config) .map_err(|_| Error::DeviceManager)?; fd.register_irqfd(device_manager.serial_evt.as_raw_fd(), 4) .map_err(Error::Irq)?;