Skip to contentSkip to conversation

add bdrv_co_drain_begin/end BlockDriver callbacks

PATCH Applied Manos Pitsidianakis 5 participants 12 messages Sep 23, 2017 – Oct 13, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

v3 cover add bdrv_co_drain_begin/end BlockDriver callbacks

This patch series renames bdrv_co_drain to bdrv_co_drain_begin and adds a new bdrv_co_drain_end callback to match bdrv_drained_begin/end and drained_begin/end of BdrvChild. This is needed because the throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly.

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

v3:
fixed commit message typo in first patch [Fam]
rephrased doc comment based on mailing discussion
v2:
add doc for callbacks and change order of request polling for completion [Stefan]

Manos Pitsidianakis (3):
block: add bdrv_co_drain_end callback
block: rename bdrv_co_drain to bdrv_co_drain_begin block/throttle.c: add bdrv_co_drain_begin/end callbacks

 include/block/block_int.h | 13 ++++++++++---
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 block/qed.c               |  6 +++---
 block/throttle.c          | 18 ++++++++++++++++++
 4 files changed, 65 insertions(+), 20 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/3 block: add bdrv_co_drain_end callback

BlockDriverState has a bdrv_co_drain() callback but no equivalent for the end of the drain. The throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly, thus bdrv_co_drain_end is needed.

---
 include/block/block_int.h | 11 +++++++++--
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 43 insertions(+), 16 deletions(-)
include/block/block_int.h +9 -2
index ba4c383393..9ebdeb6db0 100644
@@ -354,10 +354,17 @@ struct BlockDriver {
     int (*bdrv_probe_geometry)(BlockDriverState *bs, HDGeometry *geo);
 
     /**
-     * Drain and stop any internal sources of requests in the driver, and
-     * remain so until next I/O callback (e.g. bdrv_co_writev) is called.
+     * bdrv_co_drain is called if implemented in the beginning of a
+     * drain operation to drain and stop any internal sources of requests in
+     * the driver.
+     * bdrv_co_drain_end is called if implemented at the end of the drain.
+     *
+     * They should be used by the driver to e.g. manage scheduled I/O
+     * requests, or toggle an internal state. After the end of the drain new
+     * requests will continue normally.
      */
     void coroutine_fn (*bdrv_co_drain)(BlockDriverState *bs);
+    void coroutine_fn (*bdrv_co_drain_end)(BlockDriverState *bs);
 
     void (*bdrv_add_child)(BlockDriverState *parent, BlockDriverState *child,
                            Error **errp);
block/io.c +34 -14

135 lines not on this page · raw message

Signature · 1 line
2.11.0
Reviewed-by on v3 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] block: add bdrv_co_drain_end callback

Quoted 6 lines · Manos Pitsidianakis

BlockDriverState has a bdrv_co_drain() callback but no equivalent for the end of the drain. The throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly, thus bdrv_co_drain_end is needed.

Reviewed-by on v3 1/3
#3 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v3 1/3] block: add bdrv_co_drain_end callback

In reply to Manos Pitsidianakis
Quoted 10 lines · Manos Pitsidianakis

BlockDriverState has a bdrv_co_drain() callback but no equivalent for the end of the drain. The throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly, thus bdrv_co_drain_end is needed.

---
 include/block/block_int.h | 11 +++++++++--
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 43 insertions(+), 16 deletions(-)
#4 lore raw

PATCH v3 2/3 block: rename bdrv_co_drain to bdrv_co_drain_begin

In reply to Manos Pitsidianakis
---
 include/block/block_int.h | 4 ++--
 block/io.c                | 4 ++--
 block/qed.c               | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)
