Patchwork [RFC,04/13] virtio-blk: implement BlockDevOps->drain_threads_cb()

login
register
mail settings
Submitter Stefan Hajnoczi
Date June 14, 2013, 9:48 a.m.
Message ID <1371203313-26490-5-git-send-email-stefanha@redhat.com>
Download mbox | patch
Permalink /patch/251311/
State New
Headers show

Comments

Stefan Hajnoczi - June 14, 2013, 9:48 a.m.
Drain and stop the dataplane thread when bdrv_drain_all() is called.
Note that the thread will be restarted in virtio_blk_handle_output() the
next time the guest kicks the virtqueue.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/block/virtio-blk.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Paolo Bonzini - June 14, 2013, 2:23 p.m.
Il 14/06/2013 05:48, Stefan Hajnoczi ha scritto:
> Drain and stop the dataplane thread when bdrv_drain_all() is called.
> Note that the thread will be restarted in virtio_blk_handle_output() the
> next time the guest kicks the virtqueue.

Long term I still think we want to move towards

    aio_lock(bs)
    bdrv_drain(bs)
    ...
    aio_unlock(bs)

but this approach works well at this point.  It is a hack, but a very
smart one. :)

Add a comment in the code about what will start the dataplane thread,
though.

Paolo

> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  hw/block/virtio-blk.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index cf12469..f9c2b79 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -618,8 +618,20 @@ static void virtio_blk_resize(void *opaque)
>      virtio_notify_config(vdev);
>  }
>  
> +static void virtio_blk_drain_threads(void *opaque)
> +{
> +#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
> +    VirtIOBlock *s = VIRTIO_BLK(opaque);
> +
> +    if (s->dataplane) {
> +        virtio_blk_data_plane_stop(s->dataplane);
> +    }
> +#endif
> +}
> +
>  static const BlockDevOps virtio_block_ops = {
>      .resize_cb = virtio_blk_resize,
> +    .drain_threads_cb = virtio_blk_drain_threads,
>  };
>  
>  void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
>

Patch

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index cf12469..f9c2b79 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -618,8 +618,20 @@  static void virtio_blk_resize(void *opaque)
     virtio_notify_config(vdev);
 }
 
+static void virtio_blk_drain_threads(void *opaque)
+{
+#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
+    VirtIOBlock *s = VIRTIO_BLK(opaque);
+
+    if (s->dataplane) {
+        virtio_blk_data_plane_stop(s->dataplane);
+    }
+#endif
+}
+
 static const BlockDevOps virtio_block_ops = {
     .resize_cb = virtio_blk_resize,
+    .drain_threads_cb = virtio_blk_drain_threads,
 };
 
 void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)