Skip to contentSkip to conversation

vhost-user-blk: reset the device if supported

PATCH In review Yang Zhong 2 participants 2 messages Jan 10, 2020 – Jan 14, 2020

lore
Share & tools
lore

Yang Zhong

author
#0 lore raw

PATCH 1/1 vhost-user-blk: reset the device if supported

As the vhost-user-scsi did in f04724, if the vhost-user-blk backend supports the VHOST_USER_F_RESET_DEVICE protocol feature, then the device can be reset when requested.

If this feature is not supported, this reset will directly return.

---
 hw/block/vhost-user-blk.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
hw/block/vhost-user-blk.c +19 -0
index 63da9bb619..16ddc9b70c 100644
@@ -50,6 +50,10 @@ static const int user_feature_bits[] = {
     VHOST_INVALID_FEATURE_BIT
 };
 
+enum VhostUserProtocolFeature {
+    VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
+};
+
 static void vhost_user_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
@@ -290,8 +294,23 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 static void vhost_user_blk_reset(VirtIODevice *vdev)
 {
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
+    struct vhost_dev *dev = &s->dev;
 
     vhost_dev_free_inflight(s->inflight);
+
+    /*
+     * Historically, reset was not implemented so only reset devices
+     * that are expecting it.
+     */
+    if (!virtio_has_feature(dev->protocol_features,
+                            VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
+        return;
+    }
+
+    if (dev->vhost_ops->vhost_reset_device) {
+        dev->vhost_ops->vhost_reset_device(dev);
+    }
+
 }
 
 static int vhost_user_blk_connect(DeviceState *dev)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Yang Zhong

As the vhost-user-scsi did in f04724, if the vhost-user-blk backend supports the VHOST_USER_F_RESET_DEVICE protocol feature, then the device can be reset when requested.

If this feature is not supported, this reset will directly return.

---
 hw/block/vhost-user-blk.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
hw/block/vhost-user-blk.c +0 -0
index 63da9bb619..16ddc9b70c 100644

hw/block/vhost-user-blk.c static const int user_feature_bits[] = { · line 55

Quoted 6 lines
hw/block/vhost-user-blk.c +3 -0
@@ -50,6 +50,10 @@ static const int user_feature_bits[] = {
     VHOST_INVALID_FEATURE_BIT
 };
 
+enum VhostUserProtocolFeature {
+    VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
+};

vhost-user protocol constants should be defined in hw/virtio/vhost-user.h and not duplicated in device implementations.

Quoted 16 lines
hw/block/vhost-user-blk.c +7 -0
+
 static void vhost_user_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
@@ -290,8 +294,23 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 static void vhost_user_blk_reset(VirtIODevice *vdev)
 {
     VHostUserBlk *s = VHOST_USER_BLK(vdev);
+    struct vhost_dev *dev = &s->dev;
 
     vhost_dev_free_inflight(s->inflight);
+
+    /*
+     * Historically, reset was not implemented so only reset devices
+     * that are expecting it.
+     */

hw/block/vhost-user-blk.c static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) · line 314

Quoted 10 lines
hw/block/vhost-user-blk.c +9 -0
+    if (!virtio_has_feature(dev->protocol_features,
+                            VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
+        return;
+    }
+
+    if (dev->vhost_ops->vhost_reset_device) {
+        dev->vhost_ops->vhost_reset_device(dev);
+    }
+
 }

This should be a generic protocol feature that all vhost-user device implementations benefit from. Devices shouldn't have to explicitly implement it over and over again.

Why isn't vhost_user_reset_device() called already? Then it wouldn't be necessary to modify vhost_user_blk_reset().

Stefan