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