Skip to contentSkip to conversation

Two virtio-blk fixes

PATCH Superseded Fam Zheng 3 participants 7 messages Aug 2, 2016 – Aug 4, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v2 cover Two virtio-blk fixes

v2: Patch 1: address Paolo's comment to move the dropping code to below
blk_drain().
Patch 2: add Laszlo's r-b.

Fam Zheng (2):
virtio-blk: Release s->rq queue at system_reset
virtio-blk: Remove stale comment about draining

 hw/block/virtio-blk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/2 virtio-blk: Release s->rq queue at system_reset

At system_reset, there is no point in retrying the queued request, because the driver that issued the request won't be around any more.

---
 hw/block/virtio-blk.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/block/virtio-blk.c +6 -0
index 475a822..12587d9 100644
@@ -654,6 +654,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
     AioContext *ctx;
+    VirtIOBlockReq *req;
 
     /*
      * This should cancel pending requests, but can't do nicely until there
@@ -662,6 +663,11 @@ static void virtio_blk_reset(VirtIODevice *vdev)
     ctx = blk_get_aio_context(s->blk);
     aio_context_acquire(ctx);
     blk_drain(s->blk);
+    while (s->rq) {
+        req = s->rq;
+        s->rq = req->next;
+        virtio_blk_free_request(req);
+    }
 
     if (s->dataplane) {
         virtio_blk_data_plane_stop(s->dataplane);
Signature · 1 line
2.7.4
Reviewed-by on v2 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio-blk: Release s->rq queue at system_reset

Quoted 25 lines · Fam Zheng

At system_reset, there is no point in retrying the queued request, because the driver that issued the request won't be around any more.

---
 hw/block/virtio-blk.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/block/virtio-blk.c +1 -0
index 475a822..12587d9 100644
@@ -654,6 +654,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
     AioContext *ctx;
+    VirtIOBlockReq *req;
 
     /*
      * This should cancel pending requests, but can't do nicely until there
@@ -662,6 +663,11 @@ static void virtio_blk_reset(VirtIODevice *vdev)
     ctx = blk_get_aio_context(s->blk);

hw/block/virtio-blk.c static void virtio_blk_reset(VirtIODevice *vdev) · line 673

Quoted 10 lines
hw/block/virtio-blk.c +5 -0
     aio_context_acquire(ctx);
     blk_drain(s->blk);
+    while (s->rq) {
+        req = s->rq;
+        s->rq = req->next;
+        virtio_blk_free_request(req);
+    }
 
     if (s->dataplane) {
         virtio_blk_data_plane_stop(s->dataplane);

I'd prefer if Paolo's remark (about blk_drain()'s ability to produce more failed requests, stashed in s->rq) were captured in either the commit message, or in a code comment. Something like:

/* We drop queued requests after blk_drain() because blk_drain()
* itself can produce them. */

What do you think? It's your call. I certainly lacked that bit of information.

Thanks!
Laszlo

#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio-blk: Release s->rq queue at system_reset

Quoted 7 lines

I'd prefer if Paolo's remark (about blk_drain()'s ability to produce more failed requests, stashed in s->rq) were captured in either the commit message, or in a code comment. Something like:

/* We drop queued requests after blk_drain() because blk_drain()
* itself can produce them. */

It's also (perhaps especially) because blk_drain() can consume them. Fam's patch to do blk_drain() first would cause a double-free.

Paolo

Quoted 8 lines

What do you think? It's your call. I certainly lacked that bit of information.

Thanks!
Laszlo

author
#4 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio-blk: Release s->rq queue at system_reset

Quoted 10 lines · Paolo Bonzini
Quoted 7 lines

I'd prefer if Paolo's remark (about blk_drain()'s ability to produce more failed requests, stashed in s->rq) were captured in either the commit message, or in a code comment. Something like:

/* We drop queued requests after blk_drain() because blk_drain()
* itself can produce them. */

It's also (perhaps especially) because blk_drain() can consume them. Fam's patch to do blk_drain() first would cause a double-free.

That "consume" part is what I don't understand.

Shouldn't blk_drain() only process submitted requests (and further requests they dequeue indirectly), while s->rq only contains failed requests. They don't look overlap, because I suppose failed requests are only going to be processed by run state change.

What am I missing?

Fam

#5 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] virtio-blk: Release s->rq queue at system_reset

Quoted 6 lines · Fam Zheng
Quoted 2 lines
Quoted 2 lines

It's also (perhaps especially) because blk_drain() can consume them. Fam's patch to do blk_drain() first would cause a double-free.

That "consume" part is what I don't understand.

Shouldn't blk_drain() only process submitted requests (and further requests they dequeue indirectly), while s->rq only contains failed requests.

Nevermind, I was confused. virtio_blk_init_request doesn't store the requests in a list, unlike SCSI.

Paolo

author
#6 lore raw

PATCH v2 2/2 virtio-blk: Remove stale comment about draining

In reply to Fam Zheng

This is stale after commit 6e40b3bf (virtio-blk: Use blk_drain() to drain IO requests), remove it.

---
 hw/block/virtio-blk.c | 4 ----
 1 file changed, 4 deletions(-)
hw/block/virtio-blk.c +0 -4
index 12587d9..948e8b5 100644
@@ -656,10 +656,6 @@ static void virtio_blk_reset(VirtIODevice *vdev)
     AioContext *ctx;
     VirtIOBlockReq *req;
 
-    /*
-     * This should cancel pending requests, but can't do nicely until there
-     * are per-device request lists.
-     */
     ctx = blk_get_aio_context(s->blk);
     aio_context_acquire(ctx);
     blk_drain(s->blk);
Signature · 1 line
2.7.4