@@ -308,6 +308,30 @@ pub trait VhostBackend: std::marker::Sized {
308308 /// * `queue_index` - Index of the queue to modify.
309309 /// * `fd` - EventFd that will be signaled from guest.
310310 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+ }
311335}
312336
313337/// An interface for setting up vhost-based backend drivers.
@@ -394,6 +418,17 @@ pub trait VhostBackendMut: std::marker::Sized {
394418 /// * `queue_index` - Index of the queue to modify.
395419 /// * `fd` - EventFd that will be signaled from guest.
396420 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 > ;
397432}
398433
399434impl < T : VhostBackendMut > VhostBackend for RwLock < T > {
@@ -454,6 +489,14 @@ impl<T: VhostBackendMut> VhostBackend for RwLock<T> {
454489 fn set_vring_err ( & self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > {
455490 self . write ( ) . unwrap ( ) . set_vring_err ( queue_index, fd)
456491 }
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+ }
457500}
458501
459502impl < T : VhostBackendMut > VhostBackend for RefCell < T > {
@@ -512,6 +555,14 @@ impl<T: VhostBackendMut> VhostBackend for RefCell<T> {
512555 fn set_vring_err ( & self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > {
513556 self . borrow_mut ( ) . set_vring_err ( queue_index, fd)
514557 }
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+ }
515566}
516567
517568#[ cfg( any( test, feature = "test-utils" ) ) ]
@@ -543,7 +594,9 @@ impl VhostUserMemoryRegionInfo {
543594mod tests {
544595 use super :: * ;
545596
546- struct MockBackend { }
597+ struct MockBackend {
598+ status : u8 ,
599+ }
547600
548601 impl VhostBackendMut for MockBackend {
549602 fn get_features ( & mut self ) -> Result < u64 > {
@@ -625,11 +678,20 @@ mod tests {
625678 assert_eq ! ( queue_index, 1 ) ;
626679 Ok ( ( ) )
627680 }
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+ }
628690 }
629691
630692 #[ test]
631693 fn test_vring_backend_mut ( ) {
632- let b = RwLock :: new ( MockBackend { } ) ;
694+ let b = RwLock :: new ( MockBackend { status : 0 } ) ;
633695
634696 assert_eq ! ( b. get_features( ) . unwrap( ) , 0x1 ) ;
635697 b. set_features ( 0x1 ) . unwrap ( ) ;
0 commit comments