From nobody Wed May 14 20:48:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526642968060742.5480838843067; Fri, 18 May 2018 04:29:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9F7430F8DA0; Fri, 18 May 2018 11:29:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7621C9759F; Fri, 18 May 2018 11:29:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2BF60180B536; Fri, 18 May 2018 11:29:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4IBTJIN016038 for ; Fri, 18 May 2018 07:29:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id A5ED22026E03; Fri, 18 May 2018 11:29:19 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 260162026DFD for ; Fri, 18 May 2018 11:29:19 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 18 May 2018 13:28:55 +0200 Message-Id: <36d2d56645e8fcb0c795f5eb3ca2c111a1887e78.1526642823.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/15] qemu: monitor: Factor out and document code to format QMP command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 18 May 2018 11:29:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move formatting of the qemu command out of qemuMonitorJSONMakeCommandRaw to qemuMonitorJSONMakeCommandInternal to allow greater reusability and document the function better. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor_json.c | 70 +++++++++++++++++++++++++++++++---------= ---- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 6dcded9369..0b0fb7feba 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -464,40 +464,68 @@ qemuMonitorJSONHasError(virJSONValuePtr reply, } -/* Top-level commands and nested transaction list elements share a - * common structure for everything except the dictionary names. */ +/** + * qemuMonitorJSONMakeCommandInternal: + * @cmdname: QMP command name + * @arguments: a JSON object containing command arguments or NULL + * @transaction: format the command as arguments for the 'transaction' com= mand + * + * Create a JSON object used on the QMP monitor to call a command. If + * @transaction is true, the returned object is formatted to be used as a = member + * of the 'transaction' command. + * + * Note that @arguments is always consumed and should not be referenced af= ter + * the call to this function. + */ +static virJSONValuePtr +qemuMonitorJSONMakeCommandInternal(const char *cmdname, + virJSONValuePtr arguments, + bool transaction) +{ + virJSONValuePtr cmd =3D NULL; + virJSONValuePtr ret =3D NULL; + + if (!transaction) { + if (virJSONValueObjectCreate(&cmd, + "s:execute", cmdname, + "A:arguments", &arguments, NULL) < 0) + goto cleanup; + } else { + if (virJSONValueObjectCreate(&cmd, + "s:type", cmdname, + "A:data", &arguments, NULL) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, cmd); + + cleanup: + virJSONValueFree(arguments); + virJSONValueFree(cmd); + return ret; +} + + static virJSONValuePtr ATTRIBUTE_SENTINEL -qemuMonitorJSONMakeCommandRaw(bool wrap, const char *cmdname, ...) +qemuMonitorJSONMakeCommandRaw(bool transaction, + const char *cmdname, + ...) { - virJSONValuePtr obj; + virJSONValuePtr obj =3D NULL; virJSONValuePtr jargs =3D NULL; va_list args; va_start(args, cmdname); - if (!(obj =3D virJSONValueNewObject())) - goto error; - - if (virJSONValueObjectAppendString(obj, wrap ? "type" : "execute", - cmdname) < 0) - goto error; - if (virJSONValueObjectCreateVArgs(&jargs, args) < 0) - goto error; + goto cleanup; - if (jargs && - virJSONValueObjectAppend(obj, wrap ? "data" : "arguments", jargs) = < 0) - goto error; + obj =3D qemuMonitorJSONMakeCommandInternal(cmdname, jargs, transaction= ); + cleanup: va_end(args); return obj; - - error: - virJSONValueFree(obj); - virJSONValueFree(jargs); - va_end(args); - return NULL; } #define qemuMonitorJSONMakeCommand(cmdname, ...) \ --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list