[PATCH 2/2] vhost-use-blk: convert to new virtio_delete_queue

pannengyuan@huawei.com posted 2 patches 5 years, 12 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Max Reitz <mreitz@redhat.com>
There is a newer version of this series
[PATCH 2/2] vhost-use-blk: convert to new virtio_delete_queue
Posted by pannengyuan@huawei.com 5 years, 12 months ago
From: Pan Nengyuan <pannengyuan@huawei.com>

use the new virtio_delete_queue function to cleanup.

Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
---
 hw/block/vhost-user-blk.c          | 11 +++++++----
 include/hw/virtio/vhost-user-blk.h |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 2eba8b9db0..ed6a5cc03b 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -420,9 +420,10 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
     virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
                 sizeof(struct virtio_blk_config));
 
+    s->virtqs = g_new0(VirtQueue *, s->num_queues);
     for (i = 0; i < s->num_queues; i++) {
-        virtio_add_queue(vdev, s->queue_size,
-                         vhost_user_blk_handle_output);
+        s->virtqs[i] = virtio_add_queue(vdev, s->queue_size,
+                                        vhost_user_blk_handle_output);
     }
 
     s->inflight = g_new0(struct vhost_inflight, 1);
@@ -461,8 +462,9 @@ virtio_err:
     g_free(s->vqs);
     g_free(s->inflight);
     for (i = 0; i < s->num_queues; i++) {
-        virtio_del_queue(vdev, i);
+        virtio_delete_queue(s->virtqs[i]);
     }
+    g_free(s->virtqs);
     virtio_cleanup(vdev);
     vhost_user_cleanup(&s->vhost_user);
 }
@@ -482,8 +484,9 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
     g_free(s->inflight);
 
     for (i = 0; i < s->num_queues; i++) {
-        virtio_del_queue(vdev, i);
+        virtio_delete_queue(s->virtqs[i]);
     }
+    g_free(s->virtqs);
     virtio_cleanup(vdev);
     vhost_user_cleanup(&s->vhost_user);
 }
diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h
index 108bfadeeb..f68911f6f0 100644
--- a/include/hw/virtio/vhost-user-blk.h
+++ b/include/hw/virtio/vhost-user-blk.h
@@ -37,6 +37,7 @@ typedef struct VHostUserBlk {
     struct vhost_inflight *inflight;
     VhostUserState vhost_user;
     struct vhost_virtqueue *vqs;
+    VirtQueue **virtqs;
     guint watch;
     bool connected;
 } VHostUserBlk;
-- 
2.21.0.windows.1



Re: [PATCH 2/2] vhost-use-blk: convert to new virtio_delete_queue
Posted by Michael S. Tsirkin 5 years, 11 months ago
On Thu, Feb 13, 2020 at 09:28:07AM +0800, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
> 
> use the new virtio_delete_queue function to cleanup.
> 
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>

typo in subject use-blk->user-blk


