From nobody Wed May 8 20:20:38 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.zoho.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 1489625232656346.6443860975588; Wed, 15 Mar 2017 17:47:12 -0700 (PDT) Received: from localhost ([::1]:40162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coJZM-00031r-TR for importer@patchew.org; Wed, 15 Mar 2017 20:47:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46574) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coJYS-0002zR-I8 for qemu-devel@nongnu.org; Wed, 15 Mar 2017 20:46:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coJYR-0004Vq-MD for qemu-devel@nongnu.org; Wed, 15 Mar 2017 20:46:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coJYN-0004ST-J9; Wed, 15 Mar 2017 20:46:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E7661E5E; Thu, 16 Mar 2017 00:46:07 +0000 (UTC) Received: from scv.usersys.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB63160F8E; Thu, 16 Mar 2017 00:46:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8E7661E5E Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jsnow@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8E7661E5E From: John Snow To: qemu-block@nongnu.org Date: Wed, 15 Mar 2017 20:46:01 -0400 Message-Id: <20170316004603.20609-2-jsnow@redhat.com> In-Reply-To: <20170316004603.20609-1-jsnow@redhat.com> References: <20170316004603.20609-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 16 Mar 2017 00:46:07 +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] [RFC patch 1/3] blockjob: add block_job_start_shim X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, John Snow , qemu-devel@nongnu.org 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" The purpose of this shim is to allow us to pause pre-started jobs. The purpose of *that* is to allow us to buffer a pause request that will be able to take effect before the job ever does any work, allowing us to create jobs during a quiescent state (under which they will be automatically paused), then resuming the jobs after the critical section in any order, either: (1) -block_job_start -block_job_resume (via e.g. drained_end) (2) -block_job_resume (via e.g. drained_end) -block_job_start The problem that requires a shim is the idea that a job must start in the busy=3Dtrue state only its first time-- all subsequent entries require busy to be false, and the toggling of this state is otherwise handled during existing pause and yield points. The shim simply allows us to mandate that a job can "start," set busy to true, then immediately pause only if necessary. Signed-off-by: John Snow --- blockjob.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/blockjob.c b/blockjob.c index 69126af..6d08ce5 100644 --- a/blockjob.c +++ b/blockjob.c @@ -250,16 +250,28 @@ static bool block_job_started(BlockJob *job) return job->co; } =20 +/** + * This code must run after the job's coroutine has been entered, + * but not before. + */ +static void coroutine_fn block_job_start_shim(void *opaque) +{ + BlockJob *job =3D opaque; + + assert(job && job->driver && job->driver->start); + block_job_pause_point(job); + job->driver->start(job); +} + void block_job_start(BlockJob *job) { assert(job && !block_job_started(job) && job->paused && - !job->busy && job->driver->start); - job->co =3D qemu_coroutine_create(job->driver->start, job); - if (--job->pause_count =3D=3D 0) { - job->paused =3D false; - job->busy =3D true; - qemu_coroutine_enter(job->co); - } + job->driver && job->driver->start); + job->co =3D qemu_coroutine_create(block_job_start_shim, job); + job->pause_count--; + job->busy =3D true; + job->paused =3D false; + qemu_coroutine_enter(job->co); } =20 void block_job_ref(BlockJob *job) --=20 2.9.3 From nobody Wed May 8 20:20:38 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.zoho.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 1489625235168408.5436586611693; Wed, 15 Mar 2017 17:47:15 -0700 (PDT) Received: from localhost ([::1]:40165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coJZS-00035r-1s for importer@patchew.org; Wed, 15 Mar 2017 20:47:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coJYS-0002zS-Pi for qemu-devel@nongnu.org; Wed, 15 Mar 2017 20:46:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coJYR-0004Vv-Np for qemu-devel@nongnu.org; Wed, 15 Mar 2017 20:46:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coJYO-0004T5-C5; Wed, 15 Mar 2017 20:46:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 55E4D7E9D3; Thu, 16 Mar 2017 00:46:08 +0000 (UTC) Received: from scv.usersys.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id B00E760F86; Thu, 16 Mar 2017 00:46:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 55E4D7E9D3 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jsnow@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 55E4D7E9D3 From: John Snow To: qemu-block@nongnu.org Date: Wed, 15 Mar 2017 20:46:02 -0400 Message-Id: <20170316004603.20609-3-jsnow@redhat.com> In-Reply-To: <20170316004603.20609-1-jsnow@redhat.com> References: <20170316004603.20609-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 16 Mar 2017 00:46:08 +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] [RFC patch 2/3] block-backend: add drained_begin / drained_end 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: kwolf@redhat.com, pbonzini@redhat.com, John Snow , qemu-devel@nongnu.org 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: John Snow --- RFC questions: - Does the presence of blk->quiesce_counter relieve the burden of needing blk->public.io_limits_disabled? I could probably eliminate this counter entirely and just spy on the root node's quiescent state at key moments instead. I am confident I'm traipsing on delicate drain semantics. - Should I treat the separation of a quisced BDS/BB as a drained_end request as an analogue to how blk_insert_bs (in this patch) handles this? Signed-off-by: John Snow --- block/block-backend.c | 25 +++++++++++++++++++++++++ include/sysemu/block-backend.h | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 5742c09..eb85e8b 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -65,6 +65,8 @@ struct BlockBackend { bool allow_write_beyond_eof; =20 NotifierList remove_bs_notifiers, insert_bs_notifiers; + + int quiesce_counter; }; =20 typedef struct BlockBackendAIOCB { @@ -559,6 +561,11 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState = *bs, Error **errp) } bdrv_ref(bs); =20 + /* The new BDS may be quiescent, we should attempt to match */ + if (bs->quiesce_counter) { + blk_root_drained_begin(blk->root); + } + notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { throttle_timers_attach_aio_context( @@ -705,6 +712,11 @@ 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 /* @@ -1870,9 +1882,15 @@ static void blk_root_drained_begin(BdrvChild *child) { BlockBackend *blk =3D child->opaque; =20 + blk->quiesce_counter++; + /* 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 + if (blk->dev_ops && blk->dev_ops->drained_begin) { + blk->dev_ops->drained_begin(blk->dev_opaque); + } + if (blk->public.io_limits_disabled++ =3D=3D 0) { throttle_group_restart_blk(blk); } @@ -1882,6 +1900,13 @@ static void blk_root_drained_end(BdrvChild *child) { BlockBackend *blk =3D child->opaque; =20 + assert(blk->quiesce_counter); + blk->quiesce_counter--; + assert(blk->public.io_limits_disabled); --blk->public.io_limits_disabled; + + if (blk->dev_ops && blk->dev_ops->drained_end) { + blk->dev_ops->drained_end(blk->dev_opaque); + } } diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 096c17f..c6f4408 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -58,6 +58,14 @@ 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 drain request ends. + */ + void (*drained_end)(void *opaque); } BlockDevOps; =20 /* This struct is embedded in (the private) BlockBackend struct and contai= ns --=20 2.9.3 From nobody Wed May 8 20:20:38 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.zoho.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 1489625235908953.0053408327773; Wed, 15 Mar 2017 17:47:15 -0700 (PDT) Received: from localhost ([::1]:40164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coJZR-00035H-84 for importer@patchew.org; Wed, 15 Mar 2017 20:47:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coJYS-0002zT-R5 for qemu-devel@nongnu.org; Wed, 15 Mar 2017 20:46:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coJYR-0004W2-QK for qemu-devel@nongnu.org; Wed, 15 Mar 2017 20:46:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coJYP-0004TW-4S; Wed, 15 Mar 2017 20:46:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 193DC80F8E; Thu, 16 Mar 2017 00:46:09 +0000 (UTC) Received: from scv.usersys.redhat.com (dhcp-17-221.bos.redhat.com [10.18.17.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 768E360F88; Thu, 16 Mar 2017 00:46:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 193DC80F8E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jsnow@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 193DC80F8E From: John Snow To: qemu-block@nongnu.org Date: Wed, 15 Mar 2017 20:46:03 -0400 Message-Id: <20170316004603.20609-4-jsnow@redhat.com> In-Reply-To: <20170316004603.20609-1-jsnow@redhat.com> References: <20170316004603.20609-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 16 Mar 2017 00:46:09 +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] [RFC patch 3/3] blockjob: add devops to blockjob backends X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, John Snow , qemu-devel@nongnu.org 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" This lets us hook into drained_begin and drained_end requests from the backend level, which is particularly useful for making sure that all jobs associated with a particular node (whether the source or the target) receive a drain request. Suggested-by: Kevin Wolf Signed-off-by: John Snow -- RFC topics: - BlkDevOps is traditionally only for Qdev devices, and a BlockJob is not currently a 'device'... Do we want to loosen this restriction, find anoth= er way to deliver callbacks to BlockJobs attached to BlkBackends, or do some= thing crazy like make a BlockJob device object? struct JobDevice { DeviceState parent_obj; BlockJob *job; } ...?? - Not so sure about leaving the initial job refcount at 1, since we are giv= ing away a handle to this job as dev_opaque. By incrementing it to 2, however, it's not clear whose responsibility it is to decrement it again. Signed-off-by: John Snow --- blockjob.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/blockjob.c b/blockjob.c index 6d08ce5..0542677 100644 --- a/blockjob.c +++ b/blockjob.c @@ -68,6 +68,23 @@ 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, +}; + BlockJob *block_job_next(BlockJob *job) { if (!job) { @@ -205,11 +222,6 @@ void *block_job_create(const char *job_id, const Block= JobDriver *driver, } =20 job =3D g_malloc0(driver->instance_size); - error_setg(&job->blocker, "block device is in use by block job: %s", - BlockJobType_lookup[driver->job_type]); - block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort= ); - bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); - job->driver =3D driver; job->id =3D g_strdup(job_id); job->blk =3D blk; @@ -219,8 +231,20 @@ void *block_job_create(const char *job_id, const Block= JobDriver *driver, job->paused =3D true; job->pause_count =3D 1; job->refcnt =3D 1; + /* RFC: job is now stored both in bs->job and blk->dev_opaque, + * but we cannot expect the backend to know how to put down the ref + * so it'd be up to this code here to increment it anyway, making it + * a bit of a useless exercise. It would be up to us to ensure that + * we destruct the blkbackend before putting down our last reference. = */ + + error_setg(&job->blocker, "block device is in use by block job: %s", + BlockJobType_lookup[driver->job_type]); + 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); + bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); + QLIST_INSERT_HEAD(&block_jobs, job, job_list); =20 blk_add_aio_context_notifier(blk, block_job_attached_aio_context, --=20 2.9.3