From patchwork Wed Sep 20 10:23:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 816238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xy1bg3NZKz9s7h for ; Thu, 21 Sep 2017 00:00:31 +1000 (AEST) Received: from localhost ([::1]:48267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufYD-0005qy-He for incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 10:00:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufAV-00024V-PE for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:36:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dufAT-00011q-0S for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:35:59 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:20570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufAP-0000sM-HV; Wed, 20 Sep 2017 09:35:53 -0400 Received: from mail.ntua.gr (carp0.noc.ntua.gr [147.102.222.60]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v8KANNHw022771 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Sep 2017 13:23:24 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host carp0.noc.ntua.gr [147.102.222.60] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Wed, 20 Sep 2017 13:23:09 +0300 Message-Id: <20170920102311.25736-2-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170920102311.25736-1-el13635@mail.ntua.gr> References: <20170920102311.25736-1-el13635@mail.ntua.gr> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH 1/3] block: add bdrv_co_drain_end 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: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , qemu-block , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" BlockDriverState has a bdrv_do_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. Signed-off-by: Manos Pitsidianakis --- include/block/block_int.h | 2 ++ block/io.c | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index ba4c383393..ea1326e3c7 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -359,6 +359,8 @@ struct BlockDriver { */ 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); void (*bdrv_del_child)(BlockDriverState *parent, BdrvChild *child, diff --git a/block/io.c b/block/io.c index 4378ae4c7d..465345289d 100644 --- a/block/io.c +++ b/block/io.c @@ -153,6 +153,7 @@ typedef struct { Coroutine *co; BlockDriverState *bs; bool done; + bool begin; } BdrvCoDrainData; static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) @@ -160,18 +161,23 @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) BdrvCoDrainData *data = opaque; BlockDriverState *bs = data->bs; - bs->drv->bdrv_co_drain(bs); + if (data->begin) { + bs->drv->bdrv_co_drain(bs); + } else { + bs->drv->bdrv_co_drain_end(bs); + } /* Set data->done before reading bs->wakeup. */ atomic_mb_set(&data->done, true); bdrv_wakeup(bs); } -static void bdrv_drain_invoke(BlockDriverState *bs) +static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) { - BdrvCoDrainData data = { .bs = bs, .done = false }; + BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin}; - if (!bs->drv || !bs->drv->bdrv_co_drain) { + if (!bs->drv || (begin && !bs->drv->bdrv_co_drain) || + (!begin && !bs->drv->bdrv_co_drain_end)) { return; } @@ -180,7 +186,7 @@ static void bdrv_drain_invoke(BlockDriverState *bs) BDRV_POLL_WHILE(bs, !data.done); } -static bool bdrv_drain_recurse(BlockDriverState *bs) +static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) { BdrvChild *child, *tmp; bool waited; @@ -188,7 +194,7 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); /* Ensure any pending metadata writes are submitted to bs->file. */ - bdrv_drain_invoke(bs); + bdrv_drain_invoke(bs, begin); QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { BlockDriverState *bs = child->bs; @@ -205,7 +211,7 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) */ bdrv_ref(bs); } - waited |= bdrv_drain_recurse(bs); + waited |= bdrv_drain_recurse(bs, begin); if (in_main_loop) { bdrv_unref(bs); } @@ -221,12 +227,18 @@ static void bdrv_co_drain_bh_cb(void *opaque) BlockDriverState *bs = data->bs; bdrv_dec_in_flight(bs); - bdrv_drained_begin(bs); + if (data->begin) { + bdrv_drained_begin(bs); + } else { + bdrv_drained_end(bs); + } + data->done = true; aio_co_wake(co); } -static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs) +static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, + bool begin) { BdrvCoDrainData data; @@ -239,6 +251,7 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs) .co = qemu_coroutine_self(), .bs = bs, .done = false, + .begin = begin, }; bdrv_inc_in_flight(bs); aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), @@ -253,7 +266,7 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs) void bdrv_drained_begin(BlockDriverState *bs) { if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs); + bdrv_co_yield_to_drain(bs, true); return; } @@ -262,17 +275,22 @@ void bdrv_drained_begin(BlockDriverState *bs) bdrv_parent_drained_begin(bs); } - bdrv_drain_recurse(bs); + bdrv_drain_recurse(bs, true); } void bdrv_drained_end(BlockDriverState *bs) { + if (qemu_in_coroutine()) { + bdrv_co_yield_to_drain(bs, false); + return; + } assert(bs->quiesce_counter > 0); if (atomic_fetch_dec(&bs->quiesce_counter) > 1) { return; } bdrv_parent_drained_end(bs); + bdrv_drain_recurse(bs, false); aio_enable_external(bdrv_get_aio_context(bs)); } @@ -350,7 +368,7 @@ void bdrv_drain_all_begin(void) aio_context_acquire(aio_context); for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { if (aio_context == bdrv_get_aio_context(bs)) { - waited |= bdrv_drain_recurse(bs); + waited |= bdrv_drain_recurse(bs, true); } } aio_context_release(aio_context); @@ -371,6 +389,7 @@ void bdrv_drain_all_end(void) aio_context_acquire(aio_context); aio_enable_external(aio_context); bdrv_parent_drained_end(bs); + bdrv_drain_recurse(bs, false); aio_context_release(aio_context); } From patchwork Wed Sep 20 10:23:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 816240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xy1kH2slWz9s82 for ; Thu, 21 Sep 2017 00:06:15 +1000 (AEST) Received: from localhost ([::1]:48301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufdl-0003BJ-AG for incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 10:06:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufAZ-00028V-U1 for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:36:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dufAY-00015I-Vw for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:36:03 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:20570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufAO-0000sM-Qy; Wed, 20 Sep 2017 09:35:53 -0400 Received: from mail.ntua.gr (carp0.noc.ntua.gr [147.102.222.60]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v8KANOBQ022776 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Sep 2017 13:23:24 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host carp0.noc.ntua.gr [147.102.222.60] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Wed, 20 Sep 2017 13:23:10 +0300 Message-Id: <20170920102311.25736-3-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170920102311.25736-1-el13635@mail.ntua.gr> References: <20170920102311.25736-1-el13635@mail.ntua.gr> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH 2/3] block: rename bdrv_co_drain to bdrv_co_drain_begin 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: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , qemu-block , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Manos Pitsidianakis Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 2 +- block/io.c | 4 ++-- block/qed.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index ea1326e3c7..fd10f53b43 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -357,7 +357,7 @@ struct BlockDriver { * 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. */ - 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); diff --git a/block/io.c b/block/io.c index 465345289d..6b4b13b777 100644 --- a/block/io.c +++ b/block/io.c @@ -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; } diff --git a/block/qed.c b/block/qed.c index 28e2ec89e8..821dcaa055 100644 --- a/block/qed.c +++ b/block/qed.c @@ -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) From patchwork Wed Sep 20 10:23:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 816267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xy26t254Tz9s82 for ; Thu, 21 Sep 2017 00:24:06 +1000 (AEST) Received: from localhost ([::1]:48426 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufv2-0002cG-9x for incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 10:24:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufAV-00024W-Up for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:36:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dufAQ-00010P-DN for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:35:59 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:20570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufAO-0000sM-3Z; Wed, 20 Sep 2017 09:35:52 -0400 Received: from mail.ntua.gr (carp0.noc.ntua.gr [147.102.222.60]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v8KANPPB022779 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Sep 2017 13:23:25 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host carp0.noc.ntua.gr [147.102.222.60] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Wed, 20 Sep 2017 13:23:11 +0300 Message-Id: <20170920102311.25736-4-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170920102311.25736-1-el13635@mail.ntua.gr> References: <20170920102311.25736-1-el13635@mail.ntua.gr> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH 3/3] block/throttle.c: add bdrv_co_drain_begin/end callbacks 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: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , qemu-block , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Manos Pitsidianakis Reviewed-by: Stefan Hajnoczi --- block/throttle.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/throttle.c b/block/throttle.c index 5bca76300f..833175ac77 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -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, };