QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] vhost-user-blk: reset the device if supported
@ 2020-01-10 12:22 Yang Zhong
  2020-01-14 16:33 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Zhong @ 2020-01-10 12:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: yang.zhong, pbonzini, stefanha, mst

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.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
---
 hw/block/vhost-user-blk.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 63da9bb619..16ddc9b70c 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -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)
-- 
2.17.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] vhost-user-blk: reset the device if supported
  2020-01-10 12:22 [PATCH] vhost-user-blk: reset the device if supported Yang Zhong
@ 2020-01-14 16:33 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2020-01-14 16:33 UTC (permalink / raw)
  To: Yang Zhong; +Cc: pbonzini, qemu-devel, stefanha, mst

[-- Attachment #1: Type: text/plain, Size: 2151 bytes --]

On Fri, Jan 10, 2020 at 08:22:03PM +0800, Yang Zhong wrote:
> 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.
> 
> Signed-off-by: Yang Zhong <yang.zhong@intel.com>
> ---
>  hw/block/vhost-user-blk.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index 63da9bb619..16ddc9b70c 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -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.

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

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-10 12:22 [PATCH] vhost-user-blk: reset the device if supported Yang Zhong
2020-01-14 16:33 ` Stefan Hajnoczi

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git