mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-23 21:28:10 +00:00
runtime-rs: Support virtio-scsi for initdata within non-TEE
This commit introduces support for selecting `virtio-scsi` as the block device driver for QEMU during initial setup. The primary goal is to resolve a conflict in non-TEE environments: 1. The global block device configuration defaults to `virtio-scsi`. 2. The `initdata` device driver was previously designed and hardcoded to `virtio-blk-pci`. 3. This conflict prevented unified block device usage. By allowing `virtio-scsi` to be configured at cold boot, the `initdata` device can now correctly adhere to the global setting, eliminating the need for a hardcoded driver and ensuring consistent block device configuration across all supported devices (excluding rootfs). Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
@@ -979,6 +979,54 @@ impl ToQemuParams for BlockBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct DeviceScsiHd {
|
||||||
|
device: String,
|
||||||
|
|
||||||
|
bus: String,
|
||||||
|
|
||||||
|
drive: String,
|
||||||
|
|
||||||
|
devno: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeviceScsiHd {
|
||||||
|
fn new(id: &str, bus: &str, devno: Option<String>) -> DeviceScsiHd {
|
||||||
|
DeviceScsiHd {
|
||||||
|
device: "scsi-hd".to_owned(),
|
||||||
|
bus: bus.to_owned(),
|
||||||
|
drive: id.to_owned(),
|
||||||
|
devno,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn set_scsi_bus(&mut self, bus: &str) -> &mut Self {
|
||||||
|
self.bus = bus.to_owned();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn set_scsi_drive(&mut self, drive: &str) -> &mut Self {
|
||||||
|
self.drive = drive.to_owned();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ToQemuParams for DeviceScsiHd {
|
||||||
|
async fn qemu_params(&self) -> Result<Vec<String>> {
|
||||||
|
let mut params = Vec::new();
|
||||||
|
params.push(self.device.clone());
|
||||||
|
params.push(format!("drive=image-{}", self.drive));
|
||||||
|
params.push(format!("bus={}", self.bus));
|
||||||
|
if let Some(devno) = &self.devno {
|
||||||
|
params.push(format!("devno={}", devno));
|
||||||
|
}
|
||||||
|
Ok(vec!["-device".to_owned(), params.join(",")])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct DeviceVirtioBlk {
|
struct DeviceVirtioBlk {
|
||||||
bus_type: VirtioBusType,
|
bus_type: VirtioBusType,
|
||||||
@@ -2361,15 +2409,27 @@ impl<'a> QemuCmdLine<'a> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_block_device(&mut self, device_id: &str, path: &str, is_direct: bool) -> Result<()> {
|
pub fn add_block_device(
|
||||||
|
&mut self,
|
||||||
|
device_id: &str,
|
||||||
|
path: &str,
|
||||||
|
is_direct: bool,
|
||||||
|
is_scsi: bool,
|
||||||
|
) -> Result<()> {
|
||||||
self.devices
|
self.devices
|
||||||
.push(Box::new(BlockBackend::new(device_id, path, is_direct)));
|
.push(Box::new(BlockBackend::new(device_id, path, is_direct)));
|
||||||
let devno = get_devno_ccw(&mut self.ccw_subchannel, device_id);
|
let devno = get_devno_ccw(&mut self.ccw_subchannel, device_id);
|
||||||
|
if is_scsi {
|
||||||
|
self.devices
|
||||||
|
.push(Box::new(DeviceScsiHd::new(device_id, "scsi0.0", devno)));
|
||||||
|
} else {
|
||||||
self.devices.push(Box::new(DeviceVirtioBlk::new(
|
self.devices.push(Box::new(DeviceVirtioBlk::new(
|
||||||
device_id,
|
device_id,
|
||||||
bus_type(self.config),
|
bus_type(self.config),
|
||||||
devno,
|
devno,
|
||||||
)));
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,13 +132,14 @@ impl QemuInner {
|
|||||||
&block_dev.config.path_on_host,
|
&block_dev.config.path_on_host,
|
||||||
block_dev.config.is_readonly,
|
block_dev.config.is_readonly,
|
||||||
)?,
|
)?,
|
||||||
"ccw" | "blk" => cmdline.add_block_device(
|
"ccw" | "blk" | "scsi" => cmdline.add_block_device(
|
||||||
block_dev.device_id.as_str(),
|
block_dev.device_id.as_str(),
|
||||||
&block_dev.config.path_on_host,
|
&block_dev.config.path_on_host,
|
||||||
block_dev
|
block_dev
|
||||||
.config
|
.config
|
||||||
.is_direct
|
.is_direct
|
||||||
.unwrap_or(self.config.blockdev_info.block_device_cache_direct),
|
.unwrap_or(self.config.blockdev_info.block_device_cache_direct),
|
||||||
|
block_dev.config.driver_option.as_str() == "scsi",
|
||||||
)?,
|
)?,
|
||||||
unsupported => {
|
unsupported => {
|
||||||
info!(sl!(), "unsupported block device driver: {}", unsupported)
|
info!(sl!(), "unsupported block device driver: {}", unsupported)
|
||||||
|
|||||||
Reference in New Issue
Block a user