From nobody Mon May 6 04:23:27 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 1490203979587396.33467204737883; Wed, 22 Mar 2017 10:32:59 -0700 (PDT) Received: from localhost ([::1]:52492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk82-00075e-83 for importer@patchew.org; Wed, 22 Mar 2017 13:32:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk6J-0005rQ-9r for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqk6I-0003aI-I9 for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqk6E-0003Y1-4A; Wed, 22 Mar 2017 13:31:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E4C964D8C; Wed, 22 Mar 2017 17:31:06 +0000 (UTC) Received: from localhost (ovpn-117-90.phx2.redhat.com [10.3.117.90]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C40097F38B; Wed, 22 Mar 2017 17:31:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2E4C964D8C Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2E4C964D8C From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 22 Mar 2017 13:30:59 -0400 Message-Id: <20170322173102.18180-2-jcody@redhat.com> In-Reply-To: <20170322173102.18180-1-jcody@redhat.com> References: <20170322173102.18180-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 22 Mar 2017 17:31:06 +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] [PULL for-2.9 1/4] blockjob: avoid recursive AioContext locking 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: peter.maydell@linaro.org, jcody@redhat.com, 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" From: Paolo Bonzini Streaming or any other block job hangs when performed on a block device that has a non-default iothread. This happens because the AioContext is acquired twice by block_job_defer_to_main_loop_bh and then released only once by BDRV_POLL_WHILE. (Insert rants on recursive mutexes, which unfortunately are a temporary but necessary evil for iothreads at the moment). Luckily, the reason for the double acquisition is simple; the function acquires the AioContext for both the job iothread and the BDS iothread, in case the BDS iothread was changed while the job was running. It is therefore enough to skip the second acquisition when the two AioContexts are one and the same. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Message-id: 1490118490-5597-1-git-send-email-pbonzini@redhat.com Signed-off-by: Jeff Cody --- blockjob.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/blockjob.c b/blockjob.c index 69126af..2159df7 100644 --- a/blockjob.c +++ b/blockjob.c @@ -755,12 +755,16 @@ static void block_job_defer_to_main_loop_bh(void *opa= que) =20 /* Fetch BDS AioContext again, in case it has changed */ aio_context =3D blk_get_aio_context(data->job->blk); - aio_context_acquire(aio_context); + if (aio_context !=3D data->aio_context) { + aio_context_acquire(aio_context); + } =20 data->job->deferred_to_main_loop =3D false; data->fn(data->job, data->opaque); =20 - aio_context_release(aio_context); + if (aio_context !=3D data->aio_context) { + aio_context_release(aio_context); + } =20 aio_context_release(data->aio_context); =20 --=20 2.9.3 From nobody Mon May 6 04:23:27 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 1490204040379415.3437559051506; Wed, 22 Mar 2017 10:34:00 -0700 (PDT) Received: from localhost ([::1]:52495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk91-0007t2-4r for importer@patchew.org; Wed, 22 Mar 2017 13:33:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk6J-0005rT-AT for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqk6I-0003aB-Ey for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34892) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqk6F-0003YT-BH; Wed, 22 Mar 2017 13:31: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 6982C42BD2; Wed, 22 Mar 2017 17:31:07 +0000 (UTC) Received: from localhost (ovpn-117-90.phx2.redhat.com [10.3.117.90]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1277280F63; Wed, 22 Mar 2017 17:31:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6982C42BD2 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=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6982C42BD2 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 22 Mar 2017 13:31:00 -0400 Message-Id: <20170322173102.18180-3-jcody@redhat.com> In-Reply-To: <20170322173102.18180-1-jcody@redhat.com> References: <20170322173102.18180-1-jcody@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]); Wed, 22 Mar 2017 17:31: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] [PULL for-2.9 2/4] 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: peter.maydell@linaro.org, jcody@redhat.com, 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" From: John Snow 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 startup wrapper 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 wrapper simply allows us to mandate that a job can "start," set busy to true, then immediately pause only if necessary. We could avoid requiring a wrapper, but all jobs would need to do it, so it's been factored out here. Signed-off-by: John Snow Reviewed-by: Jeff Cody Message-id: 20170316212351.13797-2-jsnow@redhat.com Signed-off-by: Jeff Cody --- blockjob.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/blockjob.c b/blockjob.c index 2159df7..0e9ed03 100644 --- a/blockjob.c +++ b/blockjob.c @@ -250,16 +250,28 @@ static bool block_job_started(BlockJob *job) return job->co; } =20 +/** + * All jobs must allow a pause point before entering their job proper. This + * ensures that jobs can be paused prior to being started, then resumed la= ter. + */ +static void coroutine_fn block_job_co_entry(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_co_entry, 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 Mon May 6 04:23:27 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 1490204159332138.72564764364995; Wed, 22 Mar 2017 10:35:59 -0700 (PDT) Received: from localhost ([::1]:52507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqkAv-00010n-W4 for importer@patchew.org; Wed, 22 Mar 2017 13:35:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk6O-0005xg-K0 for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqk6I-0003aV-Uz for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqk6G-0003Yz-Gy; Wed, 22 Mar 2017 13:31:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8333B7AE98; Wed, 22 Mar 2017 17:31:08 +0000 (UTC) Received: from localhost (ovpn-117-90.phx2.redhat.com [10.3.117.90]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47EC87E635; Wed, 22 Mar 2017 17:31:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8333B7AE98 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8333B7AE98 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 22 Mar 2017 13:31:01 -0400 Message-Id: <20170322173102.18180-4-jcody@redhat.com> In-Reply-To: <20170322173102.18180-1-jcody@redhat.com> References: <20170322173102.18180-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 22 Mar 2017 17:31: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] [PULL for-2.9 3/4] 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: peter.maydell@linaro.org, jcody@redhat.com, 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" From: John Snow Allow block backends to forward drain requests to their devices/users. The initial intended purpose for this patch is to allow BBs to forward requests along to BlockJobs, which will want to pause if their associated BB has entered a drained region. Signed-off-by: John Snow Reviewed-by: Jeff Cody Message-id: 20170316212351.13797-3-jsnow@redhat.com Signed-off-by: Jeff Cody --- block/block-backend.c | 24 ++++++++++++++++++++++-- include/sysemu/block-backend.h | 8 ++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 5742c09..0b63773 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 { @@ -699,12 +701,17 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDe= vOps *ops, void *opaque) { /* All drivers that use blk_set_dev_ops() are qdevified and we want to= keep - * it that way, so we can assume blk->dev is a DeviceState if blk->dev= _ops - * is set. */ + * it that way, so we can assume blk->dev, if present, is a DeviceStat= e if + * blk->dev_ops is set. Non-device users may use dev_ops without devic= e. */ assert(!blk->legacy_dev); =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,6 +1877,12 @@ 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 @@ -1881,7 +1894,14 @@ 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.io_limits_disabled); --blk->public.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/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 096c17f..7462228 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 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.9.3 From nobody Mon May 6 04:23:27 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 1490204104896775.9697440879143; Wed, 22 Mar 2017 10:35:04 -0700 (PDT) Received: from localhost ([::1]:52498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqkA3-0000Fw-Cz for importer@patchew.org; Wed, 22 Mar 2017 13:35:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqk6K-0005sj-LB for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqk6J-0003ao-Mt for qemu-devel@nongnu.org; Wed, 22 Mar 2017 13:31:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqk6H-0003ZJ-Jg; Wed, 22 Mar 2017 13:31:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C7491B1760; Wed, 22 Mar 2017 17:31:09 +0000 (UTC) Received: from localhost (ovpn-117-90.phx2.redhat.com [10.3.117.90]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 619FD7E635; Wed, 22 Mar 2017 17:31:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9C7491B1760 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9C7491B1760 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 22 Mar 2017 13:31:02 -0400 Message-Id: <20170322173102.18180-5-jcody@redhat.com> In-Reply-To: <20170322173102.18180-1-jcody@redhat.com> References: <20170322173102.18180-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 22 Mar 2017 17:31: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] [PULL for-2.9 4/4] 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: peter.maydell@linaro.org, jcody@redhat.com, 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" From: John Snow 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 Reviewed-by: Jeff Cody Message-id: 20170316212351.13797-4-jsnow@redhat.com Signed-off-by: Jeff Cody --- blockjob.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/blockjob.c b/blockjob.c index 0e9ed03..9b619f385 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,15 @@ 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; + + 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