mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Improve resiliency of image type handling
Add an image_type to DiskConfig to specify the image type. If none is specified autodetect the image type but disable potentially unsafe behaviour in the QCOW2 backend by disabling the backing file support. If the image type is autodetected then fix it in the config so that it will be persistant across reboots and migrations/snapshot & restores. This also handles the case where the image type was not specified as part of the disk configuration. Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
+19
-2
@@ -10,6 +10,7 @@ use std::path::PathBuf;
|
||||
use std::result;
|
||||
use std::str::FromStr;
|
||||
|
||||
use block::ImageType;
|
||||
use clap::ArgMatches;
|
||||
use log::{debug, warn};
|
||||
use option_parser::{
|
||||
@@ -1096,7 +1097,8 @@ impl DiskConfig {
|
||||
ops_size=<io_ops>,ops_one_time_burst=<io_ops>,ops_refill_time=<ms>,\
|
||||
id=<device_id>,pci_segment=<segment_id>,rate_limit_group=<group_id>,\
|
||||
queue_affinity=<list_of_queue_indices_with_their_associated_cpuset>,\
|
||||
serial=<serial_number>,backing_files=on|off,sparse=on|off";
|
||||
serial=<serial_number>,backing_files=on|off,sparse=on|off,\
|
||||
image_type=<raw,qcow2,vhd,vhdx>";
|
||||
|
||||
pub fn parse(disk: &str) -> Result<Self> {
|
||||
let mut parser = OptionParser::new();
|
||||
@@ -1123,7 +1125,9 @@ impl DiskConfig {
|
||||
.add("rate_limit_group")
|
||||
.add("queue_affinity")
|
||||
.add("backing_files")
|
||||
.add("sparse");
|
||||
.add("sparse")
|
||||
.add("image_type");
|
||||
|
||||
parser.parse(disk).map_err(Error::ParseDisk)?;
|
||||
|
||||
let path = parser.get("path").map(PathBuf::from);
|
||||
@@ -1208,12 +1212,22 @@ impl DiskConfig {
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
|
||||
let backing_files = parser
|
||||
.convert::<Toggle>("backing_files")
|
||||
.map_err(Error::ParseDisk)?
|
||||
.unwrap_or(Toggle(false))
|
||||
.0;
|
||||
|
||||
let image_type = if vhost_socket.is_none() {
|
||||
parser
|
||||
.convert::<ImageType>("image_type")
|
||||
.map_err(Error::ParseDisk)?
|
||||
.unwrap_or(ImageType::Unknown)
|
||||
} else {
|
||||
ImageType::Unknown
|
||||
};
|
||||
|
||||
let bw_tb_config = if bw_size != 0 && bw_refill_time != 0 {
|
||||
Some(TokenBucketConfig {
|
||||
size: bw_size,
|
||||
@@ -1265,6 +1279,7 @@ impl DiskConfig {
|
||||
queue_affinity,
|
||||
backing_files,
|
||||
sparse,
|
||||
image_type,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3516,6 +3531,7 @@ mod unit_tests {
|
||||
queue_affinity: None,
|
||||
backing_files: false,
|
||||
sparse: true,
|
||||
image_type: ImageType::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3538,6 +3554,7 @@ mod unit_tests {
|
||||
path: None,
|
||||
vhost_socket: Some(String::from("/tmp/sock")),
|
||||
vhost_user: true,
|
||||
image_type: ImageType::Unknown,
|
||||
..disk_fixture()
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user