From nobody Tue Feb 10 05:10:43 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.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 1517019058371221.78644240700226; Fri, 26 Jan 2018 18:10:58 -0800 (PST) Received: from localhost ([::1]:43679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFxH-0007Ie-Ae for importer@patchew.org; Fri, 26 Jan 2018 21:10:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFs1-0000k5-Vt for qemu-devel@nongnu.org; Fri, 26 Jan 2018 21:05:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1efFs0-0008LI-FS for qemu-devel@nongnu.org; Fri, 26 Jan 2018 21:05:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48058) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1efFrx-0008IJ-4V; Fri, 26 Jan 2018 21:05:25 -0500 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 5670B1555A; Sat, 27 Jan 2018 02:05:24 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-231.bos.redhat.com [10.18.17.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BB0F5457C; Sat, 27 Jan 2018 02:05:23 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 26 Jan 2018 21:05:03 -0500 Message-Id: <20180127020515.27137-3-jsnow@redhat.com> In-Reply-To: <20180127020515.27137-1-jsnow@redhat.com> References: <20180127020515.27137-1-jsnow@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.29]); Sat, 27 Jan 2018 02:05:24 +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 v3 02/14] blockjobs: Add status enum 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, John Snow , pkrempa@redhat.com, jtc@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" We're about to add several new states, and booleans are becoming unwieldly and difficult to reason about. To this end, add a new "status" field and add our existing states in a redundant manner alongside the bools they are replacing: UNDEFINED: Placeholder, default state. CREATED: replaces (paused && !busy) RUNNING: replaces effectively (!paused && busy) PAUSED: Nearly redundant with info->paused, which shows pause_count. This reports the actual status of the job, which almost always matches the paused request status. It differs in that it is strictly only true when the job has actually gone dormant. READY: replaces job->ready. New state additions in coming commits will not be quite so redundant: WAITING: Waiting on Transaction. This job has finished all the work it can until the transaction converges, fails, or is canceled. This status does not feature for non-transactional jobs. PENDING: Pending authorization from user. This job has finished all the work it can until the job or transaction is finalized via block_job_finalize. If this job is in a transaction, it has already left the WAITING status. CONCLUDED: Job has ceased all operations and has a return code available for query and may be dismissed via block_job_dismiss. Signed-off-by: John Snow --- blockjob.c | 10 ++++++++++ include/block/blockjob.h | 4 ++++ qapi/block-core.json | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/blockjob.c b/blockjob.c index 9850d70cb0..6eb783a354 100644 --- a/blockjob.c +++ b/blockjob.c @@ -321,6 +321,7 @@ void block_job_start(BlockJob *job) job->pause_count--; job->busy =3D true; job->paused =3D false; + job->status =3D BLOCK_JOB_STATUS_RUNNING; bdrv_coroutine_enter(blk_bs(job->blk), job->co); } =20 @@ -601,6 +602,10 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **e= rrp) info->speed =3D job->speed; info->io_status =3D job->iostatus; info->ready =3D job->ready; + if (job->manual) { + info->has_status =3D true; + info->status =3D job->status; + } return info; } =20 @@ -704,6 +709,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, job->pause_count =3D 1; job->refcnt =3D 1; job->manual =3D manual; + job->status =3D BLOCK_JOB_STATUS_CREATED; aio_timer_init(qemu_get_aio_context(), &job->sleep_timer, QEMU_CLOCK_REALTIME, SCALE_NS, block_job_sleep_timer_cb, job); @@ -808,9 +814,12 @@ void coroutine_fn block_job_pause_point(BlockJob *job) } =20 if (block_job_should_pause(job) && !block_job_is_cancelled(job)) { + BlockJobStatus status =3D job->status; + job->status =3D BLOCK_JOB_STATUS_PAUSED; job->paused =3D true; block_job_do_yield(job, -1); job->paused =3D false; + job->status =3D status; } =20 if (job->driver->resume) { @@ -916,6 +925,7 @@ void block_job_iostatus_reset(BlockJob *job) =20 void block_job_event_ready(BlockJob *job) { + job->status =3D BLOCK_JOB_STATUS_READY; job->ready =3D true; =20 if (block_job_is_internal(job)) { diff --git a/include/block/blockjob.h b/include/block/blockjob.h index b94d0c9fa6..d8e7df7e6e 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -146,6 +146,10 @@ typedef struct BlockJob { */ bool manual; =20 + /* Current state, using 2.12+ state names + */ + BlockJobStatus status; + /** Non-NULL if this job is part of a transaction */ BlockJobTxn *txn; QLIST_ENTRY(BlockJob) txn_list; diff --git a/qapi/block-core.json b/qapi/block-core.json index 8225308904..eac89754c1 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -955,6 +955,18 @@ { 'enum': 'BlockJobType', 'data': ['commit', 'stream', 'mirror', 'backup'] } =20 +## +# @BlockJobStatus: +# +# Block Job State +# +# +# +# Since: 2.12 +## +{ 'enum': 'BlockJobStatus', + 'data': ['undefined', 'created', 'running', 'paused', 'ready'] } + ## # @BlockJobInfo: # @@ -981,12 +993,15 @@ # # @ready: true if the job may be completed (since 2.2) # +# @status: Current job state/status (since 2.12) +# # Since: 1.1 ## { 'struct': 'BlockJobInfo', 'data': {'type': 'str', 'device': 'str', 'len': 'int', 'offset': 'int', 'busy': 'bool', 'paused': 'bool', 'speed': 'in= t', - 'io-status': 'BlockDeviceIoStatus', 'ready': 'bool'} } + 'io-status': 'BlockDeviceIoStatus', 'ready': 'bool', + '*status': 'BlockJobStatus' } } =20 ## # @query-block-jobs: --=20 2.14.3