@@ -32,7 +32,10 @@ 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:: {
36
+ desc:: { split:: Descriptor as SplitDescriptor , Descriptor } ,
37
+ DescriptorChain ,
38
+ } ;
36
39
use vm_memory:: { ByteValued , Bytes , GuestAddress , GuestMemory , GuestMemoryError } ;
37
40
38
41
/// Block request parsing errors.
@@ -162,6 +165,7 @@ impl Request {
162
165
where
163
166
M : GuestMemory + ?Sized ,
164
167
{
168
+ let desc = SplitDescriptor :: from ( desc) ;
165
169
// The status MUST always be writable.
166
170
if !desc. is_write_only ( ) {
167
171
return Err ( Error :: UnexpectedReadOnlyDescriptor ) ;
@@ -183,6 +187,7 @@ impl Request {
183
187
184
188
// Checks that a descriptor meets the minimal requirements for a valid data descriptor.
185
189
fn check_data_desc ( desc : Descriptor , request_type : RequestType ) -> Result < ( ) > {
190
+ let desc = SplitDescriptor :: from ( desc) ;
186
191
// We do this check only for the device-readable buffers, as opposed to
187
192
// also check that the device doesn't want to read a device-writable buffer
188
193
// because this one is not a MUST (the device MAY do that for debugging or
@@ -234,14 +239,14 @@ impl Request {
234
239
let mut desc = desc_chain. next ( ) . ok_or ( Error :: DescriptorChainTooShort ) ?;
235
240
236
241
while desc. has_next ( ) {
237
- Request :: check_data_desc ( desc, request. request_type ) ?;
242
+ Request :: check_data_desc ( Descriptor :: from ( desc) , request. request_type ) ?;
238
243
239
244
request. data . push ( ( desc. addr ( ) , desc. len ( ) ) ) ;
240
245
desc = desc_chain. next ( ) . ok_or ( Error :: DescriptorChainTooShort ) ?;
241
246
}
242
247
let status_desc = desc;
243
248
244
- Request :: check_status_desc ( desc_chain. memory ( ) , status_desc) ?;
249
+ Request :: check_status_desc ( desc_chain. memory ( ) , Descriptor :: from ( status_desc) ) ?;
245
250
246
251
request. status_addr = status_desc. addr ( ) ;
247
252
Ok ( request)
@@ -297,9 +302,24 @@ mod tests {
297
302
// The `build_desc_chain` function will populate the `NEXT` related flags and field.
298
303
let v = [
299
304
// 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 ) ,
305
+ Descriptor :: from ( SplitDescriptor :: new (
306
+ 0x10_0000 ,
307
+ 0x100 ,
308
+ VRING_DESC_F_WRITE as u16 ,
309
+ 0 ,
310
+ ) ) ,
311
+ Descriptor :: from ( SplitDescriptor :: new (
312
+ 0x20_0000 ,
313
+ 0x100 ,
314
+ VRING_DESC_F_WRITE as u16 ,
315
+ 0 ,
316
+ ) ) ,
317
+ Descriptor :: from ( SplitDescriptor :: new (
318
+ 0x30_0000 ,
319
+ 0x100 ,
320
+ VRING_DESC_F_WRITE as u16 ,
321
+ 0 ,
322
+ ) ) ,
303
323
] ;
304
324
// Create a queue of max 16 descriptors and a descriptor chain based on the array above.
305
325
let queue = MockSplitQueue :: new ( & mem, 16 ) ;
@@ -319,10 +339,15 @@ mod tests {
319
339
) ;
320
340
321
341
let v = [
322
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
323
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
342
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
343
+ Descriptor :: from ( SplitDescriptor :: new (
344
+ 0x20_0000 ,
345
+ 0x100 ,
346
+ VRING_DESC_F_WRITE as u16 ,
347
+ 0 ,
348
+ ) ) ,
324
349
// A device-readable request status descriptor.
325
- Descriptor :: new ( 0x30_0000 , 0x100 , 0 , 0 ) ,
350
+ Descriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x100 , 0 , 0 ) ) ,
326
351
] ;
327
352
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
328
353
@@ -333,10 +358,20 @@ mod tests {
333
358
) ;
334
359
335
360
let v = [
336
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
337
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
361
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
362
+ Descriptor :: from ( SplitDescriptor :: new (
363
+ 0x20_0000 ,
364
+ 0x100 ,
365
+ VRING_DESC_F_WRITE as u16 ,
366
+ 0 ,
367
+ ) ) ,
338
368
// Status descriptor with len = 0.
339
- Descriptor :: new ( 0x30_0000 , 0x0 , VRING_DESC_F_WRITE as u16 , 0 ) ,
369
+ Descriptor :: from ( SplitDescriptor :: new (
370
+ 0x30_0000 ,
371
+ 0x0 ,
372
+ VRING_DESC_F_WRITE as u16 ,
373
+ 0 ,
374
+ ) ) ,
340
375
] ;
341
376
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
342
377
assert_eq ! (
@@ -345,9 +380,14 @@ mod tests {
345
380
) ;
346
381
347
382
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 ) ,
383
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
384
+ Descriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , 0 , 0 ) ) ,
385
+ Descriptor :: from ( SplitDescriptor :: new (
386
+ 0x30_0000 ,
387
+ 0x100 ,
388
+ VRING_DESC_F_WRITE as u16 ,
389
+ 0 ,
390
+ ) ) ,
351
391
] ;
352
392
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
353
393
@@ -377,10 +417,25 @@ mod tests {
377
417
378
418
// Invalid status address.
379
419
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 ) ,
420
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
421
+ Descriptor :: from ( SplitDescriptor :: new (
422
+ 0x20_0000 ,
423
+ 0x100 ,
424
+ VRING_DESC_F_WRITE as u16 ,
425
+ 0 ,
426
+ ) ) ,
427
+ Descriptor :: from ( SplitDescriptor :: new (
428
+ 0x30_0000 ,
429
+ 0x200 ,
430
+ VRING_DESC_F_WRITE as u16 ,
431
+ 0 ,
432
+ ) ) ,
433
+ Descriptor :: from ( SplitDescriptor :: new (
434
+ 0x1100_0000 ,
435
+ 0x100 ,
436
+ VRING_DESC_F_WRITE as u16 ,
437
+ 0 ,
438
+ ) ) ,
384
439
] ;
385
440
let req_header = RequestHeader {
386
441
request_type : VIRTIO_BLK_T_OUT ,
@@ -402,10 +457,25 @@ mod tests {
402
457
403
458
// Valid descriptor chain for OUT.
404
459
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 ) ,
460
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
461
+ Descriptor :: from ( SplitDescriptor :: new (
462
+ 0x20_0000 ,
463
+ 0x100 ,
464
+ VRING_DESC_F_WRITE as u16 ,
465
+ 0 ,
466
+ ) ) ,
467
+ Descriptor :: from ( SplitDescriptor :: new (
468
+ 0x30_0000 ,
469
+ 0x200 ,
470
+ VRING_DESC_F_WRITE as u16 ,
471
+ 0 ,
472
+ ) ) ,
473
+ Descriptor :: from ( SplitDescriptor :: new (
474
+ 0x40_0000 ,
475
+ 0x100 ,
476
+ VRING_DESC_F_WRITE as u16 ,
477
+ 0 ,
478
+ ) ) ,
409
479
] ;
410
480
let req_header = RequestHeader {
411
481
request_type : VIRTIO_BLK_T_OUT ,
@@ -447,8 +517,13 @@ mod tests {
447
517
448
518
// Valid descriptor chain for FLUSH.
449
519
let v = [
450
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
451
- Descriptor :: new ( 0x40_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
520
+ Descriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
521
+ Descriptor :: from ( SplitDescriptor :: new (
522
+ 0x40_0000 ,
523
+ 0x100 ,
524
+ VRING_DESC_F_WRITE as u16 ,
525
+ 0 ,
526
+ ) ) ,
452
527
] ;
453
528
let req_header = RequestHeader {
454
529
request_type : VIRTIO_BLK_T_FLUSH ,
0 commit comments