From nobody Mon Feb 9 01:16:28 2026 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 1489699506880312.1989647629666; Thu, 16 Mar 2017 14:25:06 -0700 (PDT) Received: from localhost ([::1]:45839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coctN-0005DT-1T for importer@patchew.org; Thu, 16 Mar 2017 17:25:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cocsL-0005Ay-HT for qemu-devel@nongnu.org; Thu, 16 Mar 2017 17:24:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cocsK-0002aY-Ir for qemu-devel@nongnu.org; Thu, 16 Mar 2017 17:24:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52003) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cocsF-0002Y7-SD; Thu, 16 Mar 2017 17:23:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E00A8804FA; Thu, 16 Mar 2017 21:23:55 +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 3445E4FA20; Thu, 16 Mar 2017 21:23:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E00A8804FA 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 E00A8804FA From: John Snow To: qemu-block@nongnu.org Date: Thu, 16 Mar 2017 17:23:49 -0400 Message-Id: <20170316212351.13797-2-jsnow@redhat.com> In-Reply-To: <20170316212351.13797-1-jsnow@redhat.com> References: <20170316212351.13797-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 16 Mar 2017 21:23:56 +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 v2 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, jcody@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 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 --- blockjob.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/blockjob.c b/blockjob.c index 69126af..69b4ec6 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