include/block/block_int.h +2 -2
index 9ebdeb6db0..51575d22b6 100644
@@ -354,7 +354,7 @@ struct BlockDriver {
     int (*bdrv_probe_geometry)(BlockDriverState *bs, HDGeometry *geo);
 
     /**
-     * bdrv_co_drain is called if implemented in the beginning of a
+     * bdrv_co_drain_begin is called if implemented in the beginning of a
      * drain operation to drain and stop any internal sources of requests in
      * the driver.
      * bdrv_co_drain_end is called if implemented at the end of the drain.
@@ -363,7 +363,7 @@ struct BlockDriver {
      * requests, or toggle an internal state. After the end of the drain new
      * requests will continue normally.
      */
-    void coroutine_fn (*bdrv_co_drain)(BlockDriverState *bs);
+    void coroutine_fn (*bdrv_co_drain_begin)(BlockDriverState *bs);
     void coroutine_fn (*bdrv_co_drain_end)(BlockDriverState *bs);
 
     void (*bdrv_add_child)(BlockDriverState *parent, BlockDriverState *child,
block/io.c +2 -2
index b0a10ad3ef..65e8094d7c 100644
@@ -162,7 +162,7 @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque)
     BlockDriverState *bs = data->bs;
 
     if (data->begin) {
-        bs->drv->bdrv_co_drain(bs);
+        bs->drv->bdrv_co_drain_begin(bs);
     } else {
         bs->drv->bdrv_co_drain_end(bs);
     }
@@ -176,7 +176,7 @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
 {
     BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin};
 
-    if (!bs->drv || (begin && !bs->drv->bdrv_co_drain) ||
+    if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) ||
             (!begin && !bs->drv->bdrv_co_drain_end)) {
         return;
     }
block/qed.c +3 -3
index 28e2ec89e8..821dcaa055 100644
@@ -265,7 +265,7 @@ static bool qed_plug_allocating_write_reqs(BDRVQEDState *s)
     assert(!s->allocating_write_reqs_plugged);
     if (s->allocating_acb != NULL) {
         /* Another allocating write came concurrently.  This cannot happen
-         * from bdrv_qed_co_drain, but it can happen when the timer runs.
+         * from bdrv_qed_co_drain_begin, but it can happen when the timer runs.
          */
         qemu_co_mutex_unlock(&s->table_lock);
         return false;
@@ -358,7 +358,7 @@ static void bdrv_qed_attach_aio_context(BlockDriverState *bs,
     }
 }
 
-static void coroutine_fn bdrv_qed_co_drain(BlockDriverState *bs)
+static void coroutine_fn bdrv_qed_co_drain_begin(BlockDriverState *bs)
 {
     BDRVQEDState *s = bs->opaque;
 
@@ -1608,7 +1608,7 @@ static BlockDriver bdrv_qed = {
     .bdrv_check               = bdrv_qed_check,
     .bdrv_detach_aio_context  = bdrv_qed_detach_aio_context,
     .bdrv_attach_aio_context  = bdrv_qed_attach_aio_context,
-    .bdrv_co_drain            = bdrv_qed_co_drain,
+    .bdrv_co_drain_begin      = bdrv_qed_co_drain_begin,
 };
 
 static void bdrv_qed_init(void)
Signature · 1 line
2.11.0
Reviewed-by on v3 2/3
#5 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v3 2/3] block: rename bdrv_co_drain to bdrv_co_drain_begin

Quoted 8 lines · Manos Pitsidianakis
---
 include/block/block_int.h | 4 ++--
 block/io.c                | 4 ++--
 block/qed.c               | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)
#6 lore raw

PATCH v3 3/3 block/throttle.c: add bdrv_co_drain_begin/end callbacks

In reply to Manos Pitsidianakis
---
 block/throttle.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
block/throttle.c +18 -0
index 5bca76300f..833175ac77 100644
@@ -197,6 +197,21 @@ static bool throttle_recurse_is_first_non_filter(BlockDriverState *bs,
     return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate);
 }
 
