@@ -32,7 +32,7 @@ use virtio_bindings::bindings::virtio_blk::{
32
32
VIRTIO_BLK_T_OUT , VIRTIO_BLK_T_WRITE_ZEROES ,
33
33
} ;
34
34
35
- use virtio_queue:: { Descriptor , DescriptorChain } ;
35
+ use virtio_queue:: { desc :: { split :: Descriptor as SplitDescriptor , Descriptor } , DescriptorChain } ;
36
36
use vm_memory:: { ByteValued , Bytes , GuestAddress , GuestMemory , GuestMemoryError } ;
37
37
38
38
/// Block request parsing errors.
@@ -162,6 +162,7 @@ impl Request {
162
162
where
163
163
M : GuestMemory + ?Sized ,
164
164
{
165
+ let desc = SplitDescriptor :: from ( desc) ;
165
166
// The status MUST always be writable.
166
167
if !desc. is_write_only ( ) {
167
168
return Err ( Error :: UnexpectedReadOnlyDescriptor ) ;
@@ -183,6 +184,7 @@ impl Request {
183
184
184
185
// Checks that a descriptor meets the minimal requirements for a valid data descriptor.
185
186
fn check_data_desc ( desc : Descriptor , request_type : RequestType ) -> Result < ( ) > {
187
+ let desc = SplitDescriptor :: from ( desc) ;
186
188
// We do this check only for the device-readable buffers, as opposed to
187
189
// also check that the device doesn't want to read a device-writable buffer
188
190
// because this one is not a MUST (the device MAY do that for debugging or
@@ -234,14 +236,14 @@ impl Request {
234
236
let mut desc = desc_chain. next ( ) . ok_or ( Error :: DescriptorChainTooShort ) ?;
235
237
236
238
while desc. has_next ( ) {
237
- Request :: check_data_desc ( desc, request. request_type ) ?;
239
+ Request :: check_data_desc ( Descriptor :: from ( desc) , request. request_type ) ?;
238
240
239
241
request. data . push ( ( desc. addr ( ) , desc. len ( ) ) ) ;
240
242
desc = desc_chain. next ( ) . ok_or ( Error :: DescriptorChainTooShort ) ?;
241
243
}
242
244
let status_desc = desc;
243
245
244
- Request :: check_status_desc ( desc_chain. memory ( ) , status_desc) ?;
246
+ Request :: check_status_desc ( desc_chain. memory ( ) , Descriptor :: from ( status_desc) ) ?;
245
247
246
248
request. status_addr = status_desc. addr ( ) ;
247
249
Ok ( request)
@@ -297,9 +299,9 @@ mod tests {
297
299
// The `build_desc_chain` function will populate the `NEXT` related flags and field.
298
300
let v = [
299
301
// A device-writable request header descriptor.
300
- Descriptor :: new ( 0x10_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
301
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
302
- Descriptor :: new ( 0x30_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
302
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
303
+ Descriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
304
+ Descriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
303
305
] ;
304
306
// Create a queue of max 16 descriptors and a descriptor chain based on the array above.
305
307
let queue = MockSplitQueue :: new ( & mem, 16 ) ;
@@ -319,10 +321,10 @@ mod tests {
319
321
) ;
320
322
321
323
let v = [
322
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
323
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
324
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
325
+ Descriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
324
326
// A device-readable request status descriptor.
325
- Descriptor :: new ( 0x30_0000 , 0x100 , 0 , 0 ) ,
327
+ Descriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x100 , 0 , 0 ) ) ,
326
328
] ;
327
329
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
328
330
@@ -333,10 +335,10 @@ mod tests {
333
335
) ;
334
336
335
337
let v = [
336
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
337
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
338
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
339
+ Descriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
338
340
// Status descriptor with len = 0.
339
- Descriptor :: new ( 0x30_0000 , 0x0 , VRING_DESC_F_WRITE as u16 , 0 ) ,
341
+ Descriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x0 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
340
342
] ;
341
343
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
342
344
assert_eq ! (
@@ -345,9 +347,9 @@ mod tests {
345
347
) ;
346
348
347
349
let v = [
348
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
349
- Descriptor :: new ( 0x20_0000 , 0x100 , 0 , 0 ) ,
350
- Descriptor :: new ( 0x30_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
350
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
351
+ Descriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , 0 , 0 ) ) ,
352
+ Descriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
351
353
] ;
352
354
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
353
355
@@ -377,10 +379,10 @@ mod tests {
377
379
378
380
// Invalid status address.
379
381
let v = [
380
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
381
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
382
- Descriptor :: new ( 0x30_0000 , 0x200 , VRING_DESC_F_WRITE as u16 , 0 ) ,
383
- Descriptor :: new ( 0x1100_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
382
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
383
+ Descriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
384
+ Descriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x200 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
385
+ Descriptor :: from ( SplitDescriptor :: new ( 0x1100_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
384
386
] ;
385
387
let req_header = RequestHeader {
386
388
request_type : VIRTIO_BLK_T_OUT ,
@@ -402,10 +404,10 @@ mod tests {
402
404
403
405
// Valid descriptor chain for OUT.
404
406
let v = [
405
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
406
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
407
- Descriptor :: new ( 0x30_0000 , 0x200 , VRING_DESC_F_WRITE as u16 , 0 ) ,
408
- Descriptor :: new ( 0x40_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
407
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
408
+ Descriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
409
+ Descriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x200 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
410
+ Descriptor :: from ( SplitDescriptor :: new ( 0x40_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
409
411
] ;
410
412
let req_header = RequestHeader {
411
413
request_type : VIRTIO_BLK_T_OUT ,
@@ -447,8 +449,8 @@ mod tests {
447
449
448
450
// Valid descriptor chain for FLUSH.
449
451
let v = [
450
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
451
- Descriptor :: new ( 0x40_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
452
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
453
+ Descriptor :: from ( SplitDescriptor :: new ( 0x40_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ) ,
452
454
] ;
453
455
let req_header = RequestHeader {
454
456
request_type : VIRTIO_BLK_T_FLUSH ,
0 commit comments