Skip to content

Commit c4058d1

Browse files
committed
sq with vhost_user_blk
Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 2b26842 commit c4058d1

File tree

1 file changed

+20
-14
lines changed
  • src/vmm/src/devices/virtio/vhost_user_block

1 file changed

+20
-14
lines changed

src/vmm/src/devices/virtio/vhost_user_block/device.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,29 @@ impl VhostUserBlock {
137137

138138
let requested_protocol_features = VhostUserProtocolFeatures::CONFIG;
139139

140-
let mut vu = VhostUserHandle::new(&config.socket, NUM_QUEUES)
140+
let mut vu_handle = VhostUserHandle::new(&config.socket, NUM_QUEUES)
141141
.map_err(VhostUserBlockError::VhostUser)?;
142-
let (acked_features, acked_protocol_features) = vu
142+
let (acked_features, acked_protocol_features) = vu_handle
143143
.negotiate_features(requested_features, requested_protocol_features)
144144
.map_err(VhostUserBlockError::VhostUser)?;
145145

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+
};
157163

158164
let activate_evt =
159165
EventFd::new(libc::EFD_NONBLOCK).map_err(VhostUserBlockError::EventFd)?;
@@ -187,7 +193,7 @@ impl VhostUserBlock {
187193
read_only,
188194
root_device: config.is_root_device,
189195

190-
vu_handle: vu,
196+
vu_handle,
191197
vu_acked_protocol_features: acked_protocol_features,
192198
})
193199
}

0 commit comments

Comments
 (0)