[PATCH python 1/1] Set hints for virPyDictToTypedParams

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

 



Predefine hints for all parameters possible to avoid wrong type
convert.

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@xxxxxxxxxxxxx>
---
 libvirt-override.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 124 insertions(+), 4 deletions(-)

diff --git a/libvirt-override.c b/libvirt-override.c
index 78a7f08..dba42d4 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -7750,7 +7750,9 @@ libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
     PyObject *dict;
     unsigned int flags;
     virTypedParameterPtr params;
-    int nparams;
+    virPyTypedParamsHintPtr hparams;
+    int nparams = 0;
+    int nhparams = 15;
     virDomainPtr ddom = NULL;

     if (!PyArg_ParseTuple(args, (char *) "OOOI:virDomainMigrate3",
@@ -7760,14 +7762,64 @@ libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
     domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
     dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);

-    if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
+    hparams = malloc(sizeof(virPyTypedParamsHint) * nhparams);
+    hparams[0].name = VIR_MIGRATE_PARAM_URI;
+    hparams[0].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[1].name = VIR_MIGRATE_PARAM_DEST_NAME;
+    hparams[1].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[2].name = VIR_MIGRATE_PARAM_DEST_XML;
+    hparams[2].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[3].name = VIR_MIGRATE_PARAM_GRAPHICS_URI;
+    hparams[3].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[4].name = VIR_MIGRATE_PARAM_BANDWIDTH;
+    hparams[4].type = VIR_TYPED_PARAM_ULLONG;
+
+    hparams[5].name = VIR_MIGRATE_PARAM_LISTEN_ADDRESS;
+    hparams[5].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[6].name = VIR_MIGRATE_PARAM_DISKS_PORT;
+    hparams[6].type = VIR_TYPED_PARAM_INT;
+
+    hparams[7].name = VIR_MIGRATE_PARAM_COMPRESSION;
+    hparams[7].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[8].name = VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS;
+    hparams[8].type = VIR_TYPED_PARAM_INT;
+
+    hparams[9].name = VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL;
+    hparams[9].type = VIR_TYPED_PARAM_INT;
+
+    hparams[10].name = VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS;
+    hparams[10].type = VIR_TYPED_PARAM_INT;
+
+    hparams[11].name = VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE;
+    hparams[11].type = VIR_TYPED_PARAM_ULLONG;
+
+    hparams[12].name = VIR_MIGRATE_PARAM_PERSIST_XML;
+    hparams[12].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[13].name = VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL;
+    hparams[13].type = VIR_TYPED_PARAM_INT;
+
+    hparams[14].name = VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT;
+    hparams[14].type = VIR_TYPED_PARAM_INT;
+
+    if (virPyDictToTypedParams(dict, &params, &nparams,
+                               hparams, nhparams) < 0) {
+        free(hparams);
         return NULL;
+    }

     LIBVIRT_BEGIN_ALLOW_THREADS;
     ddom = virDomainMigrate3(domain, dconn, params, nparams, flags);
     LIBVIRT_END_ALLOW_THREADS;

     virTypedParamsFree(params, nparams);
+    free(hparams);
     return libvirt_virDomainPtrWrap(ddom);
 }

@@ -7781,7 +7833,9 @@ libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,
     PyObject *dict;
     unsigned int flags;
     virTypedParameterPtr params;
+    virPyTypedParamsHintPtr hparams;
     int nparams;
