From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407570864317.3971584803593; Fri, 30 Mar 2018 03:59:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A96A7E9C1; Fri, 30 Mar 2018 10:59:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11F885C1A1; Fri, 30 Mar 2018 10:59:29 +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 13E904CA97; Fri, 30 Mar 2018 10:59:28 +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 w2UAxO7P011038 for ; Fri, 30 Mar 2018 06:59:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6A7D063537; Fri, 30 Mar 2018 10:59:24 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAA4084436; Fri, 30 Mar 2018 10:59:23 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:08 +0200 Message-Id: <70906b7d3517d50341a3ce63c852bb43b77902ac.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/9] util: json: Fix freeing of objects appended to virJSONValue 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 30 Mar 2018 10:59:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It was not possible to determine whether virJSONValueObjectAddVArgs and the functions using it would consume a virJSONValue or not when used with the 'a' or 'A' modifier depending on when the loop failed. Fix this by passing in a pointer to the pointer so that it can be cleared once it's successfully consumed and the callers don't have to second-guess leaving a chance of leaking or double freeing the value depending on the ordering. Fix all callers to pass a double pointer too. Signed-off-by: Peter Krempa --- src/qemu/qemu_agent.c | 7 ++----- src/qemu/qemu_block.c | 22 ++++++---------------- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_monitor_json.c | 36 ++++++++++-------------------------- src/util/virjson.c | 10 +++++++--- tests/qemublocktest.c | 4 +--- 6 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 89183c3f76..b99d5b10e3 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1336,14 +1336,13 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char = **mountpoints, return -1; cmd =3D qemuAgentMakeCommand("guest-fsfreeze-freeze-list", - "a:mountpoints", arg, NULL); + "a:mountpoints", &arg, NULL); } else { cmd =3D qemuAgentMakeCommand("guest-fsfreeze-freeze", NULL); } if (!cmd) goto cleanup; - arg =3D NULL; if (qemuAgentCommand(mon, cmd, &reply, true, VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) @@ -1611,12 +1610,10 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr mon, } if (!(cmd =3D qemuAgentMakeCommand("guest-set-vcpus", - "a:vcpus", cpus, + "a:vcpus", &cpus, NULL))) goto cleanup; - cpus =3D NULL; - if (qemuAgentCommand(mon, cmd, &reply, true, VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) goto cleanup; diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 6f81e9d96c..c0cf6a95ad 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -674,11 +674,9 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSource= Ptr src) "s:driver", "gluster", "s:volume", src->volume, "s:path", src->path, - "a:server", servers, NULL) < 0) + "a:server", &servers, NULL) < 0) goto cleanup; - servers =3D NULL; - if (src->debug && virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) < 0) goto cleanup; @@ -719,7 +717,7 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr = src) "s:driver", protocol, "S:tls-creds", src->tlsAlias, "s:vdisk-id", src->path, - "a:server", server, NULL) < 0) + "a:server", &server, NULL) < 0) virJSONValueFree(server); return ret; @@ -867,14 +865,12 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr= src) if (virJSONValueObjectCreate(&ret, "s:driver", "nbd", - "a:server", serverprops, + "a:server", &serverprops, "S:export", src->path, "S:tls-creds", src->tlsAlias, NULL) < 0) goto cleanup; - serverprops =3D NULL; - cleanup: virJSONValueFree(serverprops); return ret; @@ -902,13 +898,11 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr= src) "s:image", src->path, "S:snapshot", src->snapshot, "S:conf", src->configFile, - "A:server", servers, + "A:server", &servers, "S:user", username, NULL) < 0) goto cleanup; - servers =3D NULL; - cleanup: virJSONValueFree(servers); return ret; @@ -935,13 +929,11 @@ qemuBlockStorageSourceGetSheepdogProps(virStorageSour= cePtr src) /* libvirt does not support the 'snap-id' and 'tag' properties */ if (virJSONValueObjectCreate(&ret, "s:driver", "sheepdog", - "a:server", serverprops, + "a:server", &serverprops, "s:vdi", src->path, NULL) < 0) goto cleanup; - serverprops =3D NULL; - cleanup: virJSONValueFree(serverprops); return ret; @@ -971,13 +963,11 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr= src) if (virJSONValueObjectCreate(&ret, "s:driver", "ssh", "s:path", src->path, - "a:server", serverprops, + "a:server", &serverprops, "S:user", username, NULL) < 0) goto cleanup; - serverprops =3D NULL; - cleanup: virJSONValueFree(serverprops); return ret; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 89fd08b642..3d4130d3c0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1505,7 +1505,7 @@ qemuDiskSourceGetProps(virStorageSourcePtr src) if (!(props =3D qemuBlockStorageSourceGetBackendProps(src))) return NULL; - if (virJSONValueObjectCreate(&ret, "a:file", props, NULL) < 0) { + if (virJSONValueObjectCreate(&ret, "a:file", &props, NULL) < 0) { virJSONValueFree(props); return NULL; } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d80c4f18d1..f38d04f663 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3950,14 +3950,11 @@ int qemuMonitorJSONAddObject(qemuMonitorPtr mon, cmd =3D qemuMonitorJSONMakeCommand("object-add", "s:qom-type", type, "s:id", objalias, - "A:props", props, + "A:props", &props, NULL); if (!cmd) goto cleanup; - /* @props is part of @cmd now. Avoid double free */ - props =3D NULL; - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -4133,12 +4130,13 @@ qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJ= SONValuePtr actions) int ret =3D -1; virJSONValuePtr cmd; virJSONValuePtr reply =3D NULL; + virJSONValuePtr act =3D actions; bool protect =3D actions->protect; /* We do NOT want to free actions when recursively freeing cmd. */ actions->protect =3D true; cmd =3D qemuMonitorJSONMakeCommand("transaction", - "a:actions", actions, + "a:actions", &act, NULL); if (!cmd) goto cleanup; @@ -4425,15 +4423,12 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon, } cmd =3D qemuMonitorJSONMakeCommand("send-key", - "a:keys", keys, + "a:keys", &keys, "p:hold-time", holdtime, NULL); if (!cmd) goto cleanup; - /* @keys is part of @cmd now. Avoid double free */ - keys =3D NULL; - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -5390,15 +5385,10 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr = mon, if (!(cmd =3D qemuMonitorJSONMakeCommand("query-cpu-model-expansion", "s:type", typeStr, - "a:model", model, + "a:model", &model, NULL))) goto cleanup; - /* model will be freed when cmd is freed. we set model - * to NULL to avoid double freeing. - */ - model =3D NULL; - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -6263,13 +6253,11 @@ qemuMonitorJSONSetMigrationCapability(qemuMonitorPt= r mon, cap =3D NULL; cmd =3D qemuMonitorJSONMakeCommand("migrate-set-capabilities", - "a:capabilities", caps, + "a:capabilities", &caps, NULL); if (!cmd) goto cleanup; - caps =3D NULL; - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -6410,7 +6398,7 @@ qemuMonitorJSONBuildInetSocketAddress(const char *hos= t, return NULL; if (virJSONValueObjectCreate(&addr, "s:type", "inet", - "a:data", data, NULL) < 0) { + "a:data", &data, NULL) < 0) { virJSONValueFree(data); return NULL; } @@ -6428,7 +6416,7 @@ qemuMonitorJSONBuildUnixSocketAddress(const char *pat= h) return NULL; if (virJSONValueObjectCreate(&addr, "s:type", "unix", - "a:data", data, NULL) < 0) { + "a:data", &data, NULL) < 0) { virJSONValueFree(data); return NULL; } @@ -6454,13 +6442,10 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, return ret; if (!(cmd =3D qemuMonitorJSONMakeCommand("nbd-server-start", - "a:addr", addr, + "a:addr", &addr, NULL))) goto cleanup; - /* From now on, @addr is part of @cmd */ - addr =3D NULL; - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; @@ -6763,10 +6748,9 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrI= D, if (!(ret =3D qemuMonitorJSONMakeCommand("chardev-add", "s:id", chrID, - "a:backend", backend, + "a:backend", &backend, NULL))) goto cleanup; - backend =3D NULL; cleanup: VIR_FREE(tlsalias); diff --git a/src/util/virjson.c b/src/util/virjson.c index 6a02ddf0cc..212c158da0 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -109,8 +109,11 @@ virJSONValueGetType(const virJSONValue *value) * d: double precision floating point number * n: json null value * + * The following two cases take a pointer to a pointer to a virJSONValuePt= r. The + * pointer is cleared when the virJSONValuePtr is stolen into the object. * a: json object, must be non-NULL * A: json object, omitted if NULL + * * m: a bitmap represented as a JSON array, must be non-NULL * M: a bitmap represented as a JSON array, omitted if NULL * @@ -241,9 +244,9 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, case 'A': case 'a': { - virJSONValuePtr val =3D va_arg(args, virJSONValuePtr); + virJSONValuePtr *val =3D va_arg(args, virJSONValuePtr *); - if (!val) { + if (!(*val)) { if (type =3D=3D 'A') continue; @@ -253,7 +256,8 @@ virJSONValueObjectAddVArgs(virJSONValuePtr obj, goto cleanup; } - rc =3D virJSONValueObjectAppend(obj, key, val); + if ((rc =3D virJSONValueObjectAppend(obj, key, *val)) =3D=3D 0) + *val =3D NULL; } break; case 'M': diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index e8fac100dd..99584c759c 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -67,11 +67,9 @@ testBackingXMLjsonXML(const void *args) goto cleanup; } - if (virJSONValueObjectCreate(&wrapper, "a:file", backendprops, NULL) <= 0) + if (virJSONValueObjectCreate(&wrapper, "a:file", &backendprops, NULL) = < 0) goto cleanup; - backendprops =3D NULL; - if (!(propsstr =3D virJSONValueToString(wrapper, false))) goto cleanup; --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407571006484.3286140435647; Fri, 30 Mar 2018 03:59:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B9825D5EB; Fri, 30 Mar 2018 10:59:29 +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 DD0245D6A2; Fri, 30 Mar 2018 10:59:28 +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 7E1B2180596F; Fri, 30 Mar 2018 10:59:28 +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 w2UAxPrJ011043 for ; Fri, 30 Mar 2018 06:59:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 240886352A; Fri, 30 Mar 2018 10:59:25 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id A250A84436; Fri, 30 Mar 2018 10:59:24 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:09 +0200 Message-Id: <6602e494efce7a82295967e76b28faf5b43a1828.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/9] tests: json: Validate that attribute values are properly stolen 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 30 Mar 2018 10:59:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make sure that the 'a' and 'A' modifiers for virJSONValueObjectAddVArgs behave correctly. Signed-off-by: Peter Krempa --- tests/virjsontest.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 685df7276e..fe72b84340 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -429,6 +429,51 @@ testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) } +static int +testJSONObjectFormatSteal(const void *opaque ATTRIBUTE_UNUSED) +{ + virJSONValuePtr a1 =3D NULL; + virJSONValuePtr a2 =3D NULL; + virJSONValuePtr t1 =3D NULL; + virJSONValuePtr t2 =3D NULL; + int ret =3D -1; + + if (!(a1 =3D virJSONValueNewString("test")) || + !(a2 =3D virJSONValueNewString("test"))) { + VIR_TEST_VERBOSE("Failed to create json object"); + } + + if (virJSONValueObjectCreate(&t1, "a:t", &a1, "s:f", NULL, NULL) !=3D = -1) { + VIR_TEST_VERBOSE("virJSONValueObjectCreate(t1) should have failed\= n"); + goto cleanup; + } + + if (a1) { + VIR_TEST_VERBOSE("appended object a1 was not consumed\n"); + goto cleanup; + } + + if (virJSONValueObjectCreate(&t2, "s:f", NULL, "a:t", &a1, NULL) !=3D = -1) { + VIR_TEST_VERBOSE("virJSONValueObjectCreate(t2) should have failed\= n"); + goto cleanup; + } + + if (!a2) { + VIR_TEST_VERBOSE("appended object a2 was consumed\n"); + goto cleanup; + } + + ret =3D 0; + + cleanup: + virJSONValueFree(a1); + virJSONValueFree(a2); + virJSONValueFree(t1); + virJSONValueFree(t2); + return ret; +} + + static int mymain(void) { @@ -588,6 +633,8 @@ mymain(void) NULL, true); DO_TEST_FULL("create object with nested json in attribute", EscapeObj, NULL, NULL, true); + DO_TEST_FULL("stealing of attributes while creating objects", + ObjectFormatSteal, NULL, NULL, true); #define DO_TEST_DEFLATTEN(name, pass) \ DO_TEST_FULL(name, Deflatten, name, NULL, pass) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407583712609.5761153064144; Fri, 30 Mar 2018 03:59:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD9357B03B; Fri, 30 Mar 2018 10:59: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 8A3F65DD6B; Fri, 30 Mar 2018 10:59: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 4EA65180BAD6; Fri, 30 Mar 2018 10:59:39 +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 w2UAxPIU011052 for ; Fri, 30 Mar 2018 06:59:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id D339E6352D; Fri, 30 Mar 2018 10:59:25 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D5EF84436; Fri, 30 Mar 2018 10:59:25 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:10 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/9] qemu: monitor: Use virJSONValueObjectKeysNumber in qemuMonitorJSONGetCPUModelExpansion 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.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 30 Mar 2018 10:59:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Replace direct access to virJSONValue members by accessor. Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor_json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f38d04f663..c94d2ef4b8 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5443,7 +5443,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mo= n, if (VIR_STRDUP(machine_model->name, cpu_name) < 0) goto cleanup; - if (VIR_ALLOC_N(machine_model->props, cpu_props->data.object.npairs) <= 0) + if (VIR_ALLOC_N(machine_model->props, virJSONValueObjectKeysNumber(cpu= _props)) < 0) goto cleanup; if (virJSONValueObjectForeachKeyValue(cpu_props, --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407580064624.1383088285687; Fri, 30 Mar 2018 03:59:40 -0700 (PDT) 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 5C48D3AD87; Fri, 30 Mar 2018 10:59:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 39E9A6A03B; Fri, 30 Mar 2018 10:59:38 +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 06BC44CA9E; Fri, 30 Mar 2018 10:59: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 w2UAxQHQ011057 for ; Fri, 30 Mar 2018 06:59:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E6A26352A; Fri, 30 Mar 2018 10:59:26 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 186F38444E; Fri, 30 Mar 2018 10:59:25 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:11 +0200 Message-Id: <3b798361e7326d1dbde09bcc1d4452504da4acdf.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 4/9] qemu: agent: Avoid unnecessary JSON object type check 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.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.38]); Fri, 30 Mar 2018 10:59:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use virJSONValueObjectGetArray instead of virJSONValueObjectGet so that it's not necessary to check whether it's an array. Signed-off-by: Peter Krempa --- src/qemu/qemu_agent.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index b99d5b10e3..dfec57d992 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1502,18 +1502,12 @@ qemuAgentGetVCPUs(qemuAgentPtr mon, VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) goto cleanup; - if (!(data =3D virJSONValueObjectGet(reply, "return"))) { + if (!(data =3D virJSONValueObjectGetArray(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("guest-get-vcpus reply was missing return data")); goto cleanup; } - if (data->type !=3D VIR_JSON_TYPE_ARRAY) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("guest-get-vcpus return information was not an ar= ray")); - goto cleanup; - } - ndata =3D virJSONValueArraySize(data); if (VIR_ALLOC_N(*info, ndata) < 0) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407579786127.06437624864202; Fri, 30 Mar 2018 03:59:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67043C04BD35; Fri, 30 Mar 2018 10:59:38 +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 3BF475C582; Fri, 30 Mar 2018 10:59:38 +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 064E3181BA08; Fri, 30 Mar 2018 10:59: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 w2UAxRhu011064 for ; Fri, 30 Mar 2018 06:59:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49F7A6352D; Fri, 30 Mar 2018 10:59:27 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C80FB84436; Fri, 30 Mar 2018 10:59:26 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:12 +0200 Message-Id: <84774304f14f0439548187eaffc4db38ef7e5a81.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/9] json: Replace access to virJSONValue->type by virJSONValueGetType 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 30 Mar 2018 10:59:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/qemu/qemu_agent.c | 6 +++--- src/qemu/qemu_monitor_json.c | 18 +++++++++--------- src/util/virqemu.c | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index dfec57d992..85af53d194 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -336,7 +336,7 @@ qemuAgentIOProcessLine(qemuAgentPtr mon, goto cleanup; } - if (obj->type !=3D VIR_JSON_TYPE_OBJECT) { + if (virJSONValueGetType(obj) !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Parsed JSON reply '%s' isn't an object"), line); goto cleanup; @@ -1872,7 +1872,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoP= tr **info, goto cleanup; } - if (data->type !=3D VIR_JSON_TYPE_ARRAY) { + if (virJSONValueGetType(data) !=3D VIR_JSON_TYPE_ARRAY) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("guest-get-fsinfo return information was not " "an array")); @@ -1931,7 +1931,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoP= tr **info, goto cleanup; } - if (entry->type !=3D VIR_JSON_TYPE_ARRAY) { + if (virJSONValueGetType(entry) !=3D VIR_JSON_TYPE_ARRAY) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("guest-get-fsinfo 'disk' data was not an arra= y")); goto cleanup; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index c94d2ef4b8..de915eabb4 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -197,7 +197,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon, if (!(obj =3D virJSONValueFromString(line))) goto cleanup; - if (obj->type !=3D VIR_JSON_TYPE_OBJECT) { + if (virJSONValueGetType(obj) !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Parsed JSON reply '%s' isn't an object"), line); goto cleanup; @@ -1978,7 +1978,7 @@ qemuMonitorJSONGetBlockDev(virJSONValuePtr devices, { virJSONValuePtr dev =3D virJSONValueArrayGet(devices, idx); - if (!dev || dev->type !=3D VIR_JSON_TYPE_OBJECT) { + if (!dev || virJSONValueGetType(dev) !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-block device entry was not in expected for= mat")); return NULL; @@ -2197,7 +2197,7 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mo= n, virJSONValuePtr dev =3D virJSONValueArrayGet(devices, i); const char *dev_name; - if (!dev || dev->type !=3D VIR_JSON_TYPE_OBJECT) { + if (!dev || virJSONValueGetType(dev) !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("blockstats device entry was not " "in expected format")); @@ -3276,7 +3276,7 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonit= orPtr mon, for (i =3D 0; i < virJSONValueArraySize(formats); i++) { virJSONValuePtr dumpformat =3D virJSONValueArrayGet(formats, i); - if (!dumpformat || dumpformat->type !=3D VIR_JSON_TYPE_STRING) { + if (!dumpformat || virJSONValueGetType(dumpformat) !=3D VIR_JSON_T= YPE_STRING) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing entry in supported dump formats")); goto cleanup; @@ -4791,7 +4791,7 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr re= sult, virJSONValuePtr inserted; const char *current_dev; - if (!temp_dev || temp_dev->type !=3D VIR_JSON_TYPE_OBJECT) { + if (!temp_dev || virJSONValueGetType(temp_dev) !=3D VIR_JSON_TYPE_= OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("block_io_throttle device entry " "was not in expected format")); @@ -5261,7 +5261,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, for (j =3D 0; j < len; j++) { virJSONValuePtr blocker =3D virJSONValueArrayGet(blockers,= j); - if (blocker->type !=3D VIR_JSON_TYPE_STRING) { + if (virJSONValueGetType(blocker) !=3D VIR_JSON_TYPE_STRING= ) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unexpected value in unavailable-feat= ures " "array")); @@ -5304,7 +5304,7 @@ qemuMonitorJSONParseCPUModelProperty(const char *key, prop =3D machine_model->props + machine_model->nprops; - switch ((virJSONType) value->type) { + switch ((virJSONType) virJSONValueGetType(value)) { case VIR_JSON_TYPE_STRING: if (VIR_STRDUP(prop->value.string, virJSONValueGetString(value)) <= 0) return -1; @@ -6193,7 +6193,7 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPt= r mon, virJSONValuePtr cap =3D virJSONValueArrayGet(caps, i); const char *name; - if (!cap || cap->type !=3D VIR_JSON_TYPE_OBJECT) { + if (!cap || virJSONValueGetType(cap) !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing entry in migration capabilities list= ")); goto cleanup; @@ -6343,7 +6343,7 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon, bool kernel; bool emulated; - if (!cap || cap->type !=3D VIR_JSON_TYPE_OBJECT) { + if (!cap || virJSONValueGetType(cap) !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing entry in GIC capabilities list")); goto cleanup; diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 2e9e65f9ef..e7ea068b94 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -146,16 +146,17 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, bool nested) { struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, arrayFu= nc }; + virJSONType type =3D virJSONValueGetType(value); virJSONValuePtr elem; size_t i; - if (!key && value->type !=3D VIR_JSON_TYPE_OBJECT) { + if (!key && type !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("only JSON objects can be top level")); return -1; } - switch ((virJSONType) value->type) { + switch (type) { case VIR_JSON_TYPE_STRING: virBufferAsprintf(buf, "%s=3D", key); virQEMUBuildBufferEscapeComma(buf, value->data.string); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407583007909.3404811626259; Fri, 30 Mar 2018 03:59:43 -0700 (PDT) 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 549C628132; Fri, 30 Mar 2018 10:59:41 +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 31A2060BEF; Fri, 30 Mar 2018 10:59:41 +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 F2EF1181BA07; Fri, 30 Mar 2018 10:59:40 +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 w2UAxSEB011069 for ; Fri, 30 Mar 2018 06:59:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 058BE63537; Fri, 30 Mar 2018 10:59:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 834D96352A; Fri, 30 Mar 2018 10:59:27 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:13 +0200 Message-Id: <17118230d51f211d6d2dc556f0b0ceaefee7936f.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 6/9] util: json: Add accessor for geting a VIR_JSON_TYPE_NUMBER as string 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.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.30]); Fri, 30 Mar 2018 10:59:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Sometimes it's desired to get a JSON number as string. Add a helper. This will help in cases where we'd want to conver the internal type from string to something else. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virjson.c | 10 ++++++++++ src/util/virjson.h | 1 + 3 files changed, 12 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 03fe3b315f..989411cdca 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2038,6 +2038,7 @@ virJSONValueGetBoolean; virJSONValueGetNumberDouble; virJSONValueGetNumberInt; virJSONValueGetNumberLong; +virJSONValueGetNumberString; virJSONValueGetNumberUint; virJSONValueGetNumberUlong; virJSONValueGetString; diff --git a/src/util/virjson.c b/src/util/virjson.c index 212c158da0..6f2b52257f 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1043,6 +1043,16 @@ virJSONValueGetString(virJSONValuePtr string) } +const char * +virJSONValueGetNumberString(virJSONValuePtr number) +{ + if (number->type !=3D VIR_JSON_TYPE_NUMBER) + return NULL; + + return number->data.number; +} + + int virJSONValueGetNumberInt(virJSONValuePtr number, int *value) diff --git a/src/util/virjson.h b/src/util/virjson.h index 017a1f20ed..e80d10dea1 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -134,6 +134,7 @@ const char *virJSONValueObjectGetKey(virJSONValuePtr ob= ject, unsigned int n); virJSONValuePtr virJSONValueObjectGetValue(virJSONValuePtr object, unsigne= d int n); const char *virJSONValueGetString(virJSONValuePtr object); +const char *virJSONValueGetNumberString(virJSONValuePtr number); int virJSONValueGetNumberInt(virJSONValuePtr object, int *value); int virJSONValueGetNumberUint(virJSONValuePtr object, unsigned int *value); int virJSONValueGetNumberLong(virJSONValuePtr object, long long *value); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152240758527480.07719388919804; Fri, 30 Mar 2018 03:59:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12E5F9D0C6; Fri, 30 Mar 2018 10:59:44 +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 E4B325D6A8; Fri, 30 Mar 2018 10:59:43 +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 A6F21180BADA; Fri, 30 Mar 2018 10:59:43 +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 w2UAxSh5011075 for ; Fri, 30 Mar 2018 06:59:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id B50A384436; Fri, 30 Mar 2018 10:59:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F1ED6352A; Fri, 30 Mar 2018 10:59:28 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:14 +0200 Message-Id: <2d12b46d89bfa20ffc8219a695fb0cc1711b77d7.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 7/9] util: qemu: Don't access virJSONValue members directly in virQEMUBuildCommandLineJSONRecurse 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 30 Mar 2018 10:59:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the accessors instead. Signed-off-by: Peter Krempa --- src/util/virqemu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index e7ea068b94..d6652262fe 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -148,6 +148,7 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, struct virQEMUCommandLineJSONIteratorData data =3D { key, buf, arrayFu= nc }; virJSONType type =3D virJSONValueGetType(value); virJSONValuePtr elem; + bool tmp; size_t i; if (!key && type !=3D VIR_JSON_TYPE_OBJECT) { @@ -159,16 +160,17 @@ virQEMUBuildCommandLineJSONRecurse(const char *key, switch (type) { case VIR_JSON_TYPE_STRING: virBufferAsprintf(buf, "%s=3D", key); - virQEMUBuildBufferEscapeComma(buf, value->data.string); + virQEMUBuildBufferEscapeComma(buf, virJSONValueGetString(value)); virBufferAddLit(buf, ","); break; case VIR_JSON_TYPE_NUMBER: - virBufferAsprintf(buf, "%s=3D%s,", key, value->data.number); + virBufferAsprintf(buf, "%s=3D%s,", key, virJSONValueGetNumberStrin= g(value)); break; case VIR_JSON_TYPE_BOOLEAN: - if (value->data.boolean) + virJSONValueGetBoolean(value, &tmp); + if (tmp) virBufferAsprintf(buf, "%s=3Dyes,", key); else virBufferAsprintf(buf, "%s=3Dno,", key); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407584041590.1864771519479; Fri, 30 Mar 2018 03:59:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74FAE7E9F3; Fri, 30 Mar 2018 10:59:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C3F85D70A; Fri, 30 Mar 2018 10:59:42 +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 1723F4CAA2; Fri, 30 Mar 2018 10:59:42 +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 w2UAxTlq011085 for ; Fri, 30 Mar 2018 06:59:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 702556352D; Fri, 30 Mar 2018 10:59:29 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE4818444E; Fri, 30 Mar 2018 10:59:28 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:15 +0200 Message-Id: <2174f1a2ead95672ba6e688a18c847c1caef6816.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 8/9] qemu: monitor: Don't resist stealing 'actions' in qemuMonitorJSONTransaction 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 30 Mar 2018 10:59:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than trying to prevent stealing of the 'actions' virJSONValue into the monitor command replace the code so that it does the same thing, since 'actions' was actually not really used after calling the monitor. Signed-off-by: Peter Krempa --- src/qemu/qemu_driver.c | 4 ++-- src/qemu/qemu_monitor.c | 4 ++-- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 9 ++------- src/qemu/qemu_monitor_json.h | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7bcc4936de..8f1d58ba71 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14811,7 +14811,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr= driver, if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) goto cleanup; - ret =3D qemuMonitorTransaction(priv->mon, actions); + ret =3D qemuMonitorTransaction(priv->mon, &actions); if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) { ret =3D -1; @@ -14855,7 +14855,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr= driver, } } - if (ret =3D=3D 0 || !actions) { + if (ret =3D=3D 0 || !do_transaction) { if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver-= >caps) < 0 || (persist && virDomainSaveConfig(cfg->configDir, driver->caps, vm->newDef) < 0)) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index e169553b7e..7b647525b3 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3386,9 +3386,9 @@ qemuMonitorDriveMirror(qemuMonitorPtr mon, /* Use the transaction QMP command to run atomic snapshot commands. */ int -qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions) +qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr *actions) { - VIR_DEBUG("actions=3D%p", actions); + VIR_DEBUG("actions=3D%p", *actions); QEMU_CHECK_MONITOR_JSON(mon); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 7a22323504..d04148e568 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -898,7 +898,7 @@ int qemuMonitorDiskSnapshot(qemuMonitorPtr mon, const char *file, const char *format, bool reuse); -int qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions) +int qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr *actions) ATTRIBUTE_NONNULL(2); int qemuMonitorDriveMirror(qemuMonitorPtr mon, const char *device, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index de915eabb4..1fd09a3398 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4125,18 +4125,14 @@ qemuMonitorJSONDriveMirror(qemuMonitorPtr mon, } int -qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSONValuePtr actions) +qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSONValuePtr *actions) { int ret =3D -1; virJSONValuePtr cmd; virJSONValuePtr reply =3D NULL; - virJSONValuePtr act =3D actions; - bool protect =3D actions->protect; - /* We do NOT want to free actions when recursively freeing cmd. */ - actions->protect =3D true; cmd =3D qemuMonitorJSONMakeCommand("transaction", - "a:actions", &act, + "a:actions", actions, NULL); if (!cmd) goto cleanup; @@ -4151,7 +4147,6 @@ qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSO= NValuePtr actions) cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); - actions->protect =3D protect; return ret; } diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 846d366b27..045df4919f 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -253,7 +253,7 @@ int qemuMonitorJSONDiskSnapshot(qemuMonitorPtr mon, bool reuse) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5); -int qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSONValuePtr actions) +int qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSONValuePtr *action= s) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int qemuMonitorJSONDriveMirror(qemuMonitorPtr mon, const char *device, --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 19:40:52 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522407587759548.5748476390563; Fri, 30 Mar 2018 03:59:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48315A6E0C; Fri, 30 Mar 2018 10:59:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2221C5D756; Fri, 30 Mar 2018 10:59:41 +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 E10964CAA0; Fri, 30 Mar 2018 10:59:40 +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 w2UAxUhH011091 for ; Fri, 30 Mar 2018 06:59:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B2506352D; Fri, 30 Mar 2018 10:59:30 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id A920C63537; Fri, 30 Mar 2018 10:59:29 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 30 Mar 2018 12:59:16 +0200 Message-Id: <97740c908ec9fdf66a375caae84768792588d27c.1522407032.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 9/9] util: json: Privatize struct _virJSONValue and sub-structs 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 30 Mar 2018 10:59:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Enforce usage of accessors by hiding the implementation in the code. Signed-off-by: Peter Krempa --- src/util/virjson.c | 39 +++++++++++++++++++++++++++++++++++++++ src/util/virjson.h | 38 -------------------------------------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 6f2b52257f..3ddefc34ca 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -51,6 +51,45 @@ VIR_LOG_INIT("util.json"); +typedef struct _virJSONObject virJSONObject; +typedef virJSONObject *virJSONObjectPtr; + +typedef struct _virJSONObjectPair virJSONObjectPair; +typedef virJSONObjectPair *virJSONObjectPairPtr; + +typedef struct _virJSONArray virJSONArray; +typedef virJSONArray *virJSONArrayPtr; + + +struct _virJSONObjectPair { + char *key; + virJSONValuePtr value; +}; + +struct _virJSONObject { + size_t npairs; + virJSONObjectPairPtr pairs; +}; + +struct _virJSONArray { + size_t nvalues; + virJSONValuePtr *values; +}; + +struct _virJSONValue { + int type; /* enum virJSONType */ + bool protect; /* prevents deletion when embedded in another object */ + + union { + virJSONObject object; + virJSONArray array; + char *string; + char *number; /* int/float/etc format is context defined so we can= 't parse it here :-( */ + int boolean; + } data; +}; + + typedef struct _virJSONParserState virJSONParserState; typedef virJSONParserState *virJSONParserStatePtr; struct _virJSONParserState { diff --git a/src/util/virjson.h b/src/util/virjson.h index e80d10dea1..f7283dcf97 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -42,44 +42,6 @@ typedef enum { typedef struct _virJSONValue virJSONValue; typedef virJSONValue *virJSONValuePtr; -typedef struct _virJSONObject virJSONObject; -typedef virJSONObject *virJSONObjectPtr; - -typedef struct _virJSONObjectPair virJSONObjectPair; -typedef virJSONObjectPair *virJSONObjectPairPtr; - -typedef struct _virJSONArray virJSONArray; -typedef virJSONArray *virJSONArrayPtr; - - -struct _virJSONObjectPair { - char *key; - virJSONValuePtr value; -}; - -struct _virJSONObject { - size_t npairs; - virJSONObjectPairPtr pairs; -}; - -struct _virJSONArray { - size_t nvalues; - virJSONValuePtr *values; -}; - -struct _virJSONValue { - int type; /* enum virJSONType */ - bool protect; /* prevents deletion when embedded in another object */ - - union { - virJSONObject object; - virJSONArray array; - char *string; - char *number; /* int/float/etc format is context defined so we can= 't parse it here :-( */ - int boolean; - } data; -}; - void virJSONValueFree(virJSONValuePtr value); void virJSONValueHashFree(void *opaque, const void *name); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list