From patchwork Wed May 11 13:24:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9069821 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2DB52BF29F for ; Wed, 11 May 2016 13:31:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5743F200ED for ; Wed, 11 May 2016 13:31:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42650200D0 for ; Wed, 11 May 2016 13:31:43 +0000 (UTC) Received: from localhost ([::1]:52227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0UEo-000481-FJ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 09:31:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0U8S-0007mJ-F8 for qemu-devel@nongnu.org; Wed, 11 May 2016 09:25:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0U8M-0007tM-5y for qemu-devel@nongnu.org; Wed, 11 May 2016 09:25:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0U86-0007oQ-Qt; Wed, 11 May 2016 09:24:47 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66FAF627D6; Wed, 11 May 2016 13:24:46 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4BDOSqB028301; Wed, 11 May 2016 09:24:44 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 11 May 2016 15:24:20 +0200 Message-Id: <1462973065-9876-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1462973065-9876-1-git-send-email-kwolf@redhat.com> References: <1462973065-9876-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 11 May 2016 13:24:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 09/14] block: Drain throttling queue with BdrvChild callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Alberto Garcia --- block/block-backend.c | 32 +++++++++++++++++++++++++++----- block/io.c | 39 ++++++++++++++++++--------------------- include/block/block_int.h | 16 +++++++++++----- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 52b7b92..74429ae 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; +} diff --git a/block/io.c b/block/io.c index 1699f1e..7c213ec 100644 --- a/block/io.c +++ b/block/io.c @@ -27,7 +27,6 @@ #include "sysemu/block-backend.h" #include "block/blockjob.h" #include "block/block_int.h" -#include "block/throttle-groups.h" #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/error-report.h" @@ -46,28 +45,26 @@ static void coroutine_fn bdrv_co_do_rw(void *opaque); static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors, BdrvRequestFlags flags); -void bdrv_no_throttling_begin(BlockDriverState *bs) +static void bdrv_parent_drained_begin(BlockDriverState *bs) { - if (!bs->blk) { - return; - } + BdrvChild *c; - if (blk_get_public(bs->blk)->io_limits_disabled++ == 0) { - throttle_group_restart_blk(bs->blk); + QLIST_FOREACH(c, &bs->parents, next_parent) { + if (c->role->drained_begin) { + c->role->drained_begin(c); + } } } -void bdrv_no_throttling_end(BlockDriverState *bs) +static void bdrv_parent_drained_end(BlockDriverState *bs) { - BlockBackendPublic *blkp; + BdrvChild *c; - if (!bs->blk) { - return; + QLIST_FOREACH(c, &bs->parents, next_parent) { + if (c->role->drained_end) { + c->role->drained_end(c); + } } - - blkp = blk_get_public(bs->blk); - assert(blkp->io_limits_disabled); - --blkp->io_limits_disabled; } void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) @@ -248,17 +245,17 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs) */ void coroutine_fn bdrv_co_drain(BlockDriverState *bs) { - bdrv_no_throttling_begin(bs); + bdrv_parent_drained_begin(bs); bdrv_io_unplugged_begin(bs); bdrv_drain_recurse(bs); bdrv_co_yield_to_drain(bs); bdrv_io_unplugged_end(bs); - bdrv_no_throttling_end(bs); + bdrv_parent_drained_end(bs); } void bdrv_drain(BlockDriverState *bs) { - bdrv_no_throttling_begin(bs); + bdrv_parent_drained_begin(bs); bdrv_io_unplugged_begin(bs); bdrv_drain_recurse(bs); if (qemu_in_coroutine()) { @@ -267,7 +264,7 @@ void bdrv_drain(BlockDriverState *bs) bdrv_drain_poll(bs); } bdrv_io_unplugged_end(bs); - bdrv_no_throttling_end(bs); + bdrv_parent_drained_end(bs); } /* @@ -290,7 +287,7 @@ void bdrv_drain_all(void) if (bs->job) { block_job_pause(bs->job); } - bdrv_no_throttling_begin(bs); + bdrv_parent_drained_begin(bs); bdrv_io_unplugged_begin(bs); bdrv_drain_recurse(bs); aio_context_release(aio_context); @@ -333,7 +330,7 @@ void bdrv_drain_all(void) aio_context_acquire(aio_context); bdrv_io_unplugged_end(bs); - bdrv_no_throttling_end(bs); + bdrv_parent_drained_end(bs); if (bs->job) { block_job_resume(bs->job); } diff --git a/include/block/block_int.h b/include/block/block_int.h index 6af541e..461583b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -359,6 +359,17 @@ typedef struct BdrvAioNotifier { struct BdrvChildRole { void (*inherit_options)(int *child_flags, QDict *child_options, int parent_flags, QDict *parent_options); + + /* + * If this pair of functions is implemented, the parent doesn't issue new + * requests after returning from .drained_being() until .drained_end() is + * called. + * + * Note that this can be nested. If drained_begin() was called twice, new + * I/O is allowed only after drained_end() was called twice, too. + */ + void (*drained_begin)(BdrvChild *child); + void (*drained_end)(BdrvChild *child); }; extern const BdrvChildRole child_file; @@ -521,8 +532,6 @@ int get_tmp_filename(char *filename, int size); BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, const char *filename); -bool bdrv_start_throttled_reqs(BlockDriverState *bs); - /** * bdrv_add_before_write_notifier: @@ -705,9 +714,6 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const BdrvChildRole *child_role); void bdrv_root_unref_child(BdrvChild *child); -void bdrv_no_throttling_begin(BlockDriverState *bs); -void bdrv_no_throttling_end(BlockDriverState *bs); - void blk_dev_change_media_cb(BlockBackend *blk, bool load); bool blk_dev_has_removable_media(BlockBackend *blk); bool blk_dev_has_tray(BlockBackend *blk);