@@ -253,6 +253,7 @@ where
253
253
#[ cfg( test) ]
254
254
mod tests {
255
255
use super :: * ;
256
+ use crate :: desc:: { split:: Descriptor as SplitDescriptor , Descriptor } ;
256
257
use crate :: mock:: { DescriptorTable , MockSplitQueue } ;
257
258
use virtio_bindings:: bindings:: virtio_ring:: { VRING_DESC_F_INDIRECT , VRING_DESC_F_NEXT } ;
258
259
use vm_memory:: GuestMemoryMmap ;
@@ -281,7 +282,12 @@ mod tests {
281
282
{
282
283
// the first desc has a normal len, and the next_descriptor flag is set
283
284
// but the the index of the next descriptor is too large
284
- let desc = Descriptor :: new ( 0x1000 , 0x1000 , VRING_DESC_F_NEXT as u16 , 16 ) ;
285
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
286
+ 0x1000 ,
287
+ 0x1000 ,
288
+ VRING_DESC_F_NEXT as u16 ,
289
+ 16 ,
290
+ ) ) ;
285
291
vq. desc_table ( ) . store ( 0 , desc) . unwrap ( ) ;
286
292
287
293
let mut c = DescriptorChain :: < & GuestMemoryMmap > :: new ( m, vq. start ( ) , 16 , 0 ) ;
@@ -291,10 +297,15 @@ mod tests {
291
297
292
298
// finally, let's test an ok chain
293
299
{
294
- let desc = Descriptor :: new ( 0x1000 , 0x1000 , VRING_DESC_F_NEXT as u16 , 1 ) ;
300
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
301
+ 0x1000 ,
302
+ 0x1000 ,
303
+ VRING_DESC_F_NEXT as u16 ,
304
+ 1 ,
305
+ ) ) ;
295
306
vq. desc_table ( ) . store ( 0 , desc) . unwrap ( ) ;
296
307
297
- let desc = Descriptor :: new ( 0x2000 , 0x1000 , 0 , 0 ) ;
308
+ let desc = Descriptor :: from ( SplitDescriptor :: new ( 0x2000 , 0x1000 , 0 , 0 ) ) ;
298
309
vq. desc_table ( ) . store ( 1 , desc) . unwrap ( ) ;
299
310
300
311
let mut c = DescriptorChain :: < & GuestMemoryMmap > :: new ( m, vq. start ( ) , 16 , 0 ) ;
@@ -333,15 +344,15 @@ mod tests {
333
344
// Populate the entire descriptor table with entries. Only the last one should not have the
334
345
// VIRTQ_DESC_F_NEXT set.
335
346
for i in 0 ..QUEUE_SIZE - 1 {
336
- let desc = Descriptor :: new (
347
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
337
348
0x1000 * ( i + 1 ) as u64 ,
338
349
0x1000 ,
339
350
VRING_DESC_F_NEXT as u16 ,
340
351
i + 1 ,
341
- ) ;
352
+ ) ) ;
342
353
vq. desc_table ( ) . store ( i, desc) . unwrap ( ) ;
343
354
}
344
- let desc = Descriptor :: new ( ( 0x1000 * 16 ) as u64 , 0x1000 , 0 , 0 ) ;
355
+ let desc = Descriptor :: from ( SplitDescriptor :: new ( ( 0x1000 * 16 ) as u64 , 0x1000 , 0 , 0 ) ) ;
345
356
vq. desc_table ( ) . store ( QUEUE_SIZE - 1 , desc) . unwrap ( ) ;
346
357
347
358
let mut c = DescriptorChain :: < & GuestMemoryMmap > :: new ( m, vq. start ( ) , QUEUE_SIZE , 0 ) ;
@@ -366,18 +377,23 @@ mod tests {
366
377
let dtable = vq. desc_table ( ) ;
367
378
368
379
// Create a chain with one normal descriptor and one pointing to an indirect table.
369
- let desc = Descriptor :: new ( 0x6000 , 0x1000 , VRING_DESC_F_NEXT as u16 , 1 ) ;
380
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
381
+ 0x6000 ,
382
+ 0x1000 ,
383
+ VRING_DESC_F_NEXT as u16 ,
384
+ 1 ,
385
+ ) ) ;
370
386
dtable. store ( 0 , desc) . unwrap ( ) ;
371
387
// The spec forbids setting both VIRTQ_DESC_F_INDIRECT and VIRTQ_DESC_F_NEXT in flags. We do
372
388
// not currently enforce this rule, we just ignore the VIRTQ_DESC_F_NEXT flag.
373
- let desc = Descriptor :: new (
389
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
374
390
0x7000 ,
375
391
0x1000 ,
376
392
( VRING_DESC_F_INDIRECT | VRING_DESC_F_NEXT ) as u16 ,
377
393
2 ,
378
- ) ;
394
+ ) ) ;
379
395
dtable. store ( 1 , desc) . unwrap ( ) ;
380
- let desc = Descriptor :: new ( 0x8000 , 0x1000 , 0 , 0 ) ;
396
+ let desc = Descriptor :: from ( SplitDescriptor :: new ( 0x8000 , 0x1000 , 0 , 0 ) ) ;
381
397
dtable. store ( 2 , desc) . unwrap ( ) ;
382
398
383
399
let mut c: DescriptorChain < & GuestMemoryMmap > = DescriptorChain :: new ( m, vq. start ( ) , 16 , 0 ) ;
@@ -386,9 +402,14 @@ mod tests {
386
402
let idtable = DescriptorTable :: new ( m, GuestAddress ( 0x7000 ) , 4 ) ;
387
403
for i in 0 ..4u16 {
388
404
let desc: Descriptor = if i < 3 {
389
- Descriptor :: new ( 0x1000 * i as u64 , 0x1000 , VRING_DESC_F_NEXT as u16 , i + 1 )
405
+ Descriptor :: from ( SplitDescriptor :: new (
406
+ 0x1000 * i as u64 ,
407
+ 0x1000 ,
408
+ VRING_DESC_F_NEXT as u16 ,
409
+ i + 1 ,
410
+ ) )
390
411
} else {
391
- Descriptor :: new ( 0x1000 * i as u64 , 0x1000 , 0 , 0 )
412
+ Descriptor :: from ( SplitDescriptor :: new ( 0x1000 * i as u64 , 0x1000 , 0 , 0 ) )
392
413
} ;
393
414
idtable. store ( i, desc) . unwrap ( ) ;
394
415
}
@@ -423,12 +444,12 @@ mod tests {
423
444
let dtable = vq. desc_table ( ) ;
424
445
425
446
// Create a chain with a descriptor pointing to an indirect table with unaligned address.
426
- let desc = Descriptor :: new (
447
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
427
448
0x7001 ,
428
449
0x1000 ,
429
450
( VRING_DESC_F_INDIRECT | VRING_DESC_F_NEXT ) as u16 ,
430
451
2 ,
431
- ) ;
452
+ ) ) ;
432
453
dtable. store ( 0 , desc) . unwrap ( ) ;
433
454
434
455
let mut c: DescriptorChain < & GuestMemoryMmap > = DescriptorChain :: new ( m, vq. start ( ) , 16 , 0 ) ;
@@ -437,9 +458,14 @@ mod tests {
437
458
let idtable = DescriptorTable :: new ( m, GuestAddress ( 0x7001 ) , 4 ) ;
438
459
for i in 0 ..4u16 {
439
460
let desc: Descriptor = if i < 3 {
440
- Descriptor :: new ( 0x1000 * i as u64 , 0x1000 , VRING_DESC_F_NEXT as u16 , i + 1 )
461
+ Descriptor :: from ( SplitDescriptor :: new (
462
+ 0x1000 * i as u64 ,
463
+ 0x1000 ,
464
+ VRING_DESC_F_NEXT as u16 ,
465
+ i + 1 ,
466
+ ) )
441
467
} else {
442
- Descriptor :: new ( 0x1000 * i as u64 , 0x1000 , 0 , 0 )
468
+ Descriptor :: from ( SplitDescriptor :: new ( 0x1000 * i as u64 , 0x1000 , 0 , 0 ) )
443
469
} ;
444
470
idtable. store ( i, desc) . unwrap ( ) ;
445
471
}
@@ -465,7 +491,12 @@ mod tests {
465
491
466
492
// Create a chain with a descriptor pointing to an invalid indirect table: len not a
467
493
// multiple of descriptor size.
468
- let desc = Descriptor :: new ( 0x1000 , 0x1001 , VRING_DESC_F_INDIRECT as u16 , 0 ) ;
494
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
495
+ 0x1000 ,
496
+ 0x1001 ,
497
+ VRING_DESC_F_INDIRECT as u16 ,
498
+ 0 ,
499
+ ) ) ;
469
500
vq. desc_table ( ) . store ( 0 , desc) . unwrap ( ) ;
470
501
471
502
let mut c: DescriptorChain < & GuestMemoryMmap > =
@@ -480,12 +511,12 @@ mod tests {
480
511
481
512
// Create a chain with a descriptor pointing to an invalid indirect table: table len >
482
513
// u16::MAX.
483
- let desc = Descriptor :: new (
514
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
484
515
0x1000 ,
485
516
( u16:: MAX as u32 + 1 ) * VRING_DESC_ALIGN_SIZE ,
486
517
VRING_DESC_F_INDIRECT as u16 ,
487
518
0 ,
488
- ) ;
519
+ ) ) ;
489
520
vq. desc_table ( ) . store ( 0 , desc) . unwrap ( ) ;
490
521
491
522
let mut c: DescriptorChain < & GuestMemoryMmap > =
@@ -499,10 +530,15 @@ mod tests {
499
530
let vq = MockSplitQueue :: new ( m, 16 ) ;
500
531
501
532
// Create a chain with a descriptor pointing to an indirect table.
502
- let desc = Descriptor :: new ( 0x1000 , 0x1000 , VRING_DESC_F_INDIRECT as u16 , 0 ) ;
533
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
534
+ 0x1000 ,
535
+ 0x1000 ,
536
+ VRING_DESC_F_INDIRECT as u16 ,
537
+ 0 ,
538
+ ) ) ;
503
539
vq. desc_table ( ) . store ( 0 , desc) . unwrap ( ) ;
504
540
// It's ok for an indirect descriptor to have flags = 0.
505
- let desc = Descriptor :: new ( 0x3000 , 0x1000 , 0 , 0 ) ;
541
+ let desc = Descriptor :: from ( SplitDescriptor :: new ( 0x3000 , 0x1000 , 0 , 0 ) ) ;
506
542
m. write_obj ( desc, GuestAddress ( 0x1000 ) ) . unwrap ( ) ;
507
543
508
544
let mut c: DescriptorChain < & GuestMemoryMmap > =
@@ -511,7 +547,12 @@ mod tests {
511
547
512
548
// But it's not allowed to have an indirect descriptor that points to another indirect
513
549
// table.
514
- let desc = Descriptor :: new ( 0x3000 , 0x1000 , VRING_DESC_F_INDIRECT as u16 , 0 ) ;
550
+ let desc = Descriptor :: from ( SplitDescriptor :: new (
551
+ 0x3000 ,
552
+ 0x1000 ,
553
+ VRING_DESC_F_INDIRECT as u16 ,
554
+ 0 ,
555
+ ) ) ;
515
556
m. write_obj ( desc, GuestAddress ( 0x1000 ) ) . unwrap ( ) ;
516
557
517
558
let mut c: DescriptorChain < & GuestMemoryMmap > =
0 commit comments