mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-10 12:22:36 +00:00
runtime-rs: refactor increase_attach_count with do_increase_count
Try to reduce duplicated code in increase_attach_count with public new function do_increase_count. Fixes: #8738 Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
fff64f1c3e
commit
4f0fab938d
@ -20,6 +20,7 @@ use crate::{
|
|||||||
device::{
|
device::{
|
||||||
pci_path::PciPath,
|
pci_path::PciPath,
|
||||||
topology::{do_add_pcie_endpoint, PCIeTopology},
|
topology::{do_add_pcie_endpoint, PCIeTopology},
|
||||||
|
util::do_increase_count,
|
||||||
Device, DeviceType, PCIeDevice,
|
Device, DeviceType, PCIeDevice,
|
||||||
},
|
},
|
||||||
register_pcie_device, unregister_pcie_device, update_pcie_device, Hypervisor as hypervisor,
|
register_pcie_device, unregister_pcie_device, update_pcie_device, Hypervisor as hypervisor,
|
||||||
@ -522,18 +523,7 @@ impl Device for VfioDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn increase_attach_count(&mut self) -> Result<bool> {
|
async fn increase_attach_count(&mut self) -> Result<bool> {
|
||||||
match self.attach_count {
|
do_increase_count(&mut self.attach_count)
|
||||||
0 => {
|
|
||||||
// do real attach
|
|
||||||
self.attach_count += 1;
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
std::u64::MAX => Err(anyhow!("device was attached too many times")),
|
|
||||||
_ => {
|
|
||||||
self.attach_count += 1;
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn decrease_attach_count(&mut self) -> Result<bool> {
|
async fn decrease_attach_count(&mut self) -> Result<bool> {
|
||||||
|
@ -9,7 +9,7 @@ use async_trait::async_trait;
|
|||||||
|
|
||||||
use super::VhostUserConfig;
|
use super::VhostUserConfig;
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{topology::PCIeTopology, Device, DeviceType},
|
device::{topology::PCIeTopology, util::do_increase_count, Device, DeviceType},
|
||||||
Hypervisor as hypervisor,
|
Hypervisor as hypervisor,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -104,18 +104,7 @@ impl Device for VhostUserBlkDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn increase_attach_count(&mut self) -> Result<bool> {
|
async fn increase_attach_count(&mut self) -> Result<bool> {
|
||||||
match self.attach_count {
|
do_increase_count(&mut self.attach_count)
|
||||||
0 => {
|
|
||||||
// do real attach
|
|
||||||
self.attach_count += 1;
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
std::u64::MAX => Err(anyhow!("device was attached too many times")),
|
|
||||||
_ => {
|
|
||||||
self.attach_count += 1;
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn decrease_attach_count(&mut self) -> Result<bool> {
|
async fn decrease_attach_count(&mut self) -> Result<bool> {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
use crate::device::pci_path::PciPath;
|
use crate::device::pci_path::PciPath;
|
||||||
use crate::device::topology::PCIeTopology;
|
use crate::device::topology::PCIeTopology;
|
||||||
|
use crate::device::util::do_increase_count;
|
||||||
use crate::device::Device;
|
use crate::device::Device;
|
||||||
use crate::device::DeviceType;
|
use crate::device::DeviceType;
|
||||||
use crate::Hypervisor as hypervisor;
|
use crate::Hypervisor as hypervisor;
|
||||||
@ -135,18 +136,7 @@ impl Device for BlockDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn increase_attach_count(&mut self) -> Result<bool> {
|
async fn increase_attach_count(&mut self) -> Result<bool> {
|
||||||
match self.attach_count {
|
do_increase_count(&mut self.attach_count)
|
||||||
0 => {
|
|
||||||
// do real attach
|
|
||||||
self.attach_count += 1;
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
std::u64::MAX => Err(anyhow!("device was attached too many times")),
|
|
||||||
_ => {
|
|
||||||
self.attach_count += 1;
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn decrease_attach_count(&mut self) -> Result<bool> {
|
async fn decrease_attach_count(&mut self) -> Result<bool> {
|
||||||
|
Loading…
Reference in New Issue
Block a user