[libvirt] [libvirt-python PATCH 0/3] Couple of fixes and impl for virDomainSetIOThreadParams

First two patches are a couple of fixes I noted while implementing and looking for "similar examples". The last patch is the impl for the API (it does fix the build). John Ferlan (3): Fix typos in virDomainSetSchedulerParameters name Add missing virPyDictToTypedParams for libvirt_virDomainBlockCopy Implement API binding for virDomainSetIOThreadParams generator.py | 1 + libvirt-override-api.xml | 8 ++++++ libvirt-override.c | 56 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 2 deletions(-) -- 2.17.2

Signed-off-by: John Ferlan <jferlan@redhat.com> --- libvirt-override.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libvirt-override.c b/libvirt-override.c index e74c7dd..761b71b 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -571,7 +571,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, Py_ssize_t size = 0; virTypedParameterPtr params = NULL, new_params = NULL; - if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetScedulerParameters", + if (!PyArg_ParseTuple(args, (char *)"OO:virDomainSetSchedulerParameters", &pyobj_domain, &info)) return NULL; domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); @@ -647,7 +647,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, virTypedParameterPtr params = NULL, new_params = NULL; if (!PyArg_ParseTuple(args, - (char *)"OOI:virDomainSetScedulerParametersFlags", + (char *)"OOI:virDomainSetSchedulerParametersFlags", &pyobj_domain, &info, &flags)) return NULL; domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); -- 2.17.2

On Tue, Nov 20, 2018 at 11:17:10AM -0500, John Ferlan wrote:
Signed-off-by: John Ferlan <jferlan@redhat.com> --- libvirt-override.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Need to free params like similar API's such as libvirt_virDomainMigrate3 and libvirt_virDomainMigrateToURI3. Signed-off-by: John Ferlan <jferlan@redhat.com> --- libvirt-override.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libvirt-override.c b/libvirt-override.c index 761b71b..0353306 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -8784,6 +8784,7 @@ libvirt_virDomainBlockCopy(PyObject *self ATTRIBUTE_UNUSED, c_retval = virDomainBlockCopy(dom, disk, destxml, params, nparams, flags); LIBVIRT_END_ALLOW_THREADS; + virTypedParamsFree(params, nparams); return libvirt_intWrap(c_retval); } -- 2.17.2