+    int nhparams = 15;
     int ret = -1;

     if (!PyArg_ParseTuple(args, (char *) "OzOI:virDomainMigrate3",
@@ -7790,14 +7844,64 @@ libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,

     domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);

-    if (virPyDictToTypedParams(dict, &params, &nparams, NULL, 0) < 0)
+    hparams = malloc(sizeof(virPyTypedParamsHint) * nhparams);
+    hparams[0].name = VIR_MIGRATE_PARAM_URI;
+    hparams[0].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[1].name = VIR_MIGRATE_PARAM_DEST_NAME;
+    hparams[1].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[2].name = VIR_MIGRATE_PARAM_DEST_XML;
+    hparams[2].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[3].name = VIR_MIGRATE_PARAM_GRAPHICS_URI;
+    hparams[3].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[4].name = VIR_MIGRATE_PARAM_BANDWIDTH;
+    hparams[4].type = VIR_TYPED_PARAM_ULLONG;
+
+    hparams[5].name = VIR_MIGRATE_PARAM_LISTEN_ADDRESS;
+    hparams[5].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[6].name = VIR_MIGRATE_PARAM_DISKS_PORT;
+    hparams[6].type = VIR_TYPED_PARAM_INT;
+
+    hparams[7].name = VIR_MIGRATE_PARAM_COMPRESSION;
+    hparams[7].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[8].name = VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS;
+    hparams[8].type = VIR_TYPED_PARAM_INT;
+
+    hparams[9].name = VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL;
+    hparams[9].type = VIR_TYPED_PARAM_INT;
+
+    hparams[10].name = VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS;
+    hparams[10].type = VIR_TYPED_PARAM_INT;
+
+    hparams[11].name = VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE;
+    hparams[11].type = VIR_TYPED_PARAM_ULLONG;
+
+    hparams[12].name = VIR_MIGRATE_PARAM_PERSIST_XML;
+    hparams[12].type = VIR_TYPED_PARAM_STRING;
+
+    hparams[13].name = VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL;
+    hparams[13].type = VIR_TYPED_PARAM_INT;
+
+    hparams[14].name = VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT;
+    hparams[14].type = VIR_TYPED_PARAM_INT;
+
+    if (virPyDictToTypedParams(dict, &params, &nparams,
+                               hparams, nhparams) < 0) {
+        free(hparams);
         return NULL;
+    }

     LIBVIRT_BEGIN_ALLOW_THREADS;
     ret = virDomainMigrateToURI3(domain, dconnuri, params, nparams, flags);
     LIBVIRT_END_ALLOW_THREADS;

     virTypedParamsFree(params, nparams);
+    free(hparams);
     return libvirt_intWrap(ret);
 }
 #endif /* LIBVIR_CHECK_VERSION(1, 1, 0) */
@@ -8650,7 +8754,9 @@ libvirt_virDomainBlockCopy(PyObject *self ATTRIBUTE_UNUSED,
     char *disk = NULL;
     char *destxml = NULL;
     virTypedParameterPtr params = NULL;
+    virPyTypedParamsHintPtr hparams;
     int nparams = 0;
+    int nhparams = 3;
     unsigned int flags = 0;
     int c_retval;

@@ -8659,8 +8765,22 @@ libvirt_virDomainBlockCopy(PyObject *self ATTRIBUTE_UNUSED,
         return NULL;

     if (PyDict_Check(pyobj_dict)) {
-        if (virPyDictToTypedParams(pyobj_dict, &params, &nparams, NULL, 0) < 0)
+        hparams = malloc(sizeof(virPyTypedParamsHint) * nhparams);
+        hparams[0].name = VIR_DOMAIN_BLOCK_COPY_BANDWIDTH;
+        hparams[0].type = VIR_TYPED_PARAM_ULLONG;
+
+        hparams[1].name = VIR_DOMAIN_BLOCK_COPY_GRANULARITY;
+        hparams[1].type = VIR_TYPED_PARAM_UINT;
+
+        hparams[2].name = VIR_DOMAIN_BLOCK_COPY_BUF_SIZE;
+        hparams[2].type = VIR_TYPED_PARAM_UINT;
+
+        if (virPyDictToTypedParams(pyobj_dict, &params, &nparams,
+                                   hparams, nhparams) < 0) {
+            free(hparams);
             return NULL;
+        }
+        free(hparams);
     }

     dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
--
2.11.0

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