+static void coroutine_fn throttle_co_drain_begin(BlockDriverState *bs)
+{
+    ThrottleGroupMember *tgm = bs->opaque;
+    if (atomic_fetch_inc(&tgm->io_limits_disabled) == 0) {
+        throttle_group_restart_tgm(tgm);
+    }
+}
+
+static void coroutine_fn throttle_co_drain_end(BlockDriverState *bs)
+{
+    ThrottleGroupMember *tgm = bs->opaque;
+    assert(tgm->io_limits_disabled);
+    atomic_dec(&tgm->io_limits_disabled);
+}
+
 static BlockDriver bdrv_throttle = {
     .format_name                        =   "throttle",
     .protocol_name                      =   "throttle",
@@ -226,6 +241,9 @@ static BlockDriver bdrv_throttle = {
     .bdrv_reopen_abort                  =   throttle_reopen_abort,
     .bdrv_co_get_block_status           =   bdrv_co_get_block_status_from_file,
 
+    .bdrv_co_drain_begin                =   throttle_co_drain_begin,
+    .bdrv_co_drain_end                  =   throttle_co_drain_end,
+
     .is_filter                          =   true,
 };
 
Signature · 1 line
2.11.0
#7 lore raw
In reply to Manos Pitsidianakis
Quoted 22 lines · Manos Pitsidianakis

This patch series renames bdrv_co_drain to bdrv_co_drain_begin and adds a new bdrv_co_drain_end callback to match bdrv_drained_begin/end and drained_begin/end of BdrvChild. This is needed because the throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly.

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

v3:
fixed commit message typo in first patch [Fam]
rephrased doc comment based on mailing discussion
v2:
add doc for callbacks and change order of request polling for completion [Stefan]

Manos Pitsidianakis (3):
block: add bdrv_co_drain_end callback
block: rename bdrv_co_drain to bdrv_co_drain_begin block/throttle.c: add bdrv_co_drain_begin/end callbacks

Quoted 9 lines
 include/block/block_int.h | 13 ++++++++++---
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 block/qed.c               |  6 +++---
 block/throttle.c          | 18 ++++++++++++++++++
 4 files changed, 65 insertions(+), 20 deletions(-)
Signature · 1 line
2.11.0

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

#8 lore raw
In reply to Manos Pitsidianakis
Quoted 22 lines · Manos Pitsidianakis

This patch series renames bdrv_co_drain to bdrv_co_drain_begin and adds a new bdrv_co_drain_end callback to match bdrv_drained_begin/end and drained_begin/end of BdrvChild. This is needed because the throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly.

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

v3:
fixed commit message typo in first patch [Fam]
rephrased doc comment based on mailing discussion
v2:
add doc for callbacks and change order of request polling for completion [Stefan]

Manos Pitsidianakis (3):
block: add bdrv_co_drain_end callback
block: rename bdrv_co_drain to bdrv_co_drain_begin block/throttle.c: add bdrv_co_drain_begin/end callbacks

Quoted 5 lines
 include/block/block_int.h | 13 ++++++++++---
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 block/qed.c               |  6 +++---
 block/throttle.c          | 18 ++++++++++++++++++
 4 files changed, 65 insertions(+), 20 deletions(-)

Oops, this seems to cause a qemu-iotests failure. Please take a look:

$ ./check -qcow2 184
184 0s ... - output mismatch (see 184.out.bad)
--- /home/stefanha/qemu/tests/qemu-iotests/184.out	2017-09-19 14:51:46.673854437 +0100
+++ 184.out.bad	2017-09-26 11:13:06.946610239 +0100
@@ -142,6 +142,9 @@
         "guest": false
     }
 }
+./common.config: line 118:  9196 Segmentation fault      (core dumped) ( if [ -n "${QEMU_NEED_PID}" ]; then
+    echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid";
+fi; exec "$QEMU_PROG" $QEMU_OPTIONS "$@" )
#9 lore raw
Quoted 36 lines · Stefan Hajnoczi
Quoted 22 lines · Manos Pitsidianakis

This patch series renames bdrv_co_drain to bdrv_co_drain_begin and adds a new bdrv_co_drain_end callback to match bdrv_drained_begin/end and drained_begin/end of BdrvChild. This is needed because the throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly.

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

v3:
fixed commit message typo in first patch [Fam]
rephrased doc comment based on mailing discussion
v2:
add doc for callbacks and change order of request polling for completion [Stefan]

Manos Pitsidianakis (3):
block: add bdrv_co_drain_end callback
block: rename bdrv_co_drain to bdrv_co_drain_begin block/throttle.c: add bdrv_co_drain_begin/end callbacks

Quoted 5 lines
 include/block/block_int.h | 13 ++++++++++---
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 block/qed.c               |  6 +++---
 block/throttle.c          | 18 ++++++++++++++++++
 4 files changed, 65 insertions(+), 20 deletions(-)