On Tue, Nov 20, 2018 at 11:17:11AM -0500, John Ferlan wrote:
Need to free params like similar API's such as libvirt_virDomainMigrate3 and libvirt_virDomainMigrateToURI3.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- libvirt-override.c | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Similar to libvirt_virDomainBlockCopy (and migration API's). Create the code for the new API. Signed-off-by: John Ferlan <jferlan@redhat.com> --- generator.py | 1 + libvirt-override-api.xml | 8 +++++++ libvirt-override.c | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/generator.py b/generator.py index bd7ff11..6cb923f 100755 --- a/generator.py +++ b/generator.py @@ -440,6 +440,7 @@ skip_impl = ( 'virDomainPinEmulator', 'virDomainGetIOThreadInfo', 'virDomainPinIOThread', + 'virDomainSetIOThreadParams', 'virSecretGetValue', 'virSecretSetValue', 'virSecretGetUUID', diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml index 4e8d6c0..0a68d32 100644 --- a/libvirt-override-api.xml +++ b/libvirt-override-api.xml @@ -292,6 +292,14 @@ <arg name='cpumap' type='unsigned char *' info='pointer to a bit map of real CPUs (in 8-bit bytes) (IN) Each bit set to 1 means that corresponding CPU is usable. Bytes are stored in little-endian order: CPU0-7, 8-15... In each byte, lowest CPU number is least significant bit.'/> <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> </function> + <function name='virDomainSetIOThreadParams' file='python'> + <info>Dynamically allow changing the IOThread performance related parameters. This function requires privileged access to the hypervisor.</info> + <return type='int' info='0 in case of success, -1 in case of failure.'/> + <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> + <arg name='iothread_val' type='unsigned int' info='iothread_id number'/> + <arg name='params' type='virTypedParameterPtr' info='pointer to IOThread performance statistic parameter objects'/> + <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> + </function> <function name='virDomainSetSchedulerParameters' file='python'> <info>Change the scheduler parameters</info> <return type='int' info='-1 in case of error, 0 in case of success.'/> diff --git a/libvirt-override.c b/libvirt-override.c index 0353306..cd03ff1 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -1679,6 +1679,54 @@ libvirt_virDomainPinIOThread(PyObject *self ATTRIBUTE_UNUSED, #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */ +#if LIBVIR_CHECK_VERSION(4, 10, 4) + +static virPyTypedParamsHint virPyDomainSetIOThreadParams[] = { + { VIR_DOMAIN_IOTHREAD_POLL_MAX_NS, VIR_TYPED_PARAM_ULLONG }, + { VIR_DOMAIN_IOTHREAD_POLL_GROW, VIR_TYPED_PARAM_UINT }, + { VIR_DOMAIN_IOTHREAD_POLL_SHRINK, VIR_TYPED_PARAM_ULLONG }, +}; + +static PyObject * +libvirt_virDomainSetIOThreadParams(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) +{ + PyObject *pyobj_dom = NULL; + PyObject *pyobj_dict = NULL; + + virDomainPtr dom; + int iothread_val; + virTypedParameterPtr params = NULL; + int nparams = 0; + unsigned int flags; + int c_retval; + + if (!PyArg_ParseTuple(args, + (char *)"OiOI:virDomainSetIOThreadParams", + &pyobj_dom, &iothread_val, &pyobj_dict, &flags)) + return NULL; + + if (PyDict_Check(pyobj_dict)) { + if (virPyDictToTypedParams(pyobj_dict, ¶ms, &nparams, + virPyDomainSetIOThreadParams, + VIR_N_ELEMENTS(virPyDomainSetIOThreadParams)) < 0) { + return NULL; + } + } + + dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom); + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virDomainSetIOThreadParams(dom, iothread_val, + params, nparams, flags); + LIBVIRT_END_ALLOW_THREADS; + + virTypedParamsFree(params, nparams); + + return libvirt_intWrap(c_retval); +} +#endif /* LIBVIR_CHECK_VERSION(4, 10, 0) */ + /************************************************************************ * * * Global error handler at the Python level * @@ -9975,6 +10023,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainGetIOThreadInfo", libvirt_virDomainGetIOThreadInfo, METH_VARARGS, NULL}, {(char *) "virDomainPinIOThread", libvirt_virDomainPinIOThread, METH_VARARGS, NULL}, #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */ +#if LIBVIR_CHECK_VERSION(4, 10, 4) + {(char *) "virDomainSetIOThreadParams", libvirt_virDomainSetIOThreadParams, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(4, 10, 0) */ {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL}, #if LIBVIR_CHECK_VERSION(0, 10, 2) -- 2.17.2

On Tue, Nov 20, 2018 at 11:17:12AM -0500, John Ferlan wrote:
Similar to libvirt_virDomainBlockCopy (and migration API's). Create the code for the new API.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- generator.py | 1 + libvirt-override-api.xml | 8 +++++++ libvirt-override.c | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+)
diff --git a/generator.py b/generator.py index bd7ff11..6cb923f 100755 --- a/generator.py +++ b/generator.py @@ -440,6 +440,7 @@ skip_impl = ( 'virDomainPinEmulator', 'virDomainGetIOThreadInfo', 'virDomainPinIOThread', + 'virDomainSetIOThreadParams', 'virSecretGetValue', 'virSecretSetValue', 'virSecretGetUUID', diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml index 4e8d6c0..0a68d32 100644 --- a/libvirt-override-api.xml +++ b/libvirt-override-api.xml @@ -292,6 +292,14 @@ <arg name='cpumap' type='unsigned char *' info='pointer to a bit map of real CPUs (in 8-bit bytes) (IN) Each bit set to 1 means that corresponding CPU is usable. Bytes are stored in little-endian order: CPU0-7, 8-15... In each byte, lowest CPU number is least significant bit.'/> <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> </function> + <function name='virDomainSetIOThreadParams' file='python'> + <info>Dynamically allow changing the IOThread performance related parameters. This function requires privileged access to the hypervisor.</info> + <return type='int' info='0 in case of success, -1 in case of failure.'/> + <arg name='domain' type='virDomainPtr' info='pointer to domain object'/> + <arg name='iothread_val' type='unsigned int' info='iothread_id number'/> + <arg name='params' type='virTypedParameterPtr' info='pointer to IOThread performance statistic parameter objects'/> + <arg name='flags' type='int' info='an OR'ed set of virDomainModificationImpact'/> + </function> <function name='virDomainSetSchedulerParameters' file='python'> <info>Change the scheduler parameters</info> <return type='int' info='-1 in case of error, 0 in case of success.'/> diff --git a/libvirt-override.c b/libvirt-override.c index 0353306..cd03ff1 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -1679,6 +1679,54 @@ libvirt_virDomainPinIOThread(PyObject *self ATTRIBUTE_UNUSED,
#endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
+#if LIBVIR_CHECK_VERSION(4, 10, 4) + +static virPyTypedParamsHint virPyDomainSetIOThreadParams[] = { + { VIR_DOMAIN_IOTHREAD_POLL_MAX_NS, VIR_TYPED_PARAM_ULLONG }, + { VIR_DOMAIN_IOTHREAD_POLL_GROW, VIR_TYPED_PARAM_UINT }, + { VIR_DOMAIN_IOTHREAD_POLL_SHRINK, VIR_TYPED_PARAM_ULLONG }, +}; + +static PyObject * +libvirt_virDomainSetIOThreadParams(PyObject *self ATTRIBUTE_UNUSED, + PyObject *args) +{ + PyObject *pyobj_dom = NULL; + PyObject *pyobj_dict = NULL; + + virDomainPtr dom; + int iothread_val; + virTypedParameterPtr params = NULL; + int nparams = 0; + unsigned int flags; + int c_retval; + + if (!PyArg_ParseTuple(args, + (char *)"OiOI:virDomainSetIOThreadParams",
Nitpick: probably everywhere else the format string is on the same line as 'args'. Feels wrong :).
+ &pyobj_dom, &iothread_val, &pyobj_dict, &flags)) + return NULL; + + if (PyDict_Check(pyobj_dict)) { + if (virPyDictToTypedParams(pyobj_dict, ¶ms, &nparams, + virPyDomainSetIOThreadParams, + VIR_N_ELEMENTS(virPyDomainSetIOThreadParams)) < 0) { + return NULL; + } + }
I know that we are not consistent in parsing dictionary in our binding code which should be eventually fixed. This will silently ignore the case that params is not dict. I think that we should error out in that case, for example libvirt_virDomainSetTime returns correct error. Pavel
+ + dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom); + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virDomainSetIOThreadParams(dom, iothread_val, + params, nparams, flags); + LIBVIRT_END_ALLOW_THREADS; + + virTypedParamsFree(params, nparams); + + return libvirt_intWrap(c_retval); +} +#endif /* LIBVIR_CHECK_VERSION(4, 10, 0) */ + /************************************************************************ * * * Global error handler at the Python level * @@ -9975,6 +10023,9 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virDomainGetIOThreadInfo", libvirt_virDomainGetIOThreadInfo, METH_VARARGS, NULL}, {(char *) "virDomainPinIOThread", libvirt_virDomainPinIOThread, METH_VARARGS, NULL}, #endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */ +#if LIBVIR_CHECK_VERSION(4, 10, 4) + {(char *) "virDomainSetIOThreadParams", libvirt_virDomainSetIOThreadParams, METH_VARARGS, NULL}, +#endif /* LIBVIR_CHECK_VERSION(4, 10, 0) */ {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL}, {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL}, #if LIBVIR_CHECK_VERSION(0, 10, 2) -- 2.17.2
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
John Ferlan
-
Pavel Hrdina