> ---
>  hw/block/vhost-user-blk.c          | 11 +++++++----
>  include/hw/virtio/vhost-user-blk.h |  1 +
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index 2eba8b9db0..ed6a5cc03b 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -420,9 +420,10 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
>      virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
>                  sizeof(struct virtio_blk_config));
>  
> +    s->virtqs = g_new0(VirtQueue *, s->num_queues);
>      for (i = 0; i < s->num_queues; i++) {
> -        virtio_add_queue(vdev, s->queue_size,
> -                         vhost_user_blk_handle_output);
> +        s->virtqs[i] = virtio_add_queue(vdev, s->queue_size,
> +                                        vhost_user_blk_handle_output);
>      }
>  
>      s->inflight = g_new0(struct vhost_inflight, 1);
> @@ -461,8 +462,9 @@ virtio_err:
>      g_free(s->vqs);
>      g_free(s->inflight);
>      for (i = 0; i < s->num_queues; i++) {
> -        virtio_del_queue(vdev, i);
> +        virtio_delete_queue(s->virtqs[i]);
>      }
> +    g_free(s->virtqs);
>      virtio_cleanup(vdev);
>      vhost_user_cleanup(&s->vhost_user);
>  }
> @@ -482,8 +484,9 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
>      g_free(s->inflight);
>  
>      for (i = 0; i < s->num_queues; i++) {
> -        virtio_del_queue(vdev, i);
> +        virtio_delete_queue(s->virtqs[i]);
>      }
> +    g_free(s->virtqs);
>      virtio_cleanup(vdev);
>      vhost_user_cleanup(&s->vhost_user);
>  }
> diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h
> index 108bfadeeb..f68911f6f0 100644
> --- a/include/hw/virtio/vhost-user-blk.h
> +++ b/include/hw/virtio/vhost-user-blk.h
> @@ -37,6 +37,7 @@ typedef struct VHostUserBlk {
>      struct vhost_inflight *inflight;
>      VhostUserState vhost_user;
>      struct vhost_virtqueue *vqs;
> +    VirtQueue **virtqs;
>      guint watch;
>      bool connected;
>  } VHostUserBlk;
> -- 
> 2.21.0.windows.1
> 


Re: [PATCH 2/2] vhost-use-blk: convert to new virtio_delete_queue
Posted by Stefan Hajnoczi 5 years, 11 months ago
On Thu, Feb 13, 2020 at 09:28:07AM +0800, pannengyuan@huawei.com wrote:
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index 2eba8b9db0..ed6a5cc03b 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -420,9 +420,10 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
>      virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
>                  sizeof(struct virtio_blk_config));
>  
> +    s->virtqs = g_new0(VirtQueue *, s->num_queues);

Minor point, up to you if you want to change it: the array is fully
initialized by the for loop in the next line.  There is no need to clear
the memory first:

s/g_new0/g_new/

> diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h
> index 108bfadeeb..f68911f6f0 100644
> --- a/include/hw/virtio/vhost-user-blk.h
> +++ b/include/hw/virtio/vhost-user-blk.h
> @@ -37,6 +37,7 @@ typedef struct VHostUserBlk {
>      struct vhost_inflight *inflight;
>      VhostUserState vhost_user;
>      struct vhost_virtqueue *vqs;
> +    VirtQueue **virtqs;

Both vqs and virtqs exist and are easily confused.  Please rename vqs to
vhost_vqs.
Re: [PATCH 2/2] vhost-use-blk: convert to new virtio_delete_queue
Posted by Pan Nengyuan 5 years, 11 months ago

On 2/21/2020 7:31 PM, Stefan Hajnoczi wrote:
> On Thu, Feb 13, 2020 at 09:28:07AM +0800, pannengyuan@huawei.com wrote:
>> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
>> index 2eba8b9db0..ed6a5cc03b 100644
>> --- a/hw/block/vhost-user-blk.c
>> +++ b/hw/block/vhost-user-blk.c
>> @@ -420,9 +420,10 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
>>      virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
>>                  sizeof(struct virtio_blk_config));
>>  
>> +    s->virtqs = g_new0(VirtQueue *, s->num_queues);
> 
> Minor point, up to you if you want to change it: the array is fully
> initialized by the for loop in the next line.  There is no need to clear
> the memory first:
> 
> s/g_new0/g_new/
OK, it's fine, I will change it.

Thanks.

> 
>> diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h
>> index 108bfadeeb..f68911f6f0 100644
>> --- a/include/hw/virtio/vhost-user-blk.h
>> +++ b/include/hw/virtio/vhost-user-blk.h
>> @@ -37,6 +37,7 @@ typedef struct VHostUserBlk {
>>      struct vhost_inflight *inflight;
>>      VhostUserState vhost_user;
>>      struct vhost_virtqueue *vqs;
>> +    VirtQueue **virtqs;
> 
> Both vqs and virtqs exist and are easily confused.  Please rename vqs to
> vhost_vqs.

OK, I will do it.

Thanks.

>