@@ -13,7 +13,7 @@ use log::error;
13
13
use utils:: eventfd:: EventFd ;
14
14
use utils:: u64_to_usize;
15
15
use vhost:: vhost_user:: message:: * ;
16
- use vhost:: vhost_user:: VhostUserMaster ;
16
+ use vhost:: vhost_user:: Master ;
17
17
18
18
use super :: { VhostUserBlockError , NUM_QUEUES , QUEUE_SIZE } ;
19
19
use crate :: devices:: virtio:: block_common:: CacheType ;
@@ -23,7 +23,8 @@ use crate::devices::virtio::gen::virtio_blk::{
23
23
} ;
24
24
use crate :: devices:: virtio:: gen:: virtio_ring:: VIRTIO_RING_F_EVENT_IDX ;
25
25
use crate :: devices:: virtio:: queue:: Queue ;
26
- use crate :: devices:: virtio:: vhost_user:: VhostUserHandle ;
26
+ use crate :: devices:: virtio:: vhost_user:: VhostUserHandleBackend ;
27
+ use crate :: devices:: virtio:: vhost_user:: VhostUserHandleImpl ;
27
28
use crate :: devices:: virtio:: { ActivateError , TYPE_BLOCK } ;
28
29
use crate :: logger:: { IncMetric , METRICS } ;
29
30
use crate :: vmm_config:: drive:: BlockDeviceConfig ;
@@ -93,9 +94,10 @@ impl From<VhostUserBlockConfig> for BlockDeviceConfig {
93
94
}
94
95
}
95
96
97
+ pub type VhostUserBlock = VhostUserBlockImpl < Master > ;
98
+
96
99
/// vhost-user block device.
97
- #[ derive( Debug ) ]
98
- pub struct VhostUserBlock {
100
+ pub struct VhostUserBlockImpl < T : VhostUserHandleBackend > {
99
101
// Virtio fields.
100
102
pub avail_features : u64 ,
101
103
pub acked_features : u64 ,
@@ -116,11 +118,37 @@ pub struct VhostUserBlock {
116
118
pub read_only : bool ,
117
119
118
120
// Vhost user protocol handle
119
- pub vu_handle : VhostUserHandle ,
121
+ pub vu_handle : VhostUserHandleImpl < T > ,
120
122
pub vu_acked_protocol_features : u64 ,
121
123
}
122
124
123
- impl VhostUserBlock {
125
+ // Need custom implementation because otherwise `Debug` is required for `vhost::Master`
126
+ impl < T : VhostUserHandleBackend > std:: fmt:: Debug for VhostUserBlockImpl < T > {
127
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
128
+ f. debug_struct ( "VhostUserBlockImpl" )
129
+ . field ( "avail_features" , & self . avail_features )
130
+ . field ( "acked_features" , & self . acked_features )
131
+ . field ( "config_space" , & self . config_space )
132
+ . field ( "activate_evt" , & self . activate_evt )
133
+ . field ( "queues" , & self . queues )
134
+ . field ( "queue_evts" , & self . queue_evts )
135
+ . field ( "device_state" , & self . device_state )
136
+ . field ( "irq_trigger" , & self . irq_trigger )
137
+ . field ( "id" , & self . id )
138
+ . field ( "partuuid" , & self . partuuid )
139
+ . field ( "cache_type" , & self . cache_type )
140
+ . field ( "root_device" , & self . root_device )
141
+ . field ( "read_only" , & self . read_only )
142
+ . field ( "vu_handle" , & self . vu_handle )
143
+ . field (
144
+ "vu_acked_protocol_features" ,
145
+ & self . vu_acked_protocol_features ,
146
+ )
147
+ . finish ( )
148
+ }
149
+ }
150
+
151
+ impl < T : VhostUserHandleBackend > VhostUserBlockImpl < T > {
124
152
pub fn new ( config : VhostUserBlockConfig ) -> Result < Self , VhostUserBlockError > {
125
153
let mut requested_features = ( 1 << VIRTIO_F_VERSION_1 )
126
154
| ( 1 << VIRTIO_RING_F_EVENT_IDX )
@@ -137,7 +165,7 @@ impl VhostUserBlock {
137
165
138
166
let requested_protocol_features = VhostUserProtocolFeatures :: CONFIG ;
139
167
140
- let mut vu_handle = VhostUserHandle :: new ( & config. socket , NUM_QUEUES )
168
+ let mut vu_handle = VhostUserHandleImpl :: < T > :: new ( & config. socket , NUM_QUEUES )
141
169
. map_err ( VhostUserBlockError :: VhostUser ) ?;
142
170
let ( acked_features, acked_protocol_features) = vu_handle
143
171
. negotiate_features ( requested_features, requested_protocol_features)
0 commit comments