mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
dragonball: use const string for legacy device type
As string "com1", "com2" and "rtc" are used in two files (device_manager/mod.rs and device_manager/legacy.rs), we use public const variables COM1, COM2 and RTC to replace them respectively. Fixes: #4544 Signed-off-by: xuejun-xj <jiyunxue@alibaba.linux.com> Signed-off-by: jingshan <jingshan@linux.alibaba.com>
This commit is contained in:
parent
f6f96b8fee
commit
458f6f42f6
@ -156,18 +156,26 @@ pub(crate) mod aarch64 {
|
|||||||
|
|
||||||
type Result<T> = ::std::result::Result<T, Error>;
|
type Result<T> = ::std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
/// LegacyDeviceType: com1
|
||||||
|
pub const COM1: &str = "com1";
|
||||||
|
/// LegacyDeviceType: com2
|
||||||
|
pub const COM2: &str = "com2";
|
||||||
|
/// LegacyDeviceType: rtc
|
||||||
|
pub const RTC: &str = "rtc";
|
||||||
|
|
||||||
impl LegacyDeviceManager {
|
impl LegacyDeviceManager {
|
||||||
|
/// Create a LegacyDeviceManager instance handling legacy devices.
|
||||||
pub fn create_manager(
|
pub fn create_manager(
|
||||||
bus: &mut IoManager,
|
bus: &mut IoManager,
|
||||||
vm_fd: Option<Arc<VmFd>>,
|
vm_fd: Option<Arc<VmFd>>,
|
||||||
resources: &HashMap<String, DeviceResources>,
|
resources: &HashMap<String, DeviceResources>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let (com1_device, com1_eventfd) =
|
let (com1_device, com1_eventfd) =
|
||||||
Self::create_com_device(bus, vm_fd.as_ref(), resources.get("com1").unwrap())?;
|
Self::create_com_device(bus, vm_fd.as_ref(), resources.get(COM1).unwrap())?;
|
||||||
let (com2_device, com2_eventfd) =
|
let (com2_device, com2_eventfd) =
|
||||||
Self::create_com_device(bus, vm_fd.as_ref(), resources.get("com2").unwrap())?;
|
Self::create_com_device(bus, vm_fd.as_ref(), resources.get(COM2).unwrap())?;
|
||||||
let (rtc_device, rtc_eventfd) =
|
let (rtc_device, rtc_eventfd) =
|
||||||
Self::create_rtc_device(bus, vm_fd.as_ref(), resources.get("rtc").unwrap())?;
|
Self::create_rtc_device(bus, vm_fd.as_ref(), resources.get(RTC).unwrap())?;
|
||||||
|
|
||||||
Ok(LegacyDeviceManager {
|
Ok(LegacyDeviceManager {
|
||||||
_rtc_device: rtc_device,
|
_rtc_device: rtc_device,
|
||||||
|
@ -54,7 +54,7 @@ pub mod console_manager;
|
|||||||
pub use self::console_manager::ConsoleManager;
|
pub use self::console_manager::ConsoleManager;
|
||||||
|
|
||||||
mod legacy;
|
mod legacy;
|
||||||
pub use self::legacy::{Error as LegacyDeviceError, LegacyDeviceManager};
|
pub use self::legacy::{Error as LegacyDeviceError, LegacyDeviceManager, aarch64::{COM1, COM2, RTC}};
|
||||||
|
|
||||||
#[cfg(feature = "virtio-vsock")]
|
#[cfg(feature = "virtio-vsock")]
|
||||||
/// Device manager for user-space vsock devices.
|
/// Device manager for user-space vsock devices.
|
||||||
@ -744,9 +744,9 @@ impl DeviceManager {
|
|||||||
) -> std::result::Result<HashMap<String, DeviceResources>, StartMicroVmError> {
|
) -> std::result::Result<HashMap<String, DeviceResources>, StartMicroVmError> {
|
||||||
let mut resources = HashMap::new();
|
let mut resources = HashMap::new();
|
||||||
let legacy_devices = vec![
|
let legacy_devices = vec![
|
||||||
(DeviceType::Serial, String::from("com1")),
|
(DeviceType::Serial, String::from(COM1)),
|
||||||
(DeviceType::Serial, String::from("com2")),
|
(DeviceType::Serial, String::from(COM2)),
|
||||||
(DeviceType::RTC, String::from("rtc")),
|
(DeviceType::RTC, String::from(RTC)),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (device_type, device_id) in legacy_devices {
|
for (device_type, device_id) in legacy_devices {
|
||||||
|
Loading…
Reference in New Issue
Block a user