From 360980d93c8642fc886e9a64967bad045df4c8f4 Mon Sep 17 00:00:00 2001 From: Yang Zhong Date: Thu, 5 Sep 2019 15:39:57 +0800 Subject: [PATCH] vhost-user-blk: enable write_config for WCE In vhost-user-blk, only WCE value can be set back to device in guest kernel like echo "write through" > /sys/block/vda/cache_type So write_config() will only set WCE value from guest kernel to vhost user side. Signed-off-by: Yang Zhong --- vm-virtio/src/vhost_user/blk.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vm-virtio/src/vhost_user/blk.rs b/vm-virtio/src/vhost_user/blk.rs index e317bf076..f2d846526 100644 --- a/vm-virtio/src/vhost_user/blk.rs +++ b/vm-virtio/src/vhost_user/blk.rs @@ -61,6 +61,10 @@ impl<'a> Blk { | 1 << VIRTIO_F_VERSION_1 | VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits(); + if wce { + avail_features |= 1 << VIRTIO_BLK_F_CONFIG_WCE; + } + // Set vhost-user owner. vhost_user_blk .set_owner() @@ -190,8 +194,15 @@ impl VirtioDevice for Blk { error!("Failed to write config space"); return; } - let (_, right) = self.config_space.split_at_mut(offset as usize); - right.copy_from_slice(&data[..]); + // In fact, write_config() only handle wce value in vhost-user-blk. + // so, we can only set wce value here. + if self.config_space[offset as usize] == data[0] { + return; + } + self.vhost_user_blk + .set_config(offset as u32, VhostUserConfigFlags::WRITABLE, data) + .expect("Failed to set config"); + self.config_space[offset as usize] = data[0]; } fn activate(