@@ -308,6 +308,30 @@ pub trait VhostBackend: std::marker::Sized {
308
308
/// * `queue_index` - Index of the queue to modify.
309
309
/// * `fd` - EventFd that will be signaled from guest.
310
310
fn set_vring_err ( & self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > ;
311
+
312
+ /// Set the status.
313
+ /// The status bits follow the same definition of the device
314
+ /// status defined in virtio-spec.
315
+ ///
316
+ /// As not all backends can implement this we provide a default
317
+ /// implementation that returns an Error.
318
+ ///
319
+ /// # Arguments
320
+ /// * `status` - Status bits to set
321
+ fn set_status ( & self , _status : u8 ) -> Result < ( ) > {
322
+ Err ( Error :: InvalidOperation )
323
+ }
324
+
325
+ /// Get the status.
326
+ ///
327
+ /// The status bits follow the same definition of the device
328
+ /// status defined in virtio-spec.
329
+ ///
330
+ /// As not all backends can implement this we provide a default
331
+ /// implementation that returns an Error.
332
+ fn get_status ( & self ) -> Result < u8 > {
333
+ Err ( Error :: InvalidOperation )
334
+ }
311
335
}
312
336
313
337
/// An interface for setting up vhost-based backend drivers.
@@ -394,6 +418,17 @@ pub trait VhostBackendMut: std::marker::Sized {
394
418
/// * `queue_index` - Index of the queue to modify.
395
419
/// * `fd` - EventFd that will be signaled from guest.
396
420
fn set_vring_err ( & mut self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > ;
421
+
422
+ /// Set the status.
423
+ /// The status bits follow the same definition of the device status defined in virtio-spec.
424
+ ///
425
+ /// # Arguments
426
+ /// * `status` - Status bits to set
427
+ fn set_status ( & mut self , status : u8 ) -> Result < ( ) > ;
428
+
429
+ /// Get the status.
430
+ /// The status bits follow the same definition of the device status defined in virtio-spec.
431
+ fn get_status ( & self ) -> Result < u8 > ;
397
432
}
398
433
399
434
impl < T : VhostBackendMut > VhostBackend for RwLock < T > {
@@ -454,6 +489,14 @@ impl<T: VhostBackendMut> VhostBackend for RwLock<T> {
454
489
fn set_vring_err ( & self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > {
455
490
self . write ( ) . unwrap ( ) . set_vring_err ( queue_index, fd)
456
491
}
492
+
493
+ fn set_status ( & self , status : u8 ) -> Result < ( ) > {
494
+ self . write ( ) . unwrap ( ) . set_status ( status)
495
+ }
496
+
497
+ fn get_status ( & self ) -> Result < u8 > {
498
+ self . write ( ) . unwrap ( ) . get_status ( )
499
+ }
457
500
}
458
501
459
502
impl < T : VhostBackendMut > VhostBackend for RefCell < T > {
@@ -512,6 +555,14 @@ impl<T: VhostBackendMut> VhostBackend for RefCell<T> {
512
555
fn set_vring_err ( & self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > {
513
556
self . borrow_mut ( ) . set_vring_err ( queue_index, fd)
514
557
}
558
+
559
+ fn set_status ( & self , status : u8 ) -> Result < ( ) > {
560
+ self . borrow_mut ( ) . set_status ( status)
561
+ }
562
+
563
+ fn get_status ( & self ) -> Result < u8 > {
564
+ self . borrow_mut ( ) . get_status ( )
565
+ }
515
566
}
516
567
517
568
#[ cfg( any( test, feature = "test-utils" ) ) ]
@@ -543,7 +594,9 @@ impl VhostUserMemoryRegionInfo {
543
594
mod tests {
544
595
use super :: * ;
545
596
546
- struct MockBackend { }
597
+ struct MockBackend {
598
+ status : u8 ,
599
+ }
547
600
548
601
impl VhostBackendMut for MockBackend {
549
602
fn get_features ( & mut self ) -> Result < u64 > {
@@ -625,11 +678,20 @@ mod tests {
625
678
assert_eq ! ( queue_index, 1 ) ;
626
679
Ok ( ( ) )
627
680
}
681
+
682
+ fn set_status ( & mut self , status : u8 ) -> Result < ( ) > {
683
+ self . status = status;
684
+ Ok ( ( ) )
685
+ }
686
+
687
+ fn get_status ( & self ) -> Result < u8 > {
688
+ Ok ( self . status )
689
+ }
628
690
}
629
691
630
692
#[ test]
631
693
fn test_vring_backend_mut ( ) {
632
- let b = RwLock :: new ( MockBackend { } ) ;
694
+ let b = RwLock :: new ( MockBackend { status : 0 } ) ;
633
695
634
696
assert_eq ! ( b. get_features( ) . unwrap( ) , 0x1 ) ;
635
697
b. set_features ( 0x1 ) . unwrap ( ) ;
0 commit comments