diff options
author | Kevin Wolf <kwolf@redhat.com> | 2016-03-22 12:05:35 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-05-19 16:45:30 +0200 |
commit | c2066af0514d80a805dac82accaec1121babfa15 (patch) | |
tree | 2a1eebe6ab1f73451c39533a178986cbd5239569 /block/block-backend.c | |
parent | 22aa8b246ada8d45add8eef64d4640a20b4f7ef3 (diff) |
block: Drain throttling queue with BdrvChild callback
This removes the last part of I/O throttling from block/io.c and moves
it to the BlockBackend.
Instead of having knowledge about throttling inside io.c, we can call a
BdrvChild callback .drained_begin/end, which happens to drain the
throttled requests for BlockBackend parents.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block/block-backend.c')
-rw-r--r-- | block/block-backend.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index 52b7b922c2..74429ae36b 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -91,9 +91,14 @@ static void blk_root_inherit_options(int *child_flags, QDict *child_options, /* We're not supposed to call this function for root nodes */ abort(); } +static void blk_root_drained_begin(BdrvChild *child); +static void blk_root_drained_end(BdrvChild *child); static const BdrvChildRole child_root = { - .inherit_options = blk_root_inherit_options, + .inherit_options = blk_root_inherit_options, + + .drained_begin = blk_root_drained_begin, + .drained_end = blk_root_drained_end, }; /* @@ -818,9 +823,9 @@ int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, return ret; } - bdrv_no_throttling_begin(blk_bs(blk)); + blk_root_drained_begin(blk->root); ret = blk_pread(blk, offset, buf, count); - bdrv_no_throttling_end(blk_bs(blk)); + blk_root_drained_end(blk->root); return ret; } @@ -1633,9 +1638,9 @@ void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg) void blk_io_limits_disable(BlockBackend *blk) { assert(blk->public.throttle_state); - bdrv_no_throttling_begin(blk_bs(blk)); + bdrv_drained_begin(blk_bs(blk)); throttle_group_unregister_blk(blk); - bdrv_no_throttling_end(blk_bs(blk)); + bdrv_drained_end(blk_bs(blk)); } /* should be called before blk_set_io_limits if a limit is set */ @@ -1661,3 +1666,20 @@ void blk_io_limits_update_group(BlockBackend *blk, const char *group) blk_io_limits_disable(blk); blk_io_limits_enable(blk, group); } + +static void blk_root_drained_begin(BdrvChild *child) +{ + BlockBackend *blk = child->opaque; + + if (blk->public.io_limits_disabled++ == 0) { + throttle_group_restart_blk(blk); + } +} + +static void blk_root_drained_end(BdrvChild *child) +{ + BlockBackend *blk = child->opaque; + + assert(blk->public.io_limits_disabled); + --blk->public.io_limits_disabled; +} |