vmm: Flag --disk should be optional

Now that cloud-hypervisor VMM supports virtio-pmem, it can directly
boot a VM from an image exposed as a persistent memory block device.

That's why there is no need to force the --disk option as being
mandatory.

Fixes #90

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-07-08 15:48:39 -07:00 committed by Samuel Ortiz
parent f0a76ad424
commit d9ce29117e
3 changed files with 48 additions and 43 deletions

View File

@ -100,10 +100,7 @@ fn main() {
let cmdline = cmd_arguments.value_of("cmdline"); let cmdline = cmd_arguments.value_of("cmdline");
let disks: Vec<&str> = cmd_arguments let disks: Option<Vec<&str>> = cmd_arguments.values_of("disk").map(|x| x.collect());
.values_of("disk")
.expect("Missing argument: disk. Provide at least one")
.collect();
let net: Option<Vec<&str>> = cmd_arguments.values_of("net").map(|x| x.collect()); let net: Option<Vec<&str>> = cmd_arguments.values_of("net").map(|x| x.collect());

View File

@ -58,7 +58,7 @@ pub struct VmParams<'a> {
pub memory: &'a str, pub memory: &'a str,
pub kernel: &'a str, pub kernel: &'a str,
pub cmdline: Option<&'a str>, pub cmdline: Option<&'a str>,
pub disks: Vec<&'a str>, pub disks: Option<Vec<&'a str>>,
pub net: Option<Vec<&'a str>>, pub net: Option<Vec<&'a str>>,
pub rng: &'a str, pub rng: &'a str,
pub fs: Option<Vec<&'a str>>, pub fs: Option<Vec<&'a str>>,
@ -343,7 +343,7 @@ pub struct VmConfig<'a> {
pub memory: MemoryConfig<'a>, pub memory: MemoryConfig<'a>,
pub kernel: KernelConfig<'a>, pub kernel: KernelConfig<'a>,
pub cmdline: CmdlineConfig, pub cmdline: CmdlineConfig,
pub disks: Vec<DiskConfig<'a>>, pub disks: Option<Vec<DiskConfig<'a>>>,
pub net: Option<Vec<NetConfig<'a>>>, pub net: Option<Vec<NetConfig<'a>>>,
pub rng: RngConfig<'a>, pub rng: RngConfig<'a>,
pub fs: Option<Vec<FsConfig<'a>>>, pub fs: Option<Vec<FsConfig<'a>>>,
@ -352,9 +352,13 @@ pub struct VmConfig<'a> {
impl<'a> VmConfig<'a> { impl<'a> VmConfig<'a> {
pub fn parse(vm_params: VmParams<'a>) -> Result<Self> { pub fn parse(vm_params: VmParams<'a>) -> Result<Self> {
let mut disks: Vec<DiskConfig> = Vec::new(); let mut disks: Option<Vec<DiskConfig>> = None;
for disk in vm_params.disks.iter() { if let Some(disk_list) = &vm_params.disks {
disks.push(DiskConfig::parse(disk)?); let mut disk_config_list = Vec::new();
for item in disk_list.iter() {
disk_config_list.push(DiskConfig::parse(item)?);
}
disks = Some(disk_config_list);
} }
let mut net: Option<Vec<NetConfig>> = None; let mut net: Option<Vec<NetConfig>> = None;

View File

@ -528,42 +528,46 @@ impl DeviceManager {
let pci_root = PciRoot::new(None); let pci_root = PciRoot::new(None);
let mut pci = PciConfigIo::new(pci_root); let mut pci = PciConfigIo::new(pci_root);
for disk_cfg in &vm_cfg.disks { // Add virtio-blk if required
// Open block device path if let Some(disk_list_cfg) = &vm_cfg.disks {
let raw_img: File = OpenOptions::new() for disk_cfg in disk_list_cfg.iter() {
.read(true) // Open block device path
.write(true) let raw_img: File = OpenOptions::new()
.open(disk_cfg.path) .read(true)
.map_err(DeviceManagerError::Disk)?; .write(true)
.open(disk_cfg.path)
.map_err(DeviceManagerError::Disk)?;
// Add virtio-blk let image_type = qcow::detect_image_type(&raw_img)
let image_type = .map_err(DeviceManagerError::DetectImageType)?;
qcow::detect_image_type(&raw_img).map_err(DeviceManagerError::DetectImageType)?; let block = match image_type {
let block = match image_type { ImageType::Raw => {
ImageType::Raw => { let raw_img = vm_virtio::RawFile::new(raw_img);
let raw_img = vm_virtio::RawFile::new(raw_img); let dev =
let dev = vm_virtio::Block::new(raw_img, disk_cfg.path.to_path_buf(), false) vm_virtio::Block::new(raw_img, disk_cfg.path.to_path_buf(), false)
.map_err(DeviceManagerError::CreateVirtioBlock)?; .map_err(DeviceManagerError::CreateVirtioBlock)?;
Box::new(dev) as Box<vm_virtio::VirtioDevice> Box::new(dev) as Box<vm_virtio::VirtioDevice>
} }
ImageType::Qcow2 => { ImageType::Qcow2 => {
let qcow_img = let qcow_img = QcowFile::from(raw_img)
QcowFile::from(raw_img).map_err(DeviceManagerError::QcowDeviceCreate)?; .map_err(DeviceManagerError::QcowDeviceCreate)?;
let dev = vm_virtio::Block::new(qcow_img, disk_cfg.path.to_path_buf(), false) let dev =
.map_err(DeviceManagerError::CreateVirtioBlock)?; vm_virtio::Block::new(qcow_img, disk_cfg.path.to_path_buf(), false)
Box::new(dev) as Box<vm_virtio::VirtioDevice> .map_err(DeviceManagerError::CreateVirtioBlock)?;
} Box::new(dev) as Box<vm_virtio::VirtioDevice>
}; }
};
DeviceManager::add_virtio_pci_device( DeviceManager::add_virtio_pci_device(
block, block,
memory.clone(), memory.clone(),
allocator, allocator,
vm_fd, vm_fd,
&mut pci, &mut pci,
&mut mmio_bus, &mut mmio_bus,
&interrupt_info, &interrupt_info,
)?; )?;
}
} }
// Add virtio-net if required // Add virtio-net if required