From nobody Wed May 14 06:56:53 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 1526051381410649.5947758439213; Fri, 11 May 2018 08:09:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8491232D7457; Fri, 11 May 2018 15:09:39 +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 5617D2010CF0; Fri, 11 May 2018 15:09:39 +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 B042F1801245; Fri, 11 May 2018 15:09:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BF9Qe2008511 for ; Fri, 11 May 2018 11:09:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 797AD83B6B; Fri, 11 May 2018 15:09:26 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0090783B69; Fri, 11 May 2018 15:09:25 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:09:12 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com Subject: [libvirt] [PATCH v5 1/7] qemuMonitorJSONGetDeviceProps: Separate props processing 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: , Content-Type: text/plain; charset="utf-8" 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 11 May 2018 15:09:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The code that processes list of device properties is going to be reused. Therefore put it into a separate function. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 81 +++++++++++++++++++++++++---------------= ---- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e0ea553c41..ce7bc9e8e3 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6051,6 +6051,51 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr = mon, #undef MAKE_SET_CMD =20 =20 +static int +qemuMonitorJSONParsePropsList(virJSONValuePtr cmd, + virJSONValuePtr reply, + char ***props) +{ + virJSONValuePtr data; + char **proplist =3D NULL; + size_t n =3D 0; + size_t i; + int ret =3D -1; + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + goto cleanup; + + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); + + /* null-terminated list */ + if (VIR_ALLOC_N(proplist, n + 1) < 0) + goto cleanup; + + for (i =3D 0; i < n; i++) { + virJSONValuePtr child =3D virJSONValueArrayGet(data, i); + const char *tmp; + + if (!(tmp =3D virJSONValueObjectGetString(child, "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("reply data was missing 'name'")); + goto cleanup; + } + + if (VIR_STRDUP(proplist[i], tmp) < 0) + goto cleanup; + } + + ret =3D n; + *props =3D proplist; + proplist =3D NULL; + + cleanup: + virStringListFree(proplist); + return ret; +} + + int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon, const char *device, char ***props) @@ -6058,10 +6103,6 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon, int ret =3D -1; virJSONValuePtr cmd; virJSONValuePtr reply =3D NULL; - virJSONValuePtr data; - char **proplist =3D NULL; - size_t n =3D 0; - size_t i; =20 *props =3D NULL; =20 @@ -6078,38 +6119,10 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mo= n, goto cleanup; } =20 - if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; - - data =3D virJSONValueObjectGetArray(reply, "return"); - n =3D virJSONValueArraySize(data); - - /* null-terminated list */ - if (VIR_ALLOC_N(proplist, n + 1) < 0) - goto cleanup; - - for (i =3D 0; i < n; i++) { - virJSONValuePtr child =3D virJSONValueArrayGet(data, i); - const char *tmp; - - if (!(tmp =3D virJSONValueObjectGetString(child, "name"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("device-list-properties reply data was missin= g 'name'")); - goto cleanup; - } - - if (VIR_STRDUP(proplist[i], tmp) < 0) - goto cleanup; - } - - ret =3D n; - *props =3D proplist; - proplist =3D NULL; - + ret =3D qemuMonitorJSONParsePropsList(cmd, reply, props); cleanup: - virStringListFree(proplist); - virJSONValueFree(cmd); virJSONValueFree(reply); + virJSONValueFree(cmd); return ret; } =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list