mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add option to control backing files
Backing files (e.g. for QCOW2) interact badly with landlock since they
are not obvious from the initial VM configuration. Only enable their use
with an explicit option.
Signed-off-by: Rob Bradford <rbradford@meta.com>
Signed-off-by: Bo Chen <bchen@crusoe.ai>
(cherry picked from commit 509832298b)
This commit is contained in:
@@ -1093,7 +1093,7 @@ 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>";
|
||||
serial=<serial_number>,backing_files=on|off";
|
||||
|
||||
pub fn parse(disk: &str) -> Result<Self> {
|
||||
let mut parser = OptionParser::new();
|
||||
@@ -1118,7 +1118,8 @@ impl DiskConfig {
|
||||
.add("pci_segment")
|
||||
.add("serial")
|
||||
.add("rate_limit_group")
|
||||
.add("queue_affinity");
|
||||
.add("queue_affinity")
|
||||
.add("backing_files");
|
||||
parser.parse(disk).map_err(Error::ParseDisk)?;
|
||||
|
||||
let path = parser.get("path").map(PathBuf::from);
|
||||
@@ -1203,6 +1204,12 @@ impl DiskConfig {
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
let backing_files = parser
|
||||
.convert::<Toggle>("backing_files")
|
||||
.map_err(Error::ParseDisk)?
|
||||
.unwrap_or(Toggle(false))
|
||||
.0;
|
||||
|
||||
let bw_tb_config = if bw_size != 0 && bw_refill_time != 0 {
|
||||
Some(TokenBucketConfig {
|
||||
size: bw_size,
|
||||
@@ -1247,6 +1254,7 @@ impl DiskConfig {
|
||||
pci_segment,
|
||||
serial,
|
||||
queue_affinity,
|
||||
backing_files,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3414,6 +3422,7 @@ mod unit_tests {
|
||||
pci_segment: 0,
|
||||
serial: None,
|
||||
queue_affinity: None,
|
||||
backing_files: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2657,6 +2657,10 @@ impl DeviceManager {
|
||||
let image_type =
|
||||
detect_image_type(&mut file).map_err(DeviceManagerError::DetectImageType)?;
|
||||
|
||||
if image_type != ImageType::Qcow2 && disk_cfg.backing_files {
|
||||
warn!("Enabling backing_files option only applies for QCOW2 files");
|
||||
}
|
||||
|
||||
let image = match image_type {
|
||||
ImageType::FixedVhd => {
|
||||
// Use asynchronous backend relying on io_uring if the
|
||||
@@ -2710,7 +2714,7 @@ impl DeviceManager {
|
||||
ImageType::Qcow2 => {
|
||||
info!("Using synchronous QCOW2 disk file");
|
||||
Box::new(
|
||||
QcowDiskSync::new(file, disk_cfg.direct)
|
||||
QcowDiskSync::new(file, disk_cfg.direct, disk_cfg.backing_files)
|
||||
.map_err(DeviceManagerError::CreateQcowDiskSync)?,
|
||||
) as Box<dyn DiskFile>
|
||||
}
|
||||
|
||||
@@ -284,6 +284,8 @@ pub struct DiskConfig {
|
||||
pub serial: Option<String>,
|
||||
#[serde(default)]
|
||||
pub queue_affinity: Option<Vec<VirtQueueAffinity>>,
|
||||
#[serde(default)]
|
||||
pub backing_files: bool,
|
||||
}
|
||||
|
||||
impl ApplyLandlock for DiskConfig {
|
||||
|
||||
Reference in New Issue
Block a user