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 1517018901014986.0370702905391; Fri, 26 Jan 2018 18:08:21 -0800 (PST) Received: from localhost ([::1]:43658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFuk-0004El-9p for importer@patchew.org; Fri, 26 Jan 2018 21:08:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFs3-0000oz-2E for qemu-devel@nongnu.org; Fri, 26 Jan 2018 21:05:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1efFs1-0008Mj-Oh for qemu-devel@nongnu.org; Fri, 26 Jan 2018 21:05:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48064) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1efFry-0008JQ-Op; Fri, 26 Jan 2018 21:05:26 -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 0EA4E1555A; Sat, 27 Jan 2018 02:05:26 +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 5183A5457C; Sat, 27 Jan 2018 02:05:25 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 26 Jan 2018 21:05:05 -0500 Message-Id: <20180127020515.27137-5-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:26 +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 04/14] blockjobs: RFC add block_job_verb permission table 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" Which commands are appropriate for jobs in which state is also somewhat burdensome to keep track of. Introduce a verbs table that, as of this RFC patch, does nothing but serve as a declaration of intent. (At the very least, it forced me to consider all of the possibilities.) If this idea seems appealing, I can expand the verbs concept into a list of interfaces to consult the table and refuse inappropriate commands, mostly serving as new errors for the QMP interface. cancel: can apply to any created, running, paused or ready job. pause: can apply to any created, running, or ready job. Addition pauses can and do stack, so a paused job can also be paused. Note that a pause from the QMP context is treated separately and does not stack. resume: Only a paused job can be resumed. Only a job that has been paused via QMP can be resumed via QMP. set-speed: Any created, running, paused or ready job can tolerate a set-speed request. complete: Only a ready job may accept a complete request. Signed-off-by: John Snow --- blockjob.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/blockjob.c b/blockjob.c index d084a1e318..ea216aca5e 100644 --- a/blockjob.c +++ b/blockjob.c @@ -52,6 +52,24 @@ bool BlockJobSTT[BLOCK_JOB_STATUS__MAX][BLOCK_JOB_STATUS= __MAX] =3D { /* Y: */ [BLOCK_JOB_STATUS_READY] =3D {0, 0, 0, 1, 0}, }; =20 +enum BlockJobVerb { + BLOCK_JOB_VERB_CANCEL, + BLOCK_JOB_VERB_PAUSE, + BLOCK_JOB_VERB_RESUME, + BLOCK_JOB_VERB_SET_SPEED, + BLOCK_JOB_VERB_COMPLETE, + BLOCK_JOB_VERB__MAX +}; + +bool BlockJobVerb[BLOCK_JOB_VERB__MAX][BLOCK_JOB_STATUS__MAX] =3D { + /* U, C, R, P, Y */ + [BLOCK_JOB_VERB_CANCEL] =3D {0, 1, 1, 1, 1}, + [BLOCK_JOB_VERB_PAUSE] =3D {0, 1, 1, 1, 1}, + [BLOCK_JOB_VERB_RESUME] =3D {0, 0, 0, 1, 0}, + [BLOCK_JOB_VERB_SET_SPEED] =3D {0, 1, 1, 1, 1}, + [BLOCK_JOB_VERB_COMPLETE] =3D {0, 0, 0, 0, 1}, +}; + static void block_job_state_transition(BlockJob *job, BlockJobStatus s1) { BlockJobStatus s0 =3D job->status; --=20 2.14.3