@@ -8,10 +8,22 @@ use std::{
8
8
9
9
use compio_log:: { instrument, trace} ;
10
10
use crossbeam_queue:: SegQueue ;
11
+ cfg_if:: cfg_if! {
12
+ if #[ cfg( feature = "io-uring-cqe32" ) ] {
13
+ use io_uring:: cqueue:: Entry32 as CEntry ;
14
+ } else {
15
+ use io_uring:: cqueue:: Entry as CEntry ;
16
+ }
17
+ }
18
+ cfg_if:: cfg_if! {
19
+ if #[ cfg( feature = "io-uring-sqe128" ) ] {
20
+ use io_uring:: squeue:: Entry128 as SEntry ;
21
+ } else {
22
+ use io_uring:: squeue:: Entry as SEntry ;
23
+ }
24
+ }
11
25
use io_uring:: {
12
- cqueue,
13
26
opcode:: { AsyncCancel , Read } ,
14
- squeue,
15
27
types:: { Fd , SubmitArgs , Timespec } ,
16
28
IoUring ,
17
29
} ;
@@ -26,17 +38,27 @@ pub(crate) use crate::unix::RawOp;
26
38
/// The created entry of [`OpCode`].
27
39
pub enum OpEntry {
28
40
/// This operation creates an io-uring submission entry.
29
- Submission ( squeue:: Entry ) ,
41
+ Submission ( io_uring:: squeue:: Entry ) ,
42
+ #[ cfg( feature = "io-uring-sqe128" ) ]
43
+ /// This operation creates an 128-bit io-uring submission entry.
44
+ Submission128 ( io_uring:: squeue:: Entry128 ) ,
30
45
/// This operation is a blocking one.
31
46
Blocking ,
32
47
}
33
48
34
- impl From < squeue:: Entry > for OpEntry {
35
- fn from ( value : squeue:: Entry ) -> Self {
49
+ impl From < io_uring :: squeue:: Entry > for OpEntry {
50
+ fn from ( value : io_uring :: squeue:: Entry ) -> Self {
36
51
Self :: Submission ( value)
37
52
}
38
53
}
39
54
55
+ #[ cfg( feature = "io-uring-sqe128" ) ]
56
+ impl From < io_uring:: squeue:: Entry128 > for OpEntry {
57
+ fn from ( value : io_uring:: squeue:: Entry128 ) -> Self {
58
+ Self :: Submission128 ( value)
59
+ }
60
+ }
61
+
40
62
/// Abstraction of io-uring operations.
41
63
pub trait OpCode {
42
64
/// Create submission entry.
@@ -51,8 +73,8 @@ pub trait OpCode {
51
73
52
74
/// Low-level driver of io-uring.
53
75
pub ( crate ) struct Driver {
54
- inner : IoUring ,
55
- squeue : VecDeque < squeue :: Entry > ,
76
+ inner : IoUring < SEntry , CEntry > ,
77
+ squeue : VecDeque < SEntry > ,
56
78
notifier : Notifier ,
57
79
notifier_registered : bool ,
58
80
pool : AsyncifyPool ,
@@ -67,7 +89,7 @@ impl Driver {
67
89
instrument ! ( compio_log:: Level :: TRACE , "new" , ?builder) ;
68
90
trace ! ( "new iour driver" ) ;
69
91
Ok ( Self {
70
- inner : IoUring :: new ( builder. capacity ) ?,
92
+ inner : IoUring :: builder ( ) . build ( builder. capacity ) ?,
71
93
squeue : VecDeque :: with_capacity ( builder. capacity as usize ) ,
72
94
notifier : Notifier :: new ( ) ?,
73
95
notifier_registered : false ,
@@ -170,24 +192,38 @@ impl Driver {
170
192
pub fn cancel ( & mut self , user_data : usize , _registry : & mut Slab < RawOp > ) {
171
193
instrument ! ( compio_log:: Level :: TRACE , "cancel" , user_data) ;
172
194
trace ! ( "cancel RawOp" ) ;
195
+ #[ allow( clippy:: useless_conversion) ]
173
196
self . squeue . push_back (
174
197
AsyncCancel :: new ( user_data as _ )
175
198
. build ( )
176
- . user_data ( Self :: CANCEL ) ,
199
+ . user_data ( Self :: CANCEL )
200
+ . into ( ) ,
177
201
) ;
178
202
}
179
203
180
204
pub fn push ( & mut self , user_data : usize , op : & mut RawOp ) -> Poll < io:: Result < usize > > {
181
205
instrument ! ( compio_log:: Level :: TRACE , "push" , user_data) ;
182
206
let op_pin = op. as_pin ( ) ;
183
207
trace ! ( "push RawOp" ) ;
184
- if let OpEntry :: Submission ( entry) = op_pin. create_entry ( ) {
185
- self . squeue . push_back ( entry. user_data ( user_data as _ ) ) ;
186
- Poll :: Pending
187
- } else if self . push_blocking ( user_data, op) ? {
188
- Poll :: Pending
189
- } else {
190
- Poll :: Ready ( Err ( io:: Error :: from_raw_os_error ( libc:: EBUSY ) ) )
208
+ match op_pin. create_entry ( ) {
209
+ OpEntry :: Submission ( entry) => {
210
+ #[ allow( clippy:: useless_conversion) ]
211
+ self . squeue
212
+ . push_back ( entry. user_data ( user_data as _ ) . into ( ) ) ;
213
+ Poll :: Pending
214
+ }
215
+ #[ cfg( feature = "io-uring-sqe128" ) ]
216
+ OpEntry :: Submission128 ( _entry) => {
217
+ self . squeue . push_back ( _entry. user_data ( user_data as _ ) ) ;
218
+ Poll :: Pending
219
+ }
220
+ OpEntry :: Blocking => {
221
+ if self . push_blocking ( user_data, op) ? {
222
+ Poll :: Pending
223
+ } else {
224
+ Poll :: Ready ( Err ( io:: Error :: from_raw_os_error ( libc:: EBUSY ) ) )
225
+ }
226
+ }
191
227
}
192
228
}
193
229
@@ -223,10 +259,12 @@ impl Driver {
223
259
if !self . notifier_registered {
224
260
let fd = self . notifier . as_raw_fd ( ) ;
225
261
let dst = self . notifier . dst ( ) ;
262
+ #[ allow( clippy:: useless_conversion) ]
226
263
self . squeue . push_back (
227
264
Read :: new ( Fd ( fd) , dst. as_mut_ptr ( ) , dst. len ( ) as _ )
228
265
. build ( )
229
- . user_data ( Self :: NOTIFY ) ,
266
+ . user_data ( Self :: NOTIFY )
267
+ . into ( ) ,
230
268
) ;
231
269
trace ! ( "registered notifier" ) ;
232
270
self . notifier_registered = true
@@ -259,7 +297,7 @@ impl AsRawFd for Driver {
259
297
}
260
298
}
261
299
262
- fn create_entry ( entry : cqueue :: Entry ) -> Entry {
300
+ fn create_entry ( entry : CEntry ) -> Entry {
263
301
let result = entry. result ( ) ;
264
302
let result = if result < 0 {
265
303
let result = if result == -libc:: ECANCELED {
0 commit comments