From patchwork Sat Jan 27 02:05:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 10187253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A44E0602BD for ; Sat, 27 Jan 2018 02:11:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EFC529B99 for ; Sat, 27 Jan 2018 02:11:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DCD92AA2E; Sat, 27 Jan 2018 02:11:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5D38729B99 for ; Sat, 27 Jan 2018 02:11:34 +0000 (UTC) Received: from localhost ([::1]:43682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFxt-0008WJ-IK for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Jan 2018 21:11:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFs4-0000t7-IY for qemu-devel@nongnu.org; Fri, 26 Jan 2018 21:05:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1efFs2-0008Nv-L0 for qemu-devel@nongnu.org; Fri, 26 Jan 2018 21:05:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44690) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1efFrz-0008Jv-JX; Fri, 26 Jan 2018 21:05:27 -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 D717B81E03; 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 2D08D5457C; Sat, 27 Jan 2018 02:05:26 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Fri, 26 Jan 2018 21:05:06 -0500 Message-Id: <20180127020515.27137-6-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.25]); 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 05/14] blockjobs: add block_job_dismiss 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP For jobs that have reached their terminal state, prior to having their last reference put down (meaning jobs that have completed successfully, unsuccessfully, or have been canceled), allow the user to dismiss the job's lingering status report via block-job-dismiss. This gives management APIs the chance to conclusively determine if a job failed or succeeded, even if the event broadcast was missed. Note that jobs do not yet linger in any such state, they are freed immediately upon reaching this previously-unnamed state. such a state is added immediately in the next commit. Valid objects: Concluded: (added in a future commit); dismisses the concluded job. Signed-off-by: John Snow --- block/trace-events | 1 + blockdev.c | 14 ++++++++++++++ blockjob.c | 30 ++++++++++++++++++++++++++++++ include/block/blockjob.h | 9 +++++++++ qapi/block-core.json | 19 +++++++++++++++++++ 5 files changed, 73 insertions(+) diff --git a/block/trace-events b/block/trace-events index 11c8d5f590..8f61566770 100644 --- a/block/trace-events +++ b/block/trace-events @@ -46,6 +46,7 @@ qmp_block_job_cancel(void *job) "job %p" qmp_block_job_pause(void *job) "job %p" qmp_block_job_resume(void *job) "job %p" qmp_block_job_complete(void *job) "job %p" +qmp_block_job_dismiss(void *job) "job %p" qmp_block_stream(void *bs, void *job) "bs %p job %p" # block/file-win32.c diff --git a/blockdev.c b/blockdev.c index 2c0773bba7..5e8edff322 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3849,6 +3849,20 @@ void qmp_block_job_complete(const char *device, Error **errp) aio_context_release(aio_context); } +void qmp_block_job_dismiss(const char *id, Error **errp) +{ + AioContext *aio_context; + BlockJob *job = find_block_job(id, &aio_context, errp); + + if (!job) { + return; + } + + trace_qmp_block_job_dismiss(job); + block_job_dismiss(&job, errp); + aio_context_release(aio_context); +} + void qmp_change_backing_file(const char *device, const char *image_node_name, const char *backing_file, diff --git a/blockjob.c b/blockjob.c index ea216aca5e..5531f5c2ab 100644 --- a/blockjob.c +++ b/blockjob.c @@ -58,6 +58,7 @@ enum BlockJobVerb { BLOCK_JOB_VERB_RESUME, BLOCK_JOB_VERB_SET_SPEED, BLOCK_JOB_VERB_COMPLETE, + BLOCK_JOB_VERB_DISMISS, BLOCK_JOB_VERB__MAX }; @@ -68,6 +69,7 @@ bool BlockJobVerb[BLOCK_JOB_VERB__MAX][BLOCK_JOB_STATUS__MAX] = { [BLOCK_JOB_VERB_RESUME] = {0, 0, 0, 1, 0}, [BLOCK_JOB_VERB_SET_SPEED] = {0, 1, 1, 1, 1}, [BLOCK_JOB_VERB_COMPLETE] = {0, 0, 0, 0, 1}, + [BLOCK_JOB_VERB_DISMISS] = {0, 0, 0, 0, 0}, }; static void block_job_state_transition(BlockJob *job, BlockJobStatus s1) @@ -426,6 +428,13 @@ static void block_job_cancel_async(BlockJob *job) job->cancelled = true; } +static void block_job_do_dismiss(BlockJob *job) +{ + assert(job && job->manual == true); + block_job_state_transition(job, BLOCK_JOB_STATUS_UNDEFINED); + block_job_unref(job); +} + static int block_job_finish_sync(BlockJob *job, void (*finish)(BlockJob *, Error **errp), Error **errp) @@ -455,6 +464,9 @@ static int block_job_finish_sync(BlockJob *job, aio_poll(qemu_get_aio_context(), true); } ret = (job->cancelled && job->ret == 0) ? -ECANCELED : job->ret; + if (job->manual) { + block_job_do_dismiss(job); + } block_job_unref(job); return ret; } @@ -570,6 +582,24 @@ void block_job_complete(BlockJob *job, Error **errp) job->driver->complete(job, errp); } +void block_job_dismiss(BlockJob **jobptr, Error **errp) +{ + BlockJob *job = *jobptr; + /* similarly to _complete, this is QMP-interface only. */ + assert(job->id); + if (!job->manual) { + error_setg(errp, "The active block job '%s' was not started with " + "\'manual\': true, and so cannot be dismissed as it will " + "clean up after itself automatically", job->id); + return; + } + + error_setg(errp, "unimplemented"); + + block_job_do_dismiss(job); + *jobptr = NULL; +} + void block_job_user_pause(BlockJob *job) { job->user_paused = true; diff --git a/include/block/blockjob.h b/include/block/blockjob.h index d8e7df7e6e..7c71dc0ca7 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -241,6 +241,15 @@ void block_job_cancel(BlockJob *job); */ void block_job_complete(BlockJob *job, Error **errp); +/** + * block_job_dismiss: + * @job: The job to be dismissed. + * @errp: Error object. + * + * Remove a concluded job from the query list. + */ +void block_job_dismiss(BlockJob **job, Error **errp); + /** * block_job_query: * @job: The job to get information about. diff --git a/qapi/block-core.json b/qapi/block-core.json index eac89754c1..32aefa5a27 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2198,6 +2198,25 @@ ## { 'command': 'block-job-complete', 'data': { 'device': 'str' } } +## +# @block-job-dismiss: +# +# For jobs that have already concluded, remove them from the block-job-query +# list. This command only needs to be run for jobs which were started with +# QEMU 2.12+ job lifetime management semantics. +# +# This command will refuse to operate on any job that has not yet reached +# its terminal state. "cancel" or "complete" will still need to be used as +# appropriate. +# +# @id: The job identifier. +# +# Returns: Nothing on success +# +# Since: 2.12 +## +{ 'command': 'block-job-dismiss', 'data': { 'id': 'str' } } + ## # @BlockdevDiscardOptions: #