[libvirt] [PATCH 08/22] util: typedparam: Simplify handling of lists of typed parameters

Ján Tomko jtomko at redhat.com
Tue Sep 24 15:16:09 UTC 2019


On Thu, Sep 19, 2019 at 07:13:11PM +0200, Peter Krempa wrote:
>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 <pkrempa at redhat.com>
>---
> src/libvirt_private.syms |   9 ++
> src/util/virtypedparam.c | 222 +++++++++++++++++++++++++++++++++++++++
> src/util/virtypedparam.h |  61 +++++++++++
> 3 files changed, 292 insertions(+)
>
>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;
>+

This declaration does not have a corresponding definition.

> 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;

Consider spelling out the type names to match the virTypedParamsAdd*
APIs

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190924/f025baf7/attachment-0001.sig>


More information about the libvir-list mailing list