@@ -308,6 +308,32 @@ 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+ {
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+ }
311337}
312338
313339/// An interface for setting up vhost-based backend drivers.
@@ -394,6 +420,17 @@ pub trait VhostBackendMut: std::marker::Sized {
394420 /// * `queue_index` - Index of the queue to modify.
395421 /// * `fd` - EventFd that will be signaled from guest.
396422 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 > ;
397434}
398435
399436impl < T : VhostBackendMut > VhostBackend for RwLock < T > {
@@ -454,6 +491,14 @@ impl<T: VhostBackendMut> VhostBackend for RwLock<T> {
454491 fn set_vring_err ( & self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > {
455492 self . write ( ) . unwrap ( ) . set_vring_err ( queue_index, fd)
456493 }
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+ }
457502}
458503
459504impl < T : VhostBackendMut > VhostBackend for RefCell < T > {
@@ -512,6 +557,14 @@ impl<T: VhostBackendMut> VhostBackend for RefCell<T> {
512557 fn set_vring_err ( & self , queue_index : usize , fd : & EventFd ) -> Result < ( ) > {
513558 self . borrow_mut ( ) . set_vring_err ( queue_index, fd)
514559 }
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+ }
515568}
516569
517570#[ cfg( any( test, feature = "test-utils" ) ) ]
@@ -543,7 +596,9 @@ impl VhostUserMemoryRegionInfo {
543596mod tests {
544597 use super :: * ;
545598
546- struct MockBackend { }
599+ struct MockBackend {
600+ status : u8 ,
601+ }
547602
548603 impl VhostBackendMut for MockBackend {
549604 fn get_features ( & mut self ) -> Result < u64 > {
@@ -625,11 +680,20 @@ mod tests {
625680 assert_eq ! ( queue_index, 1 ) ;
626681 Ok ( ( ) )
627682 }
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+ }
628692 }
629693
630694 #[ test]
631695 fn test_vring_backend_mut ( ) {
632- let b = RwLock :: new ( MockBackend { } ) ;
696+ let b = RwLock :: new ( MockBackend { status : 0 } ) ;
633697
634698 assert_eq ! ( b. get_features( ) . unwrap( ) , 0x1 ) ;
635699 b. set_features ( 0x1 ) . unwrap ( ) ;
0 commit comments