Discussion:
[libvirt] [PATCH v2 0/2] Couple of fixes and impl for virDomainSetIOThreadParams
John Ferlan
2018-11-20 17:13:02 UTC
Permalink
v1: https://www.redhat.com/archives/libvir-list/2018-November/msg00772.html

Changes since v1:

- Pushed the first two patches w/ R-By

- Add/Insert a patch to handle when PyDict_Check fails

- Modify libvirt_virDomainSetIOThreadParams from code review for
the @args on the same line (not sure why I did that) and to add
the else for PyDict_Check failure with error message.

- Change the "IOThread performance parameters" to "IOThread polling
parameters" since that more closely describes them.

John Ferlan (2):
Add check for params, nparams being a dictionary
Implement API binding for virDomainSetIOThreadParams

generator.py | 1 +
libvirt-override-api.xml | 8 +++++
libvirt-override.c | 67 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+)
--
2.17.2
John Ferlan
2018-11-20 17:13:03 UTC
Permalink
If PyDict_Check fails, we should force an error rather than
blindly continuing on.

Signed-off-by: John Ferlan <***@redhat.com>
---
libvirt-override.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/libvirt-override.c b/libvirt-override.c
index 0353306..8748101 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -7861,6 +7861,11 @@ libvirt_virDomainMigrate3(PyObject *self ATTRIBUTE_UNUSED,
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
dconn = (virConnectPtr) PyvirConnect_Get(pyobj_dconn);

+ if (!PyDict_Check(dict)) {
+ PyErr_Format(PyExc_TypeError, "migration params must be a dictionary");
+ return NULL;
+ }
+
if (virPyDictToTypedParams(dict, &params, &nparams,
virPyDomainMigrate3Params,
VIR_N_ELEMENTS(virPyDomainMigrate3Params)) < 0) {
@@ -7894,6 +7899,11 @@ libvirt_virDomainMigrateToURI3(PyObject *self ATTRIBUTE_UNUSED,

domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);

+ if (!PyDict_Check(dict)) {
+ PyErr_Format(PyExc_TypeError, "migration params must be a dictionary");
+ return NULL;
+ }
+
if (virPyDictToTypedParams(dict, &params, &nparams,
virPyDomainMigrate3Params,
VIR_N_ELEMENTS(virPyDomainMigrate3Params)) < 0) {
@@ -8776,6 +8786,9 @@ libvirt_virDomainBlockCopy(PyObject *self ATTRIBUTE_UNUSED,
VIR_N_ELEMENTS(virPyDomainBlockCopyParams)) < 0) {
return NULL;
}
+ } else {
+ PyErr_Format(PyExc_TypeError, "block params must be a dictionary");
+ return NULL;
}

dom = (virDomainPtr) PyvirDomain_Get(pyobj_dom);
--
2.17.2
John Ferlan
2018-11-20 17:13:04 UTC
Permalink
Similar to libvirt_virDomainBlockCopy (and migration API's). Create
the code for the new API.

Signed-off-by: John Ferlan <***@redhat.com>
---
generator.py | 1 +
libvirt-override-api.xml | 8 ++++++
libvirt-override.c | 54 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 63 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..7f578e0 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&apos;ed set of virDomainModificationImpact'/>
</function>
+ <function name='virDomainSetIOThreadParams' file='python'>
+ <info>Dynamically allow changing the IOThread polling 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 polling parameter objects'/>
+ <arg name='flags' type='int' info='an OR&apos;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 8748101..349ac63 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -1679,6 +1679,57 @@ 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, &params, &nparams,
+ virPyDomainSetIOThreadParams,
+ VIR_N_ELEMENTS(virPyDomainSetIOThreadParams)) < 0) {
+ return NULL;
+ }
+ } else {
+ PyErr_Format(PyExc_TypeError, "IOThread polling params must be "
+ "a dictionary");
+ 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 *
@@ -9988,6 +10039,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
Pavel Hrdina
2018-11-20 17:58:49 UTC
Permalink
Post by John Ferlan
v1: https://www.redhat.com/archives/libvir-list/2018-November/msg00772.html
- Pushed the first two patches w/ R-By
- Add/Insert a patch to handle when PyDict_Check fails
- Modify libvirt_virDomainSetIOThreadParams from code review for
the else for PyDict_Check failure with error message.
- Change the "IOThread performance parameters" to "IOThread polling
parameters" since that more closely describes them.
Add check for params, nparams being a dictionary
Implement API binding for virDomainSetIOThreadParams
Reviewed-by: Pavel Hrdina <***@redhat.com>

Loading...