vfio_user: Improve flags for DMA_MAP command

Replace the use of an enum with a bitfield representation which means
that is now possible to logical OR flags together.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2023-02-07 17:22:58 +00:00 committed by Bo Chen
parent 01900e3c2b
commit 91e2601523
3 changed files with 10 additions and 15 deletions

1
Cargo.lock generated
View File

@ -1384,6 +1384,7 @@ dependencies = [
name = "vfio_user" name = "vfio_user"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bitflags",
"libc", "libc",
"log", "log",
"serde", "serde",

View File

@ -5,6 +5,7 @@ authors = ["The Cloud Hypervisor Authors"]
edition = "2021" edition = "2021"
[dependencies] [dependencies]
bitflags = "1.3.2"
libc = "0.2.139" libc = "0.2.139"
log = "0.4.17" log = "0.4.17"
serde = { version = "1.0.151", features = ["rc"] } serde = { version = "1.0.151", features = ["rc"] }

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
use bitflags::bitflags;
use std::ffi::CString; use std::ffi::CString;
use std::fs::File; use std::fs::File;
use std::io::{IoSlice, Read, Write}; use std::io::{IoSlice, Read, Write};
@ -90,19 +91,11 @@ const fn default_migration_capabilities() -> MigrationCapabilities {
MigrationCapabilities { pgsize: 4096 } MigrationCapabilities { pgsize: 4096 }
} }
#[repr(u32)] bitflags! {
#[derive(Clone, Copy, Debug)] struct DmaMapFlags: u32 {
#[allow(dead_code)] const READ_ONLY = 1 << 0;
enum DmaMapFlags { const WRITE_ONLY = 1 << 1;
Unknown = 0, const READ_WRITE = Self::READ_ONLY.bits | Self::WRITE_ONLY.bits;
ReadOnly = 1,
WriteOnly = 2,
ReadWrite = 3,
}
impl Default for DmaMapFlags {
fn default() -> Self {
Self::Unknown
} }
} }
@ -111,7 +104,7 @@ impl Default for DmaMapFlags {
struct DmaMap { struct DmaMap {
header: Header, header: Header,
argsz: u32, argsz: u32,
flags: DmaMapFlags, flags: u32,
offset: u64, offset: u64,
address: u64, address: u64,
size: u64, size: u64,
@ -367,7 +360,7 @@ impl Client {
..Default::default() ..Default::default()
}, },
argsz: (size_of::<DmaMap>() - size_of::<Header>()) as u32, argsz: (size_of::<DmaMap>() - size_of::<Header>()) as u32,
flags: DmaMapFlags::ReadWrite, flags: DmaMapFlags::READ_WRITE.bits,
offset, offset,
address, address,
size, size,