@@ -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 , RawDescriptor } ,
37
+ DescriptorChain ,
38
+ } ;
36
39
use vm_memory:: { ByteValued , Bytes , GuestAddress , GuestMemory , GuestMemoryError } ;
37
40
38
41
/// Block request parsing errors.
@@ -158,10 +161,11 @@ impl Request {
158
161
}
159
162
160
163
// Checks that a descriptor meets the minimal requirements for a valid status descriptor.
161
- fn check_status_desc < M > ( mem : & M , desc : Descriptor ) -> Result < ( ) >
164
+ fn check_status_desc < M > ( mem : & M , desc : RawDescriptor ) -> Result < ( ) >
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 ) ;
@@ -182,7 +186,8 @@ impl Request {
182
186
}
183
187
184
188
// Checks that a descriptor meets the minimal requirements for a valid data descriptor.
185
- fn check_data_desc ( desc : Descriptor , request_type : RequestType ) -> Result < ( ) > {
189
+ fn check_data_desc ( desc : RawDescriptor , 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 ( RawDescriptor :: 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 ( ) , RawDescriptor :: from ( status_desc) ) ?;
245
250
246
251
request. status_addr = status_desc. addr ( ) ;
247
252
Ok ( request)
@@ -298,9 +303,24 @@ mod tests {
298
303
// The `build_desc_chain` function will populate the `NEXT` related flags and field.
299
304
let v = [
300
305
// A device-writable request header descriptor.
301
- Descriptor :: new ( 0x10_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
302
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
303
- Descriptor :: new ( 0x30_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
306
+ RawDescriptor :: from ( SplitDescriptor :: new (
307
+ 0x10_0000 ,
308
+ 0x100 ,
309
+ VRING_DESC_F_WRITE as u16 ,
310
+ 0 ,
311
+ ) ) ,
312
+ RawDescriptor :: from ( SplitDescriptor :: new (
313
+ 0x20_0000 ,
314
+ 0x100 ,
315
+ VRING_DESC_F_WRITE as u16 ,
316
+ 0 ,
317
+ ) ) ,
318
+ RawDescriptor :: from ( SplitDescriptor :: new (
319
+ 0x30_0000 ,
320
+ 0x100 ,
321
+ VRING_DESC_F_WRITE as u16 ,
322
+ 0 ,
323
+ ) ) ,
304
324
] ;
305
325
// Create a queue of max 16 descriptors and a descriptor chain based on the array above.
306
326
let queue = MockSplitQueue :: new ( & mem, 16 ) ;
@@ -320,10 +340,15 @@ mod tests {
320
340
) ;
321
341
322
342
let v = [
323
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
324
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
343
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
344
+ RawDescriptor :: from ( SplitDescriptor :: new (
345
+ 0x20_0000 ,
346
+ 0x100 ,
347
+ VRING_DESC_F_WRITE as u16 ,
348
+ 0 ,
349
+ ) ) ,
325
350
// A device-readable request status descriptor.
326
- Descriptor :: new ( 0x30_0000 , 0x100 , 0 , 0 ) ,
351
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x30_0000 , 0x100 , 0 , 0 ) ) ,
327
352
] ;
328
353
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
329
354
@@ -334,10 +359,20 @@ mod tests {
334
359
) ;
335
360
336
361
let v = [
337
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
338
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
362
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
363
+ RawDescriptor :: from ( SplitDescriptor :: new (
364
+ 0x20_0000 ,
365
+ 0x100 ,
366
+ VRING_DESC_F_WRITE as u16 ,
367
+ 0 ,
368
+ ) ) ,
339
369
// Status descriptor with len = 0.
340
- Descriptor :: new ( 0x30_0000 , 0x0 , VRING_DESC_F_WRITE as u16 , 0 ) ,
370
+ RawDescriptor :: from ( SplitDescriptor :: new (
371
+ 0x30_0000 ,
372
+ 0x0 ,
373
+ VRING_DESC_F_WRITE as u16 ,
374
+ 0 ,
375
+ ) ) ,
341
376
] ;
342
377
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
343
378
assert_eq ! (
@@ -346,9 +381,14 @@ mod tests {
346
381
) ;
347
382
348
383
let v = [
349
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
350
- Descriptor :: new ( 0x20_0000 , 0x100 , 0 , 0 ) ,
351
- Descriptor :: new ( 0x30_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
384
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
385
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x20_0000 , 0x100 , 0 , 0 ) ) ,
386
+ RawDescriptor :: from ( SplitDescriptor :: new (
387
+ 0x30_0000 ,
388
+ 0x100 ,
389
+ VRING_DESC_F_WRITE as u16 ,
390
+ 0 ,
391
+ ) ) ,
352
392
] ;
353
393
let mut chain = queue. build_desc_chain ( & v[ ..3 ] ) . unwrap ( ) ;
354
394
@@ -378,10 +418,25 @@ mod tests {
378
418
379
419
// Invalid status address.
380
420
let v = [
381
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
382
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
383
- Descriptor :: new ( 0x30_0000 , 0x200 , VRING_DESC_F_WRITE as u16 , 0 ) ,
384
- Descriptor :: new ( 0x1100_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
421
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
422
+ RawDescriptor :: from ( SplitDescriptor :: new (
423
+ 0x20_0000 ,
424
+ 0x100 ,
425
+ VRING_DESC_F_WRITE as u16 ,
426
+ 0 ,
427
+ ) ) ,
428
+ RawDescriptor :: from ( SplitDescriptor :: new (
429
+ 0x30_0000 ,
430
+ 0x200 ,
431
+ VRING_DESC_F_WRITE as u16 ,
432
+ 0 ,
433
+ ) ) ,
434
+ RawDescriptor :: from ( SplitDescriptor :: new (
435
+ 0x1100_0000 ,
436
+ 0x100 ,
437
+ VRING_DESC_F_WRITE as u16 ,
438
+ 0 ,
439
+ ) ) ,
385
440
] ;
386
441
let req_header = RequestHeader {
387
442
request_type : VIRTIO_BLK_T_OUT ,
@@ -403,10 +458,25 @@ mod tests {
403
458
404
459
// Valid descriptor chain for OUT.
405
460
let v = [
406
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
407
- Descriptor :: new ( 0x20_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
408
- Descriptor :: new ( 0x30_0000 , 0x200 , VRING_DESC_F_WRITE as u16 , 0 ) ,
409
- Descriptor :: new ( 0x40_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
461
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
462
+ RawDescriptor :: from ( SplitDescriptor :: new (
463
+ 0x20_0000 ,
464
+ 0x100 ,
465
+ VRING_DESC_F_WRITE as u16 ,
466
+ 0 ,
467
+ ) ) ,
468
+ RawDescriptor :: from ( SplitDescriptor :: new (
469
+ 0x30_0000 ,
470
+ 0x200 ,
471
+ VRING_DESC_F_WRITE as u16 ,
472
+ 0 ,
473
+ ) ) ,
474
+ RawDescriptor :: from ( SplitDescriptor :: new (
475
+ 0x40_0000 ,
476
+ 0x100 ,
477
+ VRING_DESC_F_WRITE as u16 ,
478
+ 0 ,
479
+ ) ) ,
410
480
] ;
411
481
let req_header = RequestHeader {
412
482
request_type : VIRTIO_BLK_T_OUT ,
@@ -448,8 +518,13 @@ mod tests {
448
518
449
519
// Valid descriptor chain for FLUSH.
450
520
let v = [
451
- Descriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ,
452
- Descriptor :: new ( 0x40_0000 , 0x100 , VRING_DESC_F_WRITE as u16 , 0 ) ,
521
+ RawDescriptor :: from ( SplitDescriptor :: new ( 0x10_0000 , 0x100 , 0 , 0 ) ) ,
522
+ RawDescriptor :: from ( SplitDescriptor :: new (
523
+ 0x40_0000 ,
524
+ 0x100 ,
525
+ VRING_DESC_F_WRITE as u16 ,
526
+ 0 ,
527
+ ) ) ,
453
528
] ;
454
529
let req_header = RequestHeader {
455
530
request_type : VIRTIO_BLK_T_FLUSH ,
0 commit comments