Skip to content

Commit 3bf54e7

Browse files
author
Dorinda Bassey
committed
devices/vhost: Implement write_config for dynamic config
Implement write_config in VhostUserDevice to support virtio devices that use dynamic configuration space, such as virtio-input. Some virtio devices like virtio-input use a request-response pattern for device discovery. Without write_config support, the backend never receives the virtio_input config values, causing device initialization to fail. This implementation uses VHOST_USER_SET_CONFIG to forward writes to the backend. Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
1 parent c429631 commit 3bf54e7

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

src/devices/src/virtio/vhost_user/device.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,33 @@ impl VirtioDevice for VhostUserDevice {
393393
data.fill(0);
394394
}
395395

396-
fn write_config(&mut self, offset: u64, _data: &[u8]) {
397-
// For now, configuration space writes are not supported
398-
// This can be extended using VHOST_USER_SET_CONFIG
399-
debug!(
400-
"{}: config write at offset {} (not yet implemented)",
401-
self.device_name, offset
402-
);
396+
fn write_config(&mut self, offset: u64, data: &[u8]) {
397+
if !self.has_protocol_features {
398+
debug!(
399+
"{}: config write at offset {} skipped (no protocol features)",
400+
self.device_name, offset
401+
);
402+
return;
403+
}
404+
405+
if let Ok(mut frontend) = self.frontend.lock() {
406+
match frontend.set_config(offset as u32, VhostUserConfigFlags::empty(), data) {
407+
Ok(_) => {
408+
debug!(
409+
"{}: wrote {} bytes to config at offset {}",
410+
self.device_name,
411+
data.len(),
412+
offset
413+
);
414+
}
415+
Err(e) => {
416+
warn!(
417+
"{}: failed to write config at offset {}: {:?}",
418+
self.device_name, offset, e
419+
);
420+
}
421+
}
422+
}
403423
}
404424

405425
fn activate(

0 commit comments

Comments
 (0)