Oops, this seems to cause a qemu-iotests failure. Please take a look:

$ ./check -qcow2 184
184 0s ... - output mismatch (see 184.out.bad)

184.out.bad line 148

Quoted 7 lines
184.out.bad renamed from home/stefanha/qemu/tests/qemu-iotests/184.out +3 -0
@@ -142,6 +142,9 @@
        "guest": false
    }
 }
+./common.config: line 118:  9196 Segmentation fault      (core dumped) ( if [ -n "${QEMU_NEED_PID}" ]; then
+    echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid";
+fi; exec "$QEMU_PROG" $QEMU_OPTIONS "$@" )
 

Hey Stefan,

This is fixed in

Quoted 3 lines
Quoted 3 lines

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

Which I sent before this series and is in Kevin's branch.

#10 lore raw

Am 26.09.2017 um 14:44 hat Manos Pitsidianakis geschrieben:

Quoted 47 lines · Stefan Hajnoczi
Quoted 36 lines · Manos Pitsidianakis
Quoted 22 lines

This patch series renames bdrv_co_drain to bdrv_co_drain_begin and adds a new bdrv_co_drain_end callback to match bdrv_drained_begin/end and drained_begin/end of BdrvChild. This is needed because the throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly.

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

v3:
fixed commit message typo in first patch [Fam]
rephrased doc comment based on mailing discussion
v2:
add doc for callbacks and change order of request polling for completion [Stefan]

Manos Pitsidianakis (3):
block: add bdrv_co_drain_end callback
block: rename bdrv_co_drain to bdrv_co_drain_begin block/throttle.c: add bdrv_co_drain_begin/end callbacks

Quoted 5 lines
 include/block/block_int.h | 13 ++++++++++---
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 block/qed.c               |  6 +++---
 block/throttle.c          | 18 ++++++++++++++++++
 4 files changed, 65 insertions(+), 20 deletions(-)

Oops, this seems to cause a qemu-iotests failure. Please take a look:

$ ./check -qcow2 184
184 0s ... - output mismatch (see 184.out.bad)

184.out.bad line 148

Quoted 7 lines
184.out.bad renamed from home/stefanha/qemu/tests/qemu-iotests/184.out +3 -0
@@ -142,6 +142,9 @@
        "guest": false
    }
 }
+./common.config: line 118:  9196 Segmentation fault      (core dumped) ( if [ -n "${QEMU_NEED_PID}" ]; then
+    echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid";
+fi; exec "$QEMU_PROG" $QEMU_OPTIONS "$@" )
 

Hey Stefan,

Quoted 6 lines

This is fixed in

Quoted 3 lines
Quoted 3 lines

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

Which I sent before this series and is in Kevin's branch.

Stefan, the fix is in master by now, so you can stage this series again. (Or I can take it, if you prefer.)

Kevin

#11 lore raw
In reply to Manos Pitsidianakis
Quoted 22 lines · Manos Pitsidianakis

This patch series renames bdrv_co_drain to bdrv_co_drain_begin and adds a new bdrv_co_drain_end callback to match bdrv_drained_begin/end and drained_begin/end of BdrvChild. This is needed because the throttle driver (block/throttle.c) needs a way to mark the end of the drain in order to toggle io_limits_disabled correctly.

Based-on: <[email protected]>
"block/throttle-groups.c: allocate RestartData on the heap" Which fixes a coroutine crash in block/throttle-groups.c

v3:
fixed commit message typo in first patch [Fam]
rephrased doc comment based on mailing discussion
v2:
add doc for callbacks and change order of request polling for completion [Stefan]

Manos Pitsidianakis (3):
block: add bdrv_co_drain_end callback
block: rename bdrv_co_drain to bdrv_co_drain_begin block/throttle.c: add bdrv_co_drain_begin/end callbacks

Quoted 10 lines
 include/block/block_int.h | 13 ++++++++++---
 block/io.c                | 48 +++++++++++++++++++++++++++++++++--------------
 block/qed.c               |  6 +++---
 block/throttle.c          | 18 ++++++++++++++++++
 4 files changed, 65 insertions(+), 20 deletions(-)
Signature · 1 line
2.11.0

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan