Skip to content

Commit 81cacbf

Browse files
roypatzulinx86
authored andcommitted
refactor: rename vmm::io_uring::bindings to vmm::io_uring::gen
This is the last step we need to make sure that all bindgen generated things are inside modules called "gen". Signed-off-by: Patrick Roy <[email protected]>
1 parent a7e4044 commit 81cacbf

File tree

10 files changed

+43
-51
lines changed

10 files changed

+43
-51
lines changed
File renamed without changes.

src/vmm/src/io_uring/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![warn(missing_docs)]
55

66
#[allow(clippy::undocumented_unsafe_blocks)]
7-
mod bindings;
7+
mod gen;
88
pub mod operation;
99
mod probe;
1010
mod queue;
@@ -16,7 +16,7 @@ use std::fs::File;
1616
use std::io::Error as IOError;
1717
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
1818

19-
use bindings::io_uring_params;
19+
use gen::io_uring_params;
2020
use operation::{Cqe, FixedFd, OpCode, Operation};
2121
use probe::{ProbeWrapper, PROBE_LEN};
2222
pub use queue::completion::CQueueError;
@@ -112,7 +112,7 @@ impl<T: Debug> IoUring<T> {
112112
) -> Result<Self, IoUringError> {
113113
let mut params = io_uring_params {
114114
// Create the ring as disabled, so that we may register restrictions.
115-
flags: bindings::IORING_SETUP_R_DISABLED,
115+
flags: gen::IORING_SETUP_R_DISABLED,
116116

117117
..Default::default()
118118
};
@@ -252,7 +252,7 @@ impl<T: Debug> IoUring<T> {
252252
libc::syscall(
253253
libc::SYS_io_uring_register,
254254
self.fd.as_raw_fd(),
255-
bindings::IORING_REGISTER_ENABLE_RINGS,
255+
gen::IORING_REGISTER_ENABLE_RINGS,
256256
std::ptr::null::<libc::c_void>(),
257257
0,
258258
)
@@ -277,7 +277,7 @@ impl<T: Debug> IoUring<T> {
277277
libc::syscall(
278278
libc::SYS_io_uring_register,
279279
self.fd.as_raw_fd(),
280-
bindings::IORING_REGISTER_FILES,
280+
gen::IORING_REGISTER_FILES,
281281
files
282282
.iter()
283283
.map(|f| f.as_raw_fd())
@@ -301,7 +301,7 @@ impl<T: Debug> IoUring<T> {
301301
libc::syscall(
302302
libc::SYS_io_uring_register,
303303
self.fd.as_raw_fd(),
304-
bindings::IORING_REGISTER_EVENTFD,
304+
gen::IORING_REGISTER_EVENTFD,
305305
(&fd) as *const _,
306306
1,
307307
)
@@ -320,10 +320,10 @@ impl<T: Debug> IoUring<T> {
320320
libc::syscall(
321321
libc::SYS_io_uring_register,
322322
self.fd.as_raw_fd(),
323-
bindings::IORING_REGISTER_RESTRICTIONS,
323+
gen::IORING_REGISTER_RESTRICTIONS,
324324
restrictions
325325
.iter()
326-
.map(bindings::io_uring_restriction::from)
326+
.map(gen::io_uring_restriction::from)
327327
.collect::<Vec<_>>()
328328
.as_mut_slice()
329329
.as_mut_ptr(),
@@ -341,7 +341,7 @@ impl<T: Debug> IoUring<T> {
341341
// An alternative fix would be to keep an internal counter that tracks the number of
342342
// submitted entries that haven't been completed and makes sure it doesn't exceed
343343
// (2 * num_entries).
344-
if (params.features & bindings::IORING_FEAT_NODROP) == 0 {
344+
if (params.features & gen::IORING_FEAT_NODROP) == 0 {
345345
return Err(IoUringError::UnsupportedFeature("IORING_FEAT_NODROP"));
346346
}
347347

@@ -356,7 +356,7 @@ impl<T: Debug> IoUring<T> {
356356
libc::syscall(
357357
libc::SYS_io_uring_register,
358358
self.fd.as_raw_fd(),
359-
bindings::IORING_REGISTER_PROBE,
359+
gen::IORING_REGISTER_PROBE,
360360
probes.as_mut_fam_struct_ptr(),
361361
PROBE_LEN,
362362
)
@@ -367,7 +367,7 @@ impl<T: Debug> IoUring<T> {
367367
let supported_opcodes: HashSet<u8> = probes
368368
.as_slice()
369369
.iter()
370-
.filter(|op| ((u32::from(op.flags)) & bindings::IO_URING_OP_SUPPORTED) != 0)
370+
.filter(|op| ((u32::from(op.flags)) & gen::IO_URING_OP_SUPPORTED) != 0)
371371
.map(|op| op.op)
372372
.collect();
373373

src/vmm/src/io_uring/operation/cqe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::fmt::Debug;
55

6-
use crate::io_uring::bindings::io_uring_cqe;
6+
use crate::io_uring::gen::io_uring_cqe;
77
use crate::vstate::memory::ByteValued;
88

99
// SAFETY: Struct is POD and contains no references or niches.

src/vmm/src/io_uring/operation/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::fmt::{self, Debug};
1212
pub use cqe::Cqe;
1313
pub(crate) use sqe::Sqe;
1414

15-
use crate::io_uring::bindings::{self, io_uring_sqe, IOSQE_FIXED_FILE_BIT};
15+
use crate::io_uring::gen::{self, io_uring_sqe, IOSQE_FIXED_FILE_BIT};
1616

1717
/// The index of a registered fd.
1818
pub type FixedFd = u32;
@@ -24,11 +24,11 @@ pub type FixedFd = u32;
2424
/// Supported operation types.
2525
pub enum OpCode {
2626
/// Read operation.
27-
Read = bindings::IORING_OP_READ as u8,
27+
Read = gen::IORING_OP_READ as u8,
2828
/// Write operation.
29-
Write = bindings::IORING_OP_WRITE as u8,
29+
Write = gen::IORING_OP_WRITE as u8,
3030
/// Fsync operation.
31-
Fsync = bindings::IORING_OP_FSYNC as u8,
31+
Fsync = gen::IORING_OP_FSYNC as u8,
3232
}
3333

3434
// Useful for outputting errors.
@@ -120,7 +120,7 @@ impl<T: Debug> Operation<T> {
120120
// Needed for proptesting.
121121
#[cfg(test)]
122122
pub(crate) fn set_linked(&mut self) {
123-
self.flags |= 1 << bindings::IOSQE_IO_LINK_BIT;
123+
self.flags |= 1 << gen::IOSQE_IO_LINK_BIT;
124124
}
125125

126126
/// Transform the operation into an `Sqe`.

src/vmm/src/io_uring/operation/sqe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::fmt::{self};
55

6-
use crate::io_uring::bindings::io_uring_sqe;
6+
use crate::io_uring::gen::io_uring_sqe;
77
use crate::vstate::memory::ByteValued;
88

99
// SAFETY: Struct is POD and contains no references or niches.

src/vmm/src/io_uring/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use utils::fam::{FamStruct, FamStructWrapper};
55
use utils::generate_fam_struct_impl;
66

7-
use crate::io_uring::bindings::{io_uring_probe, io_uring_probe_op};
7+
use crate::io_uring::gen::{io_uring_probe, io_uring_probe_op};
88

99
// There is no max for the number of operations returned by probing. So we fallback to using the
1010
// number of values representable in a u8;

src/vmm/src/io_uring/queue/completion.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::sync::atomic::Ordering;
99
use vm_memory::{Bytes, VolatileMemory, VolatileMemoryError};
1010

1111
use super::mmap::{mmap, MmapError};
12-
use crate::io_uring::bindings;
12+
use crate::io_uring::gen;
1313
use crate::io_uring::operation::Cqe;
1414
use crate::vstate::memory::MmapRegion;
1515

@@ -43,15 +43,15 @@ pub(crate) struct CompletionQueue {
4343
impl CompletionQueue {
4444
pub(crate) fn new(
4545
io_uring_fd: RawFd,
46-
params: &bindings::io_uring_params,
46+
params: &gen::io_uring_params,
4747
) -> Result<Self, CQueueError> {
4848
let offsets = params.cq_off;
4949

5050
// Map the CQ_ring. The actual size of the ring is `num_entries * size_of(entry_type)`.
5151
// To this we add an offset as per the io_uring specifications.
5252
let ring_size = (params.cq_off.cqes as usize)
53-
+ (params.cq_entries as usize) * std::mem::size_of::<bindings::io_uring_cqe>();
54-
let cqes = mmap(ring_size, io_uring_fd, bindings::IORING_OFF_CQ_RING.into())?;
53+
+ (params.cq_entries as usize) * std::mem::size_of::<gen::io_uring_cqe>();
54+
let cqes = mmap(ring_size, io_uring_fd, gen::IORING_OFF_CQ_RING.into())?;
5555

5656
let ring = cqes.as_volatile_slice();
5757
let ring_mask = ring.read_obj(offsets.ring_mask as usize)?;
@@ -86,8 +86,8 @@ impl CompletionQueue {
8686

8787
// validate that we have smth to fetch
8888
if Wrapping(unmasked_tail) - self.unmasked_head > Wrapping(0) {
89-
let cqe: bindings::io_uring_cqe = ring.read_obj(
90-
self.cqes_off + (head as usize) * std::mem::size_of::<bindings::io_uring_cqe>(),
89+
let cqe: gen::io_uring_cqe = ring.read_obj(
90+
self.cqes_off + (head as usize) * std::mem::size_of::<gen::io_uring_cqe>(),
9191
)?;
9292

9393
// increase the head

src/vmm/src/io_uring/queue/submission.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use utils::syscall::SyscallReturnCode;
1212
use vm_memory::{VolatileMemory, VolatileMemoryError};
1313

1414
use super::mmap::{mmap, MmapError};
15-
use crate::io_uring::bindings;
15+
use crate::io_uring::gen;
1616
use crate::io_uring::operation::Sqe;
1717
use crate::vstate::memory::{Bytes, MmapRegion};
1818

@@ -54,7 +54,7 @@ pub(crate) struct SubmissionQueue {
5454
impl SubmissionQueue {
5555
pub(crate) fn new(
5656
io_uring_fd: RawFd,
57-
params: &bindings::io_uring_params,
57+
params: &gen::io_uring_params,
5858
) -> Result<Self, SQueueError> {
5959
let (ring, sqes) = Self::mmap(io_uring_fd, params)?;
6060
let ring_slice = ring.as_volatile_slice();
@@ -99,10 +99,11 @@ impl SubmissionQueue {
9999
}
100100

101101
// retrieve and populate the sqe
102-
if let Err(err) = self.sqes.as_volatile_slice().write_obj(
103-
sqe.0,
104-
(tail as usize) * mem::size_of::<bindings::io_uring_sqe>(),
105-
) {
102+
if let Err(err) = self
103+
.sqes
104+
.as_volatile_slice()
105+
.write_obj(sqe.0, (tail as usize) * mem::size_of::<gen::io_uring_sqe>())
106+
{
106107
return Err((SQueueError::VolatileMemory(err), sqe.user_data()));
107108
}
108109

@@ -128,7 +129,7 @@ impl SubmissionQueue {
128129
let mut flags = 0;
129130

130131
if min_complete > 0 {
131-
flags |= bindings::IORING_ENTER_GETEVENTS;
132+
flags |= gen::IORING_ENTER_GETEVENTS;
132133
}
133134
// SAFETY: Safe because values are valid and we check the return value.
134135
let submitted = SyscallReturnCode(unsafe {
@@ -154,28 +155,19 @@ impl SubmissionQueue {
154155

155156
fn mmap(
156157
io_uring_fd: RawFd,
157-
params: &bindings::io_uring_params,
158+
params: &gen::io_uring_params,
158159
) -> Result<(MmapRegion, MmapRegion), SQueueError> {
159160
// map the SQ_ring. The actual size of the ring is `num_entries * size_of(entry_type)`.
160161
// To this we add an offset as per the io_uring specifications.
161162
let sqe_ring_size =
162163
(params.sq_off.array as usize) + (params.sq_entries as usize) * mem::size_of::<u32>();
163164

164-
let sqe_ring = mmap(
165-
sqe_ring_size,
166-
io_uring_fd,
167-
bindings::IORING_OFF_SQ_RING.into(),
168-
)?;
165+
let sqe_ring = mmap(sqe_ring_size, io_uring_fd, gen::IORING_OFF_SQ_RING.into())?;
169166

170167
// map the SQEs.
171-
let sqes_array_size =
172-
(params.sq_entries as usize) * mem::size_of::<bindings::io_uring_sqe>();
168+
let sqes_array_size = (params.sq_entries as usize) * mem::size_of::<gen::io_uring_sqe>();
173169

174-
let sqes = mmap(
175-
sqes_array_size,
176-
io_uring_fd,
177-
bindings::IORING_OFF_SQES.into(),
178-
)?;
170+
let sqes = mmap(sqes_array_size, io_uring_fd, gen::IORING_OFF_SQES.into())?;
179171

180172
Ok((sqe_ring, sqes))
181173
}

src/vmm/src/io_uring/restriction.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use std::convert::From;
1414

15-
use crate::io_uring::bindings;
15+
use crate::io_uring::gen;
1616
use crate::io_uring::operation::OpCode;
1717

1818
/// Adds support for restricting the operations allowed by io_uring.
@@ -24,7 +24,7 @@ pub enum Restriction {
2424
RequireFixedFds,
2525
}
2626

27-
impl From<&Restriction> for bindings::io_uring_restriction {
27+
impl From<&Restriction> for gen::io_uring_restriction {
2828
fn from(restriction: &Restriction) -> Self {
2929
use Restriction::*;
3030

@@ -33,13 +33,13 @@ impl From<&Restriction> for bindings::io_uring_restriction {
3333

3434
match restriction {
3535
AllowOpCode(opcode) => {
36-
instance.opcode = u16::try_from(bindings::IORING_RESTRICTION_SQE_OP).unwrap();
36+
instance.opcode = u16::try_from(gen::IORING_RESTRICTION_SQE_OP).unwrap();
3737
instance.__bindgen_anon_1.sqe_op = *opcode as u8;
3838
}
3939
RequireFixedFds => {
4040
instance.opcode =
41-
u16::try_from(bindings::IORING_RESTRICTION_SQE_FLAGS_REQUIRED).unwrap();
42-
instance.__bindgen_anon_1.sqe_flags = 1 << bindings::IOSQE_FIXED_FILE_BIT;
41+
u16::try_from(gen::IORING_RESTRICTION_SQE_FLAGS_REQUIRED).unwrap();
42+
instance.__bindgen_anon_1.sqe_flags = 1 << gen::IOSQE_FIXED_FILE_BIT;
4343
}
4444
};
4545

tools/bindgen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fc-bindgen \
153153
--allowlist-type "io_uring_.+" \
154154
--allowlist-type "io_.qring_offsets" \
155155
"amazonlinux-v5.10.y/include/uapi/linux/io_uring.h" \
156-
>src/vmm/src/io_uring/bindings.rs
156+
>src/vmm/src/io_uring/gen.rs
157157

158158
# Apply any patches
159159
info "Apply patches"

0 commit comments

Comments
 (0)