From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913229; cv=none; d=zoho.com; s=zohoarc; b=ZFQ1nfpy4KKZOCCKO9p4pT4VE2/lvf0xqBixKzeK7v+8zb5lJT7DM8RnwSbT0nRg3qfEK1B3AbreSeN2V4N9RjZ1Ndq3qZ+RvAIe0PodQF+XfPsaslxOeshkbqTaxVdIODLt8fSbPRfPZEcEh3pEVoPZ2JdRRPngWtnQJg1h4lk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913229; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GKEnskhBJDvu88Gsurpo7tRk636vd1qqHxPMNthCRUw=; b=aSX9u6BQjmiq1/Gsf07/vqGHnvKPiOTniyAGtOICeCvze8PekhmEvNrP00cSRcDIl+RT84CKyBVzBwy0iicz0orEA+q/Mb/ubxdf9+gNjrC9uL7DV0fpbFSu6Z9f/DXLNJ5H0QrLEYs9i085zUEZRckDVUPjipChupbD6WFNO0o= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913229408160.03474068210573; Thu, 19 Sep 2019 10:13:49 -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 84F6D3082E66; Thu, 19 Sep 2019 17:13:47 +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 605585C1D4; Thu, 19 Sep 2019 17:13:47 +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 280624EE6F; Thu, 19 Sep 2019 17:13:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDUST004564 for ; Thu, 19 Sep 2019 13:13:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7A28760C18; Thu, 19 Sep 2019 17:13:30 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 840DF60BF1 for ; Thu, 19 Sep 2019 17:13:29 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:04 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/22] util: typedparam: Split out public APIs into a separate file 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.46]); Thu, 19 Sep 2019 17:13:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Some of the typed parameter APIs are exported publically, but the implementation was intermixed with private functions. Introduce virtypedparam-public.c, move all public API functions there and purge the comments stating that some functions are public. This will decrease the likelyhood of messing up the expectations as well as it will become more clear which of them are actually public. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/Makefile.am | 2 +- docs/apibuild.py | 2 +- src/util/Makefile.inc.am | 1 + src/util/virtypedparam-public.c | 795 ++++++++++++++++++++++++++++++++ src/util/virtypedparam.c | 775 ------------------------------- 5 files changed, 798 insertions(+), 777 deletions(-) create mode 100644 src/util/virtypedparam-public.c diff --git a/docs/Makefile.am b/docs/Makefile.am index 7a5d3450fc..faa5e76555 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -318,7 +318,7 @@ $(APIBUILD_STAMP): $(srcdir)/apibuild.py \ $(top_srcdir)/src/libvirt-admin.c \ $(top_srcdir)/src/util/virerror.c \ $(top_srcdir)/src/util/virevent.c \ - $(top_srcdir)/src/util/virtypedparam.c + $(top_srcdir)/src/util/virtypedparam-public.c $(AM_V_GEN)srcdir=3D$(srcdir) builddir=3D$(builddir) $(PYTHON) $(APIBUILD) touch $@ diff --git a/docs/apibuild.py b/docs/apibuild.py index dbdc1c95af..92886e1276 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -52,7 +52,7 @@ included_files =3D { "libvirt-stream.c": "Stream interfaces for the libvirt library", "virerror.c": "implements error handling and reporting code for libvirt", "virevent.c": "event loop for monitoring file handles", - "virtypedparam.c": "virTypedParameters APIs", + "virtypedparam-public.c": "virTypedParameters APIs", } qemu_included_files =3D { diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 46866cf213..f239ab611c 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -207,6 +207,7 @@ UTIL_SOURCES =3D \ util/virtime.h \ util/virtpm.c \ util/virtpm.h \ + util/virtypedparam-public.c \ util/virtypedparam.c \ util/virtypedparam.h \ util/virusb.c \ diff --git a/src/util/virtypedparam-public.c b/src/util/virtypedparam-publi= c.c new file mode 100644 index 0000000000..585e851f38 --- /dev/null +++ b/src/util/virtypedparam-public.c @@ -0,0 +1,795 @@ +/* + * virtypedparam-public.c: utility functions for dealing with virTypedPara= meters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ +#include +#include "virtypedparam.h" + +#include "viralloc.h" +#include "virerror.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +/* The following APIs are public and their signature may never change. */ + +/** + * virTypedParamsGet: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * + * Finds typed parameter called @name. + * + * Returns pointer to the parameter or NULL if it does not exist in @param= s. + * This function does not raise an error, even when returning NULL. + */ +virTypedParameterPtr +virTypedParamsGet(virTypedParameterPtr params, + int nparams, + const char *name) +{ + size_t i; + + /* No need to reset errors, since this function doesn't report any. */ + + if (!params || !name) + return NULL; + + for (i =3D 0; i < nparams; i++) { + if (STREQ(params[i].field, name)) + return params + i; + } + + return NULL; +} + + +#define VIR_TYPED_PARAM_CHECK_TYPE(check_type) \ + do { if (param->type !=3D check_type) { \ + virReportError(VIR_ERR_INVALID_ARG, \ + _("Invalid type '%s' requested for parameter '%s', = " \ + "actual type is '%s'"), \ + virTypedParameterTypeToString(check_type), \ + name, \ + virTypedParameterTypeToString(param->type)); \ + virDispatchError(NULL); \ + return -1; \ + } } while (0) + + +/** + * virTypedParamsGetInt: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * @value: where to store the parameter's value + * + * Finds typed parameter called @name and store its int value in @value. T= he + * function fails with VIR_ERR_INVALID_ARG error if the parameter does not + * have the expected type. By passing NULL as @value, the function may be + * used to check presence and type of the parameter. + * + * Returns 1 on success, 0 when the parameter does not exist in @params, or + * -1 on error. + */ +int +virTypedParamsGetInt(virTypedParameterPtr params, + int nparams, + const char *name, + int *value) +{ + virTypedParameterPtr param; + + virResetLastError(); + + if (!(param =3D virTypedParamsGet(params, nparams, name))) + return 0; + + VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_INT); + if (value) + *value =3D param->value.i; + + return 1; +} + + +/** + * virTypedParamsGetUInt: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * @value: where to store the parameter's value + * + * Finds typed parameter called @name and store its unsigned int value in + * @value. The function fails with VIR_ERR_INVALID_ARG error if the parame= ter + * does not have the expected type. By passing NULL as @value, the function + * may be used to check presence and type of the parameter. + * + * Returns 1 on success, 0 when the parameter does not exist in @params, or + * -1 on error. + */ +int +virTypedParamsGetUInt(virTypedParameterPtr params, + int nparams, + const char *name, + unsigned int *value) +{ + virTypedParameterPtr param; + + virResetLastError(); + + if (!(param =3D virTypedParamsGet(params, nparams, name))) + return 0; + + VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_UINT); + if (value) + *value =3D param->value.ui; + + return 1; +} + + +/** + * virTypedParamsGetLLong: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * @value: where to store the parameter's value + * + * Finds typed parameter called @name and store its long long int value in + * @value. The function fails with VIR_ERR_INVALID_ARG error if the parame= ter + * does not have the expected type. By passing NULL as @value, the function + * may be used to check presence and type of the parameter. + * + * Returns 1 on success, 0 when the parameter does not exist in @params, or + * -1 on error. + */ +int +virTypedParamsGetLLong(virTypedParameterPtr params, + int nparams, + const char *name, + long long *value) +{ + virTypedParameterPtr param; + + virResetLastError(); + + if (!(param =3D virTypedParamsGet(params, nparams, name))) + return 0; + + VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_LLONG); + if (value) + *value =3D param->value.l; + + return 1; +} + + +/** + * virTypedParamsGetULLong: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * @value: where to store the parameter's value + * + * Finds typed parameter called @name and store its unsigned long long int + * value in @value. The function fails with VIR_ERR_INVALID_ARG error if t= he + * parameter does not have the expected type. By passing NULL as @value, t= he + * function may be used to check presence and type of the parameter. + * + * Returns 1 on success, 0 when the parameter does not exist in @params, or + * -1 on error. + */ +int +virTypedParamsGetULLong(virTypedParameterPtr params, + int nparams, + const char *name, + unsigned long long *value) +{ + virTypedParameterPtr param; + + virResetLastError(); + + if (!(param =3D virTypedParamsGet(params, nparams, name))) + return 0; + + VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_ULLONG); + if (value) + *value =3D param->value.ul; + + return 1; +} + + +/** + * virTypedParamsGetDouble: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * @value: where to store the parameter's value + * + * Finds typed parameter called @name and store its double value in @value. + * The function fails with VIR_ERR_INVALID_ARG error if the parameter does= not + * have the expected type. By passing NULL as @value, the function may be = used + * to check presence and type of the parameter. + * + * Returns 1 on success, 0 when the parameter does not exist in @params, or + * -1 on error. + */ +int +virTypedParamsGetDouble(virTypedParameterPtr params, + int nparams, + const char *name, + double *value) +{ + virTypedParameterPtr param; + + virResetLastError(); + + if (!(param =3D virTypedParamsGet(params, nparams, name))) + return 0; + + VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_DOUBLE); + if (value) + *value =3D param->value.d; + + return 1; +} + + +/** + * virTypedParamsGetBoolean: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * @value: where to store the parameter's value + * + * Finds typed parameter called @name and store its boolean value in @valu= e. + * The function fails with VIR_ERR_INVALID_ARG error if the parameter does= not + * have the expected type. By passing NULL as @value, the function may be = used + * to check presence and type of the parameter. + * + * Returns 1 on success, 0 when the parameter does not exist in @params, or + * -1 on error. + */ +int +virTypedParamsGetBoolean(virTypedParameterPtr params, + int nparams, + const char *name, + int *value) +{ + virTypedParameterPtr param; + + virResetLastError(); + + if (!(param =3D virTypedParamsGet(params, nparams, name))) + return 0; + + VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_BOOLEAN); + if (value) + *value =3D !!param->value.b; + + return 1; +} + + +/** + * virTypedParamsGetString: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @name: name of the parameter to find + * @value: where to store the parameter's value + * + * Finds typed parameter called @name and store its char * value in @value. + * The function does not create a copy of the string and the caller must n= ot + * free the string @value points to. The function fails with + * VIR_ERR_INVALID_ARG error if the parameter does not have the expected t= ype. + * By passing NULL as @value, the function may be used to check presence a= nd + * type of the parameter. + * + * Returns 1 on success, 0 when the parameter does not exist in @params, or + * -1 on error. + */ +int +virTypedParamsGetString(virTypedParameterPtr params, + int nparams, + const char *name, + const char **value) +{ + virTypedParameterPtr param; + + virResetLastError(); + + if (!(param =3D virTypedParamsGet(params, nparams, name))) + return 0; + + VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_STRING); + if (value) + *value =3D param->value.s; + + return 1; +} + + +/** + * virTypedParamsAddInt: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @value: the value to store into the new parameter + * + * Adds new parameter called @name with int type and sets its value to @va= lue. + * If @params array points to NULL or to a space that is not large enough = to + * accommodate the new parameter (@maxparams < @nparams + 1), the function + * allocates more space for it and updates @maxparams. On success, @nparams + * is incremented by one. The function fails with VIR_ERR_INVALID_ARG error + * if the parameter already exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddInt(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + int value) +{ + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (virTypedParameterAssign(*params + n, name, + VIR_TYPED_PARAM_INT, value) < 0) + goto error; + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + + +/** + * virTypedParamsAddUInt: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @value: the value to store into the new parameter + * + * Adds new parameter called @name with unsigned int type and sets its val= ue + * to @value. If @params array points to NULL or to a space that is not la= rge + * enough to accommodate the new parameter (@maxparams < @nparams + 1), the + * function allocates more space for it and updates @maxparams. On success, + * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG + * error if the parameter already exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddUInt(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + unsigned int value) +{ + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (virTypedParameterAssign(*params + n, name, + VIR_TYPED_PARAM_UINT, value) < 0) + goto error; + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + + +/** + * virTypedParamsAddLLong: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @value: the value to store into the new parameter + * + * Adds new parameter called @name with long long int type and sets its va= lue + * to @value. If @params array points to NULL or to a space that is not la= rge + * enough to accommodate the new parameter (@maxparams < @nparams + 1), the + * function allocates more space for it and updates @maxparams. On success, + * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG + * error if the parameter already exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddLLong(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + long long value) +{ + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (virTypedParameterAssign(*params + n, name, + VIR_TYPED_PARAM_LLONG, value) < 0) + goto error; + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + + +/** + * virTypedParamsAddULLong: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @value: the value to store into the new parameter + * + * Adds new parameter called @name with unsigned long long type and sets i= ts + * value to @value. If @params array points to NULL or to a space that is = not + * large enough to accommodate the new parameter (@maxparams < @nparams + = 1), + * the function allocates more space for it and updates @maxparams. On suc= cess, + * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG + * error if the parameter already exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddULLong(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + unsigned long long value) +{ + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (virTypedParameterAssign(*params + n, name, + VIR_TYPED_PARAM_ULLONG, value) < 0) + goto error; + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + + +/** + * virTypedParamsAddDouble: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @value: the value to store into the new parameter + * + * Adds new parameter called @name with double type and sets its value to + * @value. If @params array points to NULL or to a space that is not large + * enough to accommodate the new parameter (@maxparams < @nparams + 1), the + * function allocates more space for it and updates @maxparams. On success, + * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG + * error if the parameter already exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddDouble(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + double value) +{ + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (virTypedParameterAssign(*params + n, name, + VIR_TYPED_PARAM_DOUBLE, value) < 0) + goto error; + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + + +/** + * virTypedParamsAddBoolean: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @value: the value to store into the new parameter + * + * Adds new parameter called @name with boolean type and sets its value to + * @value. If @params array points to NULL or to a space that is not large + * enough to accommodate the new parameter (@maxparams < @nparams + 1), the + * function allocates more space for it and updates @maxparams. On success, + * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG + * error if the parameter already exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddBoolean(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + int value) +{ + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (virTypedParameterAssign(*params + n, name, + VIR_TYPED_PARAM_BOOLEAN, value) < 0) + goto error; + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + + +/** + * virTypedParamsAddString: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @value: the value to store into the new parameter + * + * Adds new parameter called @name with char * type and sets its value to + * @value. The function creates its own copy of @value string, which needs= to + * be freed using virTypedParamsFree or virTypedParamsClear. If @params ar= ray + * points to NULL or to a space that is not large enough to accommodate the + * new parameter (@maxparams < @nparams + 1), the function allocates more + * space for it and updates @maxparams. On success, @nparams is incremented + * by one. The function fails with VIR_ERR_INVALID_ARG error if the parame= ter + * already exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddString(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + const char *value) +{ + char *str =3D NULL; + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (VIR_STRDUP(str, value) < 0) + goto error; + + if (virTypedParameterAssign(*params + n, name, + VIR_TYPED_PARAM_STRING, str) < 0) { + VIR_FREE(str); + goto error; + } + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + +/** + * virTypedParamsAddStringList: + * @params: array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to store values to + * @values: the values to store into the new parameters + * + * Packs NULL-terminated list of strings @values into @params under the + * key @name. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddStringList(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + const char **values) +{ + size_t i; + int rv =3D -1; + + if (!values) + return 0; + + for (i =3D 0; values[i]; i++) { + if ((rv =3D virTypedParamsAddString(params, nparams, maxparams, + name, values[i])) < 0) + break; + } + + return rv; +} + + +/** + * virTypedParamsAddFromString: + * @params: pointer to the array of typed parameters + * @nparams: number of parameters in the @params array + * @maxparams: maximum number of parameters that can be stored in @params + * array without allocating more memory + * @name: name of the parameter to find + * @type: type of the parameter + * @value: the value to store into the new parameter encoded as a string + * + * Adds new parameter called @name with the requested @type and parses its + * value from the @value string. If the requested type is string, the func= tion + * creates its own copy of the @value string, which needs to be freed using + * virTypedParamsFree or virTypedParamsClear. If @params array points to N= ULL + * or to a space that is not large enough to accommodate the new parameter + * (@maxparams < @nparams + 1), the function allocates more space for it a= nd + * updates @maxparams. On success, @nparams is incremented by one. The + * function fails with VIR_ERR_INVALID_ARG error if the parameter already + * exists in @params. + * + * Returns 0 on success, -1 on error. + */ +int +virTypedParamsAddFromString(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *name, + int type, + const char *value) +{ + size_t max =3D *maxparams; + size_t n =3D *nparams; + + virResetLastError(); + + if (VIR_RESIZE_N(*params, max, n, 1) < 0) + goto error; + *maxparams =3D max; + + if (virTypedParameterAssignFromStr(*params + n, name, type, value) < 0) + goto error; + + *nparams +=3D 1; + return 0; + + error: + virDispatchError(NULL); + return -1; +} + + +/** + * virTypedParamsClear: + * @params: the array of typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters. The memory occupied by @par= ams + * is not freed; use virTypedParamsFree if you want it to be freed too. + * + * Returns nothing. + */ +void +virTypedParamsClear(virTypedParameterPtr params, + int nparams) +{ + size_t i; + + if (!params) + return; + + for (i =3D 0; i < nparams; i++) { + if (params[i].type =3D=3D VIR_TYPED_PARAM_STRING) + VIR_FREE(params[i].value.s); + } +} + + +/** + * virTypedParamsFree: + * @params: the array of typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters and the memory occupied by + * @params. + * + * Returns nothing. + */ +void +virTypedParamsFree(virTypedParameterPtr params, + int nparams) +{ + virTypedParamsClear(params, nparams); + VIR_FREE(params); +} diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 779714d146..7abf0257ce 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -43,12 +43,6 @@ VIR_ENUM_IMPL(virTypedParameter, "string", ); -/* When editing this file, ensure that public exported functions - * (those in libvirt_public.syms) either trigger no errors, or else - * reset error on entrance and call virDispatchError() on exit; while - * internal utility functions (those in libvirt_private.syms) may - * report errors that the caller will dispatch. */ - static int virTypedParamsSortName(const void *left, const void *right) { @@ -452,40 +446,6 @@ virTypedParamsCopy(virTypedParameterPtr *dst, } -/* The following APIs are public and their signature may never change. */ - -/** - * virTypedParamsGet: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * - * Finds typed parameter called @name. - * - * Returns pointer to the parameter or NULL if it does not exist in @param= s. - * This function does not raise an error, even when returning NULL. - */ -virTypedParameterPtr -virTypedParamsGet(virTypedParameterPtr params, - int nparams, - const char *name) -{ - size_t i; - - /* No need to reset errors, since this function doesn't report any. */ - - if (!params || !name) - return NULL; - - for (i =3D 0; i < nparams; i++) { - if (STREQ(params[i].field, name)) - return params + i; - } - - return NULL; -} - - /** * virTypedParamsFilter: * @params: array of typed parameters @@ -528,273 +488,6 @@ virTypedParamsFilter(virTypedParameterPtr params, } -#define VIR_TYPED_PARAM_CHECK_TYPE(check_type) \ - do { if (param->type !=3D check_type) { \ - virReportError(VIR_ERR_INVALID_ARG, \ - _("Invalid type '%s' requested for parameter '%s', = " \ - "actual type is '%s'"), \ - virTypedParameterTypeToString(check_type), \ - name, \ - virTypedParameterTypeToString(param->type)); \ - virDispatchError(NULL); \ - return -1; \ - } } while (0) - - -/** - * virTypedParamsGetInt: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * @value: where to store the parameter's value - * - * Finds typed parameter called @name and store its int value in @value. T= he - * function fails with VIR_ERR_INVALID_ARG error if the parameter does not - * have the expected type. By passing NULL as @value, the function may be - * used to check presence and type of the parameter. - * - * Returns 1 on success, 0 when the parameter does not exist in @params, or - * -1 on error. - */ -int -virTypedParamsGetInt(virTypedParameterPtr params, - int nparams, - const char *name, - int *value) -{ - virTypedParameterPtr param; - - virResetLastError(); - - if (!(param =3D virTypedParamsGet(params, nparams, name))) - return 0; - - VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_INT); - if (value) - *value =3D param->value.i; - - return 1; -} - - -/** - * virTypedParamsGetUInt: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * @value: where to store the parameter's value - * - * Finds typed parameter called @name and store its unsigned int value in - * @value. The function fails with VIR_ERR_INVALID_ARG error if the parame= ter - * does not have the expected type. By passing NULL as @value, the function - * may be used to check presence and type of the parameter. - * - * Returns 1 on success, 0 when the parameter does not exist in @params, or - * -1 on error. - */ -int -virTypedParamsGetUInt(virTypedParameterPtr params, - int nparams, - const char *name, - unsigned int *value) -{ - virTypedParameterPtr param; - - virResetLastError(); - - if (!(param =3D virTypedParamsGet(params, nparams, name))) - return 0; - - VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_UINT); - if (value) - *value =3D param->value.ui; - - return 1; -} - - -/** - * virTypedParamsGetLLong: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * @value: where to store the parameter's value - * - * Finds typed parameter called @name and store its long long int value in - * @value. The function fails with VIR_ERR_INVALID_ARG error if the parame= ter - * does not have the expected type. By passing NULL as @value, the function - * may be used to check presence and type of the parameter. - * - * Returns 1 on success, 0 when the parameter does not exist in @params, or - * -1 on error. - */ -int -virTypedParamsGetLLong(virTypedParameterPtr params, - int nparams, - const char *name, - long long *value) -{ - virTypedParameterPtr param; - - virResetLastError(); - - if (!(param =3D virTypedParamsGet(params, nparams, name))) - return 0; - - VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_LLONG); - if (value) - *value =3D param->value.l; - - return 1; -} - - -/** - * virTypedParamsGetULLong: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * @value: where to store the parameter's value - * - * Finds typed parameter called @name and store its unsigned long long int - * value in @value. The function fails with VIR_ERR_INVALID_ARG error if t= he - * parameter does not have the expected type. By passing NULL as @value, t= he - * function may be used to check presence and type of the parameter. - * - * Returns 1 on success, 0 when the parameter does not exist in @params, or - * -1 on error. - */ -int -virTypedParamsGetULLong(virTypedParameterPtr params, - int nparams, - const char *name, - unsigned long long *value) -{ - virTypedParameterPtr param; - - virResetLastError(); - - if (!(param =3D virTypedParamsGet(params, nparams, name))) - return 0; - - VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_ULLONG); - if (value) - *value =3D param->value.ul; - - return 1; -} - - -/** - * virTypedParamsGetDouble: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * @value: where to store the parameter's value - * - * Finds typed parameter called @name and store its double value in @value. - * The function fails with VIR_ERR_INVALID_ARG error if the parameter does= not - * have the expected type. By passing NULL as @value, the function may be = used - * to check presence and type of the parameter. - * - * Returns 1 on success, 0 when the parameter does not exist in @params, or - * -1 on error. - */ -int -virTypedParamsGetDouble(virTypedParameterPtr params, - int nparams, - const char *name, - double *value) -{ - virTypedParameterPtr param; - - virResetLastError(); - - if (!(param =3D virTypedParamsGet(params, nparams, name))) - return 0; - - VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_DOUBLE); - if (value) - *value =3D param->value.d; - - return 1; -} - - -/** - * virTypedParamsGetBoolean: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * @value: where to store the parameter's value - * - * Finds typed parameter called @name and store its boolean value in @valu= e. - * The function fails with VIR_ERR_INVALID_ARG error if the parameter does= not - * have the expected type. By passing NULL as @value, the function may be = used - * to check presence and type of the parameter. - * - * Returns 1 on success, 0 when the parameter does not exist in @params, or - * -1 on error. - */ -int -virTypedParamsGetBoolean(virTypedParameterPtr params, - int nparams, - const char *name, - int *value) -{ - virTypedParameterPtr param; - - virResetLastError(); - - if (!(param =3D virTypedParamsGet(params, nparams, name))) - return 0; - - VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_BOOLEAN); - if (value) - *value =3D !!param->value.b; - - return 1; -} - - -/** - * virTypedParamsGetString: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @name: name of the parameter to find - * @value: where to store the parameter's value - * - * Finds typed parameter called @name and store its char * value in @value. - * The function does not create a copy of the string and the caller must n= ot - * free the string @value points to. The function fails with - * VIR_ERR_INVALID_ARG error if the parameter does not have the expected t= ype. - * By passing NULL as @value, the function may be used to check presence a= nd - * type of the parameter. - * - * Returns 1 on success, 0 when the parameter does not exist in @params, or - * -1 on error. - */ -int -virTypedParamsGetString(virTypedParameterPtr params, - int nparams, - const char *name, - const char **value) -{ - virTypedParameterPtr param; - - virResetLastError(); - - if (!(param =3D virTypedParamsGet(params, nparams, name))) - return 0; - - VIR_TYPED_PARAM_CHECK_TYPE(VIR_TYPED_PARAM_STRING); - if (value) - *value =3D param->value.s; - - return 1; -} - - /** * virTypedParamsGetStringList: * @params: array of typed parameters @@ -852,474 +545,6 @@ virTypedParamsGetStringList(virTypedParameterPtr para= ms, } -/** - * virTypedParamsAddInt: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @value: the value to store into the new parameter - * - * Adds new parameter called @name with int type and sets its value to @va= lue. - * If @params array points to NULL or to a space that is not large enough = to - * accommodate the new parameter (@maxparams < @nparams + 1), the function - * allocates more space for it and updates @maxparams. On success, @nparams - * is incremented by one. The function fails with VIR_ERR_INVALID_ARG error - * if the parameter already exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddInt(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - int value) -{ - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (virTypedParameterAssign(*params + n, name, - VIR_TYPED_PARAM_INT, value) < 0) - goto error; - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - - -/** - * virTypedParamsAddUInt: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @value: the value to store into the new parameter - * - * Adds new parameter called @name with unsigned int type and sets its val= ue - * to @value. If @params array points to NULL or to a space that is not la= rge - * enough to accommodate the new parameter (@maxparams < @nparams + 1), the - * function allocates more space for it and updates @maxparams. On success, - * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG - * error if the parameter already exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddUInt(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - unsigned int value) -{ - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (virTypedParameterAssign(*params + n, name, - VIR_TYPED_PARAM_UINT, value) < 0) - goto error; - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - - -/** - * virTypedParamsAddLLong: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @value: the value to store into the new parameter - * - * Adds new parameter called @name with long long int type and sets its va= lue - * to @value. If @params array points to NULL or to a space that is not la= rge - * enough to accommodate the new parameter (@maxparams < @nparams + 1), the - * function allocates more space for it and updates @maxparams. On success, - * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG - * error if the parameter already exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddLLong(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - long long value) -{ - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (virTypedParameterAssign(*params + n, name, - VIR_TYPED_PARAM_LLONG, value) < 0) - goto error; - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - - -/** - * virTypedParamsAddULLong: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @value: the value to store into the new parameter - * - * Adds new parameter called @name with unsigned long long type and sets i= ts - * value to @value. If @params array points to NULL or to a space that is = not - * large enough to accommodate the new parameter (@maxparams < @nparams + = 1), - * the function allocates more space for it and updates @maxparams. On suc= cess, - * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG - * error if the parameter already exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddULLong(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - unsigned long long value) -{ - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (virTypedParameterAssign(*params + n, name, - VIR_TYPED_PARAM_ULLONG, value) < 0) - goto error; - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - - -/** - * virTypedParamsAddDouble: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @value: the value to store into the new parameter - * - * Adds new parameter called @name with double type and sets its value to - * @value. If @params array points to NULL or to a space that is not large - * enough to accommodate the new parameter (@maxparams < @nparams + 1), the - * function allocates more space for it and updates @maxparams. On success, - * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG - * error if the parameter already exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddDouble(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - double value) -{ - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (virTypedParameterAssign(*params + n, name, - VIR_TYPED_PARAM_DOUBLE, value) < 0) - goto error; - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - - -/** - * virTypedParamsAddBoolean: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @value: the value to store into the new parameter - * - * Adds new parameter called @name with boolean type and sets its value to - * @value. If @params array points to NULL or to a space that is not large - * enough to accommodate the new parameter (@maxparams < @nparams + 1), the - * function allocates more space for it and updates @maxparams. On success, - * @nparams is incremented by one. The function fails with VIR_ERR_INVALID= _ARG - * error if the parameter already exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddBoolean(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - int value) -{ - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (virTypedParameterAssign(*params + n, name, - VIR_TYPED_PARAM_BOOLEAN, value) < 0) - goto error; - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - - -/** - * virTypedParamsAddString: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @value: the value to store into the new parameter - * - * Adds new parameter called @name with char * type and sets its value to - * @value. The function creates its own copy of @value string, which needs= to - * be freed using virTypedParamsFree or virTypedParamsClear. If @params ar= ray - * points to NULL or to a space that is not large enough to accommodate the - * new parameter (@maxparams < @nparams + 1), the function allocates more - * space for it and updates @maxparams. On success, @nparams is incremented - * by one. The function fails with VIR_ERR_INVALID_ARG error if the parame= ter - * already exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddString(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - const char *value) -{ - char *str =3D NULL; - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (VIR_STRDUP(str, value) < 0) - goto error; - - if (virTypedParameterAssign(*params + n, name, - VIR_TYPED_PARAM_STRING, str) < 0) { - VIR_FREE(str); - goto error; - } - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - -/** - * virTypedParamsAddStringList: - * @params: array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to store values to - * @values: the values to store into the new parameters - * - * Packs NULL-terminated list of strings @values into @params under the - * key @name. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddStringList(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - const char **values) -{ - size_t i; - int rv =3D -1; - - if (!values) - return 0; - - for (i =3D 0; values[i]; i++) { - if ((rv =3D virTypedParamsAddString(params, nparams, maxparams, - name, values[i])) < 0) - break; - } - - return rv; -} - - -/** - * virTypedParamsAddFromString: - * @params: pointer to the array of typed parameters - * @nparams: number of parameters in the @params array - * @maxparams: maximum number of parameters that can be stored in @params - * array without allocating more memory - * @name: name of the parameter to find - * @type: type of the parameter - * @value: the value to store into the new parameter encoded as a string - * - * Adds new parameter called @name with the requested @type and parses its - * value from the @value string. If the requested type is string, the func= tion - * creates its own copy of the @value string, which needs to be freed using - * virTypedParamsFree or virTypedParamsClear. If @params array points to N= ULL - * or to a space that is not large enough to accommodate the new parameter - * (@maxparams < @nparams + 1), the function allocates more space for it a= nd - * updates @maxparams. On success, @nparams is incremented by one. The - * function fails with VIR_ERR_INVALID_ARG error if the parameter already - * exists in @params. - * - * Returns 0 on success, -1 on error. - */ -int -virTypedParamsAddFromString(virTypedParameterPtr *params, - int *nparams, - int *maxparams, - const char *name, - int type, - const char *value) -{ - size_t max =3D *maxparams; - size_t n =3D *nparams; - - virResetLastError(); - - if (VIR_RESIZE_N(*params, max, n, 1) < 0) - goto error; - *maxparams =3D max; - - if (virTypedParameterAssignFromStr(*params + n, name, type, value) < 0) - goto error; - - *nparams +=3D 1; - return 0; - - error: - virDispatchError(NULL); - return -1; -} - - -/** - * virTypedParamsClear: - * @params: the array of typed parameters - * @nparams: number of parameters in the @params array - * - * Frees all memory used by string parameters. The memory occupied by @par= ams - * is not freed; use virTypedParamsFree if you want it to be freed too. - * - * Returns nothing. - */ -void -virTypedParamsClear(virTypedParameterPtr params, - int nparams) -{ - size_t i; - - if (!params) - return; - - for (i =3D 0; i < nparams; i++) { - if (params[i].type =3D=3D VIR_TYPED_PARAM_STRING) - VIR_FREE(params[i].value.s); - } -} - - -/** - * virTypedParamsFree: - * @params: the array of typed parameters - * @nparams: number of parameters in the @params array - * - * Frees all memory used by string parameters and the memory occupied by - * @params. - * - * Returns nothing. - */ -void -virTypedParamsFree(virTypedParameterPtr params, - int nparams) -{ - virTypedParamsClear(params, nparams); - VIR_FREE(params); -} - /** * virTypedParamsRemoteFree: * @remote_params_val: array of typed parameters as specified by --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913216; cv=none; d=zoho.com; s=zohoarc; b=jmwNaMxzQqNpMB7sxhWnfiqrqjYiQJX+ZrZv9YQNAutsEZOkvK96Qa7ARZkTCVXI3ZWELaShtgtOoN4UFT4Vh0Ov+/inu7zFUEsQ41sQhPdV79oAx19ZPpeBgUImiDHJA7u+e3BBOp5GzxtaQLaKZKN6eQWCLSizY3vbuYGJA2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913216; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=iDdCUflqBm/IaXRy32PwcHC7TR39W58mdaMeehPQRKw=; b=Qn4oYaLIANr+Al/J+ig+qW+P7SnXPSuWuloioK1+wUAqOGOfC0aa2iLmNONKXBYW6Ek0YBjxXu/iNLJd3SPOZwwMBOhWg8gX478W/ZikogLXZJTaIRkvuL5vLdH+LM+uc4mftaVFwDd3bq8pd/4Nko4hHof1Z8e5OpHhmzvw8b0= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913216319528.9608647591642; Thu, 19 Sep 2019 10:13:36 -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 6E980C057FA6; Thu, 19 Sep 2019 17:13:34 +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 0430C10016EB; Thu, 19 Sep 2019 17:13: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 C5583180B536; Thu, 19 Sep 2019 17:13:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDVpG004573 for ; Thu, 19 Sep 2019 13:13:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4B2E260C18; Thu, 19 Sep 2019 17:13:31 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7FE360BF1 for ; Thu, 19 Sep 2019 17:13:30 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:05 +0200 Message-Id: <94805a4eaab848787b008560441ea27789dc3ced.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/22] util: typedparam: Purge public bits from virTypedParamsGetStringList 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.32]); Thu, 19 Sep 2019 17:13:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function is not exported in the public API thus the error dispatching is not required. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virtypedparam.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 7abf0257ce..acf8c39602 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -514,8 +514,6 @@ virTypedParamsGetStringList(virTypedParameterPtr params, int nfiltered; virTypedParameterPtr *filtered =3D NULL; - virResetLastError(); - virCheckNonNullArgGoto(values, error); *values =3D NULL; @@ -540,7 +538,6 @@ virTypedParamsGetStringList(virTypedParameterPtr params, if (values) VIR_FREE(*values); VIR_FREE(filtered); - virDispatchError(NULL); return -1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913219; cv=none; d=zoho.com; s=zohoarc; b=YQNKm8NQEW+LocAPTN1KAQKa+XjLdisTNFx3XhBkgJrkJ5Bpkj8g5ttWzQY0/Kr0it5bCKdkErecgIt7srvaNe2lgyy6dJvtykAUJawoiKo56LRhZ2KZmeX57QvjCpr9so//d81Vb2ZeFI0naPkXh6DOBTXwcOdAL5QEyGxWQxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913219; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=NBLHt++VfykjWVy0SjYcrdoq7PBmP8uEhCMuhV1dyPI=; b=Hp4D/F1UtAlo+1GztTK64bOY2vl6FuRPgAk0ZkE2/TNUWJg/n3td/5HhClXF6xYXrR69h/x2wPONFI28uYsgoJ4AwP32ADmH+9u9GxO1b0QBl0XgC/p0Jy1gxhvNzVBob2EGCTWCWJRhQYZwfvOI3EaNKn/FgBC9HWdA0T0kTNc= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913219827355.8330731755698; Thu, 19 Sep 2019 10:13:39 -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 F0C2A91762; Thu, 19 Sep 2019 17:13:36 +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 C76435D6B0; Thu, 19 Sep 2019 17:13:36 +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 7E5504EE6A; Thu, 19 Sep 2019 17:13:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDW3u004582 for ; Thu, 19 Sep 2019 13:13:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1AE0660C18; Thu, 19 Sep 2019 17:13:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 981BB60BF1 for ; Thu, 19 Sep 2019 17:13:31 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:06 +0200 Message-Id: <1135716c792a1e9729dcbe68d078904cf5280da1.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/22] util: typedparam: Move and unexport virTypedParameterAssignFromStr 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 19 Sep 2019 17:13:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The function is only used as a helper in virTypedParamsAddFromString. Make it static and move it to virtypedparam-public.c. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/virtypedparam-public.c | 95 +++++++++++++++++++++++++++++++++ src/util/virtypedparam.c | 93 -------------------------------- src/util/virtypedparam.h | 6 --- 4 files changed, 95 insertions(+), 100 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 39812227aa..8af9e7c95e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3229,7 +3229,6 @@ virTPMSwtpmSetupFeatureTypeFromString; # util/virtypedparam.h virTypedParameterAssign; -virTypedParameterAssignFromStr; virTypedParameterToString; virTypedParameterTypeFromString; virTypedParameterTypeToString; diff --git a/src/util/virtypedparam-public.c b/src/util/virtypedparam-publi= c.c index 585e851f38..fb7f178c6c 100644 --- a/src/util/virtypedparam-public.c +++ b/src/util/virtypedparam-public.c @@ -25,6 +25,101 @@ #define VIR_FROM_THIS VIR_FROM_NONE +/* Assign name, type, and convert the argument from a const string. + * In case of a string, the string is copied. + * Return 0 on success, -1 after an error message on failure. */ +static int +virTypedParameterAssignFromStr(virTypedParameterPtr param, + const char *name, + int type, + const char *val) +{ + int ret =3D -1; + + if (!val) { + virReportError(VIR_ERR_INVALID_ARG, _("NULL value for field '%s'"), + name); + goto cleanup; + } + + if (virStrcpyStatic(param->field, name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long= "), + name); + goto cleanup; + } + + param->type =3D type; + switch (type) { + case VIR_TYPED_PARAM_INT: + if (virStrToLong_i(val, NULL, 10, ¶m->value.i) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Invalid value for field '%s': expected int"), + name); + goto cleanup; + } + break; + case VIR_TYPED_PARAM_UINT: + if (virStrToLong_ui(val, NULL, 10, ¶m->value.ui) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Invalid value for field '%s': " + "expected unsigned int"), + name); + goto cleanup; + } + break; + case VIR_TYPED_PARAM_LLONG: + if (virStrToLong_ll(val, NULL, 10, ¶m->value.l) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Invalid value for field '%s': " + "expected long long"), + name); + goto cleanup; + } + break; + case VIR_TYPED_PARAM_ULLONG: + if (virStrToLong_ull(val, NULL, 10, ¶m->value.ul) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Invalid value for field '%s': " + "expected unsigned long long"), + name); + goto cleanup; + } + break; + case VIR_TYPED_PARAM_DOUBLE: + if (virStrToDouble(val, NULL, ¶m->value.d) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("Invalid value for field '%s': " + "expected double"), + name); + goto cleanup; + } + break; + case VIR_TYPED_PARAM_BOOLEAN: + if (STRCASEEQ(val, "true") || STREQ(val, "1")) { + param->value.b =3D true; + } else if (STRCASEEQ(val, "false") || STREQ(val, "0")) { + param->value.b =3D false; + } else { + virReportError(VIR_ERR_INVALID_ARG, + _("Invalid boolean value for field '%s'"), name= ); + goto cleanup; + } + break; + case VIR_TYPED_PARAM_STRING: + if (VIR_STRDUP(param->value.s, val) < 0) + goto cleanup; + break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected type %d for field %s"), type, name); + goto cleanup; + } + + ret =3D 0; + cleanup: + return ret; +} + /* The following APIs are public and their signature may never change. */ /** diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index acf8c39602..d9f8203796 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -260,99 +260,6 @@ virTypedParameterAssign(virTypedParameterPtr param, co= nst char *name, return ret; } -/* Assign name, type, and convert the argument from a const string. - * In case of a string, the string is copied. - * Return 0 on success, -1 after an error message on failure. */ -int -virTypedParameterAssignFromStr(virTypedParameterPtr param, const char *nam= e, - int type, const char *val) -{ - int ret =3D -1; - - if (!val) { - virReportError(VIR_ERR_INVALID_ARG, _("NULL value for field '%s'"), - name); - goto cleanup; - } - - if (virStrcpyStatic(param->field, name) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long= "), - name); - goto cleanup; - } - - param->type =3D type; - switch (type) { - case VIR_TYPED_PARAM_INT: - if (virStrToLong_i(val, NULL, 10, ¶m->value.i) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Invalid value for field '%s': expected int"), - name); - goto cleanup; - } - break; - case VIR_TYPED_PARAM_UINT: - if (virStrToLong_ui(val, NULL, 10, ¶m->value.ui) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Invalid value for field '%s': " - "expected unsigned int"), - name); - goto cleanup; - } - break; - case VIR_TYPED_PARAM_LLONG: - if (virStrToLong_ll(val, NULL, 10, ¶m->value.l) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Invalid value for field '%s': " - "expected long long"), - name); - goto cleanup; - } - break; - case VIR_TYPED_PARAM_ULLONG: - if (virStrToLong_ull(val, NULL, 10, ¶m->value.ul) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Invalid value for field '%s': " - "expected unsigned long long"), - name); - goto cleanup; - } - break; - case VIR_TYPED_PARAM_DOUBLE: - if (virStrToDouble(val, NULL, ¶m->value.d) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("Invalid value for field '%s': " - "expected double"), - name); - goto cleanup; - } - break; - case VIR_TYPED_PARAM_BOOLEAN: - if (STRCASEEQ(val, "true") || STREQ(val, "1")) { - param->value.b =3D true; - } else if (STRCASEEQ(val, "false") || STREQ(val, "0")) { - param->value.b =3D false; - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("Invalid boolean value for field '%s'"), name= ); - goto cleanup; - } - break; - case VIR_TYPED_PARAM_STRING: - if (VIR_STRDUP(param->value.s, val) < 0) - goto cleanup; - break; - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected type %d for field %s"), type, name); - goto cleanup; - } - - ret =3D 0; - cleanup: - return ret; -} - /** * virTypedParamsReplaceString: diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index f9d22b24fb..cad6953f5d 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -85,12 +85,6 @@ int virTypedParameterAssign(virTypedParameterPtr param, = const char *name, int type, /* TYPE arg */ ...) ATTRIBUTE_RETURN_CHECK; -int virTypedParameterAssignFromStr(virTypedParameterPtr param, - const char *name, - int type, - const char *val) - ATTRIBUTE_RETURN_CHECK; - int virTypedParamsReplaceString(virTypedParameterPtr *params, int *nparams, const char *name, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913237; cv=none; d=zoho.com; s=zohoarc; b=bUgFHjqhJOV1zit2/ucIqG+mreCo43GjGNj6yfZrzgdK50sFd3jLD4CKGs7UIVRkv82VGLZHNfYuGw6pYYNzTnxJ2F6bJTVN10Clh6tD/OarDk2KS5afLkS9UEjY3HjFA01SM9c0ZOA0Obi4fhP2sHFQh9tcSD+jt9oqmyBx8h8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913237; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KypHUSIZBxp4Gz1POWO2/jpHW71K51xQQfnzXfQPUFE=; b=kYU9jGBYcDccicj55pD4csoSKWWZB35KDM5aIz/JHoBOWIAQlqIyTe4b+AogJJ5Izu0HwWonXoEjncFsiVy4u3Ez9OQP3k2hTsdYlYKJUYI+zPPkOR9w98CWftlwraFo1TjhxcHm4M+YwPlohAkZoN064hxiHE5WbxtNtHledA8= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913237823207.52845978377616; Thu, 19 Sep 2019 10:13:57 -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 42C9AC05683F; Thu, 19 Sep 2019 17:13:56 +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 1AC6C5DA60; Thu, 19 Sep 2019 17:13:56 +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 C8C774EE72; Thu, 19 Sep 2019 17:13:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDWRV004591 for ; Thu, 19 Sep 2019 13:13:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id E089E60C18; Thu, 19 Sep 2019 17:13:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68AA760BF1 for ; Thu, 19 Sep 2019 17:13:32 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:07 +0200 Message-Id: <94e6ee244b02ce4944a7716e68d2a9ead7518158.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/22] util: typedparam: Remove pointless cleanup label from virTypedParameterAssignFromStr 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.32]); Thu, 19 Sep 2019 17:13:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virtypedparam-public.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/util/virtypedparam-public.c b/src/util/virtypedparam-publi= c.c index fb7f178c6c..eaa9f433e7 100644 --- a/src/util/virtypedparam-public.c +++ b/src/util/virtypedparam-public.c @@ -34,18 +34,16 @@ virTypedParameterAssignFromStr(virTypedParameterPtr par= am, int type, const char *val) { - int ret =3D -1; - if (!val) { virReportError(VIR_ERR_INVALID_ARG, _("NULL value for field '%s'"), name); - goto cleanup; + return -1; } if (virStrcpyStatic(param->field, name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long= "), name); - goto cleanup; + return -1; } param->type =3D type; @@ -55,7 +53,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, virReportError(VIR_ERR_INVALID_ARG, _("Invalid value for field '%s': expected int"), name); - goto cleanup; + return -1; } break; case VIR_TYPED_PARAM_UINT: @@ -64,7 +62,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, _("Invalid value for field '%s': " "expected unsigned int"), name); - goto cleanup; + return -1; } break; case VIR_TYPED_PARAM_LLONG: @@ -73,7 +71,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, _("Invalid value for field '%s': " "expected long long"), name); - goto cleanup; + return -1; } break; case VIR_TYPED_PARAM_ULLONG: @@ -82,7 +80,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, _("Invalid value for field '%s': " "expected unsigned long long"), name); - goto cleanup; + return -1; } break; case VIR_TYPED_PARAM_DOUBLE: @@ -91,7 +89,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, _("Invalid value for field '%s': " "expected double"), name); - goto cleanup; + return -1; } break; case VIR_TYPED_PARAM_BOOLEAN: @@ -102,22 +100,20 @@ virTypedParameterAssignFromStr(virTypedParameterPtr p= aram, } else { virReportError(VIR_ERR_INVALID_ARG, _("Invalid boolean value for field '%s'"), name= ); - goto cleanup; + return -1; } break; case VIR_TYPED_PARAM_STRING: if (VIR_STRDUP(param->value.s, val) < 0) - goto cleanup; + return -1; break; default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected type %d for field %s"), type, name); - goto cleanup; + return -1; } - ret =3D 0; - cleanup: - return ret; + return 0; } /* The following APIs are public and their signature may never change. */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913229; cv=none; d=zoho.com; s=zohoarc; b=anWqoBH5O8FXefDUjmAI5xM1ilQXNQrdgjSXl6GS06M8AR7Gfl+WLxlyha9d+npu9pK8N7f5emo0D102BrAMEkXk5AKmrUAizEgGlHgffTQzDuX839bA/uNMr4iRJ0p7+YfeaYPy2M+0mq7+YGI2IGFZuRV5Xi7++21y7KzLdvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913229; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Ted5RD/5L0TE417FFh5zKlIOYXgwFmcSscgeEo5GeRU=; b=FFV692EJLNsCXF+DbQ+f/A1ryC8t5mxytNDCIkDQOlPszqrWL9Zao3MKlLbWRgwYp1U8HLTGZjApUWTdDcehVfrpS8crC/8lZSch+cjP0RZ+70mStDiNzTrF3vP4hT5gfcgliTfxn13UK3HLmybkT++LO1oktk8zstGA5LbBu6E= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913229393602.1959834119442; Thu, 19 Sep 2019 10:13:49 -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 45BAE309BF13; Thu, 19 Sep 2019 17:13:47 +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 23CA3196AE; Thu, 19 Sep 2019 17:13:47 +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 D6EF44EE6D; Thu, 19 Sep 2019 17:13:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDZNC004610 for ; Thu, 19 Sep 2019 13:13:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id C264D60C18; Thu, 19 Sep 2019 17:13:35 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B2ED60BF1 for ; Thu, 19 Sep 2019 17:13:33 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:08 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/22] docs: apibuild: Purge irrelevant typed parameter APIs from ignore 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.45]); Thu, 19 Sep 2019 17:13:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The internal helpers are not considered any more so we don't have to ignore them either. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- docs/apibuild.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index 92886e1276..b59050f5ce 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -95,13 +95,8 @@ ignored_functions =3D { "virDomainMigrateConfirm3": "private function for migration", "virDomainMigratePrepareTunnel3": "private function for tunnelled migrat= ion", "DllMain": "specific function for Win32", - "virTypedParamsValidate": "internal function in virtypedparam.c", "virTypedParameterValidateSet": "internal function in virtypedparam.c", - "virTypedParameterAssign": "internal function in virtypedparam.c", "virTypedParameterAssignFromStr": "internal function in virtypedparam.c", - "virTypedParameterToString": "internal function in virtypedparam.c", - "virTypedParamsCheck": "internal function in virtypedparam.c", - "virTypedParamsCopy": "internal function in virtypedparam.c", "virDomainMigrateBegin3Params": "private function for migration", "virDomainMigrateFinish3Params": "private function for migration", "virDomainMigratePerform3Params": "private function for migration", --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913247; cv=none; d=zoho.com; s=zohoarc; b=EdzjXoeBBwlpR6F8kPzxTVJY3HhXgLAY/ZjnXjchawATb3AWAgwBPzIKQkTPMKNpXgwcFJJnOMQ6kiWPLdEO8LpOh9kVzh/SG9mtfMoEwIdD0cqtDhq9Vvocgqq4wH9piuzOOKxLDLJtLD8TJqOeaKuIRBiRCp6h9I7eh/3bLCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913247; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=X4j5fx3OddD3SkpHSK1hhvKcd3neEgv5i53ju9PbhR0=; b=jgJui+RXxp1MPCYYS++EtTIaJ6GxtILtRC9+KNbB5eF35oOPNd8Mp5DPlo6YLUkBGs1CbhsHEfsNCeB83NvdItYeSdPxuqQcbOd/2gAdVYGfKg+ghdxzd9S7Dw3tl3Wiyf0laFd+Ra6FbDr6aFnSX9T3RkSU1qMkVh3YGf5kstg= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913247312200.48332151842897; Thu, 19 Sep 2019 10:14:07 -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 6FECE44FB1; Thu, 19 Sep 2019 17:14:05 +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 489DB404D; Thu, 19 Sep 2019 17:14:05 +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 0299B180BA9F; Thu, 19 Sep 2019 17:14:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDcil004632 for ; Thu, 19 Sep 2019 13:13:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8107960BF1; Thu, 19 Sep 2019 17:13:38 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 080B060C5E for ; Thu, 19 Sep 2019 17:13:35 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:09 +0200 Message-Id: <119fdbec5f2d3ee4a9c6a5d8d5f55d73773c2d25.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/22] util: typedparam: Separate code to assign value to typed parameter 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.30]); Thu, 19 Sep 2019 17:14:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The code will be reused in other function. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virtypedparam.c | 55 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index d9f8203796..9f86166707 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -205,24 +205,12 @@ virTypedParameterToString(virTypedParameterPtr param) return value; } -/* Assign name, type, and the appropriately typed arg to param; in the - * case of a string, the caller is assumed to have malloc'd a string, - * or can pass NULL to have this function malloc an empty string. - * Return 0 on success, -1 after an error message on failure. */ -int -virTypedParameterAssign(virTypedParameterPtr param, const char *name, - int type, ...) -{ - va_list ap; - int ret =3D -1; - - va_start(ap, type); - if (virStrcpyStatic(param->field, name) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long= "), - name); - goto cleanup; - } +static int +virTypedParameterAssignValueAP(virTypedParameterPtr param, + int type, + va_list ap) +{ param->type =3D type; switch (type) { case VIR_TYPED_PARAM_INT: @@ -246,17 +234,40 @@ virTypedParameterAssign(virTypedParameterPtr param, c= onst char *name, case VIR_TYPED_PARAM_STRING: param->value.s =3D va_arg(ap, char *); if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) - goto cleanup; + return -1; break; default: virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected type %d for field %s"), type, name); - goto cleanup; + _("unexpected type %d for field %s"), type, + NULLSTR(param->field)); + return -1; } - ret =3D 0; - cleanup: + return 0; +} + + +/* Assign name, type, and the appropriately typed arg to param; in the + * case of a string, the caller is assumed to have malloc'd a string, + * or can pass NULL to have this function malloc an empty string. + * Return 0 on success, -1 after an error message on failure. */ +int +virTypedParameterAssign(virTypedParameterPtr param, const char *name, + int type, ...) +{ + va_list ap; + int ret =3D -1; + + if (virStrcpyStatic(param->field, name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long= "), + name); + return -1; + } + + va_start(ap, type); + ret =3D virTypedParameterAssignValueAP(param, type, ap); va_end(ap); + return ret; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913238; cv=none; d=zoho.com; s=zohoarc; b=jPzzNjSRgRNYfLhefhpXhSlCS1mCsSnDKLYEqzlqq88JYNkjvbbMb/BIiKF8aIVoC8U1giCV6xTBO00FnWnET7hJQYZ3LCfKCDt1IPu1em6NfJ0rO01E/UkWKFDxCcmaaaWSkyfY8ZZ+5iA04IvmpjIcQRcbXe0M+/SWazYv0Y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913238; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vPPQpyR+ayzocjUSga9nSKRCmNxSw+yguIXbpaYCnIA=; b=Ml/UfG6DVKpvFuKozy5u42ApyM1iACOiKBsDekd8ME28wWNk3E8TzOT5cBzbIpyd4yPdOuFWZDuCLey5hMpVfmvS00HF1E0nyzidYcof+36wIINhpbA+olgvgi23RtJo9PKOqX1XwuU97L3sKwVF4ygiOhVR0T6u2ZsF4SSnN4A= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913238229409.0807768790976; Thu, 19 Sep 2019 10:13:58 -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 4C8913002607; Thu, 19 Sep 2019 17:13:56 +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 289C84105; Thu, 19 Sep 2019 17:13:56 +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 D5F5F180BA9A; Thu, 19 Sep 2019 17:13:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDdim004639 for ; Thu, 19 Sep 2019 13:13:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 52F3260C18; Thu, 19 Sep 2019 17:13:39 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE02B60BF1 for ; Thu, 19 Sep 2019 17:13:38 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:10 +0200 Message-Id: <12ae794220768680ee3831202b5b56147ee7fa86.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/22] util: typedparam: Optionally copy strings passed to virTypedParameterAssignValue 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.40]); Thu, 19 Sep 2019 17:13:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Some code paths pass in already pointers to strings which should be added directly as the value of the typed parameter. To allow more universal use of virTypedParameterAssignValue add a flag which allows to copy the value in place. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virtypedparam.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 9f86166707..720b88dd10 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -209,7 +209,8 @@ virTypedParameterToString(virTypedParameterPtr param) static int virTypedParameterAssignValueAP(virTypedParameterPtr param, int type, - va_list ap) + va_list ap, + bool copystr) { param->type =3D type; switch (type) { @@ -232,7 +233,13 @@ virTypedParameterAssignValueAP(virTypedParameterPtr pa= ram, param->value.b =3D !!va_arg(ap, int); break; case VIR_TYPED_PARAM_STRING: - param->value.s =3D va_arg(ap, char *); + if (copystr) { + if (VIR_STRDUP(param->value.s, va_arg(ap, char *)) < 0) + return -1; + } else { + param->value.s =3D va_arg(ap, char *); + } + if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) return -1; break; @@ -265,7 +272,7 @@ virTypedParameterAssign(virTypedParameterPtr param, con= st char *name, } va_start(ap, type); - ret =3D virTypedParameterAssignValueAP(param, type, ap); + ret =3D virTypedParameterAssignValueAP(param, type, ap, false); va_end(ap); return ret; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913247; cv=none; d=zoho.com; s=zohoarc; b=iG6sJp44LQTKVJkGwBjz5jJAdS7c2IA/ZS3lscRaStcDacT4xpgCCBT9NVC8A+F90pv1tBncjnNDPOvEPy3zGPS38x43PSwLhDGcDSzlZNSTVybR+pvNVHpy7MOc4GzXZ23SUtgAqEvDaA3eH0/X7ggKcf3gvqEikhiwc/CuF0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913247; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=V2pJqbFTzHMrnrkuHH60Hf1hASnz3IU82H1g1ePO66U=; b=YXqpdOjcZTW/0xTRr1nSxM1LOldgj37GueUNzwiUCl6l7xZ7yzTqJvt0DO9A/qaVp+1aLtnG8Gkh7TzKMLGItux+xkZyIEQavhLwl4IO5rJ1b3OjQcrgcHzJiyS0FDqebiKlg6o9ig5Q5pB+0gYgYYG44cirzHlvxrvjHQiEMbU= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913247287446.43916929085844; Thu, 19 Sep 2019 10:14:07 -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 768873071549; Thu, 19 Sep 2019 17:14:05 +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 52C454242; Thu, 19 Sep 2019 17:14:05 +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 0A0EE4EE73; Thu, 19 Sep 2019 17:14:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDeAr004648 for ; Thu, 19 Sep 2019 13:13:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 222E960C5E; Thu, 19 Sep 2019 17:13:40 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EAA260BF1 for ; Thu, 19 Sep 2019 17:13:39 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:11 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/22] util: typedparam: Simplify handling of lists of typed parameters 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.49]); Thu, 19 Sep 2019 17:14:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a new set of helpers including a new data structure which simplifies keeping and construction of lists of typed parameters. The use of VIR_RESIZE_N in the virTypedParamsAdd API has performance benefits but requires passing around 3 arguments. Use of them lead to a set of macros with embedded jumps used in the qemu statistics code. This patch introduces 'virTypedParamList' type which aggregates the necessary list-keeping variables and also a new set of functions to add new typed parameters to a list. These new helpers use printf-like format string and arguments to format the argument name as the stats code often uses indexed typed parameters. The accessor function then allows extracting the typed parameter list in the same format as virTypedParamsAdd* functions would do. One additional benefit is also that the list function can easily be used with VIR_AUTOPTR. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 9 ++ src/util/virtypedparam.c | 222 +++++++++++++++++++++++++++++++++++++++ src/util/virtypedparam.h | 61 +++++++++++ 3 files changed, 292 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8af9e7c95e..8f6d0492d6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3232,6 +3232,15 @@ virTypedParameterAssign; virTypedParameterToString; virTypedParameterTypeFromString; virTypedParameterTypeToString; +virTypedParamListAddB; +virTypedParamListAddD; +virTypedParamListAddI; +virTypedParamListAddLL; +virTypedParamListAddS; +virTypedParamListAddUI; +virTypedParamListAddULL; +virTypedParamListFree; +virTypedParamListStealParams; virTypedParamsCheck; virTypedParamsCopy; virTypedParamsDeserialize; diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 720b88dd10..785495460f 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -254,6 +254,23 @@ virTypedParameterAssignValueAP(virTypedParameterPtr pa= ram, } +static int +virTypedParameterAssignValue(virTypedParameterPtr param, + bool copystr, + int type, + ...) +{ + int ret; + va_list ap; + + va_start(ap, type); + ret =3D virTypedParameterAssignValueAP(param, type, ap, copystr); + va_end(ap); + + return ret; +} + + /* Assign name, type, and the appropriately typed arg to param; in the * case of a string, the caller is assumed to have malloc'd a string, * or can pass NULL to have this function malloc an empty string. @@ -725,3 +742,208 @@ virTypedParamsSerialize(virTypedParameterPtr params, virTypedParamsRemoteFree(params_val, nparams); return rv; } + + +void +virTypedParamListFree(virTypedParamListPtr list) +{ + if (!list) + return; + + virTypedParamsFree(list->par, list->npar); + VIR_FREE(list); +} + + +size_t +virTypedParamListStealParams(virTypedParamListPtr list, + virTypedParameterPtr *params) +{ + size_t ret =3D list->npar; + + VIR_STEAL_PTR(*params, list->par); + list->npar =3D 0; + list->par_alloc =3D 0; + + return ret; +} + + +static int ATTRIBUTE_FMT_PRINTF(2, 0) +virTypedParamSetNameVPrintf(virTypedParameterPtr par, + const char *fmt, + va_list ap) +{ + if (vsnprintf(par->field, VIR_TYPED_PARAM_FIELD_LENGTH, fmt, ap) > VIR= _TYPED_PARAM_FIELD_LENGTH) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Field name too lon= g")); + return -1; + } + + return 0; +} + + +static virTypedParameterPtr +virTypedParamListExtend(virTypedParamListPtr list) +{ + if (VIR_RESIZE_N(list->par, list->par_alloc, list->npar, 1) < 0) + return NULL; + + list->npar++; + + return list->par + (list->npar - 1); +} + + +int +virTypedParamListAddI(virTypedParamListPtr list, + int value, + const char *namefmt, + ...) +{ + virTypedParameterPtr par; + va_list ap; + int ret; + + if (!(par =3D virTypedParamListExtend(list)) || + virTypedParameterAssignValue(par, true, VIR_TYPED_PARAM_INT, value= ) < 0) + return -1; + + va_start(ap, namefmt); + ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + va_end(ap); + + return ret; +} + + +int +virTypedParamListAddUI(virTypedParamListPtr list, + unsigned int value, + const char *namefmt, + ...) +{ + virTypedParameterPtr par; + va_list ap; + int ret; + + if (!(par =3D virTypedParamListExtend(list)) || + virTypedParameterAssignValue(par, true, VIR_TYPED_PARAM_UINT, valu= e) < 0) + return -1; + + va_start(ap, namefmt); + ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + va_end(ap); + + return ret; +} + + +int +virTypedParamListAddLL(virTypedParamListPtr list, + long long value, + const char *namefmt, + ...) +{ + virTypedParameterPtr par; + va_list ap; + int ret; + + if (!(par =3D virTypedParamListExtend(list)) || + virTypedParameterAssignValue(par, true, VIR_TYPED_PARAM_LLONG, val= ue) < 0) + return -1; + + va_start(ap, namefmt); + ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + va_end(ap); + + return ret; +} + + +int +virTypedParamListAddULL(virTypedParamListPtr list, + unsigned long long value, + const char *namefmt, + ...) +{ + virTypedParameterPtr par; + va_list ap; + int ret; + + if (!(par =3D virTypedParamListExtend(list)) || + virTypedParameterAssignValue(par, true, VIR_TYPED_PARAM_ULLONG, va= lue) < 0) + return -1; + + va_start(ap, namefmt); + ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + va_end(ap); + + return ret; +} + + +int +virTypedParamListAddS(virTypedParamListPtr list, + const char *value, + const char *namefmt, + ...) +{ + virTypedParameterPtr par; + va_list ap; + int ret; + + if (!(par =3D virTypedParamListExtend(list)) || + virTypedParameterAssignValue(par, true, VIR_TYPED_PARAM_STRING, va= lue) < 0) + return -1; + + va_start(ap, namefmt); + ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + va_end(ap); + + return ret; +} + + +int +virTypedParamListAddB(virTypedParamListPtr list, + bool value, + const char *namefmt, + ...) +{ + virTypedParameterPtr par; + va_list ap; + int ret; + + if (!(par =3D virTypedParamListExtend(list)) || + virTypedParameterAssignValue(par, true, VIR_TYPED_PARAM_BOOLEAN, v= alue) < 0) + return -1; + + va_start(ap, namefmt); + ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + va_end(ap); + + return ret; +} + + +int +virTypedParamListAddD(virTypedParamListPtr list, + double value, + const char *namefmt, + ...) +{ + virTypedParameterPtr par; + va_list ap; + int ret; + + if (!(par =3D virTypedParamListExtend(list)) || + virTypedParameterAssignValue(par, true, VIR_TYPED_PARAM_DOUBLE, va= lue) < 0) + return -1; + + va_start(ap, namefmt); + ret =3D virTypedParamSetNameVPrintf(par, namefmt, ap); + va_end(ap); + + return ret; +} diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index cad6953f5d..2f6fad9d1a 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -24,6 +24,7 @@ #include "internal.h" #include "virutil.h" #include "virenum.h" +#include "virautoclean.h" /** * VIR_TYPED_PARAM_MULTIPLE: @@ -94,6 +95,15 @@ int virTypedParamsCopy(virTypedParameterPtr *dst, virTypedParameterPtr src, int nparams); + +int virTypedParamsAddPrintf(virTypedParameterPtr *params, + int *nparams, + int *maxparams, + const char *namefmt, + int type, + ...) + ATTRIBUTE_FMT_PRINTF(4, 0) ATTRIBUTE_RETURN_CHECK; + char *virTypedParameterToString(virTypedParameterPtr param); void virTypedParamsRemoteFree(virTypedParameterRemotePtr remote_params_val, @@ -128,3 +138,54 @@ VIR_ENUM_DECL(virTypedParameter); VIR_FREE(_value); \ } \ } while (0) + +typedef struct _virTypedParamList virTypedParamList; +typedef virTypedParamList *virTypedParamListPtr; + +struct _virTypedParamList { + virTypedParameterPtr par; + size_t npar; + size_t par_alloc; +}; + +void virTypedParamListFree(virTypedParamListPtr list); +VIR_DEFINE_AUTOPTR_FUNC(virTypedParamList, virTypedParamListFree); + +size_t virTypedParamListStealParams(virTypedParamListPtr list, + virTypedParameterPtr *params); + +int virTypedParamListAddI(virTypedParamListPtr list, + int value, + const char *namefmt, + ...) + ATTRIBUTE_FMT_PRINTF(3, 4) ATTRIBUTE_RETURN_CHECK; +int virTypedParamListAddUI(virTypedParamListPtr list, + unsigned int value, + const char *namefmt, + ...) + ATTRIBUTE_FMT_PRINTF(3, 4) ATTRIBUTE_RETURN_CHECK; +int virTypedParamListAddLL(virTypedParamListPtr list, + long long value, + const char *namefmt, + ...) + ATTRIBUTE_FMT_PRINTF(3, 4) ATTRIBUTE_RETURN_CHECK; +int virTypedParamListAddULL(virTypedParamListPtr list, + unsigned long long value, + const char *namefmt, + ...) + ATTRIBUTE_FMT_PRINTF(3, 4) ATTRIBUTE_RETURN_CHECK; +int virTypedParamListAddS(virTypedParamListPtr list, + const char *value, + const char *namefmt, + ...) + ATTRIBUTE_FMT_PRINTF(3, 4) ATTRIBUTE_RETURN_CHECK; +int virTypedParamListAddB(virTypedParamListPtr list, + bool value, + const char *namefmt, + ...) + ATTRIBUTE_FMT_PRINTF(3, 4) ATTRIBUTE_RETURN_CHECK; +int virTypedParamListAddD(virTypedParamListPtr list, + double value, + const char *namefmt, + ...) + ATTRIBUTE_FMT_PRINTF(3, 4) ATTRIBUTE_RETURN_CHECK; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913253; cv=none; d=zoho.com; s=zohoarc; b=bbg7rHkuFygsKnAjMyqlJAjOze27wOvfe5Jv8aFcy+n4K62QZGb92oJrPs6fJlJ2/r0R1rEsFpwxC3pGcgXFYk8ei419q9mUtj+F6l93pVKRFjh+izhPuekuX4B2AjEakI+lKwgJq9ScySpHK2pFqO0Idh1md8O4Bk9F7HTDYNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913253; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6wYqqWkSyIS2kytOSrMOdJzeVAqkC08dwkF1OvS4yCM=; b=cfzh6bjgdcdzvKbaEyKkKF34glYXnkW+cgpXh/s2Ey5ph21WbsLWvk9C9x/zVzWg/G0Xy1gh+rEflKqpDSlB7544s7DFcJl8w/dFpQib2GjAvIP6XK7gNuNUT+IZWtXKloklAD+k3LiJN2UWUBog6WrHE9/D9ypY9h00fUS36zs= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913253601307.6091004951073; Thu, 19 Sep 2019 10:14:13 -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 AA90D308212D; Thu, 19 Sep 2019 17:14:11 +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 82FC86046B; Thu, 19 Sep 2019 17:14:11 +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 3C47C1803B37; Thu, 19 Sep 2019 17:14:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDeYr004663 for ; Thu, 19 Sep 2019 13:13:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id E7B8860C18; Thu, 19 Sep 2019 17:13:40 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E64B60BF1 for ; Thu, 19 Sep 2019 17:13:40 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:12 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/22] qemu: Remove stale comment for qemuDomainBlockStats 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.47]); Thu, 19 Sep 2019 17:14:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We no longer use HMP for this API. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1e041a8bac..9315b78c48 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11548,10 +11548,6 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr drive= r, } -/* This uses the 'info blockstats' monitor command which was - * integrated into both qemu & kvm in late 2007. If the command is - * not supported we detect this and return the appropriate error. - */ static int qemuDomainBlockStats(virDomainPtr dom, const char *path, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913253; cv=none; d=zoho.com; s=zohoarc; b=PIdskNZg4b8ba2/pKeJYHAtBtnbh0mS1sl9fDVPdOQWl327560O1WBLQZT7UULtONH3jZXt90sv+wzeQyM2YPr7cQQ0InAtTqMdo9Z3uwTdngPowis54vQKSU+hLhkQf+JlcVAkq0MWnJiJH35787w6Zw9W0zsYKwLWH3N0QrGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913253; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=yfpnBQvNDuitsnRJbYBtVmUdE1ZkIgNxMcb4qpC6zxY=; b=k09gguDSX0ncRof/1FiMx0e+qmREWatfJESYeLMtsRCSmb4pKE4LHPEr9W5RVa4jKFNMF68YC7lbP9uGgMg6hIXG8unfK3yRetxUziqr8bCAg+IrX0fwNu2G2fmlM4QJxSARqiIbAcGCc0uIk3daHm/F+uNIAThkNpfXiHpA6oA= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913253187377.90271821321915; Thu, 19 Sep 2019 10:14:13 -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 8F9EDC04B940; Thu, 19 Sep 2019 17:14:11 +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 69B1010027C5; Thu, 19 Sep 2019 17:14:11 +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 289091803B49; Thu, 19 Sep 2019 17:14:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDf1l004670 for ; Thu, 19 Sep 2019 13:13:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id B893F60C18; Thu, 19 Sep 2019 17:13:41 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4142E60BF1 for ; Thu, 19 Sep 2019 17:13:41 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:13 +0200 Message-Id: <6bffb0892189340169af7b3b3eff3e83b0d825d3.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/22] qemu: monitor: Refactor cleanup in qemuMonitorJSONBlockStatsCollectData 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.31]); Thu, 19 Sep 2019 17:14:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTOFREE and get rid of the cleanup label. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e4404f0199..ccf9290838 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2529,8 +2529,7 @@ static qemuBlockStatsPtr qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev, int *nstats) { - qemuBlockStatsPtr bstats =3D NULL; - qemuBlockStatsPtr ret =3D NULL; + VIR_AUTOFREE(qemuBlockStatsPtr) bstats =3D NULL; virJSONValuePtr parent; virJSONValuePtr parentstats; virJSONValuePtr stats; @@ -2539,11 +2538,11 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePt= r dev, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("blockstats stats entry was not " "in expected format")); - goto cleanup; + return NULL; } if (VIR_ALLOC(bstats) < 0) - goto cleanup; + return NULL; #define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \ if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \ @@ -2551,7 +2550,7 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr = dev, if (virJSONValueObjectGetNumberLong(stats, NAME, &VAR) < 0) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ _("cannot read %s statistic"), NAME); \ - goto cleanup; \ + return NULL; \ } \ } QEMU_MONITOR_BLOCK_STAT_GET("rd_bytes", bstats->rd_bytes, true); @@ -2571,11 +2570,7 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr= dev, bstats->wr_highest_offset_valid =3D true; } - VIR_STEAL_PTR(ret, bstats); - - cleanup: - VIR_FREE(bstats); - return ret; + VIR_RETURN_PTR(bstats); } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913260; cv=none; d=zoho.com; s=zohoarc; b=H3b2B4tZHIv4d/enrkXOMsEBmTwmKXDzzw8aYgpDTNVQQ4dezin4JA1zQ5qXFKnxVnGnKKXA3QmxYxhKnitwk4xH2DYS26S/5lHWkzI5c79SrG55m0o1EjxKjGUjewwWExsY9xfS7bIuG9v0mpXVrx70NtSg1uCakgxZjbr9qXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913260; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VH6Y5/SgqGtaBU5xWz4HEAKFyfzdkzZFukCl5SItrpk=; b=Mhfj7FJeExbaxWroMVnmmI6G6oWDU68hWP++TNuPpyxVRYEWmOfZ50VQeWu8/0gx6/HR3gU6NNgq0do1aBW/bbDvTVXIjO1nBRgzakUKJPQe+yfoTTK6iLl70XLyEuVjRCrr3eR4HvadjqDvrH6tlSnmmEYdUuLkhGWeDAaaao8= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913260620895.878192798221; Thu, 19 Sep 2019 10:14:20 -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 D9657308FBB4; Thu, 19 Sep 2019 17:14:18 +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 B3AA15C3F8; Thu, 19 Sep 2019 17:14:18 +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 75E274EE95; Thu, 19 Sep 2019 17:14:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDgXO004682 for ; Thu, 19 Sep 2019 13:13:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 892C460C18; Thu, 19 Sep 2019 17:13:42 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1211360BF1 for ; Thu, 19 Sep 2019 17:13:41 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:14 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/22] qemu: monitor: Refactor cleanup in qemuMonitorJSONGetOneBlockStatsInfo 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.43]); Thu, 19 Sep 2019 17:14:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTOFREE and get rid of the cleanup label. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index ccf9290838..8d0ef62c8b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2603,17 +2603,16 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr= dev, virHashTablePtr hash, bool backingChain) { - qemuBlockStatsPtr bstats =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(qemuBlockStatsPtr) bstats =3D NULL; int nstats =3D 0; const char *qdevname =3D NULL; const char *nodename =3D NULL; - char *devicename =3D NULL; + VIR_AUTOFREE(char *) devicename =3D NULL; virJSONValuePtr backing; if (dev_name && !(devicename =3D qemuDomainStorageAlias(dev_name, depth))) - goto cleanup; + return -1; qdevname =3D virJSONValueObjectGetString(dev, "qdev"); nodename =3D virJSONValueObjectGetString(dev, "node-name"); @@ -2621,35 +2620,31 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr= dev, if (!devicename && !qdevname && !nodename) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("blockstats device entry was not in expected form= at")); - goto cleanup; + return -1; } if (!(bstats =3D qemuMonitorJSONBlockStatsCollectData(dev, &nstats))) - goto cleanup; + return -1; if (devicename && qemuMonitorJSONAddOneBlockStatsInfo(bstats, devicename, hash) < 0) - goto cleanup; + return -1; if (qdevname && STRNEQ_NULLABLE(qdevname, devicename) && qemuMonitorJSONAddOneBlockStatsInfo(bstats, qdevname, hash) < 0) - goto cleanup; + return -1; if (nodename && qemuMonitorJSONAddOneBlockStatsInfo(bstats, nodename, hash) < 0) - goto cleanup; + return -1; if (backingChain && (backing =3D virJSONValueObjectGetObject(dev, "backing")) && qemuMonitorJSONGetOneBlockStatsInfo(backing, dev_name, depth + 1, hash, true) < 0) - goto cleanup; + return -1; - ret =3D nstats; - cleanup: - VIR_FREE(bstats); - VIR_FREE(devicename); - return ret; + return nstats; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913229; cv=none; d=zoho.com; s=zohoarc; b=LwekC9jzRPGcwlRT12uVef1ZMJ4KAr0TgAgWXjqq0B5dT/i2AnZpF1xnxp2zjQCS4w72An6KdLh3oQcUhQL8Pz8zRSNPW0JLJBvgt7w6GXSZ+TacPwJb41LvSYBkI4TWgPBlub0cA6VsLQU9uR9PTS12aw6ID/bxew7Pigyocgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913229; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=e+iGhjCHbpCryLp/dEKJHV43R35iAzIFvATn/OMf/PM=; b=cTdKIMewrVcts7f/y+LaVtoncRJb/zan4FpTmWVaTQ5FZU6krbtMKncwx7KyAxCnSo8lWlMz1Qe0xHLgBM6aKISfrqJvPQMHYlI9DVHJgbHsQCJiry1kh72DBiPsZMqmRGxUfeRnCXBwhSbMpMgsOuWuVg0GgtfjXHnP+h73BzU= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913229037407.51068949935245; Thu, 19 Sep 2019 10:13:49 -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 41E7710C093C; Thu, 19 Sep 2019 17:13:47 +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 1DC09608A5; Thu, 19 Sep 2019 17:13:47 +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 D0F47180B536; Thu, 19 Sep 2019 17:13:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDhFu004691 for ; Thu, 19 Sep 2019 13:13:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 59DCE60C18; Thu, 19 Sep 2019 17:13:43 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D672760BF1 for ; Thu, 19 Sep 2019 17:13:42 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:15 +0200 Message-Id: <47556fba1d5b10d53632e15a779fbcb86512dd6d.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/22] qemu: monitor: Refactor cleanup in qemuMonitorJSONGetAllBlockStatsInfo 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 19 Sep 2019 17:13:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTOPTR and get rid of the cleanup label. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8d0ef62c8b..9be122a465 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2678,11 +2678,10 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr = mon, virHashTablePtr hash, bool backingChain) { - int ret =3D -1; int nstats =3D 0; int rc; size_t i; - virJSONValuePtr devices; + VIR_AUTOPTR(virJSONValue) devices =3D NULL; if (!(devices =3D qemuMonitorJSONQueryBlockstats(mon))) return -1; @@ -2695,14 +2694,14 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr = mon, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("blockstats device entry was not " "in expected format")); - goto cleanup; + return -1; } if (!(dev_name =3D virJSONValueObjectGetString(dev, "device"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("blockstats device entry was not " "in expected format")); - goto cleanup; + return -1; } if (*dev_name =3D=3D '\0') @@ -2712,17 +2711,13 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr = mon, backingChain); if (rc < 0) - goto cleanup; + return -1; if (rc > nstats) nstats =3D rc; } - ret =3D nstats; - - cleanup: - virJSONValueFree(devices); - return ret; + return nstats; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913261; cv=none; d=zoho.com; s=zohoarc; b=UWadOgW/Or5k9t5xwm4YQIYdoc37Fuy1FzfnjqtpPSB3v3WLutxx93PNV//151UCaNgc6sTtO9eBcMuN8I3MO5sLr1FY0a6u5O59FENm5cwv16PVNbNGk50QUZeaMDc43DZVa10gqHQvCWt1+PP/EFf68TD5FLxhQ1vjQNEmLfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913261; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HA/Aj89C9tldVD8auVAZP4WJu7tFp1FJaasYmdng+aU=; b=LMu7i8iNnrhZFC3cDMZyDDXi8Ub8PoRGkPPTU+8Blob5OWipUGNzcXuZ1D42Cej8iluDq8UjpbheQKrGWReGKczZcQHWfcyqXNi+trNiFLHA16+M0nvJN3sDDAN+cht2KDJ5K6t5gIhgRrFLfhhcGOAq2WWHyM7Y8MxaAUP20Xk= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913261101800.3398197107944; Thu, 19 Sep 2019 10:14:21 -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 742DE309BF1A; Thu, 19 Sep 2019 17:14:19 +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 4A08260623; Thu, 19 Sep 2019 17:14:19 +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 07F0F4EEB7; Thu, 19 Sep 2019 17:14:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDiOh004698 for ; Thu, 19 Sep 2019 13:13:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2842C60C83; Thu, 19 Sep 2019 17:13:44 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5C6260BF1 for ; Thu, 19 Sep 2019 17:13:43 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:16 +0200 Message-Id: <4fedcd522b31993061ba935269f2cd0010eb9e6b.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/22] qemu: monitor: Change fields in qemuBlockStats to 'unsigned' 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 19 Sep 2019 17:14:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" None of the fields actually return negative values. The internal implementation of BlockAcctStats struct in qemu uses uint64_t and the last place using -1 in libvirt was in the HMP monitor code which was deleted. Change the internal type to unsigned long long and ensure that all public conversions don't overflow. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 35 ++++++++++++++++++++++------------- src/qemu/qemu_monitor.h | 16 ++++++++-------- src/qemu/qemu_monitor_json.c | 2 +- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9315b78c48..ab41e51700 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11416,8 +11416,7 @@ qemuDomainBlockStatsGatherTotals(qemuBlockStatsPtr = data, qemuBlockStatsPtr total) { #define QEMU_BLOCK_STAT_TOTAL(NAME) \ - if (data->NAME > 0) \ - total->NAME +=3D data->NAME + total->NAME +=3D data->NAME QEMU_BLOCK_STAT_TOTAL(wr_bytes); QEMU_BLOCK_STAT_TOTAL(wr_req); @@ -11573,10 +11572,14 @@ qemuDomainBlockStats(virDomainPtr dom, if (qemuDomainBlocksStatsGather(driver, vm, path, false, &blockstats) = < 0) goto endjob; - stats->rd_req =3D blockstats->rd_req; - stats->rd_bytes =3D blockstats->rd_bytes; - stats->wr_req =3D blockstats->wr_req; - stats->wr_bytes =3D blockstats->wr_bytes; + if (VIR_ASSIGN_IS_OVERFLOW(stats->rd_req, blockstats->rd_req) || + VIR_ASSIGN_IS_OVERFLOW(stats->rd_bytes, blockstats->rd_bytes) || + VIR_ASSIGN_IS_OVERFLOW(stats->wr_req, blockstats->wr_req) || + VIR_ASSIGN_IS_OVERFLOW(stats->wr_bytes, blockstats->wr_bytes)) { + virReportError(VIR_ERR_OVERFLOW, "%s", _("statistic value too larg= e")); + goto endjob; + } + /* qemu doesn't report the error count */ stats->errs =3D -1; @@ -11638,9 +11641,15 @@ qemuDomainBlockStatsFlags(virDomainPtr dom, nstats =3D 0; #define QEMU_BLOCK_STATS_ASSIGN_PARAM(VAR, NAME) \ - if (nstats < *nparams && (blockstats->VAR) !=3D -1) { \ + if (nstats < *nparams) { \ + long long tmp; \ + if (VIR_ASSIGN_IS_OVERFLOW(tmp, (blockstats->VAR))) { \ + virReportError(VIR_ERR_OVERFLOW, \ + _("value of '%s' is too large"), NAME); \ + goto endjob; \ + } \ if (virTypedParameterAssign(params + nstats, NAME, \ - VIR_TYPED_PARAM_LLONG, (blockstats->VA= R)) < 0) \ + VIR_TYPED_PARAM_LLONG, tmp) < 0) \ goto endjob; \ nstats++; \ } @@ -21490,11 +21499,11 @@ do { \ char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ "block.%zu.%s", num, name); \ - if (value >=3D 0 && virTypedParamsAddULLong(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - value) < 0) \ + if (virTypedParamsAddULLong(&(record)->params, \ + &(record)->nparams, \ + maxparams, \ + param_name, \ + value) < 0) \ goto cleanup; \ } while (0) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 70000a1c72..321ca2b53a 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -651,14 +651,14 @@ virJSONValuePtr qemuMonitorQueryBlockstats(qemuMonito= rPtr mon); typedef struct _qemuBlockStats qemuBlockStats; typedef qemuBlockStats *qemuBlockStatsPtr; struct _qemuBlockStats { - long long rd_req; - long long rd_bytes; - long long wr_req; - long long wr_bytes; - long long rd_total_times; - long long wr_total_times; - long long flush_req; - long long flush_total_times; + unsigned long long rd_req; + unsigned long long rd_bytes; + unsigned long long wr_req; + unsigned long long wr_bytes; + unsigned long long rd_total_times; + unsigned long long wr_total_times; + unsigned long long flush_req; + unsigned long long flush_total_times; unsigned long long capacity; unsigned long long physical; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 9be122a465..26cd9057e4 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2547,7 +2547,7 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr = dev, #define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \ if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \ (*nstats)++; \ - if (virJSONValueObjectGetNumberLong(stats, NAME, &VAR) < 0) { \ + if (virJSONValueObjectGetNumberUlong(stats, NAME, &VAR) < 0) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ _("cannot read %s statistic"), NAME); \ return NULL; \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913238; cv=none; d=zoho.com; s=zohoarc; b=Jix1PYmLwLbbTyCaUZ8bBU7Ur9BHmXZQNfEhDxwqlRrXx1VT9OZnL80YSHCsRekFMbFJ1gSYFPto4VDkqRbkZTaZ+puxxAY1homhU/6Enmi8xQOIOLZ28AnVev4N0E+anYyxQUdlfNn4Roac1iGCmWVUtXcfxiHoEOyk+G7jSTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913238; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zYENMe4f/Z+C2WKhBXZomNv2tDsnKHbf6/9JIeQnZv8=; b=jGJ/WzXnaeISXjpAX36id9TSUW+5NtrHcKUTPmP11lhXdh9BiGUuMEgQOoYOPdydnCXeFgEHneyVELCB78IWVfL2kM19kiIypXh2gmH8joSnp8IKyYF5Tdi2ebJM5Rt9oMhdKGZcxJsPPGTqkfgUax+B1txUEtyerBdWfIeT2nQ= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913238056122.63491667506241; Thu, 19 Sep 2019 10:13:58 -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 4B14C302C096; Thu, 19 Sep 2019 17:13:56 +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 238B61001947; Thu, 19 Sep 2019 17:13:56 +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 D0DE7180BA99; Thu, 19 Sep 2019 17:13:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDlVq004731 for ; Thu, 19 Sep 2019 13:13:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9D56860E3E; Thu, 19 Sep 2019 17:13:47 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2614860BF1 for ; Thu, 19 Sep 2019 17:13:44 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:17 +0200 Message-Id: <36c7bc6b0ce3b1e9f39325edc6102f46d864deca.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/22] qemu: driver: Remove pointless macro QEMU_BLOCK_STAT_TOTAL 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.46]); Thu, 19 Sep 2019 17:13:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ab41e51700..2814d6825a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11415,18 +11415,14 @@ static int qemuDomainBlockStatsGatherTotals(qemuBlockStatsPtr data, qemuBlockStatsPtr total) { -#define QEMU_BLOCK_STAT_TOTAL(NAME) \ - total->NAME +=3D data->NAME - - QEMU_BLOCK_STAT_TOTAL(wr_bytes); - QEMU_BLOCK_STAT_TOTAL(wr_req); - QEMU_BLOCK_STAT_TOTAL(rd_bytes); - QEMU_BLOCK_STAT_TOTAL(rd_req); - QEMU_BLOCK_STAT_TOTAL(flush_req); - QEMU_BLOCK_STAT_TOTAL(wr_total_times); - QEMU_BLOCK_STAT_TOTAL(rd_total_times); - QEMU_BLOCK_STAT_TOTAL(flush_total_times); -#undef QEMU_BLOCK_STAT_TOTAL + total->wr_bytes +=3D data->wr_bytes; + total->wr_req +=3D data->wr_req; + total->rd_bytes +=3D data->rd_bytes; + total->rd_req +=3D data->rd_req; + total->flush_req +=3D data->flush_req; + total->wr_total_times +=3D data->wr_total_times; + total->rd_total_times +=3D data->rd_total_times; + total->flush_total_times +=3D data->flush_total_times; return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913247; cv=none; d=zoho.com; s=zohoarc; b=h/Ekt2j/RiyTl1OJN6SE9ee3myfbOZW6y2udZmX3BGH2HKtk6WGq6hobH2OkukTsgaeziNL71noyNhC88FOA/PjiA0Ituz3cyHMc2iadZ4gXTZEMLqK6m7Y8qIWNBCVp1Agpg9pzI8DyFXZzRWzJ7PMiUw9E1w+avJQFQKXA8Lg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913247; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=iMTz7Uvv6JyUZ43pBtBzgGJTEl2HZC/cIeI02TA2YB8=; b=iSz95o/7/Ks8KXsq8WguSzjDWwrCU8Y+M8ZFOkJBbXgmISZPwxcYfKf+8l2fJAJr1gspHLmKoxN7REHwkAtIrmZZS78iD79NGDC4UfHiFdCUonumeClUvCophaFEq2O/C6Fas83JPV6bacSLhffJ99nNQreSm1ajljhCnuXJYcs= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913247307571.793881159604; Thu, 19 Sep 2019 10:14:07 -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 74926307D925; Thu, 19 Sep 2019 17:14:05 +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 4DEEF10027A0; Thu, 19 Sep 2019 17:14:05 +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 076664EE72; Thu, 19 Sep 2019 17:14:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDov4004753 for ; Thu, 19 Sep 2019 13:13:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68C7160C5E; Thu, 19 Sep 2019 17:13:50 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E49C860C80 for ; Thu, 19 Sep 2019 17:13:47 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:18 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/22] qemu: driver: Don't return anything from qemuDomainBlockStatsGatherTotals 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.48]); Thu, 19 Sep 2019 17:14:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2814d6825a..98ada96fe7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11411,7 +11411,7 @@ qemuDomainBlockResize(virDomainPtr dom, } -static int +static void qemuDomainBlockStatsGatherTotals(qemuBlockStatsPtr data, qemuBlockStatsPtr total) { @@ -11423,7 +11423,6 @@ qemuDomainBlockStatsGatherTotals(qemuBlockStatsPtr = data, total->wr_total_times +=3D data->wr_total_times; total->rd_total_times +=3D data->rd_total_times; total->flush_total_times +=3D data->flush_total_times; - return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913269; cv=none; d=zoho.com; s=zohoarc; b=iZb1fLtJxUo3Fu6VLtuk1m9Qf8iaV/7eCtvX59VYUSKWutHE414UwIM1m5JkhOiy7sBHtKXv4ZQQbTam9EQ6H0EuP4gjUvvMDT9kBYmrfmdAywnQ5echh+djv4oU0pvazC++4+XIDru/Ur+3iE2Y0CV1mlGbjxoY3sI0JD1Pq3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913269; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/MgELH4IkF82fACd0UFaK79p4tEyDb3zfJc7w1lVqes=; b=itrMG45yQwjF65BTjdQqkJxzPhTshKxELzpEXsL98mKf4zJi/mQ2l2Si2FVTTtNEpsvjzL/p0M0SeYeQt2sIcUCfThAojCaeDcGe36SB9nE9VaPYYThTvHD673OvYmy0OSRRpwA7bJHFU+k4FyvLS//ftuBXIQZZQhq2qX5JWqE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913269089385.3713860877209; Thu, 19 Sep 2019 10:14:29 -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 71AB38A1CAC; Thu, 19 Sep 2019 17:14:27 +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 4CAF65D70D; Thu, 19 Sep 2019 17:14: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 0EDC9180BAA3; Thu, 19 Sep 2019 17:14:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDqEO004768 for ; Thu, 19 Sep 2019 13:13:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id E315060C5E; Thu, 19 Sep 2019 17:13:52 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BEEC60C80 for ; Thu, 19 Sep 2019 17:13:50 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:19 +0200 Message-Id: <9ca744f29d2195bf4d0c760fbebf079a8417cdd2.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/22] qemu: driver: Remove QEMU_ADD_BLOCK_PARAM_LL macro 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 19 Sep 2019 17:14:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use QEMU_ADD_BLOCK_PARAM_ULL instead since all parameters are now unsigned. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 98ada96fe7..9c24e435e9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21488,20 +21488,6 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr drive= r ATTRIBUTE_UNUSED, goto cleanup; \ } while (0) -/* expects a LL, but typed parameter must be ULL */ -#define QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, num, name, value) \ -do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ - "block.%zu.%s", num, name); \ - if (virTypedParamsAddULLong(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - value) < 0) \ - goto cleanup; \ -} while (0) - #define QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, num, name, value) \ do { \ char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ @@ -21680,14 +21666,14 @@ qemuDomainGetStatsBlockExportFrontend(const char = *frontendname, goto cleanup; } - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "rd.reqs", entry-= >rd_req); - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "rd.bytes", entry= ->rd_bytes); - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "rd.times", entry= ->rd_total_times); - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "wr.reqs", entry-= >wr_req); - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "wr.bytes", entry= ->wr_bytes); - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "wr.times", entry= ->wr_total_times); - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "fl.reqs", entry-= >flush_req); - QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "fl.times", entry= ->flush_total_times); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "rd.reqs", entry= ->rd_req); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "rd.bytes", entr= y->rd_bytes); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "rd.times", entr= y->rd_total_times); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "wr.reqs", entry= ->wr_req); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "wr.bytes", entr= y->wr_bytes); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "wr.times", entr= y->wr_total_times); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "fl.reqs", entry= ->flush_req); + QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "fl.times", entr= y->flush_total_times); ret =3D 0; cleanup: @@ -21882,8 +21868,6 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, return ret; } -#undef QEMU_ADD_BLOCK_PARAM_LL - #undef QEMU_ADD_BLOCK_PARAM_ULL #undef QEMU_ADD_NAME_PARAM --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913268; cv=none; d=zoho.com; s=zohoarc; b=dKBEIDE83t7sDH7vHIdqgDnxLr7zXc5WVhW7ID86Ld/OwBXVcpaynwY+qFlw5XoJUEZjIF+6f3qIF7yMEdBBOtvjKUm6QPgC3OGgJCBoxsNaAGG9IcOPb2MkFy7q5ieVVfX0mdTrP3uthXe3+Xj8Cy+0ioDYJhjB0Pawre7eRXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913268; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/m8Sliz1OXMNIwFFVx1wjZrv5fqCKex+l2MMfp2D6AM=; b=RNMaDRvup3Q64fVzEXpCBqDmJZldd4lcKG8Kp6CnhDo6KZsYxVhSAZoYjG2A86zV+KwKgiYr1n6Qw+6qoNmzuzbYJ/0DVZ2b6MnVvVDK8l2Q92+oSpbU0+OYzvBT6kIahJeqSlxY4bCFuLD1Zkrt+bidKhl1X3kHYC3ZxvPe9fM= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913268697728.3361089273533; Thu, 19 Sep 2019 10:14:28 -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 0EBC33086E22; Thu, 19 Sep 2019 17:14:27 +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 DF6FB5DA5B; Thu, 19 Sep 2019 17:14:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9CE0F180BA9F; Thu, 19 Sep 2019 17:14:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDt9T004788 for ; Thu, 19 Sep 2019 13:13:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C90760E3E; Thu, 19 Sep 2019 17:13:55 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id F360760C5E for ; Thu, 19 Sep 2019 17:13:53 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:20 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 17/22] qemu: Use virTypedParamList in the bulk stats gathering functions 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.44]); Thu, 19 Sep 2019 17:14:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The bulk stats functions are specific as they pass around the list into many sub-functions and also a substantial amount of the entries uses formatted names for indexing purposes. This makes them ideal to be converted to the new virTypedParamList helpers. Unfortunately given how the functions are used this requires a big-bang rewrite of all of the calls to add entries to the parameter list. Given that a substantial simplification is achieved as well as a prety significant change to the original code is required some macros which were used only sporradically were replaced by inline calls rather than tweaking the macros first and deleting them later. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 472 ++++++++++++----------------------------- 1 file changed, 139 insertions(+), 333 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9c24e435e9..c33fd6824c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20907,22 +20907,13 @@ qemuConnectGetDomainCapabilities(virConnectPtr co= nn, static int qemuDomainGetStatsState(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags ATTRIBUTE_UNUSED) { - if (virTypedParamsAddInt(&record->params, - &record->nparams, - maxparams, - "state.state", - dom->state.state) < 0) + if (virTypedParamListAddI(params, dom->state.state, "state.state") < 0) return -1; - if (virTypedParamsAddInt(&record->params, - &record->nparams, - maxparams, - "state.reason", - dom->state.reason) < 0) + if (virTypedParamListAddI(params, dom->state.reason, "state.reason") <= 0) return -1; return 0; @@ -21063,10 +21054,8 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr drive= r, static int qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams) + virTypedParamListPtr params) { - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; virQEMUResctrlMonDataPtr *resdata =3D NULL; size_t nresdata =3D 0; size_t i =3D 0; @@ -21080,49 +21069,29 @@ qemuDomainGetStatsCpuCache(virQEMUDriverPtr drive= r, VIR_RESCTRL_MONITOR_TYPE_CACHE) < 0) goto cleanup; - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "cpu.cache.monitor.count"); - if (virTypedParamsAddUInt(&record->params, &record->nparams, - maxparams, param_name, nresdata) < 0) + if (virTypedParamListAddUI(params, nresdata, "cpu.cache.monitor.count"= ) < 0) goto cleanup; for (i =3D 0; i < nresdata; i++) { - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "cpu.cache.monitor.%zu.name", i); - if (virTypedParamsAddString(&record->params, - &record->nparams, - maxparams, - param_name, - resdata[i]->name) < 0) + if (virTypedParamListAddS(params, resdata[i]->name, + "cpu.cache.monitor.%zu.name", i) < 0) goto cleanup; - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "cpu.cache.monitor.%zu.vcpus", i); - if (virTypedParamsAddString(&record->params, &record->nparams, - maxparams, param_name, - resdata[i]->vcpus) < 0) + if (virTypedParamListAddS(params, resdata[i]->vcpus, + "cpu.cache.monitor.%zu.vcpus", i) < 0) goto cleanup; - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "cpu.cache.monitor.%zu.bank.count", i); - if (virTypedParamsAddUInt(&record->params, &record->nparams, - maxparams, param_name, - resdata[i]->nstats) < 0) + if (virTypedParamListAddUI(params, resdata[i]->nstats, + "cpu.cache.monitor.%zu.bank.count", i) = < 0) goto cleanup; for (j =3D 0; j < resdata[i]->nstats; j++) { - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "cpu.cache.monitor.%zu.bank.%zu.id", i, j); - if (virTypedParamsAddUInt(&record->params, &record->nparams, - maxparams, param_name, - resdata[i]->stats[j]->id) < 0) + if (virTypedParamListAddUI(params, resdata[i]->stats[j]->id, + "cpu.cache.monitor.%zu.bank.%zu.id"= , i, j) < 0) goto cleanup; - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "cpu.cache.monitor.%zu.bank.%zu.bytes", i, j); - if (virTypedParamsAddUInt(&record->params, &record->nparams, - maxparams, param_name, - resdata[i]->stats[j]->vals[0]) < 0) + if (virTypedParamListAddUI(params, resdata[i]->stats[j]->vals[= 0], + "cpu.cache.monitor.%zu.bank.%zu.byt= es", i, j) < 0) goto cleanup; } } @@ -21138,8 +21107,7 @@ qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, static int qemuDomainGetStatsCpuCgroup(virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams) + virTypedParamListPtr params) { qemuDomainObjPrivatePtr priv =3D dom->privateData; unsigned long long cpu_time =3D 0; @@ -21151,25 +21119,13 @@ qemuDomainGetStatsCpuCgroup(virDomainObjPtr dom, return 0; err =3D virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time); - if (!err && virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "cpu.time", - cpu_time) < 0) + if (!err && virTypedParamListAddULL(params, cpu_time, "cpu.time") < 0) return -1; err =3D virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time); - if (!err && virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "cpu.user", - user_time) < 0) + if (!err && virTypedParamListAddULL(params, user_time, "cpu.user") < 0) return -1; - if (!err && virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "cpu.system", - sys_time) < 0) + if (!err && virTypedParamListAddULL(params, sys_time, "cpu.system") < = 0) return -1; return 0; @@ -21179,14 +21135,13 @@ qemuDomainGetStatsCpuCgroup(virDomainObjPtr dom, static int qemuDomainGetStatsCpu(virQEMUDriverPtr driver, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags ATTRIBUTE_UNUSED) { - if (qemuDomainGetStatsCpuCgroup(dom, record, maxparams) < 0) + if (qemuDomainGetStatsCpuCgroup(dom, params) < 0) return -1; - if (qemuDomainGetStatsCpuCache(driver, dom, record, maxparams) < 0) + if (qemuDomainGetStatsCpuCache(driver, dom, params) < 0) return -1; return 0; @@ -21196,8 +21151,7 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver, static int qemuDomainGetStatsBalloon(virQEMUDriverPtr driver, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags) { virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR]; @@ -21211,18 +21165,11 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver, cur_balloon =3D dom->def->mem.cur_balloon; } - if (virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "balloon.current", - cur_balloon) < 0) + if (virTypedParamListAddULL(params, cur_balloon, "balloon.current") < = 0) return -1; - if (virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - "balloon.maximum", - virDomainDefGetMemoryTotal(dom->def)) < 0) + if (virTypedParamListAddULL(params, virDomainDefGetMemoryTotal(dom->de= f), + "balloon.maximum") < 0) return -1; if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) @@ -21235,11 +21182,7 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver, #define STORE_MEM_RECORD(TAG, NAME) \ if (stats[i].tag =3D=3D VIR_DOMAIN_MEMORY_STAT_ ##TAG) \ - if (virTypedParamsAddULLong(&record->params, \ - &record->nparams, \ - maxparams, \ - "balloon." NAME, \ - stats[i].val) < 0) \ + if (virTypedParamListAddULL(params, stats[i].val, "balloon." NAME)= < 0) \ return -1; for (i =3D 0; i < nr_stats; i++) { @@ -21266,30 +21209,22 @@ qemuDomainGetStatsBalloon(virQEMUDriverPtr driver, static int qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags) { virDomainVcpuDefPtr vcpu; qemuDomainVcpuPrivatePtr vcpupriv; size_t i; int ret =3D -1; - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; virVcpuInfoPtr cpuinfo =3D NULL; unsigned long long *cpuwait =3D NULL; - if (virTypedParamsAddUInt(&record->params, - &record->nparams, - maxparams, - "vcpu.current", - virDomainDefGetVcpus(dom->def)) < 0) + if (virTypedParamListAddUI(params, virDomainDefGetVcpus(dom->def), + "vcpu.current") < 0) return -1; - if (virTypedParamsAddUInt(&record->params, - &record->nparams, - maxparams, - "vcpu.maximum", - virDomainDefGetVcpusMax(dom->def)) < 0) + if (virTypedParamListAddUI(params, virDomainDefGetVcpusMax(dom->def), + "vcpu.maximum") < 0) return -1; if (VIR_ALLOC_N(cpuinfo, virDomainDefGetVcpus(dom->def)) < 0 || @@ -21312,34 +21247,20 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, } for (i =3D 0; i < virDomainDefGetVcpus(dom->def); i++) { - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "vcpu.%u.state", cpuinfo[i].number); - if (virTypedParamsAddInt(&record->params, - &record->nparams, - maxparams, - param_name, - cpuinfo[i].state) < 0) + if (virTypedParamListAddI(params, cpuinfo[i].state, + "vcpu.%u.state", cpuinfo[i].number) < 0) goto cleanup; /* stats below are available only if the VM is alive */ if (!virDomainObjIsActive(dom)) continue; - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "vcpu.%u.time", cpuinfo[i].number); - if (virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - param_name, - cpuinfo[i].cpuTime) < 0) + if (virTypedParamListAddULL(params, cpuinfo[i].cpuTime, + "vcpu.%u.time", cpuinfo[i].number) < 0) goto cleanup; - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "vcpu.%u.wait", cpuinfo[i].number); - if (virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - param_name, - cpuwait[i]) < 0) + + if (virTypedParamListAddULL(params, cpuwait[i], + "vcpu.%u.wait", cpuinfo[i].number) < 0) goto cleanup; /* state below is extracted from the individual vcpu structs */ @@ -21349,13 +21270,10 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, vcpupriv =3D QEMU_DOMAIN_VCPU_PRIVATE(vcpu); if (vcpupriv->halted !=3D VIR_TRISTATE_BOOL_ABSENT) { - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, - "vcpu.%u.halted", cpuinfo[i].number); - if (virTypedParamsAddBoolean(&record->params, - &record->nparams, - maxparams, - param_name, - vcpupriv->halted =3D=3D VIR_TRIST= ATE_BOOL_YES) < 0) + if (virTypedParamListAddB(params, + vcpupriv->halted =3D=3D VIR_TRISTATE= _BOOL_YES, + "vcpu.%u.halted", + cpuinfo[i].number) < 0) goto cleanup; } } @@ -21368,49 +21286,15 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, return ret; } -#define QEMU_ADD_COUNT_PARAM(record, maxparams, type, count) \ -do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, "%s.count", type); \ - if (virTypedParamsAddUInt(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - count) < 0) \ - goto cleanup; \ -} while (0) - -#define QEMU_ADD_NAME_PARAM(record, maxparams, type, subtype, num, name) \ -do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ - "%s.%zu.%s", type, num, subtype); \ - if (virTypedParamsAddString(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - name) < 0) \ - goto cleanup; \ -} while (0) - -#define QEMU_ADD_NET_PARAM(record, maxparams, num, name, value) \ -do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ - "net.%zu.%s", num, name); \ - if (value >=3D 0 && virTypedParamsAddULLong(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - value) < 0) \ - return -1; \ -} while (0) +#define QEMU_ADD_NET_PARAM(params, num, name, value) \ + if (value >=3D 0 && \ + virTypedParamListAddULL((params), (value), "net.%zu.%s", (num), (n= ame)) < 0) \ + return -1; static int qemuDomainGetStatsInterface(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags ATTRIBUTE_UNUSED) { size_t i; @@ -21420,7 +21304,8 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver= ATTRIBUTE_UNUSED, if (!virDomainObjIsActive(dom)) return 0; - QEMU_ADD_COUNT_PARAM(record, maxparams, "net", dom->def->nnets); + if (virTypedParamListAddUI(params, dom->def->nnets, "net.count") < 0) + goto cleanup; /* Check the path is one of the domain's network interfaces. */ for (i =3D 0; i < dom->def->nnets; i++) { @@ -21434,8 +21319,8 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver= ATTRIBUTE_UNUSED, actualType =3D virDomainNetGetActualType(net); - QEMU_ADD_NAME_PARAM(record, maxparams, - "net", "name", i, net->ifname); + if (virTypedParamListAddS(params, net->ifname, "net.%zu.name", i) = < 0) + goto cleanup; if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER) { if (virNetDevOpenvswitchInterfaceStats(net->ifname, &tmp) < 0)= { @@ -21450,21 +21335,21 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driv= er ATTRIBUTE_UNUSED, } } - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "rx.bytes", tmp.rx_bytes); - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "rx.pkts", tmp.rx_packets); - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "rx.errs", tmp.rx_errs); - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "rx.drop", tmp.rx_drop); - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "tx.bytes", tmp.tx_bytes); - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "tx.pkts", tmp.tx_packets); - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "tx.errs", tmp.tx_errs); - QEMU_ADD_NET_PARAM(record, maxparams, i, + QEMU_ADD_NET_PARAM(params, i, "tx.drop", tmp.tx_drop); } @@ -21475,39 +21360,16 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driv= er ATTRIBUTE_UNUSED, #undef QEMU_ADD_NET_PARAM -#define QEMU_ADD_BLOCK_PARAM_UI(record, maxparams, num, name, value) \ - do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ - "block.%zu.%s", num, name); \ - if (virTypedParamsAddUInt(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - value) < 0) \ - goto cleanup; \ - } while (0) - -#define QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, num, name, value) \ -do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ - "block.%zu.%s", num, name); \ - if (virTypedParamsAddULLong(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - value) < 0) \ - goto cleanup; \ -} while (0) +#define QEMU_ADD_BLOCK_PARAM_ULL(params, num, name, value) \ + if (virTypedParamListAddULL((params), (value), "block.%zu.%s", (num), = (name)) < 0) \ + goto cleanup /* refresh information by opening images on the disk */ static int qemuDomainGetStatsOneBlockFallback(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, virStorageSourcePtr src, size_t block_idx) { @@ -21522,13 +21384,13 @@ qemuDomainGetStatsOneBlockFallback(virQEMUDriverP= tr driver, } if (src->allocation) - QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, + QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, "allocation", src->allocation); if (src->capacity) - QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, + QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, "capacity", src->capacity); if (src->physical) - QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, + QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, "physical", src->physical); ret =3D 0; cleanup: @@ -21576,8 +21438,7 @@ static int qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, const char *entryname, virStorageSourcePtr src, size_t block_idx, @@ -21589,8 +21450,8 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver, /* the VM is offline so we have to go and load the stast from the disk= by * ourselves */ if (!virDomainObjIsActive(dom)) { - ret =3D qemuDomainGetStatsOneBlockFallback(driver, cfg, dom, recor= d, - maxparams, src, block_idx= ); + ret =3D qemuDomainGetStatsOneBlockFallback(driver, cfg, dom, param= s, + src, block_idx); goto cleanup; } @@ -21602,18 +21463,18 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr drive= r, goto cleanup; } - QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, + QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, "allocation", entry->wr_highest_offset); if (entry->capacity) - QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, + QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, "capacity", entry->capacity); if (entry->physical) { - QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, + QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, "physical", entry->physical); } else { if (qemuDomainStorageUpdatePhysical(driver, cfg, dom, src) =3D=3D = 0) - QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, + QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, "physical", src->physical); } @@ -21627,8 +21488,7 @@ static int qemuDomainGetStatsBlockExportBackendStorage(const char *entryname, virHashTablePtr stats, size_t recordnr, - virDomainStatsRecordPtr record= s, - int *nrecords) + virTypedParamListPtr params) { qemuBlockStats *entry; int ret =3D -1; @@ -21639,7 +21499,7 @@ qemuDomainGetStatsBlockExportBackendStorage(const c= har *entryname, } if (entry->write_threshold) - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "threshold", + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "threshold", entry->write_threshold); ret =3D 0; @@ -21652,8 +21512,7 @@ static int qemuDomainGetStatsBlockExportFrontend(const char *frontendname, virHashTablePtr stats, size_t recordnr, - virDomainStatsRecordPtr records, - int *nrecords) + virTypedParamListPtr params) { qemuBlockStats *entry; int ret =3D -1; @@ -21666,14 +21525,14 @@ qemuDomainGetStatsBlockExportFrontend(const char = *frontendname, goto cleanup; } - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "rd.reqs", entry= ->rd_req); - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "rd.bytes", entr= y->rd_bytes); - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "rd.times", entr= y->rd_total_times); - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "wr.reqs", entry= ->wr_req); - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "wr.bytes", entr= y->wr_bytes); - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "wr.times", entr= y->wr_total_times); - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "fl.reqs", entry= ->flush_req); - QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "fl.times", entr= y->flush_total_times); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "rd.reqs", entry->rd_req); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "rd.bytes", entry->rd_bytes= ); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "rd.times", entry->rd_total= _times); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "wr.reqs", entry->wr_req); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "wr.bytes", entry->wr_bytes= ); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "wr.times", entry->wr_total= _times); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "fl.reqs", entry->flush_req= ); + QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "fl.times", entry->flush_to= tal_times); ret =3D 0; cleanup: @@ -21685,18 +21544,20 @@ static int qemuDomainGetStatsBlockExportHeader(virDomainDiskDefPtr disk, virStorageSourcePtr src, size_t recordnr, - virDomainStatsRecordPtr records, - int *nrecords) + virTypedParamListPtr params) { int ret =3D -1; - QEMU_ADD_NAME_PARAM(records, nrecords, "block", "name", recordnr, disk= ->dst); + if (virTypedParamListAddS(params, disk->dst, "block.%zu.name", recordn= r) < 0) + goto cleanup; + + if (virStorageSourceIsLocalStorage(src) && src->path && + virTypedParamListAddS(params, src->path, "block.%zu.path", recordn= r) < 0) + goto cleanup; - if (virStorageSourceIsLocalStorage(src) && src->path) - QEMU_ADD_NAME_PARAM(records, nrecords, "block", "path", recordnr, = src->path); - if (src->id) - QEMU_ADD_BLOCK_PARAM_UI(records, nrecords, recordnr, "backingIndex= ", - src->id); + if (src->id && + virTypedParamListAddUI(params, src->id, "block.%zu.backingIndex", = recordnr) < 0) + goto cleanup; ret =3D 0; cleanup: @@ -21708,8 +21569,7 @@ static int qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk, virHashTablePtr stats, virHashTablePtr nodestats, - virDomainStatsRecordPtr records, - int *nrecords, + virTypedParamListPtr params, size_t *recordnr, bool visitBacking, virQEMUDriverPtr driver, @@ -21736,7 +21596,7 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefP= tr disk, "skip getting stats", disk->dst); return qemuDomainGetStatsBlockExportHeader(disk, disk->src, *recor= dnr, - records, nrecords); + params); } for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backingSt= ore) { @@ -21757,25 +21617,24 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDe= fPtr disk, backendstoragealias =3D alias; } - if (qemuDomainGetStatsBlockExportHeader(disk, n, *recordnr, - records, nrecords) < 0) + if (qemuDomainGetStatsBlockExportHeader(disk, n, *recordnr, params= ) < 0) goto cleanup; /* The following stats make sense only for the frontend device */ if (n =3D=3D disk->src) { if (qemuDomainGetStatsBlockExportFrontend(frontendalias, stats= , *recordnr, - records, nrecords) <= 0) + params) < 0) goto cleanup; } - if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords, + if (qemuDomainGetStatsOneBlock(driver, cfg, dom, params, backendalias, n, *recordnr, stats) < 0) goto cleanup; if (qemuDomainGetStatsBlockExportBackendStorage(backendstoragealia= s, stats, *recordnr, - records, nrecords)= < 0) + params) < 0) goto cleanup; VIR_FREE(alias); @@ -21796,8 +21655,7 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefP= tr disk, static int qemuDomainGetStatsBlock(virQEMUDriverPtr driver, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags) { size_t i; @@ -21846,18 +21704,19 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, /* When listing backing chains, it's easier to fix up the count * after the iteration than it is to iterate twice; but we still * want count listed first. */ - count_index =3D record->nparams; - QEMU_ADD_COUNT_PARAM(record, maxparams, "block", 0); + count_index =3D params->npar; + if (virTypedParamListAddUI(params, 0, "block.count") < 0) + goto cleanup; for (i =3D 0; i < dom->def->ndisks; i++) { if (qemuDomainGetStatsBlockExportDisk(dom->def->disks[i], stats, n= odestats, - record, maxparams, &visited, + params, &visited, visitBacking, driver, cfg, d= om, blockdev) < 0) goto cleanup; } - record->params[count_index].value.ui =3D visited; + params->par[count_index].value.ui =3D visited; ret =3D 0; cleanup: @@ -21870,39 +21729,10 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, #undef QEMU_ADD_BLOCK_PARAM_ULL -#undef QEMU_ADD_NAME_PARAM - -#define QEMU_ADD_IOTHREAD_PARAM_UI(record, maxparams, id, name, value) \ - do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ - "iothread.%u.%s", id, name); \ - if (virTypedParamsAddUInt(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - value) < 0) \ - goto cleanup; \ - } while (0) - -#define QEMU_ADD_IOTHREAD_PARAM_ULL(record, maxparams, id, name, value) \ -do { \ - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \ - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \ - "iothread.%u.%s", id, name); \ - if (virTypedParamsAddULLong(&(record)->params, \ - &(record)->nparams, \ - maxparams, \ - param_name, \ - value) < 0) \ - goto cleanup; \ -} while (0) - static int qemuDomainGetStatsIOThread(virQEMUDriverPtr driver, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags ATTRIBUTE_UNUSED) { qemuDomainObjPrivatePtr priv =3D dom->privateData; @@ -21923,22 +21753,20 @@ qemuDomainGetStatsIOThread(virQEMUDriverPtr drive= r, if (niothreads =3D=3D 0) return 0; - QEMU_ADD_COUNT_PARAM(record, maxparams, "iothread", niothreads); + if (virTypedParamListAddUI(params, niothreads, "iothread.count") < 0) + goto cleanup; for (i =3D 0; i < niothreads; i++) { if (iothreads[i]->poll_valid) { - QEMU_ADD_IOTHREAD_PARAM_ULL(record, maxparams, - iothreads[i]->iothread_id, - "poll-max-ns", - iothreads[i]->poll_max_ns); - QEMU_ADD_IOTHREAD_PARAM_UI(record, maxparams, - iothreads[i]->iothread_id, - "poll-grow", - iothreads[i]->poll_grow); - QEMU_ADD_IOTHREAD_PARAM_UI(record, maxparams, - iothreads[i]->iothread_id, - "poll-shrink", - iothreads[i]->poll_shrink); + if (virTypedParamListAddULL(params, iothreads[i]->poll_max_ns, + "iothread.%zu.poll-max-ns", i) < 0) + goto cleanup; + if (virTypedParamListAddUI(params, iothreads[i]->poll_grow, + "iothread.%zu.poll-grow", i) < 0) + goto cleanup; + if (virTypedParamListAddUI(params, iothreads[i]->poll_shrink, + "iothread.%zu.poll-shrink", i) < 0) + goto cleanup; } } @@ -21952,32 +21780,19 @@ qemuDomainGetStatsIOThread(virQEMUDriverPtr drive= r, return ret; } -#undef QEMU_ADD_IOTHREAD_PARAM_UI - -#undef QEMU_ADD_IOTHREAD_PARAM_ULL - -#undef QEMU_ADD_COUNT_PARAM static int qemuDomainGetStatsPerfOneEvent(virPerfPtr perf, virPerfEventType type, - virDomainStatsRecordPtr record, - int *maxparams) + virTypedParamListPtr params) { - char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; uint64_t value =3D 0; if (virPerfReadEvent(perf, type, &value) < 0) return -1; - snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, "perf.%s", - virPerfEventTypeToString(type)); - - if (virTypedParamsAddULLong(&record->params, - &record->nparams, - maxparams, - param_name, - value) < 0) + if (virTypedParamListAddULL(params, value, "perf.%s", + virPerfEventTypeToString(type)) < 0) return -1; return 0; @@ -21986,8 +21801,7 @@ qemuDomainGetStatsPerfOneEvent(virPerfPtr perf, static int qemuDomainGetStatsPerf(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr params, unsigned int privflags ATTRIBUTE_UNUSED) { size_t i; @@ -21998,8 +21812,7 @@ qemuDomainGetStatsPerf(virQEMUDriverPtr driver ATTR= IBUTE_UNUSED, if (!virPerfEventIsEnabled(priv->perf, i)) continue; - if (qemuDomainGetStatsPerfOneEvent(priv->perf, i, - record, maxparams) < 0) + if (qemuDomainGetStatsPerfOneEvent(priv->perf, i, params) < 0) goto cleanup; } @@ -22012,8 +21825,7 @@ qemuDomainGetStatsPerf(virQEMUDriverPtr driver ATTR= IBUTE_UNUSED, typedef int (*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver, virDomainObjPtr dom, - virDomainStatsRecordPtr record, - int *maxparams, + virTypedParamListPtr list, unsigned int flags); struct qemuDomainGetStatsWorker { @@ -22084,37 +21896,31 @@ qemuDomainGetStats(virConnectPtr conn, virDomainStatsRecordPtr *record, unsigned int flags) { - int maxparams =3D 0; - virDomainStatsRecordPtr tmp; + VIR_AUTOFREE(virDomainStatsRecordPtr) tmp =3D NULL; + VIR_AUTOPTR(virTypedParamList) params =3D NULL; size_t i; - int ret =3D -1; - if (VIR_ALLOC(tmp) < 0) - goto cleanup; + if (VIR_ALLOC(params) < 0) + return -1; for (i =3D 0; qemuDomainGetStatsWorkers[i].func; i++) { if (stats & qemuDomainGetStatsWorkers[i].stats) { - if (qemuDomainGetStatsWorkers[i].func(conn->privateData, dom, = tmp, - &maxparams, flags) < 0) - goto cleanup; + if (qemuDomainGetStatsWorkers[i].func(conn->privateData, dom, = params, + flags) < 0) + return -1; } } + if (VIR_ALLOC(tmp) < 0) + return -1; + if (!(tmp->dom =3D virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id))) - goto cleanup; - - *record =3D tmp; - tmp =3D NULL; - ret =3D 0; - - cleanup: - if (tmp) { - virTypedParamsFree(tmp->params, tmp->nparams); - VIR_FREE(tmp); - } + return -1; - return ret; + tmp->nparams =3D virTypedParamListStealParams(params, &tmp->params); + VIR_STEAL_PTR(*record, tmp); + return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913253; cv=none; d=zoho.com; s=zohoarc; b=Dz7gMCHfqYrKTHqBnUM8MnejkgLGvs2MgLIsaFgDCMsPrEoNn1QvpiMLantJ1gIaKXPYgKzZxLdKi4u27XQgyd1sLEkaYIqtMK6CnNoOUnWXqtOQON120m/kY1PwjH1TyTh1X2TFQWhkJvlHas7OwMPdjkqi5fKTJ/ffpT4j0uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913253; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/4Jy5LwzzUcCb8+2AjvqFpbzLmBoKxkY5sxYzp6vQ1U=; b=XBUFmyZWVAbOuCkI64UzbC8ZDmrIWJUs7LQPXQzirtLun3gyMEohvaTBLTxqv4Yz3Hp3K91kD9aR+YB5wsUpEkrwVkdzf9ObyG3bucfSIV0FqZ86Y56rytoPXpsERag0dR4Ep25TZ8ebpoBqeeUMBcuoK8Y6SXYJ3UHLmqyEOsI= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913253787881.2285480074631; Thu, 19 Sep 2019 10:14:13 -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 D13363C919; Thu, 19 Sep 2019 17:14:11 +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 A0C015C28C; Thu, 19 Sep 2019 17:14:11 +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 5FB47180B536; Thu, 19 Sep 2019 17:14:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHDwC7004807 for ; Thu, 19 Sep 2019 13:13:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6858660BF1; Thu, 19 Sep 2019 17:13:58 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5FD260C5E for ; Thu, 19 Sep 2019 17:13:55 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 18/22] qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsOneBlockFallback 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.39]); Thu, 19 Sep 2019 17:14:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The open-coded version does not take much more space and additionally we get rid of the hidden goto. This also requires us to remove the 'cleanup' section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c33fd6824c..b703436744 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21373,8 +21373,6 @@ qemuDomainGetStatsOneBlockFallback(virQEMUDriverPtr= driver, virStorageSourcePtr src, size_t block_idx) { - int ret =3D -1; - if (virStorageSourceIsEmpty(src)) return 0; @@ -21383,18 +21381,22 @@ qemuDomainGetStatsOneBlockFallback(virQEMUDriverP= tr driver, return 0; } - if (src->allocation) - QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, - "allocation", src->allocation); - if (src->capacity) - QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, - "capacity", src->capacity); - if (src->physical) - QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, - "physical", src->physical); - ret =3D 0; - cleanup: - return ret; + if (src->allocation && + virTypedParamListAddULL(params, src->allocation, + "block.%zu.allocation", block_idx) < 0) + return -1; + + if (src->capacity && + virTypedParamListAddULL(params, src->capacity, + "block.%zu.capacity", block_idx) < 0) + return -1; + + if (src->physical && + virTypedParamListAddULL(params, src->physical, + "block.%zu.physical", block_idx) < 0) + return -1; + + return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913277; cv=none; d=zoho.com; s=zohoarc; b=l0wIvi/Td0TTsMMvbZiIvgHcEHply4QY0Qc4wIBaYw3/PBmVSa7RqOJfE0SMccaXoOvBprcCbi49t69UyYmzk6agjV45gr/4wLM8Uz0xIfcPcoK+h0EqMoD3naUiwY8+/ll/29HElzBsbJqb4GeIzl1DJq9AicyTin/mkknb2B0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913277; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=3tw08t+ezuGdUcvvw0SVE6E6gmWoeL5Bt9S6ELeNDUE=; b=KsjGQm6xX9JMVQjDGpPZhyGWSh26W3JZIhNfI6xRxWaDwE2asgVdJM6NKjgw1Y29Xc0G43qDKe/y9HU37csRnW6Dge89qnzZYtji//uM9ekciBg63Y0g9k8ouDjTsqxysTPcYtUFZPCzS8p8E2aKQEUeSx3Gl29uZYOEG2uksJo= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913277651498.67906480700447; Thu, 19 Sep 2019 10:14:37 -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 119E9302C099; Thu, 19 Sep 2019 17:14:36 +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 E04D25C3F8; Thu, 19 Sep 2019 17:14:35 +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 9FE864EEB7; Thu, 19 Sep 2019 17:14:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHE1i8004827 for ; Thu, 19 Sep 2019 13:14:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6614E60C83; Thu, 19 Sep 2019 17:14:01 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2EF560BF1 for ; Thu, 19 Sep 2019 17:13:58 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 19/22] qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsOneBlock 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.46]); Thu, 19 Sep 2019 17:14:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b703436744..703f07a388 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21447,42 +21447,42 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr drive= r, virHashTablePtr stats) { qemuBlockStats *entry; - int ret =3D -1; /* the VM is offline so we have to go and load the stast from the disk= by * ourselves */ if (!virDomainObjIsActive(dom)) { - ret =3D qemuDomainGetStatsOneBlockFallback(driver, cfg, dom, param= s, - src, block_idx); - goto cleanup; + return qemuDomainGetStatsOneBlockFallback(driver, cfg, dom, params, + src, block_idx); } /* In case where qemu didn't provide the stats we stop here rather than * trying to refresh the stats from the disk. Inability to provide sta= ts is * usually caused by blocked storage so this would make libvirtd hang = */ - if (!stats || !entryname || !(entry =3D virHashLookup(stats, entryname= ))) { - ret =3D 0; - goto cleanup; - } + if (!stats || !entryname || !(entry =3D virHashLookup(stats, entryname= ))) + return 0; - QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, - "allocation", entry->wr_highest_offset); + if (virTypedParamListAddULL(params, entry->wr_highest_offset, + "block.%zu.allocation", block_idx) < 0) + return -1; + + if (entry->capacity && + virTypedParamListAddULL(params, entry->capacity, + "block.%zu.capacity", block_idx) < 0) + return -1; - if (entry->capacity) - QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, - "capacity", entry->capacity); if (entry->physical) { - QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, - "physical", entry->physical); + if (virTypedParamListAddULL(params, entry->physical, + "block.%zu.physical", block_idx) < 0) + return -1; } else { - if (qemuDomainStorageUpdatePhysical(driver, cfg, dom, src) =3D=3D = 0) - QEMU_ADD_BLOCK_PARAM_ULL(params, block_idx, - "physical", src->physical); + if (qemuDomainStorageUpdatePhysical(driver, cfg, dom, src) =3D=3D = 0) { + if (virTypedParamListAddULL(params, src->physical, + "block.%zu.physical", block_idx) <= 0) + return -1; + } } - ret =3D 0; - cleanup: - return ret; + return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913288; cv=none; d=zoho.com; s=zohoarc; b=Xoh+thEBtZ3KdfHORl0Yh5AKdOUE3gIXV0SdZsQIx+7o3W9LUcHFkoMf3XjgsaTKi6bqcaYSeqFAzURp4CurPW/zdZwJU+0lu2ykFZjBjdBhwgCirmEavlAq0mvFVVfG7+wFo2dXg7GYOzpzfCxjtk00gnkluykN4dRw6Bcwklk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913288; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=wbx6mjm5pFECWdqvpC3pwNECyjH/BSqEgmA7V3jnfD4=; b=M2cCmbltd2WKwyRwilJuQnr90j5LZyecaOkiBZ7NP7PIjjYZJGGajVUzUkLNUYU/KHbnyAnyu5OZyPel8SxxfCF1ODj99A3ajpEpYI45GJV9fsdD+sM7fck6yQZWWG/o3ejab3oD2qBV2FoASUptTpkHOwjY+/BV8y+9PZRBpwg= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913288986639.8655292527202; Thu, 19 Sep 2019 10:14:48 -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 4A870302C092; Thu, 19 Sep 2019 17:14:47 +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 2602160872; Thu, 19 Sep 2019 17:14:47 +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 D931C4EEB7; Thu, 19 Sep 2019 17:14:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHE7fO004855 for ; Thu, 19 Sep 2019 13:14:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0CA8A60C5E; Thu, 19 Sep 2019 17:14:07 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A3BE60BF1 for ; Thu, 19 Sep 2019 17:14:01 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:23 +0200 Message-Id: <0b1b0fd5aa695d5f1e3d4a3c930bc9fa6be3d1ac.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 20/22] qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsBlockExportBackendStorage 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 19 Sep 2019 17:14:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 703f07a388..2163d14cea 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21493,20 +21493,16 @@ qemuDomainGetStatsBlockExportBackendStorage(const= char *entryname, virTypedParamListPtr params) { qemuBlockStats *entry; - int ret =3D -1; - if (!stats || !entryname || !(entry =3D virHashLookup(stats, entryname= ))) { - ret =3D 0; - goto cleanup; - } + if (!stats || !entryname || !(entry =3D virHashLookup(stats, entryname= ))) + return 0; - if (entry->write_threshold) - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "threshold", - entry->write_threshold); + if (entry->write_threshold && + virTypedParamListAddULL(params, entry->write_threshold, + "block.%zu.threshold", recordnr) < 0) + return -1; - ret =3D 0; - cleanup: - return ret; + return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913260; cv=none; d=zoho.com; s=zohoarc; b=ZWhxNu7dqJd2CcMPMee0JOviVJvZ16u22F5GE3UJsQlY7tiQZ96vi3zIroW9uYQsPu+BLnvTOeEiQVpCUVkK1jqJ2mi6INCU7xT4PzMB9YgWOA+uTpDsWqSXgq60dtRhD1vJPIlTO3Dbk1UNxgNtFJZ6eQyUs1czJJ1cCdsKTTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913260; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=E+Z9HdR7i5x3DbnsDZ39l0fJvL5yd4yj5CR+96W9uNg=; b=NgCKtYU1VaCJCIcM0aY7bKFNRtnB6K0EX0LRyCfUFOfgFmd6YkNi40TuE0gt79kS4uwkiwPR0W2VR4hViFYtFJs7vg5QQKevUqxxCQyLbC/xNKGkZGr4PxHdckxvlKITFfvABR/H9vkaJsVweAeYxrnYGgAdVQHV5kUR/pDhk/U= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913260685751.0282092060738; Thu, 19 Sep 2019 10:14:20 -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 EAD3AC04BD33; Thu, 19 Sep 2019 17:14:18 +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 B66596062A; Thu, 19 Sep 2019 17:14:18 +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 7786F180BA9E; Thu, 19 Sep 2019 17:14:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHEAYN004944 for ; Thu, 19 Sep 2019 13:14:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9029060C5E; Thu, 19 Sep 2019 17:14:10 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1831160C83 for ; Thu, 19 Sep 2019 17:14:07 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:24 +0200 Message-Id: <52c4f188e02a7dfddb0503e12e1662056bd18279.1568911535.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 21/22] qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsBlockExportFrontend 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 19 Sep 2019 17:14:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The macro now became unused so it was deleted. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2163d14cea..f0f08dcbfc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21360,10 +21360,6 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr drive= r ATTRIBUTE_UNUSED, #undef QEMU_ADD_NET_PARAM -#define QEMU_ADD_BLOCK_PARAM_ULL(params, num, name, value) \ - if (virTypedParamListAddULL((params), (value), "block.%zu.%s", (num), = (name)) < 0) \ - goto cleanup - /* refresh information by opening images on the disk */ static int qemuDomainGetStatsOneBlockFallback(virQEMUDriverPtr driver, @@ -21509,32 +21505,28 @@ qemuDomainGetStatsBlockExportBackendStorage(const= char *entryname, static int qemuDomainGetStatsBlockExportFrontend(const char *frontendname, virHashTablePtr stats, - size_t recordnr, - virTypedParamListPtr params) + size_t idx, + virTypedParamListPtr par) { - qemuBlockStats *entry; - int ret =3D -1; + qemuBlockStats *en; /* In case where qemu didn't provide the stats we stop here rather than * trying to refresh the stats from the disk. Inability to provide sta= ts is * usually caused by blocked storage so this would make libvirtd hang = */ - if (!stats || !frontendname || !(entry =3D virHashLookup(stats, fronte= ndname))) { - ret =3D 0; - goto cleanup; - } + if (!stats || !frontendname || !(en =3D virHashLookup(stats, frontendn= ame))) + return 0; - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "rd.reqs", entry->rd_req); - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "rd.bytes", entry->rd_bytes= ); - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "rd.times", entry->rd_total= _times); - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "wr.reqs", entry->wr_req); - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "wr.bytes", entry->wr_bytes= ); - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "wr.times", entry->wr_total= _times); - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "fl.reqs", entry->flush_req= ); - QEMU_ADD_BLOCK_PARAM_ULL(params, recordnr, "fl.times", entry->flush_to= tal_times); + if (virTypedParamListAddULL(par, en->rd_req, "block.%zu.rd.reqs", idx)= < 0 || + virTypedParamListAddULL(par, en->rd_bytes, "block.%zu.rd.bytes", i= dx) < 0 || + virTypedParamListAddULL(par, en->rd_total_times, "block.%zu.rd.tim= es", idx) < 0 || + virTypedParamListAddULL(par, en->wr_req, "block.%zu.wr.reqs", idx)= < 0 || + virTypedParamListAddULL(par, en->wr_bytes, "block.%zu.wr.bytes", i= dx) < 0 || + virTypedParamListAddULL(par, en->wr_total_times, "block.%zu.wr.tim= es", idx) < 0 || + virTypedParamListAddULL(par, en->flush_req, "block.%zu.fl.reqs", i= dx) < 0 || + virTypedParamListAddULL(par, en->flush_total_times, "block.%zu.fl.= times", idx) < 0) + return -1; - ret =3D 0; - cleanup: - return ret; + return 0; } @@ -21725,7 +21717,6 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver, return ret; } -#undef QEMU_ADD_BLOCK_PARAM_ULL static int qemuDomainGetStatsIOThread(virQEMUDriverPtr driver, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 8 02:24:47 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 ARC-Seal: i=1; a=rsa-sha256; t=1568913279; cv=none; d=zoho.com; s=zohoarc; b=Rc2iO56CxhwSY5P7TSytPkKOMBYuxafpU0irglKVuGastS4+wFDqhIYF8U7Tqxvsfgr8IJ0byw+ALOPefDf9Z8AOlSNmFm8ykD/QEaTZuSpq/VXxnIXM7qecgrfpOBmjsEFP+3tz23w7P+G0PffnOnMkgFFhsQWQRvKtJxT85Q8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568913279; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=NB7yqbKvw6EHcoNDT96wh4EtSytQC4l9AtYWSz/K7Cs=; b=S6kNrr30xGDT34RLVI+JHPUmFemVPSz5Ox0KeEbnz7p99ZF7oVYVyDY9HxL2VaQVFGXHUip4vsRWYVJwCr+tgkSCn2TL7RA8/qPEDanMdr3vcLkRtS64fmqj/FgtST9S31N9NSrB15TlyLtY6rpZcjT3eRMxsQnmoPCfYcUwbak= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568913279868671.2685852237295; Thu, 19 Sep 2019 10:14: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 1BA68308FB9D; Thu, 19 Sep 2019 17:14:37 +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 E70B05C226; Thu, 19 Sep 2019 17:14:36 +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 9AEE2180BAA6; Thu, 19 Sep 2019 17:14:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8JHEFeq005026 for ; Thu, 19 Sep 2019 13:14:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3CFBC60C5E; Thu, 19 Sep 2019 17:14:15 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA23260C83 for ; Thu, 19 Sep 2019 17:14:10 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 19 Sep 2019 19:13:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 22/22] qemu: driver: Remove unused cleanup labels in stats gathering functions 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.43]); Thu, 19 Sep 2019 17:14:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f0f08dcbfc..319f2d9476 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21536,22 +21536,18 @@ qemuDomainGetStatsBlockExportHeader(virDomainDisk= DefPtr disk, size_t recordnr, virTypedParamListPtr params) { - int ret =3D -1; - if (virTypedParamListAddS(params, disk->dst, "block.%zu.name", recordn= r) < 0) - goto cleanup; + return -1; if (virStorageSourceIsLocalStorage(src) && src->path && virTypedParamListAddS(params, src->path, "block.%zu.path", recordn= r) < 0) - goto cleanup; + return -1; if (src->id && virTypedParamListAddUI(params, src->id, "block.%zu.backingIndex", = recordnr) < 0) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - return ret; + return 0; } @@ -21795,20 +21791,16 @@ qemuDomainGetStatsPerf(virQEMUDriverPtr driver AT= TRIBUTE_UNUSED, { size_t i; qemuDomainObjPrivatePtr priv =3D dom->privateData; - int ret =3D -1; for (i =3D 0; i < VIR_PERF_EVENT_LAST; i++) { if (!virPerfEventIsEnabled(priv->perf, i)) continue; if (qemuDomainGetStatsPerfOneEvent(priv->perf, i, params) < 0) - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - return ret; + return 0; } typedef int --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list