From nobody Wed Oct 29 17:26:07 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 1526651241816349.36972487989146; Fri, 18 May 2018 06:47:21 -0700 (PDT) Received: from localhost ([::1]:39038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJfj1-0005QT-UD for importer@patchew.org; Fri, 18 May 2018 09:47:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJfL1-0000XI-IY for qemu-devel@nongnu.org; Fri, 18 May 2018 09:22:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJfL0-0006V9-8x for qemu-devel@nongnu.org; Fri, 18 May 2018 09:22:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51512 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 1fJfKu-0006QU-Jd; Fri, 18 May 2018 09:22:20 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 401BD401EF14; Fri, 18 May 2018 13:22:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-149.ams2.redhat.com [10.36.117.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5A6C2024CBE; Fri, 18 May 2018 13:22:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 18 May 2018 15:21:11 +0200 Message-Id: <20180518132114.4070-38-kwolf@redhat.com> In-Reply-To: <20180518132114.4070-1-kwolf@redhat.com> References: <20180518132114.4070-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 18 May 2018 13:22:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 18 May 2018 13:22:20 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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] [PATCH v2 37/40] 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, jsnow@redhat.com, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com 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 | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/qemu/job.h | 3 +++ job-qmp.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ job.c | 2 +- 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/qapi/job.json b/qapi/job.json index b84dc6c820..932d5928e9 100644 --- a/qapi/job.json +++ b/qapi/job.json @@ -205,3 +205,48 @@ # 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 +# @offset to @len. The value is monotonically increa= sing. +# +# @total-progress: Estimated @offset value at the completion of the j= ob. +# This value can arbitrarily change while the 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 8e106e5d15..37f32266ba 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