runtime-rs: Introduce Capability of HybridVsockSupport.

Introduce HybridVsock Cap to judge which kind of vm socket will
be supported by the Hypervisor.
Use `is_hybrid_vsock_supported` to tell if an hypervisor supports
hybrid-vsock, if not, it supports legacy vsock.

Fixes: #8474

Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
alex.lyn 2023-12-04 14:18:46 +08:00
parent 6af0592274
commit c5178dd258

View File

@ -17,6 +17,8 @@ pub enum CapabilityBits {
MultiQueueSupport, MultiQueueSupport,
/// hypervisor supports filesystem share /// hypervisor supports filesystem share
FsSharingSupport, FsSharingSupport,
/// hypervisor supports hybrid-vsock
HybridVsockSupport,
} }
/// Capabilities describe a virtcontainers hypervisor capabilities through a bit mask. /// Capabilities describe a virtcontainers hypervisor capabilities through a bit mask.
@ -60,6 +62,11 @@ impl Capabilities {
self.flags.and(CapabilityBits::MultiQueueSupport) != 0 self.flags.and(CapabilityBits::MultiQueueSupport) != 0
} }
/// is_hybrid_vsock_supported tells if an hypervisor supports hybrid-vsock support.
pub fn is_hybrid_vsock_supported(&self) -> bool {
self.flags.and(CapabilityBits::HybridVsockSupport) != 0
}
/// is_fs_sharing_supported tells if an hypervisor supports host filesystem sharing. /// is_fs_sharing_supported tells if an hypervisor supports host filesystem sharing.
pub fn is_fs_sharing_supported(&self) -> bool { pub fn is_fs_sharing_supported(&self) -> bool {
self.flags.and(CapabilityBits::FsSharingSupport) != 0 self.flags.and(CapabilityBits::FsSharingSupport) != 0
@ -77,6 +84,9 @@ mod tests {
let mut cap = Capabilities::new(); let mut cap = Capabilities::new();
assert!(!cap.is_block_device_supported()); assert!(!cap.is_block_device_supported());
// test legacy vsock support
assert!(!cap.is_hybrid_vsock_supported());
// test set block device support // test set block device support
cap.set(CapabilityBits::BlockDeviceSupport); cap.set(CapabilityBits::BlockDeviceSupport);
assert!(cap.is_block_device_supported()); assert!(cap.is_block_device_supported());
@ -102,6 +112,10 @@ mod tests {
| CapabilityBits::MultiQueueSupport | CapabilityBits::MultiQueueSupport
| CapabilityBits::FsSharingSupport, | CapabilityBits::FsSharingSupport,
); );
assert!(cap.is_fs_sharing_supported()) assert!(cap.is_fs_sharing_supported());
// test set hybrid-vsock support
cap.set(CapabilityBits::HybridVsockSupport);
assert!(cap.is_hybrid_vsock_supported());
} }
} }