From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967209975774.5930412571885; Wed, 29 Nov 2017 06:53:29 -0800 (PST) Received: from localhost ([::1]:43470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3jk-00076o-0A for importer@patchew.org; Wed, 29 Nov 2017 09:53:20 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 >=3D 1); } =20 -/* 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); =20 void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes); -bool bdrv_requests_pending(BlockDriverState *bs); =20 void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in); --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967241225687.3646195229359; Wed, 29 Nov 2017 06:54:01 -0800 (PST) Received: from localhost ([::1]:43471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3k9-0007Tq-Ut for importer@patchew.org; Wed, 29 Nov 2017 09:53:46 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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); =20 +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; }; =20 /** @@ -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) =3D=3D 0; } =20 /** @@ -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; =20 @@ -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 =3D=3D 1; } =20 /** @@ -564,4 +577,12 @@ void aio_context_set_poll_params(AioContext *ctx, int6= 4_t max_ns, int64_t grow, int64_t shrink, Error **errp); =20 +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 *o= paque); +void aio_context_del_drain_ops(AioContext *ctx, + AioDrainFn *begin, AioDrainFn *end, void *o= paque); + #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; =20 ctx =3D (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioConte= xt)); + QTAILQ_INIT(&ctx->drain_ops); aio_context_setup(ctx); =20 ret =3D 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 =3D 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 =3D 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 =3D false; + } + } +} + +/* Called with ctx->lock */ +void aio_context_add_drain_ops(AioContext *ctx, + AioDrainFn *begin, AioDrainFn *end, void *o= paque) +{ + AioDrainOps *ops =3D g_new0(AioDrainOps, 1); + ops->drained_begin =3D begin; + ops->drained_end =3D end; + ops->opaque =3D opaque; + ops->is_new =3D true; + QTAILQ_INSERT_TAIL(&ctx->drain_ops, ops, next); + ctx->drain_ops_updated =3D true; +} + +/* Called with ctx->lock */ +void aio_context_del_drain_ops(AioContext *ctx, + AioDrainFn *begin, AioDrainFn *end, void *o= paque) +{ + AioDrainOps *ops; + + QTAILQ_FOREACH(ops, &ctx->drain_ops, next) { + if (ops->drained_begin =3D=3D begin && + ops->drained_end =3D=3D end && + ops->opaque =3D=3D opaque) { + QTAILQ_REMOVE(&ctx->drain_ops, ops, next); + ctx->drain_ops_updated =3D true; + g_free(ops); + return; + } + } +} --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967339667602.126134917963; Wed, 29 Nov 2017 06:55:39 -0800 (PST) Received: from localhost ([::1]:43488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3lw-0000WB-VS for importer@patchew.org; Wed, 29 Nov 2017 09:55:37 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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); =20 +static void block_job_drained_begin(void *opaque) +{ + BlockJob *job =3D opaque; + block_job_pause(job); +} + +static void block_job_drained_end(void *opaque) +{ + BlockJob *job =3D opaque; + block_job_resume(job); +} + +static const BlockDevOps block_job_dev_ops =3D { + .drained_begin =3D block_job_drained_begin, + .drained_end =3D block_job_drained_end, +}; + void block_job_unref(BlockJob *job) { if (--job->refcnt =3D=3D 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 =3D opaque; =20 + aio_context_add_drain_ops(blk_get_aio_context(job->blk), + block_job_drained_begin, block_job_drained_e= nd, + 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 =3D opaque; =20 + aio_context_del_drain_ops(blk_get_aio_context(job->blk), + block_job_drained_begin, block_job_drained_e= nd, + job); /* In case the job terminates during aio_poll()... */ block_job_ref(job); =20 @@ -217,23 +244,6 @@ static const BdrvChildRole child_job =3D { .stay_at_node =3D true, }; =20 -static void block_job_drained_begin(void *opaque) -{ - BlockJob *job =3D opaque; - block_job_pause(job); -} - -static void block_job_drained_end(void *opaque) -{ - BlockJob *job =3D opaque; - block_job_resume(job); -} - -static const BlockDevOps block_job_dev_ops =3D { - .drained_begin =3D block_job_drained_begin, - .drained_end =3D 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 BlockJ= obDriver *driver, bs->job =3D job; =20 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_e= nd, + job); bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); =20 QLIST_INSERT_HEAD(&block_jobs, job, job_list); --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967252685377.8516077458813; Wed, 29 Nov 2017 06:54:12 -0800 (PST) Received: from localhost ([::1]:43475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3kU-0007kU-VM for importer@patchew.org; Wed, 29 Nov 2017 09:54:07 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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; } =20 +static void throttle_drained_begin(void *opaque) +{ + BlockDriverState *bs =3D opaque; + ThrottleGroupMember *tgm =3D bs->opaque; + + if (atomic_fetch_inc(&tgm->io_limits_disabled) =3D=3D 0) { + throttle_group_restart_tgm(tgm); + } +} + +static void throttle_drained_end(void *opaque) +{ + BlockDriverState *bs =3D opaque; + ThrottleGroupMember *tgm =3D 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 =3D 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); } =20 @@ -153,6 +175,9 @@ static void throttle_attach_aio_context(BlockDriverStat= e *bs, AioContext *new_context) { ThrottleGroupMember *tgm =3D bs->opaque; + aio_context_add_drain_ops(new_context, + throttle_drained_begin, throttle_drained_end, + bs); throttle_group_attach_aio_context(tgm, new_context); } =20 @@ -199,17 +224,12 @@ static bool throttle_recurse_is_first_non_filter(Bloc= kDriverState *bs, =20 static void coroutine_fn throttle_co_drain_begin(BlockDriverState *bs) { - ThrottleGroupMember *tgm =3D bs->opaque; - if (atomic_fetch_inc(&tgm->io_limits_disabled) =3D=3D 0) { - throttle_group_restart_tgm(tgm); - } + throttle_drained_begin(bs); } =20 static void coroutine_fn throttle_co_drain_end(BlockDriverState *bs) { - ThrottleGroupMember *tgm =3D bs->opaque; - assert(tgm->io_limits_disabled); - atomic_dec(&tgm->io_limits_disabled); + throttle_drained_end(bs); } =20 static BlockDriver bdrv_throttle =3D { --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967493292329.5886694115285; Wed, 29 Nov 2017 06:58:13 -0800 (PST) Received: from localhost ([::1]:43503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3oN-0003cC-HZ for importer@patchew.org; Wed, 29 Nov 2017 09:58:07 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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); } =20 +static void bdrv_qed_drained_begin(void *opaque) +{ + BlockDriverState *bs =3D opaque; + BDRVQEDState *s =3D bs->opaque; + + /* Fire the timer immediately in order to start doing I/O as soon as t= he + * 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 =3D bs->opaque; =20 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); } =20 static void bdrv_qed_attach_aio_context(BlockDriverState *bs, @@ -356,19 +377,14 @@ static void bdrv_qed_attach_aio_context(BlockDriverSt= ate *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); } =20 static void coroutine_fn bdrv_qed_co_drain_begin(BlockDriverState *bs) { - BDRVQEDState *s =3D bs->opaque; - - /* Fire the timer immediately in order to start doing I/O as soon as t= he - * 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); } =20 static void bdrv_qed_init_state(BlockDriverState *bs) --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967406249697.761754223081; Wed, 29 Nov 2017 06:56:46 -0800 (PST) Received: from localhost ([::1]:43495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3mz-0001Vk-HW for importer@patchew.org; Wed, 29 Nov 2017 09:56:41 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, AioCo= ntext *new_context) { AioContext *ctx =3D bdrv_get_aio_context(bs); =20 - aio_disable_external(ctx); - bdrv_parent_drained_begin(bs); + aio_context_drained_begin(ctx); bdrv_drain(bs); /* ensure there are no in-flight requests */ =20 while (aio_poll(ctx, false)) { @@ -4760,8 +4759,7 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioCo= ntext *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); } =20 --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967421523371.456717590205; Wed, 29 Nov 2017 06:57:01 -0800 (PST) Received: from localhost ([::1]:43498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3nI-0001mb-MN for importer@patchew.org; Wed, 29 Nov 2017 09:57:00 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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); =20 -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 =3D MAX(dst->opt_transfer, src->opt_transfer); @@ -141,71 +119,6 @@ typedef struct { bool begin; } BdrvCoDrainData; =20 -static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) -{ - BdrvCoDrainData *data =3D opaque; - BlockDriverState *bs =3D 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 =3D { .bs =3D bs, .done =3D false, .begin =3D beg= in}; - - if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) || - (!begin && !bs->drv->bdrv_co_drain_end)) { - return; - } - - data.co =3D 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 =3D BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); - - QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { - BlockDriverState *bs =3D child->bs; - bool in_main_loop =3D - qemu_get_current_aio_context() =3D=3D 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 |=3D 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 =3D opaque; @@ -256,12 +169,13 @@ void bdrv_drained_begin(BlockDriverState *bs) return; } =20 - if (atomic_fetch_inc(&bs->quiesce_counter) =3D=3D 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); } =20 void bdrv_drained_end(BlockDriverState *bs) @@ -275,9 +189,7 @@ void bdrv_drained_end(BlockDriverState *bs) return; } =20 - 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)); } =20 /* @@ -324,14 +236,11 @@ void bdrv_drain_all_begin(void) BdrvNextIterator it; GSList *aio_ctxs =3D NULL, *ctx; =20 - block_job_pause_all(); - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 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); =20 if (!g_slist_find(aio_ctxs, aio_context)) { @@ -347,14 +256,13 @@ void bdrv_drain_all_begin(void) */ while (waited) { waited =3D false; - for (ctx =3D aio_ctxs; ctx !=3D NULL; ctx =3D ctx->next) { AioContext *aio_context =3D ctx->data; =20 aio_context_acquire(aio_context); for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { if (aio_context =3D=3D bdrv_get_aio_context(bs)) { - waited |=3D bdrv_drain_recurse(bs, true); + waited |=3D BDRV_POLL_WHILE(bs, atomic_read(&bs->in_fl= ight) > 0); } } aio_context_release(aio_context); @@ -373,13 +281,9 @@ void bdrv_drain_all_end(void) AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 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(); } =20 void bdrv_drain_all(void) --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967603858307.24210198660455; Wed, 29 Nov 2017 07:00:03 -0800 (PST) Received: from localhost ([::1]:43515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3qD-000588-4Q for importer@patchew.org; Wed, 29 Nov 2017 10:00:01 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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)); } =20 -static void bdrv_child_cb_drained_begin(BdrvChild *child) -{ - BlockDriverState *bs =3D child->opaque; - bdrv_drained_begin(bs); -} - -static void bdrv_child_cb_drained_end(BdrvChild *child) -{ - BlockDriverState *bs =3D child->opaque; - bdrv_drained_end(bs); -} - static int bdrv_child_cb_inactivate(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; @@ -887,8 +875,6 @@ static void bdrv_inherited_options(int *child_flags, QD= ict *child_options, const BdrvChildRole child_file =3D { .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_inherited_options, - .drained_begin =3D bdrv_child_cb_drained_begin, - .drained_end =3D bdrv_child_cb_drained_end, .inactivate =3D bdrv_child_cb_inactivate, }; =20 @@ -909,8 +895,6 @@ static void bdrv_inherited_fmt_options(int *child_flags= , QDict *child_options, const BdrvChildRole child_format =3D { .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_inherited_fmt_options, - .drained_begin =3D bdrv_child_cb_drained_begin, - .drained_end =3D bdrv_child_cb_drained_end, .inactivate =3D bdrv_child_cb_inactivate, }; =20 @@ -1022,8 +1006,6 @@ const BdrvChildRole child_backing =3D { .attach =3D bdrv_backing_attach, .detach =3D bdrv_backing_detach, .inherit_options =3D bdrv_backing_options, - .drained_begin =3D bdrv_child_cb_drained_begin, - .drained_end =3D bdrv_child_cb_drained_end, .inactivate =3D bdrv_child_cb_inactivate, .update_filename =3D bdrv_backing_update_filename, }; @@ -1973,9 +1955,6 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, assert(bdrv_get_aio_context(old_bs) =3D=3D bdrv_get_aio_context(ne= w_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 *chil= d, =20 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); - } =20 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 { =20 NotifierList remove_bs_notifiers, insert_bs_notifiers; =20 - int quiesce_counter; VMChangeStateEntry *vmsh; bool force_allow_inactivate; }; @@ -245,9 +244,6 @@ static const BdrvChildRole child_root =3D { .get_name =3D blk_root_get_name, .get_parent_desc =3D blk_root_get_parent_desc, =20 - .drained_begin =3D blk_root_drained_begin, - .drained_end =3D blk_root_drained_end, - .activate =3D blk_root_activate, .inactivate =3D blk_root_inactivate, }; @@ -887,11 +883,6 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDev= Ops *ops, =20 blk->dev_ops =3D ops; blk->dev_opaque =3D opaque; - - /* Are we currently quiesced? Should we enforce this right now? */ - if (blk->quiesce_counter && ops->drained_begin) { - ops->drained_begin(opaque); - } } =20 /* @@ -2068,12 +2059,6 @@ static void blk_root_drained_begin(BdrvChild *child) { BlockBackend *blk =3D child->opaque; =20 - if (++blk->quiesce_counter =3D=3D 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.= */ =20 @@ -2085,14 +2070,7 @@ static void blk_root_drained_begin(BdrvChild *child) static void blk_root_drained_end(BdrvChild *child) { BlockBackend *blk =3D child->opaque; - assert(blk->quiesce_counter); =20 assert(blk->public.throttle_group_member.io_limits_disabled); atomic_dec(&blk->public.throttle_group_member.io_limits_disabled); - - if (--blk->quiesce_counter =3D=3D 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); } =20 -static const BlockDevOps block_job_dev_ops =3D { - .drained_begin =3D block_job_drained_begin, - .drained_end =3D block_job_drained_end, -}; - void block_job_unref(BlockJob *job) { if (--job->refcnt =3D=3D 0) { @@ -680,7 +675,6 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort= ); bs->job =3D job; =20 - 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_e= nd, 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, HDGeomet= ry *geo); void bdrv_io_plug(BlockDriverState *bs); void bdrv_io_unplug(BlockDriverState *bs); =20 -/** - * 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); =20 - /* - * 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; =20 /* This struct is embedded in (the private) BlockBackend struct and contai= ns --=20 2.14.3 From nobody Mon Apr 29 04:44:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511967392729965.1240199027405; Wed, 29 Nov 2017 06:56:32 -0800 (PST) Received: from localhost ([::1]:43494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eK3mi-0001HC-Tg for importer@patchew.org; Wed, 29 Nov 2017 09:56:24 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Block= JobDriver *driver, return job; } =20 -void block_job_pause_all(void) -{ - BlockJob *job =3D NULL; - while ((job =3D block_job_next(job))) { - AioContext *aio_context =3D 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) } } =20 -void block_job_resume_all(void) -{ - BlockJob *job =3D NULL; - while ((job =3D block_job_next(job))) { - AioContext *aio_context =3D 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 t= ype, int64_t ns); */ void block_job_yield(BlockJob *job); =20 -/** - * 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. --=20 2.14.3