mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
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:
parent
f0a76ad424
commit
d9ce29117e
@ -100,10 +100,7 @@ fn main() {
|
||||
|
||||
let cmdline = cmd_arguments.value_of("cmdline");
|
||||
|
||||
let disks: Vec<&str> = cmd_arguments
|
||||
.values_of("disk")
|
||||
.expect("Missing argument: disk. Provide at least one")
|
||||
.collect();
|
||||
let disks: Option<Vec<&str>> = cmd_arguments.values_of("disk").map(|x| x.collect());
|
||||
|
||||
let net: Option<Vec<&str>> = cmd_arguments.values_of("net").map(|x| x.collect());
|
||||
|
||||
|
@ -58,7 +58,7 @@ pub struct VmParams<'a> {
|
||||
pub memory: &'a str,
|
||||
pub kernel: &'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 rng: &'a str,
|
||||
pub fs: Option<Vec<&'a str>>,
|
||||
@ -343,7 +343,7 @@ pub struct VmConfig<'a> {
|
||||
pub memory: MemoryConfig<'a>,
|
||||
pub kernel: KernelConfig<'a>,
|
||||
pub cmdline: CmdlineConfig,
|
||||
pub disks: Vec<DiskConfig<'a>>,
|
||||
pub disks: Option<Vec<DiskConfig<'a>>>,
|
||||
pub net: Option<Vec<NetConfig<'a>>>,
|
||||
pub rng: RngConfig<'a>,
|
||||
pub fs: Option<Vec<FsConfig<'a>>>,
|
||||
@ -352,9 +352,13 @@ pub struct VmConfig<'a> {
|
||||
|
||||
impl<'a> VmConfig<'a> {
|
||||
pub fn parse(vm_params: VmParams<'a>) -> Result<Self> {
|
||||
let mut disks: Vec<DiskConfig> = Vec::new();
|
||||
for disk in vm_params.disks.iter() {
|
||||
disks.push(DiskConfig::parse(disk)?);
|
||||
let mut disks: Option<Vec<DiskConfig>> = None;
|
||||
if let Some(disk_list) = &vm_params.disks {
|
||||
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;
|
||||
|
@ -528,42 +528,46 @@ impl DeviceManager {
|
||||
let pci_root = PciRoot::new(None);
|
||||
let mut pci = PciConfigIo::new(pci_root);
|
||||
|
||||
for disk_cfg in &vm_cfg.disks {
|
||||
// Open block device path
|
||||
let raw_img: File = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(disk_cfg.path)
|
||||
.map_err(DeviceManagerError::Disk)?;
|
||||
// Add virtio-blk if required
|
||||
if let Some(disk_list_cfg) = &vm_cfg.disks {
|
||||
for disk_cfg in disk_list_cfg.iter() {
|
||||
// Open block device path
|
||||
let raw_img: File = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(disk_cfg.path)
|
||||
.map_err(DeviceManagerError::Disk)?;
|
||||
|
||||
// Add virtio-blk
|
||||
let image_type =
|
||||
qcow::detect_image_type(&raw_img).map_err(DeviceManagerError::DetectImageType)?;
|
||||
let block = match image_type {
|
||||
ImageType::Raw => {
|
||||
let raw_img = vm_virtio::RawFile::new(raw_img);
|
||||
let dev = vm_virtio::Block::new(raw_img, disk_cfg.path.to_path_buf(), false)
|
||||
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
||||
Box::new(dev) as Box<vm_virtio::VirtioDevice>
|
||||
}
|
||||
ImageType::Qcow2 => {
|
||||
let qcow_img =
|
||||
QcowFile::from(raw_img).map_err(DeviceManagerError::QcowDeviceCreate)?;
|
||||
let dev = vm_virtio::Block::new(qcow_img, disk_cfg.path.to_path_buf(), false)
|
||||
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
||||
Box::new(dev) as Box<vm_virtio::VirtioDevice>
|
||||
}
|
||||
};
|
||||
let image_type = qcow::detect_image_type(&raw_img)
|
||||
.map_err(DeviceManagerError::DetectImageType)?;
|
||||
let block = match image_type {
|
||||
ImageType::Raw => {
|
||||
let raw_img = vm_virtio::RawFile::new(raw_img);
|
||||
let dev =
|
||||
vm_virtio::Block::new(raw_img, disk_cfg.path.to_path_buf(), false)
|
||||
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
||||
Box::new(dev) as Box<vm_virtio::VirtioDevice>
|
||||
}
|
||||
ImageType::Qcow2 => {
|
||||
let qcow_img = QcowFile::from(raw_img)
|
||||
.map_err(DeviceManagerError::QcowDeviceCreate)?;
|
||||
let dev =
|
||||
vm_virtio::Block::new(qcow_img, disk_cfg.path.to_path_buf(), false)
|
||||
.map_err(DeviceManagerError::CreateVirtioBlock)?;
|
||||
Box::new(dev) as Box<vm_virtio::VirtioDevice>
|
||||
}
|
||||
};
|
||||
|
||||
DeviceManager::add_virtio_pci_device(
|
||||
block,
|
||||
memory.clone(),
|
||||
allocator,
|
||||
vm_fd,
|
||||
&mut pci,
|
||||
&mut mmio_bus,
|
||||
&interrupt_info,
|
||||
)?;
|
||||
DeviceManager::add_virtio_pci_device(
|
||||
block,
|
||||
memory.clone(),
|
||||
allocator,
|
||||
vm_fd,
|
||||
&mut pci,
|
||||
&mut mmio_bus,
|
||||
&interrupt_info,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Add virtio-net if required
|
||||
|
Loading…
Reference in New Issue
Block a user