From cc6b671101644636ee2299a2682a1b12260ea5f0 Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Wed, 17 Apr 2024 15:53:43 -0700 Subject: [PATCH] runtime-rs: Update storage source for pci block devices In case of block devices using virtio-block, we need to pass the pci-path as the storage source field to the agent. Current the virt-path is being passed which works just for mmio block devices. In the future when support is added for scsi, block-ccw and pmem devices, the storage source would need to be handled accordingly. Fixes: #9034 Signed-off-by: Archana Shinde Signed-off-by: James O. D. Hunt --- .../kata-types/src/config/hypervisor/mod.rs | 12 ++++++-- .../resource/src/rootfs/block_rootfs.rs | 29 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/libs/kata-types/src/config/hypervisor/mod.rs b/src/libs/kata-types/src/config/hypervisor/mod.rs index c23fe02b69..08a95bf8df 100644 --- a/src/libs/kata-types/src/config/hypervisor/mod.rs +++ b/src/libs/kata-types/src/config/hypervisor/mod.rs @@ -50,9 +50,15 @@ pub const VIRTIO_BLK_PCI: &str = "virtio-blk-pci"; /// Virtual MMIO block device driver. pub const VIRTIO_BLK_MMIO: &str = "virtio-blk-mmio"; -const VIRTIO_BLK_CCW: &str = "virtio-blk-ccw"; -const VIRTIO_SCSI: &str = "virtio-scsi"; -const VIRTIO_PMEM: &str = "virtio-pmem"; +/// Virtual CCW block device driver. +pub const VIRTIO_BLK_CCW: &str = "virtio-blk-ccw"; + +/// Virtual SCSI block device driver. +pub const VIRTIO_SCSI: &str = "virtio-scsi"; + +/// Virtual PMEM device driver. +pub const VIRTIO_PMEM: &str = "virtio-pmem"; + const VIRTIO_9P: &str = "virtio-9p"; const VIRTIO_FS: &str = "virtio-fs"; const VIRTIO_FS_INLINE: &str = "inline-virtio-fs"; diff --git a/src/runtime-rs/crates/resource/src/rootfs/block_rootfs.rs b/src/runtime-rs/crates/resource/src/rootfs/block_rootfs.rs index 33b0ff2168..e32dddc096 100644 --- a/src/runtime-rs/crates/resource/src/rootfs/block_rootfs.rs +++ b/src/runtime-rs/crates/resource/src/rootfs/block_rootfs.rs @@ -16,6 +16,9 @@ use hypervisor::{ }, BlockConfig, }; +use kata_types::config::hypervisor::{ + VIRTIO_BLK_CCW, VIRTIO_BLK_MMIO, VIRTIO_BLK_PCI, VIRTIO_PMEM, VIRTIO_SCSI, +}; use kata_types::mount::Mount; use nix::sys::stat::{self, SFlag}; use std::fs; @@ -48,7 +51,7 @@ impl BlockRootfs { let block_device_config = &mut BlockConfig { major: stat::major(dev_id) as i64, minor: stat::minor(dev_id) as i64, - driver_option: block_driver, + driver_option: block_driver.clone(), ..Default::default() }; @@ -67,8 +70,30 @@ impl BlockRootfs { let mut device_id: String = "".to_owned(); if let DeviceType::Block(device) = device_info { storage.driver = device.config.driver_option; - storage.source = device.config.virt_path; device_id = device.device_id; + + match block_driver.as_str() { + VIRTIO_BLK_PCI => { + storage.source = device + .config + .pci_path + .ok_or("PCI path missing for pci block device") + .map_err(|e| anyhow!(e))? + .to_string(); + } + VIRTIO_BLK_MMIO => { + storage.source = device.config.virt_path; + } + VIRTIO_SCSI | VIRTIO_BLK_CCW | VIRTIO_PMEM => { + return Err(anyhow!( + "Complete support for block driver {} has not been implemented yet", + block_driver + )); + } + _ => { + return Err(anyhow!("Unknown block driver : {}", block_driver)); + } + } } Ok(Self {