mirror of
https://github.com/kata-containers/kata-containers.git
synced 2026-07-28 18:42:34 +00:00
runtime-rs: Consolidate virtio-blk shared types into BlockModern module
Move the block device type definitions shared between BlockDevice and
BlockDeviceModern — VIRTIO_BLOCK_{PCI,MMIO,CCW}/VIRTIO_PMEM constants,
KATA_*_DEV_TYPE aliases, and the BlockDeviceAio / BlockDeviceFormat
enums — from virtio_blk.rs into virtio_blk_modern.rs, so they live
alongside the BlockModern handler that will replace the legacy
BlockDevice.
Add a `format: BlockDeviceFormat` field to BlockConfigModern to match
the legacy BlockConfig. Update mod.rs re-exports accordingly.
No behavior change; pure relocation plus the new field.
Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
committed by
Fabiano Fidêncio
parent
525b68e332
commit
28e2318a35
@@ -28,12 +28,8 @@ pub use vfio_device::{
|
||||
};
|
||||
pub use vhost_user::{VhostUserConfig, VhostUserDevice, VhostUserType};
|
||||
pub use vhost_user_net::VhostUserNetDevice;
|
||||
pub use virtio_blk::{
|
||||
BlockConfig, BlockDevice, BlockDeviceAio, BlockDeviceFormat, KATA_BLK_DEV_TYPE,
|
||||
KATA_CCW_DEV_TYPE, KATA_MMIO_BLK_DEV_TYPE, KATA_NVDIMM_DEV_TYPE, KATA_SCSI_DEV_TYPE,
|
||||
VIRTIO_BLOCK_CCW, VIRTIO_BLOCK_MMIO, VIRTIO_BLOCK_PCI, VIRTIO_PMEM,
|
||||
};
|
||||
pub use virtio_blk_modern::{BlockConfigModern, BlockDeviceModern, BlockDeviceModernHandle};
|
||||
pub use virtio_blk::{BlockConfig, BlockDevice,};
|
||||
pub use virtio_blk_modern::{BlockConfigModern, BlockDeviceFormat, BlockDeviceAio, BlockDeviceModern, BlockDeviceModernHandle, VIRTIO_BLOCK_CCW, VIRTIO_BLOCK_MMIO, VIRTIO_BLOCK_PCI, VIRTIO_PMEM,};
|
||||
pub use virtio_fs::{
|
||||
ShareFsConfig, ShareFsDevice, ShareFsMountConfig, ShareFsMountOperation, ShareFsMountType,
|
||||
};
|
||||
@@ -41,3 +37,8 @@ pub use virtio_net::{Address, NetworkConfig, NetworkDevice};
|
||||
pub use virtio_vsock::{
|
||||
HybridVsockConfig, HybridVsockDevice, VsockConfig, VsockDevice, DEFAULT_GUEST_VSOCK_CID,
|
||||
};
|
||||
pub use kata_types::device::{
|
||||
DRIVER_BLK_CCW_TYPE as KATA_CCW_DEV_TYPE, DRIVER_BLK_MMIO_TYPE as KATA_MMIO_BLK_DEV_TYPE,
|
||||
DRIVER_BLK_PCI_TYPE as KATA_BLK_DEV_TYPE, DRIVER_NVDIMM_TYPE as KATA_NVDIMM_DEV_TYPE,
|
||||
DRIVER_SCSI_TYPE as KATA_SCSI_DEV_TYPE,
|
||||
};
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use crate::BlockDeviceAio;
|
||||
use crate::BlockDeviceFormat;
|
||||
use crate::device::pci_path::PciPath;
|
||||
use crate::device::topology::PCIeTopology;
|
||||
use crate::device::util::do_decrease_count;
|
||||
@@ -13,68 +15,6 @@ use crate::device::DeviceType;
|
||||
use crate::Hypervisor as hypervisor;
|
||||
use anyhow::{Context, Result};
|
||||
use async_trait::async_trait;
|
||||
pub use kata_types::device::{
|
||||
DRIVER_BLK_CCW_TYPE as KATA_CCW_DEV_TYPE, DRIVER_BLK_MMIO_TYPE as KATA_MMIO_BLK_DEV_TYPE,
|
||||
DRIVER_BLK_PCI_TYPE as KATA_BLK_DEV_TYPE, DRIVER_NVDIMM_TYPE as KATA_NVDIMM_DEV_TYPE,
|
||||
DRIVER_SCSI_TYPE as KATA_SCSI_DEV_TYPE,
|
||||
};
|
||||
|
||||
/// VIRTIO_BLOCK_PCI indicates block driver is virtio-pci based
|
||||
pub const VIRTIO_BLOCK_PCI: &str = "virtio-blk-pci";
|
||||
pub const VIRTIO_BLOCK_MMIO: &str = "virtio-blk-mmio";
|
||||
pub const VIRTIO_BLOCK_CCW: &str = "virtio-blk-ccw";
|
||||
pub const VIRTIO_PMEM: &str = "virtio-pmem";
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub enum BlockDeviceAio {
|
||||
// IoUring is the Linux io_uring I/O implementation.
|
||||
#[default]
|
||||
IoUring,
|
||||
|
||||
// Native is the native Linux AIO implementation.
|
||||
Native,
|
||||
|
||||
// Threads is the pthread asynchronous I/O implementation.
|
||||
Threads,
|
||||
}
|
||||
|
||||
impl BlockDeviceAio {
|
||||
pub fn new(aio: &str) -> Self {
|
||||
match aio {
|
||||
"native" => BlockDeviceAio::Native,
|
||||
"threads" => BlockDeviceAio::Threads,
|
||||
_ => BlockDeviceAio::IoUring,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlockDeviceAio {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let to_string = match *self {
|
||||
BlockDeviceAio::Native => "native".to_string(),
|
||||
BlockDeviceAio::Threads => "threads".to_string(),
|
||||
_ => "iouring".to_string(),
|
||||
};
|
||||
write!(f, "{to_string}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub enum BlockDeviceFormat {
|
||||
#[default]
|
||||
Raw,
|
||||
Vmdk,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlockDeviceFormat {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let to_string = match *self {
|
||||
BlockDeviceFormat::Raw => "raw".to_string(),
|
||||
BlockDeviceFormat::Vmdk => "vmdk".to_string(),
|
||||
};
|
||||
write!(f, "{to_string}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct BlockConfig {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::device::driver::BlockDeviceAio;
|
||||
use crate::device::pci_path::PciPath;
|
||||
use crate::device::topology::PCIeTopology;
|
||||
use crate::device::util::do_decrease_count;
|
||||
@@ -17,6 +16,63 @@ use crate::Hypervisor as hypervisor;
|
||||
use anyhow::{Context, Result};
|
||||
use async_trait::async_trait;
|
||||
|
||||
/// VIRTIO_BLOCK_PCI indicates block driver is virtio-pci based
|
||||
pub const VIRTIO_BLOCK_PCI: &str = "virtio-blk-pci";
|
||||
pub const VIRTIO_BLOCK_MMIO: &str = "virtio-blk-mmio";
|
||||
pub const VIRTIO_BLOCK_CCW: &str = "virtio-blk-ccw";
|
||||
pub const VIRTIO_PMEM: &str = "virtio-pmem";
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub enum BlockDeviceAio {
|
||||
// IoUring is the Linux io_uring I/O implementation.
|
||||
#[default]
|
||||
IoUring,
|
||||
|
||||
// Native is the native Linux AIO implementation.
|
||||
Native,
|
||||
|
||||
// Threads is the pthread asynchronous I/O implementation.
|
||||
Threads,
|
||||
}
|
||||
|
||||
impl BlockDeviceAio {
|
||||
pub fn new(aio: &str) -> Self {
|
||||
match aio {
|
||||
"native" => BlockDeviceAio::Native,
|
||||
"threads" => BlockDeviceAio::Threads,
|
||||
_ => BlockDeviceAio::IoUring,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlockDeviceAio {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let to_string = match *self {
|
||||
BlockDeviceAio::Native => "native".to_string(),
|
||||
BlockDeviceAio::Threads => "threads".to_string(),
|
||||
_ => "iouring".to_string(),
|
||||
};
|
||||
write!(f, "{to_string}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub enum BlockDeviceFormat {
|
||||
#[default]
|
||||
Raw,
|
||||
Vmdk,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlockDeviceFormat {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let to_string = match *self {
|
||||
BlockDeviceFormat::Raw => "raw".to_string(),
|
||||
BlockDeviceFormat::Vmdk => "vmdk".to_string(),
|
||||
};
|
||||
write!(f, "{to_string}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct BlockConfigModern {
|
||||
/// Path of the drive.
|
||||
@@ -32,6 +88,9 @@ pub struct BlockConfigModern {
|
||||
/// Don't close `path_on_host` file when dropping the device.
|
||||
pub no_drop: bool,
|
||||
|
||||
/// raw, vmdk, etc. And default to raw if not set.
|
||||
pub format: BlockDeviceFormat,
|
||||
|
||||
/// Specifies cache-related options for block devices.
|
||||
/// Denotes whether use of O_DIRECT (bypass the host page cache) is enabled.
|
||||
/// If not set, use configurarion block_device_cache_direct.
|
||||
|
||||
Reference in New Issue
Block a user