virtio_sys: add virtio_fs bindings

Replace the hand-written bindings in the virtio-fs device with
automatically generated bindings from bindgen.

BUG=None
TEST=./virtio_sys/bindgen.sh

Change-Id: Ia11a2d97f3546515196a41764107e7aaece8ad82
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4103907
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2022-12-13 13:45:02 -08:00 committed by crosvm LUCI
parent dde912b8d1
commit bb54c5e169
6 changed files with 56 additions and 19 deletions

View file

@ -22,6 +22,8 @@ use remain::sorted;
use resources::Alloc;
use sync::Mutex;
use thiserror::Error;
use virtio_sys::virtio_fs::virtio_fs_config;
use virtio_sys::virtio_fs::VIRTIO_FS_SHMCAP_ID_CACHE;
use vm_control::FsMappingRequest;
use vm_control::VmResponse;
use vm_memory::GuestMemory;
@ -59,25 +61,9 @@ const FS_BAR_NUM: u8 = 4;
const FS_BAR_OFFSET: u64 = 0;
const FS_BAR_SIZE: u64 = 1 << 33;
/// Defined in kernel/include/uapi/linux/virtio_fs.h.
const VIRTIO_FS_SHMCAP_ID_CACHE: u8 = 0;
/// The maximum allowable length of the tag used to identify a specific virtio-fs device.
pub const FS_MAX_TAG_LEN: usize = 36;
/// kernel/include/uapi/linux/virtio_fs.h
#[repr(C, packed)]
#[derive(Clone, Copy)]
pub struct virtio_fs_config {
/// Filesystem name (UTF-8, not NUL-terminated, padded with NULs)
pub tag: [u8; FS_MAX_TAG_LEN],
/// Number of request queues
pub num_request_queues: Le32,
}
// Safe because all members are plain old data and any value is valid.
unsafe impl DataInit for virtio_fs_config {}
/// Errors that may occur during the creation or operation of an Fs device.
#[sorted]
#[derive(Error, Debug)]
@ -353,7 +339,7 @@ impl VirtioDevice for Fs {
FS_BAR_NUM,
FS_BAR_OFFSET,
FS_BAR_SIZE,
VIRTIO_FS_SHMCAP_ID_CACHE,
VIRTIO_FS_SHMCAP_ID_CACHE as u8,
))]
}
}

View file

@ -27,6 +27,7 @@ use futures::future::Abortable;
use hypervisor::ProtectionType;
use sync::Mutex;
pub use sys::start_device as run_fs_device;
use virtio_sys::virtio_fs::virtio_fs_config;
use vm_memory::GuestMemory;
use vmm_vhost::message::VhostUserProtocolFeatures;
use vmm_vhost::message::VhostUserVirtioFeatures;
@ -35,7 +36,6 @@ use crate::virtio;
use crate::virtio::copy_config;
use crate::virtio::fs::passthrough::PassthroughFs;
use crate::virtio::fs::process_fs_queue;
use crate::virtio::fs::virtio_fs_config;
use crate::virtio::fs::FS_MAX_TAG_LEN;
use crate::virtio::vhost::user::device::handler::sys::Doorbell;
use crate::virtio::vhost::user::device::handler::VhostUserBackend;

View file

@ -4,9 +4,9 @@
use data_model::DataInit;
use data_model::Le32;
use virtio_sys::virtio_fs::virtio_fs_config;
use vmm_vhost::message::VhostUserProtocolFeatures;
use crate::virtio::fs::virtio_fs_config;
use crate::virtio::fs::FS_MAX_TAG_LEN;
use crate::virtio::fs::QUEUE_SIZE;
use crate::virtio::vhost::user::vmm::Connection;

View file

@ -35,6 +35,24 @@ bindgen_generate \
| replace_linux_int_types \
> virtio_sys/src/virtio_config.rs
VIRTIO_FS_EXTRA="// Added by virtio_sys/bindgen.sh
use data_model::DataInit;
use data_model::Le32;
// Safe because all members are plain old data and any value is valid.
unsafe impl DataInit for virtio_fs_config {}"
bindgen_generate \
--raw-line "${VIRTIO_FS_EXTRA}" \
--allowlist-var='VIRTIO_FS_.*' \
--allowlist-type='virtio_fs_.*' \
"${BINDGEN_LINUX_X86_HEADERS}/include/linux/virtio_fs.h" \
-- \
-isystem "${BINDGEN_LINUX_X86_HEADERS}/include" \
| replace_linux_int_types \
| replace_linux_endian_types \
> virtio_sys/src/virtio_fs.rs
VIRTIO_IDS_EXTRAS="
//! This file defines virtio device IDs. IDs with large values (counting down
//! from 63) are nonstandard and not defined by the virtio specification.

View file

@ -15,6 +15,7 @@ use base::ioctl_iowr_nr;
pub mod vhost;
pub mod virtio_config;
pub mod virtio_fs;
pub mod virtio_ids;
pub mod virtio_mmio;
pub mod virtio_net;

View file

@ -0,0 +1,32 @@
/* automatically generated by tools/bindgen-all-the-things */
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::upper_case_acronyms)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
// Added by virtio_sys/bindgen.sh
use data_model::DataInit;
use data_model::Le32;
// Safe because all members are plain old data and any value is valid.
unsafe impl DataInit for virtio_fs_config {}
pub const VIRTIO_FS_SHMCAP_ID_CACHE: u32 = 0;
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct virtio_fs_config {
pub tag: [u8; 36usize],
pub num_request_queues: Le32,
}
impl Default for virtio_fs_config {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}