mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-22 04:18:53 +00:00
Merge pull request #11905 from Apokleos/coldplug-scsidev
runtime-rs: Support virtio-scsi for initdata within non-TEE
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)]
|
||||
struct DeviceVirtioBlk {
|
||||
bus_type: VirtioBusType,
|
||||
@@ -2361,15 +2409,27 @@ impl<'a> QemuCmdLine<'a> {
|
||||
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
|
||||
.push(Box::new(BlockBackend::new(device_id, path, is_direct)));
|
||||
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(
|
||||
device_id,
|
||||
bus_type(self.config),
|
||||
devno,
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@@ -132,13 +132,14 @@ impl QemuInner {
|
||||
&block_dev.config.path_on_host,
|
||||
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.config.path_on_host,
|
||||
block_dev
|
||||
.config
|
||||
.is_direct
|
||||
.unwrap_or(self.config.blockdev_info.block_device_cache_direct),
|
||||
block_dev.config.driver_option.as_str() == "scsi",
|
||||
)?,
|
||||
unsupported => {
|
||||
info!(sl!(), "unsupported block device driver: {}", unsupported)
|
||||
|
@@ -434,10 +434,11 @@ impl ResourceManagerInner {
|
||||
// create block device for kata agent,
|
||||
// if driver is virtio-blk-pci, the id will be pci address.
|
||||
if let DeviceType::Block(device) = device_info {
|
||||
// The following would work for drivers virtio-blk-pci and mmio.
|
||||
// Once scsi support is added, need to handle scsi identifiers.
|
||||
// The following would work for drivers virtio-blk-pci and virtio-mmio and virtio-scsi.
|
||||
let id = if let Some(pci_path) = device.config.pci_path {
|
||||
pci_path.to_string()
|
||||
} else if let Some(scsi_address) = device.config.scsi_addr {
|
||||
scsi_address
|
||||
} else {
|
||||
device.config.virt_path.clone()
|
||||
};
|
||||
|
Reference in New Issue
Block a user