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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
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@xxxxxxxxxx>

Jano

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux