@@ -137,23 +137,29 @@ impl VhostUserBlock {
137
137
138
138
let requested_protocol_features = VhostUserProtocolFeatures :: CONFIG ;
139
139
140
- let mut vu = VhostUserHandle :: new ( & config. socket , NUM_QUEUES )
140
+ let mut vu_handle = VhostUserHandle :: new ( & config. socket , NUM_QUEUES )
141
141
. map_err ( VhostUserBlockError :: VhostUser ) ?;
142
- let ( acked_features, acked_protocol_features) = vu
142
+ let ( acked_features, acked_protocol_features) = vu_handle
143
143
. negotiate_features ( requested_features, requested_protocol_features)
144
144
. map_err ( VhostUserBlockError :: VhostUser ) ?;
145
145
146
- // Buffer only used for size checks.
147
- let buffer = [ 0u8 ; BLOCK_CONFIG_SPACE_SIZE as usize ] ;
148
- let ( _, config_space) = vu
149
- . socket_handle ( )
150
- . get_config (
151
- VHOST_USER_CONFIG_OFFSET ,
152
- BLOCK_CONFIG_SPACE_SIZE ,
153
- VhostUserConfigFlags :: WRITABLE ,
154
- & buffer,
155
- )
156
- . map_err ( VhostUserBlockError :: Vhost ) ?;
146
+ // Get config from backend if CONFIG is acked or use empty buffer.
147
+ let config_space = if acked_protocol_features & VhostUserProtocolFeatures :: CONFIG != 0 {
148
+ // This buffer is read only. Ask vhost implementation why.
149
+ let buffer = [ 0u8 ; BLOCK_CONFIG_SPACE_SIZE as usize ] ;
150
+ let ( _, new_config_space) = vu_handle
151
+ . vu
152
+ . get_config (
153
+ VHOST_USER_CONFIG_OFFSET ,
154
+ BLOCK_CONFIG_SPACE_SIZE ,
155
+ VhostUserConfigFlags :: WRITABLE ,
156
+ & buffer,
157
+ )
158
+ . map_err ( VhostUserBlockError :: Vhost ) ?;
159
+ new_config_space
160
+ } else {
161
+ vec ! [ ]
162
+ } ;
157
163
158
164
let activate_evt =
159
165
EventFd :: new ( libc:: EFD_NONBLOCK ) . map_err ( VhostUserBlockError :: EventFd ) ?;
@@ -187,7 +193,7 @@ impl VhostUserBlock {
187
193
read_only,
188
194
root_device : config. is_root_device ,
189
195
190
- vu_handle : vu ,
196
+ vu_handle,
191
197
vu_acked_protocol_features : acked_protocol_features,
192
198
} )
193
199
}
0 commit comments