mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 11:25: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 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());
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -528,7 +528,9 @@ 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
|
||||||
|
if let Some(disk_list_cfg) = &vm_cfg.disks {
|
||||||
|
for disk_cfg in disk_list_cfg.iter() {
|
||||||
// Open block device path
|
// Open block device path
|
||||||
let raw_img: File = OpenOptions::new()
|
let raw_img: File = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
@ -536,20 +538,21 @@ impl DeviceManager {
|
|||||||
.open(disk_cfg.path)
|
.open(disk_cfg.path)
|
||||||
.map_err(DeviceManagerError::Disk)?;
|
.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 = vm_virtio::Block::new(raw_img, disk_cfg.path.to_path_buf(), false)
|
let dev =
|
||||||
|
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 =
|
||||||
|
vm_virtio::Block::new(qcow_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>
|
||||||
}
|
}
|
||||||
@ -565,6 +568,7 @@ impl DeviceManager {
|
|||||||
&interrupt_info,
|
&interrupt_info,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add virtio-net if required
|
// Add virtio-net if required
|
||||||
if let Some(net_list_cfg) = &vm_cfg.net {
|
if let Some(net_list_cfg) = &vm_cfg.net {
|
||||||
|
Loading…
Reference in New Issue
Block a user