From nobody Thu Dec 18 17:58:58 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527083602418970.4658770963198; Wed, 23 May 2018 06:53:22 -0700 (PDT) Received: from localhost ([::1]:33565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLUCb-0000MR-Pr for importer@patchew.org; Wed, 23 May 2018 09:53:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLTZY-0002UE-Ex for qemu-devel@nongnu.org; Wed, 23 May 2018 09:13:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLTZT-0007Jh-J2 for qemu-devel@nongnu.org; Wed, 23 May 2018 09:12:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35050 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLTZJ-0007Cv-EH; Wed, 23 May 2018 09:12:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F1604023826; Wed, 23 May 2018 13:12:41 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.118.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61AC485787; Wed, 23 May 2018 13:12:40 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 23 May 2018 15:11:52 +0200 Message-Id: <20180523131155.12359-44-kwolf@redhat.com> In-Reply-To: <20180523131155.12359-1-kwolf@redhat.com> References: <20180523131155.12359-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 23 May 2018 13:12:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 23 May 2018 13:12:41 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 43/46] job: Add query-jobs QMP command 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, 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" This adds a minimal query-jobs implementation that shouldn't pose many design questions. It can later be extended to expose more information, and especially job-specific information. Signed-off-by: Kevin Wolf --- qapi/job.json | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/qemu/job.h | 3 +++ job-qmp.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ job.c | 2 +- 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/qapi/job.json b/qapi/job.json index b84dc6c820..970124de76 100644 --- a/qapi/job.json +++ b/qapi/job.json @@ -205,3 +205,49 @@ # Since: 2.13 ## { 'command': 'job-finalize', 'data': { 'id': 'str' } } + +## +# @JobInfo: +# +# Information about a job. +# +# @id: The job identifier +# +# @type: The kind of job that is being performed +# +# @status: Current job state/status +# +# @current-progress: Progress made until now. The unit is arbitrary and= the +# value can only meaningfully be used for the ratio = of +# @current-progress to @total-progress. The value is +# monotonically increasing. +# +# @total-progress: Estimated @current-progress value at the completio= n of +# the job. This value can arbitrarily change while t= he +# job is running, in both directions. +# +# @error: If this field is present, the job failed; if it is +# still missing in the CONCLUDED state, this indicat= es +# successful completion. +# +# The value is a human-readable error message to des= cribe +# the reason for the job failure. It should not be p= arsed +# by applications. +# +# Since: 2.13 +## +{ 'struct': 'JobInfo', + 'data': { 'id': 'str', 'type': 'JobType', 'status': 'JobStatus', + 'current-progress': 'int', 'total-progress': 'int', + '*error': 'str' } } + +## +# @query-jobs: +# +# Return information about jobs. +# +# Returns: a list with a @JobInfo for each active job +# +# Since: 2.13 +## +{ 'command': 'query-jobs', 'returns': ['JobInfo'] } diff --git a/include/qemu/job.h b/include/qemu/job.h index 92d1d249fe..8c8badf75e 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -392,6 +392,9 @@ JobType job_type(const Job *job); /** Returns the enum string for the JobType of a given Job. */ const char *job_type_str(const Job *job); =20 +/** Returns true if the job should not be visible to the management layer.= */ +bool job_is_internal(Job *job); + /** Returns whether the job is scheduled for cancellation. */ bool job_is_cancelled(Job *job); =20 diff --git a/job-qmp.c b/job-qmp.c index b2e18cfd9c..7f38f63336 100644 --- a/job-qmp.c +++ b/job-qmp.c @@ -132,3 +132,57 @@ void qmp_job_dismiss(const char *id, Error **errp) job_dismiss(&job, errp); aio_context_release(aio_context); } + +static JobInfo *job_query_single(Job *job, Error **errp) +{ + JobInfo *info; + const char *errmsg =3D NULL; + + assert(!job_is_internal(job)); + + if (job->ret < 0) { + errmsg =3D strerror(-job->ret); + } + + info =3D g_new(JobInfo, 1); + *info =3D (JobInfo) { + .id =3D g_strdup(job->id), + .type =3D job_type(job), + .status =3D job->status, + .current_progress =3D job->progress_current, + .total_progress =3D job->progress_total, + .has_error =3D !!errmsg, + .error =3D g_strdup(errmsg), + }; + + return info; +} + +JobInfoList *qmp_query_jobs(Error **errp) +{ + JobInfoList *head =3D NULL, **p_next =3D &head; + Job *job; + + for (job =3D job_next(NULL); job; job =3D job_next(job)) { + JobInfoList *elem; + AioContext *aio_context; + + if (job_is_internal(job)) { + continue; + } + elem =3D g_new0(JobInfoList, 1); + aio_context =3D job->aio_context; + aio_context_acquire(aio_context); + elem->value =3D job_query_single(job, errp); + aio_context_release(aio_context); + if (!elem->value) { + g_free(elem); + qapi_free_JobInfoList(head); + return NULL; + } + *p_next =3D elem; + p_next =3D &elem->next; + } + + return head; +} diff --git a/job.c b/job.c index 599a1042cf..f026661b0f 100644 --- a/job.c +++ b/job.c @@ -158,7 +158,7 @@ static int job_txn_apply(JobTxn *txn, int fn(Job *), bo= ol lock) return rc; } =20 -static bool job_is_internal(Job *job) +bool job_is_internal(Job *job) { return (job->id =3D=3D NULL); } --=20 2.13.6