From patchwork Wed Nov 29 14:49:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842602 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 3yn3Qw0rjNz9s83 for ; Thu, 30 Nov 2017 01:52:08 +1100 (AEDT) Received: from localhost ([::1]:43464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3iY-0005KI-3E for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:52:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3hr-0005I1-O9 for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3hq-0005ql-Sc for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3hi-0005nh-EW; Wed, 29 Nov 2017 09:51:14 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C4F78553E; Wed, 29 Nov 2017 14:51:13 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91BA55C891; Wed, 29 Nov 2017 14:50:45 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:48 +0800 Message-Id: <20171129144956.11409-2-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 29 Nov 2017 14:51:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 1/9] block: Remove unused bdrv_requests_pending 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng Reviewed-by: Alberto Garcia --- block/io.c | 18 ------------------ include/block/block_int.h | 1 - 2 files changed, 19 deletions(-) diff --git a/block/io.c b/block/io.c index 4fdf93a014..7f07972489 100644 --- a/block/io.c +++ b/block/io.c @@ -134,24 +134,6 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs) assert(old >= 1); } -/* Check if any requests are in-flight (including throttled requests) */ -bool bdrv_requests_pending(BlockDriverState *bs) -{ - BdrvChild *child; - - if (atomic_read(&bs->in_flight)) { - return true; - } - - QLIST_FOREACH(child, &bs->children, next) { - if (bdrv_requests_pending(child->bs)) { - return true; - } - } - - return false; -} - typedef struct { Coroutine *co; BlockDriverState *bs; diff --git a/include/block/block_int.h b/include/block/block_int.h index a5482775ec..e107163594 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1045,7 +1045,6 @@ bool blk_dev_is_tray_open(BlockBackend *blk); bool blk_dev_is_medium_locked(BlockBackend *blk); void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes); -bool bdrv_requests_pending(BlockDriverState *bs); void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in); From patchwork Wed Nov 29 14:49:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842603 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 3yn3RQ6N64z9sBZ for ; Thu, 30 Nov 2017 01:52:34 +1100 (AEDT) Received: from localhost ([::1]:43465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3iy-0005V5-V0 for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:52:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3i8-0005TU-Od for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3i7-00061K-I1 for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3i2-0005wU-QW; Wed, 29 Nov 2017 09:51:34 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7D1180480; Wed, 29 Nov 2017 14:51:33 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0F2C5C269; Wed, 29 Nov 2017 14:51:13 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:49 +0800 Message-Id: <20171129144956.11409-3-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 29 Nov 2017 14:51:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 2/9] aio: Add drain begin/end API to AioContext 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng --- include/block/aio.h | 27 +++++++++++++++++--- util/async.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index e9aeeaec94..40c2f64544 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -47,6 +47,15 @@ typedef void QEMUBHFunc(void *opaque); typedef bool AioPollFn(void *opaque); typedef void IOHandler(void *opaque); +typedef void AioDrainFn(void *opaque); +typedef struct AioDrainOps { + AioDrainFn *drained_begin; + AioDrainFn *drained_end; + void *opaque; + bool is_new; + QTAILQ_ENTRY(AioDrainOps) next; +} AioDrainOps; + struct Coroutine; struct ThreadPool; struct LinuxAioState; @@ -147,6 +156,9 @@ struct AioContext { int epollfd; bool epoll_enabled; bool epoll_available; + + QTAILQ_HEAD(, AioDrainOps) drain_ops; + bool drain_ops_updated; }; /** @@ -441,9 +453,9 @@ int64_t aio_compute_timeout(AioContext *ctx); * * Disable the further processing of external clients. */ -static inline void aio_disable_external(AioContext *ctx) +static inline bool aio_disable_external(AioContext *ctx) { - atomic_inc(&ctx->external_disable_cnt); + return atomic_fetch_inc(&ctx->external_disable_cnt) == 0; } /** @@ -452,7 +464,7 @@ static inline void aio_disable_external(AioContext *ctx) * * Enable the processing of external clients. */ -static inline void aio_enable_external(AioContext *ctx) +static inline bool aio_enable_external(AioContext *ctx) { int old; @@ -462,6 +474,7 @@ static inline void aio_enable_external(AioContext *ctx) /* Kick event loop so it re-arms file descriptors */ aio_notify(ctx); } + return old == 1; } /** @@ -564,4 +577,12 @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, int64_t grow, int64_t shrink, Error **errp); +void aio_context_drained_begin(AioContext *ctx); +void aio_context_drained_end(AioContext *ctx); + +void aio_context_add_drain_ops(AioContext *ctx, + AioDrainFn *begin, AioDrainFn *end, void *opaque); +void aio_context_del_drain_ops(AioContext *ctx, + AioDrainFn *begin, AioDrainFn *end, void *opaque); + #endif diff --git a/util/async.c b/util/async.c index 4dd9d95a9e..cca0efd263 100644 --- a/util/async.c +++ b/util/async.c @@ -402,6 +402,7 @@ AioContext *aio_context_new(Error **errp) AioContext *ctx; ctx = (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext)); + QTAILQ_INIT(&ctx->drain_ops); aio_context_setup(ctx); ret = event_notifier_init(&ctx->notifier, false); @@ -506,3 +507,75 @@ void aio_context_release(AioContext *ctx) { qemu_rec_mutex_unlock(&ctx->lock); } + +/* Called with ctx->lock */ +void aio_context_drained_begin(AioContext *ctx) +{ + AioDrainOps *ops; + + /* TODO: When all external fds are handled in the following drain_ops + * callbacks, aio_disable_external can be dropped. */ + aio_disable_external(ctx); +restart: + ctx->drain_ops_updated = false; + QTAILQ_FOREACH(ops, &ctx->drain_ops, next) { + ops->drained_begin(ops->opaque); + if (ctx->drain_ops_updated) { + goto restart; + } + } +} + +/* Called with ctx->lock */ +void aio_context_drained_end(AioContext *ctx) +{ + AioDrainOps *ops; + +restart: + ctx->drain_ops_updated = false; + QTAILQ_FOREACH(ops, &ctx->drain_ops, next) { + if (ops->is_new) { + continue; + } + ops->drained_end(ops->opaque); + if (ctx->drain_ops_updated) { + goto restart; + } + } + if (aio_enable_external(ctx)) { + QTAILQ_FOREACH(ops, &ctx->drain_ops, next) { + ops->is_new = false; + } + } +} + +/* Called with ctx->lock */ +void aio_context_add_drain_ops(AioContext *ctx, + AioDrainFn *begin, AioDrainFn *end, void *opaque) +{ + AioDrainOps *ops = g_new0(AioDrainOps, 1); + ops->drained_begin = begin; + ops->drained_end = end; + ops->opaque = opaque; + ops->is_new = true; + QTAILQ_INSERT_TAIL(&ctx->drain_ops, ops, next); + ctx->drain_ops_updated = true; +} + +/* Called with ctx->lock */ +void aio_context_del_drain_ops(AioContext *ctx, + AioDrainFn *begin, AioDrainFn *end, void *opaque) +{ + AioDrainOps *ops; + + QTAILQ_FOREACH(ops, &ctx->drain_ops, next) { + if (ops->drained_begin == begin && + ops->drained_end == end && + ops->opaque == opaque) { + QTAILQ_REMOVE(&ctx->drain_ops, ops, next); + ctx->drain_ops_updated = true; + g_free(ops); + return; + } + } +} From patchwork Wed Nov 29 14:49:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842605 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 3yn3Tc4LXBz9sBZ for ; Thu, 30 Nov 2017 01:54:28 +1100 (AEDT) Received: from localhost ([::1]:43476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3ko-0007rK-GG for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:54:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3iC-0005WG-1S for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3iB-00063D-8o for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63398) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3i8-000621-Qf; Wed, 29 Nov 2017 09:51:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8F83C070E3B; Wed, 29 Nov 2017 14:51:39 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EA705C269; Wed, 29 Nov 2017 14:51:34 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:50 +0800 Message-Id: <20171129144956.11409-4-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 29 Nov 2017 14:51:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 3/9] blockjob: Implement AioContext drain ops 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng --- blockjob.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/blockjob.c b/blockjob.c index ff9a614531..86d060c89c 100644 --- a/blockjob.c +++ b/blockjob.c @@ -148,6 +148,23 @@ static void block_job_attached_aio_context(AioContext *new_context, void *opaque); static void block_job_detach_aio_context(void *opaque); +static void block_job_drained_begin(void *opaque) +{ + BlockJob *job = opaque; + block_job_pause(job); +} + +static void block_job_drained_end(void *opaque) +{ + BlockJob *job = opaque; + block_job_resume(job); +} + +static const BlockDevOps block_job_dev_ops = { + .drained_begin = block_job_drained_begin, + .drained_end = block_job_drained_end, +}; + void block_job_unref(BlockJob *job) { if (--job->refcnt == 0) { @@ -157,6 +174,10 @@ void block_job_unref(BlockJob *job) blk_remove_aio_context_notifier(job->blk, block_job_attached_aio_context, block_job_detach_aio_context, job); + aio_context_del_drain_ops(blk_get_aio_context(job->blk), + block_job_drained_begin, + block_job_drained_end, + job); blk_unref(job->blk); error_free(job->blocker); g_free(job->id); @@ -170,6 +191,9 @@ static void block_job_attached_aio_context(AioContext *new_context, { BlockJob *job = opaque; + aio_context_add_drain_ops(blk_get_aio_context(job->blk), + block_job_drained_begin, block_job_drained_end, + job); if (job->driver->attached_aio_context) { job->driver->attached_aio_context(job, new_context); } @@ -192,6 +216,9 @@ static void block_job_detach_aio_context(void *opaque) { BlockJob *job = opaque; + aio_context_del_drain_ops(blk_get_aio_context(job->blk), + block_job_drained_begin, block_job_drained_end, + job); /* In case the job terminates during aio_poll()... */ block_job_ref(job); @@ -217,23 +244,6 @@ static const BdrvChildRole child_job = { .stay_at_node = true, }; -static void block_job_drained_begin(void *opaque) -{ - BlockJob *job = opaque; - block_job_pause(job); -} - -static void block_job_drained_end(void *opaque) -{ - BlockJob *job = opaque; - block_job_resume(job); -} - -static const BlockDevOps block_job_dev_ops = { - .drained_begin = block_job_drained_begin, - .drained_end = block_job_drained_end, -}; - void block_job_remove_all_bdrv(BlockJob *job) { GSList *l; @@ -671,6 +681,9 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, bs->job = job; blk_set_dev_ops(blk, &block_job_dev_ops, job); + aio_context_add_drain_ops(blk_get_aio_context(blk), + block_job_drained_begin, block_job_drained_end, + job); bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); QLIST_INSERT_HEAD(&block_jobs, job, job_list); From patchwork Wed Nov 29 14:49:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842604 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 3yn3Rs6wXcz9t16 for ; Thu, 30 Nov 2017 01:52:57 +1100 (AEDT) Received: from localhost ([::1]:43469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3jM-0006Ll-1k for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:52:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3iI-0005hF-Q2 for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3iI-00067C-2t for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:51:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56626) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3iD-00063q-3T; Wed, 29 Nov 2017 09:51:45 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33C1685550; Wed, 29 Nov 2017 14:51:44 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49F5E5C1AB; Wed, 29 Nov 2017 14:51:40 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:51 +0800 Message-Id: <20171129144956.11409-5-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 29 Nov 2017 14:51:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 4/9] throttle: Implement AioContext drain ops 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng --- block/throttle.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/block/throttle.c b/block/throttle.c index 833175ac77..35b740e3de 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -70,6 +70,25 @@ fin: return ret; } +static void throttle_drained_begin(void *opaque) +{ + BlockDriverState *bs = opaque; + ThrottleGroupMember *tgm = bs->opaque; + + if (atomic_fetch_inc(&tgm->io_limits_disabled) == 0) { + throttle_group_restart_tgm(tgm); + } +} + +static void throttle_drained_end(void *opaque) +{ + BlockDriverState *bs = opaque; + ThrottleGroupMember *tgm = bs->opaque; + + assert(tgm->io_limits_disabled); + atomic_dec(&tgm->io_limits_disabled); +} + static int throttle_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -146,6 +165,9 @@ static int throttle_co_flush(BlockDriverState *bs) static void throttle_detach_aio_context(BlockDriverState *bs) { ThrottleGroupMember *tgm = bs->opaque; + aio_context_del_drain_ops(bdrv_get_aio_context(bs), + throttle_drained_begin, throttle_drained_end, + bs); throttle_group_detach_aio_context(tgm); } @@ -153,6 +175,9 @@ static void throttle_attach_aio_context(BlockDriverState *bs, AioContext *new_context) { ThrottleGroupMember *tgm = bs->opaque; + aio_context_add_drain_ops(new_context, + throttle_drained_begin, throttle_drained_end, + bs); throttle_group_attach_aio_context(tgm, new_context); } @@ -199,17 +224,12 @@ static bool throttle_recurse_is_first_non_filter(BlockDriverState *bs, 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); - } + throttle_drained_begin(bs); } 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); + throttle_drained_end(bs); } static BlockDriver bdrv_throttle = { From patchwork Wed Nov 29 14:49:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842609 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 3yn3Xk0BDYz9sBZ for ; Thu, 30 Nov 2017 01:57:10 +1100 (AEDT) Received: from localhost ([::1]:43497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3nQ-0001ib-3B for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:57:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3iR-0005vD-Tp for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3iR-0006FL-5z for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:19003) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3iM-0006BE-MB; Wed, 29 Nov 2017 09:51:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE808C0008D4; Wed, 29 Nov 2017 14:51:53 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id C09C25C1AB; Wed, 29 Nov 2017 14:51:44 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:52 +0800 Message-Id: <20171129144956.11409-6-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 29 Nov 2017 14:51:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 5/9] qed: Implement AioContext drain ops 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng --- block/qed.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/block/qed.c b/block/qed.c index 821dcaa055..8ddaa31e7c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -337,12 +337,33 @@ static void qed_cancel_need_check_timer(BDRVQEDState *s) timer_del(s->need_check_timer); } +static void bdrv_qed_drained_begin(void *opaque) +{ + BlockDriverState *bs = opaque; + BDRVQEDState *s = bs->opaque; + + /* Fire the timer immediately in order to start doing I/O as soon as the + * header is flushed. + */ + if (s->need_check_timer && timer_pending(s->need_check_timer)) { + qed_cancel_need_check_timer(s); + qed_need_check_timer_entry(s); + } +} + +static void bdrv_qed_drained_end(void *opaque) +{ +} + static void bdrv_qed_detach_aio_context(BlockDriverState *bs) { BDRVQEDState *s = bs->opaque; qed_cancel_need_check_timer(s); timer_free(s->need_check_timer); + aio_context_del_drain_ops(bdrv_get_aio_context(bs), + bdrv_qed_drained_begin, bdrv_qed_drained_end, + bs); } static void bdrv_qed_attach_aio_context(BlockDriverState *bs, @@ -356,19 +377,14 @@ static void bdrv_qed_attach_aio_context(BlockDriverState *bs, if (s->header.features & QED_F_NEED_CHECK) { qed_start_need_check_timer(s); } + aio_context_add_drain_ops(new_context, + bdrv_qed_drained_begin, bdrv_qed_drained_end, + bs); } static void coroutine_fn bdrv_qed_co_drain_begin(BlockDriverState *bs) { - BDRVQEDState *s = bs->opaque; - - /* Fire the timer immediately in order to start doing I/O as soon as the - * header is flushed. - */ - if (s->need_check_timer && timer_pending(s->need_check_timer)) { - qed_cancel_need_check_timer(s); - qed_need_check_timer_entry(s); - } + bdrv_qed_drained_begin(bs); } static void bdrv_qed_init_state(BlockDriverState *bs) From patchwork Wed Nov 29 14:49:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842607 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 3yn3Vt2f35z9sBZ for ; Thu, 30 Nov 2017 01:55:34 +1100 (AEDT) Received: from localhost ([::1]:43484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3ls-0000JH-El for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:55:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3iT-0005ze-7H for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3iS-0006G1-JN for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3iQ-0006Eo-I6; Wed, 29 Nov 2017 09:51:58 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96B90C0587D8; Wed, 29 Nov 2017 14:51:57 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A6465C269; Wed, 29 Nov 2017 14:51:54 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:53 +0800 Message-Id: <20171129144956.11409-7-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 29 Nov 2017 14:51:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 6/9] block: Use aio_context_drained_begin in bdrv_set_aio_context 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng --- block.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 9a1a0d1e73..949f0dec11 100644 --- a/block.c +++ b/block.c @@ -4745,8 +4745,7 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) { AioContext *ctx = bdrv_get_aio_context(bs); - aio_disable_external(ctx); - bdrv_parent_drained_begin(bs); + aio_context_drained_begin(ctx); bdrv_drain(bs); /* ensure there are no in-flight requests */ while (aio_poll(ctx, false)) { @@ -4760,8 +4759,7 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) */ aio_context_acquire(new_context); bdrv_attach_aio_context(bs, new_context); - bdrv_parent_drained_end(bs); - aio_enable_external(ctx); + aio_context_drained_end(ctx); aio_context_release(new_context); } From patchwork Wed Nov 29 14:49:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842608 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 3yn3WG0Z6Dz9t16 for ; Thu, 30 Nov 2017 01:55:54 +1100 (AEDT) Received: from localhost ([::1]:43490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3mC-0000ay-4Z for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:55:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3ia-0006KV-PK for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3iZ-0006M8-Qg for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42888) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3iU-0006Gs-WC; Wed, 29 Nov 2017 09:52:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03FE6883CA; Wed, 29 Nov 2017 14:52:02 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F74E5C269; Wed, 29 Nov 2017 14:51:57 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:54 +0800 Message-Id: <20171129144956.11409-8-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 29 Nov 2017 14:52:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 7/9] block: Switch to use AIO drained begin/end API 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Instead of the recursion of the "disable/enable external requests" operations on the graph, we switch to AioContext's API to disable/enable on the whole AioContext altogether. Strictly it is be a bit more than necessary, but as all drained sections are short, it is not a big problem. Drained end can just get away with that. The other half of drained begin is to wait for requests, which we can do with BDRV_POLL_WHILE() in a loop. Signed-off-by: Fam Zheng --- block/io.c | 116 ++++++------------------------------------------------------- 1 file changed, 10 insertions(+), 106 deletions(-) diff --git a/block/io.c b/block/io.c index 7f07972489..914037b21a 100644 --- a/block/io.c +++ b/block/io.c @@ -40,28 +40,6 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags); -void bdrv_parent_drained_begin(BlockDriverState *bs) -{ - BdrvChild *c; - - QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c->role->drained_begin) { - c->role->drained_begin(c); - } - } -} - -void bdrv_parent_drained_end(BlockDriverState *bs) -{ - BdrvChild *c; - - QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c->role->drained_end) { - c->role->drained_end(c); - } - } -} - static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) { dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer); @@ -141,71 +119,6 @@ typedef struct { bool begin; } BdrvCoDrainData; -static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) -{ - BdrvCoDrainData *data = opaque; - BlockDriverState *bs = data->bs; - - if (data->begin) { - bs->drv->bdrv_co_drain_begin(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, bool begin) -{ - BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin}; - - if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) || - (!begin && !bs->drv->bdrv_co_drain_end)) { - return; - } - - data.co = qemu_coroutine_create(bdrv_drain_invoke_entry, &data); - bdrv_coroutine_enter(bs, data.co); - BDRV_POLL_WHILE(bs, !data.done); -} - -static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) -{ - BdrvChild *child, *tmp; - bool waited; - - /* Ensure any pending metadata writes are submitted to bs->file. */ - bdrv_drain_invoke(bs, begin); - - /* Wait for drained requests to finish */ - waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); - - QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { - BlockDriverState *bs = child->bs; - bool in_main_loop = - qemu_get_current_aio_context() == qemu_get_aio_context(); - assert(bs->refcnt > 0); - if (in_main_loop) { - /* In case the recursive bdrv_drain_recurse processes a - * block_job_defer_to_main_loop BH and modifies the graph, - * let's hold a reference to bs until we are done. - * - * IOThread doesn't have such a BH, and it is not safe to call - * bdrv_unref without BQL, so skip doing it there. - */ - bdrv_ref(bs); - } - waited |= bdrv_drain_recurse(bs, begin); - if (in_main_loop) { - bdrv_unref(bs); - } - } - - return waited; -} - static void bdrv_co_drain_bh_cb(void *opaque) { BdrvCoDrainData *data = opaque; @@ -256,12 +169,13 @@ void bdrv_drained_begin(BlockDriverState *bs) return; } - if (atomic_fetch_inc(&bs->quiesce_counter) == 0) { - aio_disable_external(bdrv_get_aio_context(bs)); - bdrv_parent_drained_begin(bs); + if (atomic_fetch_inc(&bs->quiesce_counter) > 0) { + return; + } + aio_context_drained_begin(bdrv_get_aio_context(bs)); + while (BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0)) { + /* Loop until no progress is made. */ } - - bdrv_drain_recurse(bs, true); } void bdrv_drained_end(BlockDriverState *bs) @@ -275,9 +189,7 @@ void bdrv_drained_end(BlockDriverState *bs) return; } - bdrv_parent_drained_end(bs); - bdrv_drain_recurse(bs, false); - aio_enable_external(bdrv_get_aio_context(bs)); + aio_context_drained_end(bdrv_get_aio_context(bs)); } /* @@ -324,14 +236,11 @@ void bdrv_drain_all_begin(void) BdrvNextIterator it; GSList *aio_ctxs = NULL, *ctx; - block_job_pause_all(); - for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { AioContext *aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - bdrv_parent_drained_begin(bs); - aio_disable_external(aio_context); + aio_context_drained_begin(aio_context); aio_context_release(aio_context); if (!g_slist_find(aio_ctxs, aio_context)) { @@ -347,14 +256,13 @@ void bdrv_drain_all_begin(void) */ while (waited) { waited = false; - for (ctx = aio_ctxs; ctx != NULL; ctx = ctx->next) { AioContext *aio_context = ctx->data; 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, true); + waited |= BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); } } aio_context_release(aio_context); @@ -373,13 +281,9 @@ void bdrv_drain_all_end(void) AioContext *aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - aio_enable_external(aio_context); - bdrv_parent_drained_end(bs); - bdrv_drain_recurse(bs, false); + aio_context_drained_end(aio_context); aio_context_release(aio_context); } - - block_job_resume_all(); } void bdrv_drain_all(void) From patchwork Wed Nov 29 14:49:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842610 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 3yn3bB4Tdvz9sBZ for ; Thu, 30 Nov 2017 01:59:18 +1100 (AEDT) Received: from localhost ([::1]:43511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3pU-0004PD-OX for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:59:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3il-0006WE-Re for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3ik-0006YF-Gk for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38242) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3if-0006R8-KW; Wed, 29 Nov 2017 09:52:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEC4AC0587D8; Wed, 29 Nov 2017 14:52:12 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 919C45C670; Wed, 29 Nov 2017 14:52:02 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:55 +0800 Message-Id: <20171129144956.11409-9-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 29 Nov 2017 14:52:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 8/9] block: Drop old drained_{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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng --- block.c | 24 ------------------------ block/block-backend.c | 22 ---------------------- blockjob.c | 6 ------ include/block/block.h | 16 ---------------- include/block/block_int.h | 11 ----------- include/sysemu/block-backend.h | 8 -------- 6 files changed, 87 deletions(-) diff --git a/block.c b/block.c index 949f0dec11..4434441df5 100644 --- a/block.c +++ b/block.c @@ -810,18 +810,6 @@ static char *bdrv_child_get_parent_desc(BdrvChild *c) return g_strdup(bdrv_get_device_or_node_name(parent)); } -static void bdrv_child_cb_drained_begin(BdrvChild *child) -{ - BlockDriverState *bs = child->opaque; - bdrv_drained_begin(bs); -} - -static void bdrv_child_cb_drained_end(BdrvChild *child) -{ - BlockDriverState *bs = child->opaque; - bdrv_drained_end(bs); -} - static int bdrv_child_cb_inactivate(BdrvChild *child) { BlockDriverState *bs = child->opaque; @@ -887,8 +875,6 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options, const BdrvChildRole child_file = { .get_parent_desc = bdrv_child_get_parent_desc, .inherit_options = bdrv_inherited_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_end = bdrv_child_cb_drained_end, .inactivate = bdrv_child_cb_inactivate, }; @@ -909,8 +895,6 @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options, const BdrvChildRole child_format = { .get_parent_desc = bdrv_child_get_parent_desc, .inherit_options = bdrv_inherited_fmt_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_end = bdrv_child_cb_drained_end, .inactivate = bdrv_child_cb_inactivate, }; @@ -1022,8 +1006,6 @@ const BdrvChildRole child_backing = { .attach = bdrv_backing_attach, .detach = bdrv_backing_detach, .inherit_options = bdrv_backing_options, - .drained_begin = bdrv_child_cb_drained_begin, - .drained_end = bdrv_child_cb_drained_end, .inactivate = bdrv_child_cb_inactivate, .update_filename = bdrv_backing_update_filename, }; @@ -1973,9 +1955,6 @@ static void bdrv_replace_child_noperm(BdrvChild *child, assert(bdrv_get_aio_context(old_bs) == bdrv_get_aio_context(new_bs)); } if (old_bs) { - if (old_bs->quiesce_counter && child->role->drained_end) { - child->role->drained_end(child); - } if (child->role->detach) { child->role->detach(child); } @@ -1986,9 +1965,6 @@ static void bdrv_replace_child_noperm(BdrvChild *child, if (new_bs) { QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); - if (new_bs->quiesce_counter && child->role->drained_begin) { - child->role->drained_begin(child); - } if (child->role->attach) { child->role->attach(child); diff --git a/block/block-backend.c b/block/block-backend.c index baef8e7abc..05855ab767 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -68,7 +68,6 @@ struct BlockBackend { NotifierList remove_bs_notifiers, insert_bs_notifiers; - int quiesce_counter; VMChangeStateEntry *vmsh; bool force_allow_inactivate; }; @@ -245,9 +244,6 @@ static const BdrvChildRole child_root = { .get_name = blk_root_get_name, .get_parent_desc = blk_root_get_parent_desc, - .drained_begin = blk_root_drained_begin, - .drained_end = blk_root_drained_end, - .activate = blk_root_activate, .inactivate = blk_root_inactivate, }; @@ -887,11 +883,6 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, blk->dev_ops = ops; blk->dev_opaque = opaque; - - /* Are we currently quiesced? Should we enforce this right now? */ - if (blk->quiesce_counter && ops->drained_begin) { - ops->drained_begin(opaque); - } } /* @@ -2068,12 +2059,6 @@ static void blk_root_drained_begin(BdrvChild *child) { BlockBackend *blk = child->opaque; - if (++blk->quiesce_counter == 1) { - if (blk->dev_ops && blk->dev_ops->drained_begin) { - blk->dev_ops->drained_begin(blk->dev_opaque); - } - } - /* Note that blk->root may not be accessible here yet if we are just * attaching to a BlockDriverState that is drained. Use child instead. */ @@ -2085,14 +2070,7 @@ static void blk_root_drained_begin(BdrvChild *child) static void blk_root_drained_end(BdrvChild *child) { BlockBackend *blk = child->opaque; - assert(blk->quiesce_counter); assert(blk->public.throttle_group_member.io_limits_disabled); atomic_dec(&blk->public.throttle_group_member.io_limits_disabled); - - if (--blk->quiesce_counter == 0) { - if (blk->dev_ops && blk->dev_ops->drained_end) { - blk->dev_ops->drained_end(blk->dev_opaque); - } - } } diff --git a/blockjob.c b/blockjob.c index 86d060c89c..809111bf24 100644 --- a/blockjob.c +++ b/blockjob.c @@ -160,11 +160,6 @@ static void block_job_drained_end(void *opaque) block_job_resume(job); } -static const BlockDevOps block_job_dev_ops = { - .drained_begin = block_job_drained_begin, - .drained_end = block_job_drained_end, -}; - void block_job_unref(BlockJob *job) { if (--job->refcnt == 0) { @@ -680,7 +675,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort); bs->job = job; - blk_set_dev_ops(blk, &block_job_dev_ops, job); aio_context_add_drain_ops(blk_get_aio_context(blk), block_job_drained_begin, block_job_drained_end, job); diff --git a/include/block/block.h b/include/block/block.h index c05cac57e5..df73e77200 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -579,22 +579,6 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); void bdrv_io_plug(BlockDriverState *bs); void bdrv_io_unplug(BlockDriverState *bs); -/** - * bdrv_parent_drained_begin: - * - * Begin a quiesced section of all users of @bs. This is part of - * bdrv_drained_begin. - */ -void bdrv_parent_drained_begin(BlockDriverState *bs); - -/** - * bdrv_parent_drained_end: - * - * End a quiesced section of all users of @bs. This is part of - * bdrv_drained_end. - */ -void bdrv_parent_drained_end(BlockDriverState *bs); - /** * bdrv_drained_begin: * diff --git a/include/block/block_int.h b/include/block/block_int.h index e107163594..8eed595682 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -535,17 +535,6 @@ struct BdrvChildRole { * caller is responsible for freeing the memory. */ char *(*get_parent_desc)(BdrvChild *child); - /* - * If this pair of functions is implemented, the parent doesn't issue new - * requests after returning from .drained_begin() 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); - /* Notifies the parent that the child has been activated/inactivated (e.g. * when migration is completing) and it can start/stop requesting * permissions and doing I/O on it. */ diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index c4e52a5fa3..9e81232a83 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -58,14 +58,6 @@ typedef struct BlockDevOps { * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque); - /* - * Runs when the backend receives a drain request. - */ - void (*drained_begin)(void *opaque); - /* - * Runs when the backend's last drain request ends. - */ - void (*drained_end)(void *opaque); } BlockDevOps; /* This struct is embedded in (the private) BlockBackend struct and contains From patchwork Wed Nov 29 14:49:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 842606 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 3yn3VZ1p8Hz9t16 for ; Thu, 30 Nov 2017 01:55:18 +1100 (AEDT) Received: from localhost ([::1]:43481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3lc-000054-A3 for incoming@patchwork.ozlabs.org; Wed, 29 Nov 2017 09:55:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3im-0006Wt-Ge for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eK3il-0006Ym-HP for qemu-devel@nongnu.org; Wed, 29 Nov 2017 09:52:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eK3ij-0006WE-GM; Wed, 29 Nov 2017 09:52:17 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9686F85541; Wed, 29 Nov 2017 14:52:16 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-98.pek2.redhat.com [10.72.12.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B7C35C1AB; Wed, 29 Nov 2017 14:52:12 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 29 Nov 2017 22:49:56 +0800 Message-Id: <20171129144956.11409-10-famz@redhat.com> In-Reply-To: <20171129144956.11409-1-famz@redhat.com> References: <20171129144956.11409-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 29 Nov 2017 14:52:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 9/9] blockjob: Drop unused functions 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 , qemu-block@nongnu.org, jcody@redhat.com, Max Reitz , Stefan Hajnoczi , pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Fam Zheng --- blockjob.c | 24 ------------------------ include/block/blockjob_int.h | 14 -------------- 2 files changed, 38 deletions(-) diff --git a/blockjob.c b/blockjob.c index 809111bf24..bfeb7c4ace 100644 --- a/blockjob.c +++ b/blockjob.c @@ -699,18 +699,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, return job; } -void block_job_pause_all(void) -{ - BlockJob *job = NULL; - while ((job = block_job_next(job))) { - AioContext *aio_context = blk_get_aio_context(job->blk); - - aio_context_acquire(aio_context); - block_job_pause(job); - aio_context_release(aio_context); - } -} - void block_job_early_fail(BlockJob *job) { block_job_unref(job); @@ -764,18 +752,6 @@ void coroutine_fn block_job_pause_point(BlockJob *job) } } -void block_job_resume_all(void) -{ - BlockJob *job = NULL; - while ((job = block_job_next(job))) { - AioContext *aio_context = blk_get_aio_context(job->blk); - - aio_context_acquire(aio_context); - block_job_resume(job); - aio_context_release(aio_context); - } -} - void block_job_enter(BlockJob *job) { if (!block_job_started(job)) { diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index 43f3be2965..4b43367608 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -156,20 +156,6 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns); */ void block_job_yield(BlockJob *job); -/** - * block_job_pause_all: - * - * Asynchronously pause all jobs. - */ -void block_job_pause_all(void); - -/** - * block_job_resume_all: - * - * Resume all block jobs. Must be paired with a preceding block_job_pause_all. - */ -void block_job_resume_all(void); - /** * block_job_early_fail: * @bs: The block device.