From nobody Mon May 6 04:10:38 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; 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 155386656556193.39883613255404; Fri, 29 Mar 2019 06:36:05 -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 A42A4307D85B; Fri, 29 Mar 2019 13:36:02 +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 7C1ED19026; Fri, 29 Mar 2019 13:36:01 +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 B74E5180338A; Fri, 29 Mar 2019 13:36:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2TDXm8S026945 for ; Fri, 29 Mar 2019 09:33:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5EB5117C70; Fri, 29 Mar 2019 13:33:48 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB8FE17C69 for ; Fri, 29 Mar 2019 13:33:47 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:38 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/7] util: buffer: Remove struct member munging 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-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.48]); Fri, 29 Mar 2019 13:36:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This was meant to stop abusing the members directly, but we don't do this for other internal structs. Additionally this did not stop the test from touching the members. Remove the header obscurization. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/util/virbuffer.c | 12 ------------ src/util/virbuffer.h | 16 ++++++---------- tests/virbuftest.c | 2 +- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 12bdd13d39..8bb9c8e1fa 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -23,24 +23,12 @@ #include #include "c-ctype.h" -#define __VIR_BUFFER_C__ - #include "virbuffer.h" #include "virerror.h" #include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE -/* If adding more fields, ensure to edit buf.h to match - the number of fields */ -struct _virBuffer { - unsigned int size; - unsigned int use; - unsigned int error; /* errno value, or -1 for usage error */ - int indent; - char *content; -}; - /** * virBufferFail * @buf: the buffer diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index b399c90154..16cd8515d6 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -35,19 +35,15 @@ typedef struct _virBuffer virBuffer; typedef virBuffer *virBufferPtr; -# ifndef __VIR_BUFFER_C__ -# define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL } +# define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL } -/* This struct must be kept in sync with the real struct - in the buf.c impl file */ struct _virBuffer { - unsigned int a; - unsigned int b; - unsigned int c; - int d; - char *e; + unsigned int size; + unsigned int use; + unsigned int error; /* errno value, or -1 for usage error */ + int indent; + char *content; }; -# endif const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 34f02b1281..b608da94d4 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -29,7 +29,7 @@ static int testBufInfiniteLoop(const void *data) * which was the case after the above addchar at the time of the bug. * This test is a bit fragile, since it relies on virBuffer internals. */ - if (virAsprintf(&addstr, "%*s", buf->a - buf->b - 1, "a") < 0) + if (virAsprintf(&addstr, "%*s", buf->size - buf->use - 1, "a") < 0) goto out; if (info->doEscape) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 04:10:38 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; 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 1553866470894978.3209783636254; Fri, 29 Mar 2019 06:34: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 5AF7D308339F; Fri, 29 Mar 2019 13:34: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 2723561B80; Fri, 29 Mar 2019 13:34: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 27F83180338C; Fri, 29 Mar 2019 13:34:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2TDXnLt026953 for ; Fri, 29 Mar 2019 09:33:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D81118E3E; Fri, 29 Mar 2019 13:33:49 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAB7C17C69 for ; Fri, 29 Mar 2019 13:33:48 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:39 +0100 Message-Id: <7ae0b96a9e38043e459823ef36ab1249254ffcd7.1553866155.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/7] util: buffer: Use 'size_t' for buffer size variables 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-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.44]); Fri, 29 Mar 2019 13:34:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use size_t for all sizes. The '*' modifier unfortunately does require an int so a temporary variable is necessary in the tests. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/util/virbuffer.c | 2 +- src/util/virbuffer.h | 6 +++--- tests/virbuftest.c | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 8bb9c8e1fa..2e1e4abead 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -339,7 +339,7 @@ virBufferCheckErrorInternal(const virBuffer *buf, * * Return the string usage in bytes */ -unsigned int +size_t virBufferUse(const virBuffer *buf) { if (buf =3D=3D NULL) diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 16cd8515d6..18957ae02c 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -38,8 +38,8 @@ typedef virBuffer *virBufferPtr; # define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL } struct _virBuffer { - unsigned int size; - unsigned int use; + size_t size; + size_t use; unsigned int error; /* errno value, or -1 for usage error */ int indent; char *content; @@ -69,7 +69,7 @@ VIR_DEFINE_AUTOCLEAN_FUNC(virBuffer, virBufferFreeAndRese= t); # define virBufferCheckError(buf) \ virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__= , \ __LINE__) -unsigned int virBufferUse(const virBuffer *buf); +size_t virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd); void virBufferAddChar(virBufferPtr buf, char c); diff --git a/tests/virbuftest.c b/tests/virbuftest.c index b608da94d4..778754d7c1 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -20,6 +20,7 @@ static int testBufInfiniteLoop(const void *data) char *addstr =3D NULL, *bufret =3D NULL; int ret =3D -1; const struct testInfo *info =3D data; + int len; virBufferAddChar(buf, 'a'); @@ -29,7 +30,8 @@ static int testBufInfiniteLoop(const void *data) * which was the case after the above addchar at the time of the bug. * This test is a bit fragile, since it relies on virBuffer internals. */ - if (virAsprintf(&addstr, "%*s", buf->size - buf->use - 1, "a") < 0) + len =3D buf->size - buf->use - 1; + if (virAsprintf(&addstr, "%*s", len, "a") < 0) goto out; if (info->doEscape) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 04:10:38 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; 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 1553866570838454.5939714366932; Fri, 29 Mar 2019 06:36:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 72F5D88AB2; Fri, 29 Mar 2019 13:36:09 +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 4E8B91001DD6; Fri, 29 Mar 2019 13:36:09 +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 0B80E18033A2; Fri, 29 Mar 2019 13:36:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2TDXngK026960 for ; Fri, 29 Mar 2019 09:33:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id F17D817C69; Fri, 29 Mar 2019 13:33:49 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AC4E18E3F for ; Fri, 29 Mar 2019 13:33:49 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:40 +0100 Message-Id: <3daf3f8f54ffd9dd899ed15d99086aabfa8dda2e.1553866155.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/7] util: json: Use virBuffer in JSON->string conversion 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Mar 2019 13:36:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The last step of the conversion involves copying of the generated JSON into a separate string. We can use a virBuffer to do this as this will also allow to subsequently use the buffer when we actually need to do some other formatting of the string. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/util/virjson.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index d5d66f879f..7dfc589944 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -28,6 +28,7 @@ #include "virlog.h" #include "virstring.h" #include "virutil.h" +#include "virbuffer.h" #if WITH_YAJL # include @@ -1969,17 +1970,18 @@ virJSONValueToStringOne(virJSONValuePtr object, } -char * -virJSONValueToString(virJSONValuePtr object, +static int +virJSONValueToBuffer(virJSONValuePtr object, + virBufferPtr buf, bool pretty) { yajl_gen g; const unsigned char *str; - char *ret =3D NULL; yajl_size_t len; # ifndef WITH_YAJL2 yajl_gen_config conf =3D { pretty ? 1 : 0, pretty ? " " : " "}; # endif + int ret =3D -1; VIR_DEBUG("object=3D%p", object); @@ -2009,13 +2011,12 @@ virJSONValueToString(virJSONValuePtr object, goto cleanup; } - ignore_value(VIR_STRDUP(ret, (const char *)str)); + virBufferAdd(buf, (const char *) str, len); + ret =3D 0; cleanup: yajl_gen_free(g); - VIR_DEBUG("result=3D%s", NULLSTR(ret)); - return ret; } @@ -2030,17 +2031,36 @@ virJSONValueFromString(const char *jsonstring ATTRI= BUTE_UNUSED) } -char * -virJSONValueToString(virJSONValuePtr object ATTRIBUTE_UNUSED, +static int +virJSONValueToBuffer(virJSONValuePtr object ATTRIBUTE_UNUSED, + virBufferPtr buf ATTRIBUTE_UNUSED, bool pretty ATTRIBUTE_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No JSON parser implementation is available")); - return NULL; + return -1; } #endif +char * +virJSONValueToString(virJSONValuePtr object, + bool pretty) +{ + VIR_AUTOCLEAN(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + char *ret =3D NULL; + + if (virJSONValueToBuffer(object, &buf, pretty) < 0) + return NULL; + + ret =3D virBufferContentAndReset(&buf); + + VIR_DEBUG("result=3D%s", NULLSTR(ret)); + + return ret; +} + + /** * virJSONStringReformat: * @jsonstr: string to reformat --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 04:10:38 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; 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 1553866476455952.2902825431103; Fri, 29 Mar 2019 06:34:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA7AAC010930; Fri, 29 Mar 2019 13:34:34 +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 7B20683E87; Fri, 29 Mar 2019 13:34:34 +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 35C263FA46; Fri, 29 Mar 2019 13:34:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2TDXoCQ026965 for ; Fri, 29 Mar 2019 09:33:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C18D417C69; Fri, 29 Mar 2019 13:33:50 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AFCB18E2F for ; Fri, 29 Mar 2019 13:33:50 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:41 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] util: json: Don't bother logging output string in virJSONValueToString 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 29 Mar 2019 13:34:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We have tests that validate the XML formatter. Additionally almost every guide tells users to disable JSON logging. Drop logging of output string in virJSONValueToString. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/util/virjson.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 7dfc589944..19857d2f2f 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -2048,16 +2048,11 @@ virJSONValueToString(virJSONValuePtr object, bool pretty) { VIR_AUTOCLEAN(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char *ret =3D NULL; if (virJSONValueToBuffer(object, &buf, pretty) < 0) return NULL; - ret =3D virBufferContentAndReset(&buf); - - VIR_DEBUG("result=3D%s", NULLSTR(ret)); - - return ret; + return virBufferContentAndReset(&buf); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 04:10:38 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; 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 1553866528872909.2921775275319; Fri, 29 Mar 2019 06:35:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 583E13092649; Fri, 29 Mar 2019 13:35:27 +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 274B76B806; Fri, 29 Mar 2019 13:35:27 +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 D517E41F3F; Fri, 29 Mar 2019 13:35:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2TDXpUt026976 for ; Fri, 29 Mar 2019 09:33:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 916E817C70; Fri, 29 Mar 2019 13:33:51 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B67717C69 for ; Fri, 29 Mar 2019 13:33:50 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:42 +0100 Message-Id: <1aa694c11d980f890ae7448f3d15faee54587331.1553866155.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/7] util: json: Export virJSONValueToBuffer 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-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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 29 Mar 2019 13:35:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/libvirt_private.syms | 1 + src/util/virjson.c | 4 ++-- src/util/virjson.h | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 73ef24d66f..7b9ea23ab9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2202,6 +2202,7 @@ virJSONValueObjectKeysNumber; virJSONValueObjectRemoveKey; virJSONValueObjectStealArray; virJSONValueObjectStealObject; +virJSONValueToBuffer; virJSONValueToString; diff --git a/src/util/virjson.c b/src/util/virjson.c index 19857d2f2f..c519f8139e 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1970,7 +1970,7 @@ virJSONValueToStringOne(virJSONValuePtr object, } -static int +int virJSONValueToBuffer(virJSONValuePtr object, virBufferPtr buf, bool pretty) @@ -2031,7 +2031,7 @@ virJSONValueFromString(const char *jsonstring ATTRIBU= TE_UNUSED) } -static int +int virJSONValueToBuffer(virJSONValuePtr object ATTRIBUTE_UNUSED, virBufferPtr buf ATTRIBUTE_UNUSED, bool pretty ATTRIBUTE_UNUSED) diff --git a/src/util/virjson.h b/src/util/virjson.h index 3dee103aba..ec86603794 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -26,6 +26,7 @@ # include "internal.h" # include "virbitmap.h" # include "viralloc.h" +# include "virbuffer.h" # include @@ -143,6 +144,10 @@ int virJSONValueArrayAppendString(virJSONValuePtr obje= ct, const char *value); virJSONValuePtr virJSONValueFromString(const char *jsonstring); char *virJSONValueToString(virJSONValuePtr object, bool pretty); +int virJSONValueToBuffer(virJSONValuePtr object, + virBufferPtr buf, + bool pretty) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; typedef int (*virJSONValueObjectIteratorFunc)(const char *key, virJSONValuePtr value, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 04:10:38 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; 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 1553866577183669.3610122515464; Fri, 29 Mar 2019 06:36:17 -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 35C41306CA36; Fri, 29 Mar 2019 13:36:16 +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 0F08018E3E; Fri, 29 Mar 2019 13:36:16 +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 C24C841F3E; Fri, 29 Mar 2019 13:36:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2TDXqjh026986 for ; Fri, 29 Mar 2019 09:33:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 618F417C70; Fri, 29 Mar 2019 13:33:52 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF78117C69 for ; Fri, 29 Mar 2019 13:33:51 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:43 +0100 Message-Id: <0f7825e9523477975be01a3ca9439694132c57f9.1553866155.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/7] qemu: monitor: Remove few debug statements 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-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.43]); Fri, 29 Mar 2019 13:36:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The internal qemu machinery already logs the sent message via the PROBE point in qemuMonitorSend and the monitor receive function. Those are way better as they are easy grepable. Remove the additional ones from the monitor code which just duplicate the sent data. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/qemu/qemu_monitor_json.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 743a88b914..c7a7e3fa56 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -301,14 +301,8 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon, msg.txLength =3D strlen(msg.txBuffer); msg.txFD =3D scm_fd; - VIR_DEBUG("Send command '%s' for write with FD %d", cmdstr, scm_fd); - ret =3D qemuMonitorSend(mon, &msg); - VIR_DEBUG("Receive command reply ret=3D%d rxObject=3D%p", - ret, msg.rxObject); - - if (ret =3D=3D 0) { if (!msg.rxObject) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 04:10:38 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; 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 1553866480839738.6285379129703; Fri, 29 Mar 2019 06:34:40 -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 04F6B80E5D; Fri, 29 Mar 2019 13:34: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 C95411900A; Fri, 29 Mar 2019 13:34: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 867A31803389; Fri, 29 Mar 2019 13:34:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2TDXroV026991 for ; Fri, 29 Mar 2019 09:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3021017C70; Fri, 29 Mar 2019 13:33:53 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE87A17C69 for ; Fri, 29 Mar 2019 13:33:52 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:44 +0100 Message-Id: <9ee8d1bb1f39278d7dfa343395277602d6637f13.1553866155.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/7] qemu: monitor: Avoid unnecessary copies of command 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: , 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.25]); Fri, 29 Mar 2019 13:34:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use virJSONValueToBuffer so that we can append the command terminator string without copying of the string again. Also avoid a 'strlen' as we can query the buffer use size. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/qemu/qemu_monitor_json.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index c7a7e3fa56..8e6c3ccd63 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -277,7 +277,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon, { int ret =3D -1; qemuMonitorMessage msg; - char *cmdstr =3D NULL; + VIR_AUTOCLEAN(virBuffer) cmdbuf =3D VIR_BUFFER_INITIALIZER; char *id =3D NULL; *reply =3D NULL; @@ -294,11 +294,15 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon, } } - if (!(cmdstr =3D virJSONValueToString(cmd, false))) + if (virJSONValueToBuffer(cmd, &cmdbuf, false) < 0) goto cleanup; - if (virAsprintf(&msg.txBuffer, "%s\r\n", cmdstr) < 0) + virBufferAddLit(&cmdbuf, "\r\n"); + + if (virBufferCheckError(&cmdbuf) < 0) goto cleanup; - msg.txLength =3D strlen(msg.txBuffer); + + msg.txLength =3D virBufferUse(&cmdbuf); + msg.txBuffer =3D virBufferContentAndReset(&cmdbuf); msg.txFD =3D scm_fd; ret =3D qemuMonitorSend(mon, &msg); @@ -315,7 +319,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon, cleanup: VIR_FREE(id); - VIR_FREE(cmdstr); VIR_FREE(msg.txBuffer); return ret; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list