Python support for both set and get block I/O throttle.
Signed-off-by: Zhi Yong Wu <wuzhy(a)linux.vnet.ibm.com>
Signed-off-by: Lei Li <lilei(a)linux.vnet.ibm.com>
---
python/generator.py | 2 +
python/libvirt-override-api.xml | 16 +++++++
python/libvirt-override.c | 85 +++++++++++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/python/generator.py b/python/generator.py
index 71afdb7..88c52b9 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -414,6 +414,8 @@ skip_impl = (
'virDomainGetBlockJobInfo',
'virDomainMigrateGetMaxSpeed',
'virDomainBlockStatsFlags',
+ 'virDomainSetBlockIoTune',
+ 'virDomainGetBlockIoTune',
)
qemu_skip_impl = (
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index ef02f34..e8d9138 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -375,5 +375,21 @@
<arg name='flags' type='unsigned int' info='flags, currently
unused, pass 0.'/>
<return type='unsigned long' info='current max migration speed, or
None in case of error'/>
</function>
+ <function name='virDomainSetBlockIoTune' file='python'>
+ <info>Change the I/O throttle for a block device</info>
+ <arg name='dom' type='virDomainPtr' info='pointer to the
domain'/>
+ <arg name='disk' type='const char *' info='disk
name'/>
+ <arg name='info' type='virDomainBlockIoTuneInfoPtr' info='io
throttle limits'/>
+ <arg name='flags' type='unsigned int' info='an
OR'ed set of virDomainModificationImpact'/>
+ <return type='virDomainSetBlockIoTuneInfo' info='0 in case of
operation has started, -1 in case of failure'/>
+ </function>
+ <function name='virDomainGetBlockIoTune' file='python'>
+ <info>Get the I/O throttle a block device</info>
+ <arg name='dom' type='virDomainPtr' info='pointer to the
domain'/>
+ <arg name='disk' type='const char *' info='disk
name'/>
+ <arg name='reply' type='virDomainBlockIoTuneInfoPtr'
info='io throttle info'/>
+ <arg name='flags' type='unsigned int' info='an
OR'ed set of virDomainModificationImpact'/>
+ <return type='virDomainGetBlockIoTuneInfo' info='A dictionary
containing block I/O limits information.'/>
+ </function>
</symbols>
</api>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 1759bae..d4b023a 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3195,6 +3195,89 @@ LIBVIRT_END_ALLOW_THREADS;
return ret;
}
+static PyObject *
+libvirt_virDomainSetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ virDomainPtr domain;
+ PyObject *pyobj_domain, *pyinfo;
+ const char *disk;
+ unsigned int flags;
+ virDomainBlockIoTuneInfo info;
+ int c_ret;
+ PyObject *ret;
+
+ if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainSetBlockIoTune",
+ &pyobj_domain, &disk, &pyinfo, &flags))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ info.total_bytes_sec = (unsigned long long)PyLong_AsLongLong(PyDict_GetItem(pyinfo,
+ libvirt_constcharPtrWrap("bps")));
+ info.read_bytes_sec = (unsigned long long)PyLong_AsLongLong(PyDict_GetItem(pyinfo,
+ libvirt_constcharPtrWrap("bps_rd")));
+ info.write_bytes_sec = (unsigned long long)PyLong_AsLongLong(PyDict_GetItem(pyinfo,
+ libvirt_constcharPtrWrap("bps_wr")));
+ info.total_iops_sec = (unsigned long long)PyLong_AsLongLong(PyDict_GetItem(pyinfo,
+ libvirt_constcharPtrWrap("iops")));
+ info.read_iops_sec = (unsigned long long)PyLong_AsLongLong(PyDict_GetItem(pyinfo,
+ libvirt_constcharPtrWrap("iops_rd")));
+ info.write_iops_sec = (unsigned long long)PyLong_AsLongLong(PyDict_GetItem(pyinfo,
+ libvirt_constcharPtrWrap("iops_wr")));
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_ret = virDomainSetBlockIoTune(domain, disk, &info, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (c_ret < 0) {
+ return VIR_PY_NONE;
+ }
+
+ return VIR_PY_INT_SUCCESS;
+}
+
+static PyObject *
+libvirt_virDomainGetBlockIoTune(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ virDomainPtr domain;
+ PyObject *pyobj_domain;
+ const char *disk;
+ unsigned int flags;
+ virDomainBlockIoTuneInfo reply;
+ int c_ret;
+ PyObject *ret;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetBlockIoTune",
+ &pyobj_domain, &disk, &flags))
+ return(NULL);
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_ret = virDomainGetBlockIoTune(domain, disk, &reply, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (c_ret < 0)
+ return VIR_PY_NONE;
+
+ if ((ret = PyDict_New()) == NULL)
+ return VIR_PY_NONE;
+
+ PyDict_SetItem(ret, libvirt_constcharPtrWrap("total_bytes_sec"),
+ libvirt_ulonglongWrap(reply.total_bytes_sec));
+ PyDict_SetItem(ret, libvirt_constcharPtrWrap("read_bytes_sec"),
+ libvirt_ulonglongWrap(reply.read_bytes_sec));
+ PyDict_SetItem(ret, libvirt_constcharPtrWrap("write_bytes_sec"),
+ libvirt_ulonglongWrap(reply.write_bytes_sec));
+ PyDict_SetItem(ret, libvirt_constcharPtrWrap("total_iops_sec"),
+ libvirt_ulonglongWrap(reply.total_iops_sec));
+ PyDict_SetItem(ret, libvirt_constcharPtrWrap("read_iops_sec"),
+ libvirt_ulonglongWrap(reply.read_iops_sec));
+ PyDict_SetItem(ret, libvirt_constcharPtrWrap("write_iops_sec"),
+ libvirt_ulonglongWrap(reply.write_iops_sec));
+ return ret;
+}
+
/*******************************************
* Helper functions to avoid importing modules
* for every callback
@@ -4837,6 +4920,8 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames,
METH_VARARGS, NULL},
{(char *) "virDomainRevertToSnapshot", libvirt_virDomainRevertToSnapshot,
METH_VARARGS, NULL},
{(char *) "virDomainGetBlockJobInfo", libvirt_virDomainGetBlockJobInfo,
METH_VARARGS, NULL},
+ {(char *) "virDomainSetBlockIoTune", libvirt_virDomainSetBlockIoTune,
METH_VARARGS, NULL},
+ {(char *) "virDomainGetBlockIoTune", libvirt_virDomainGetBlockIoTune,
METH_VARARGS, NULL},
{(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS,
NULL},
{(char *) "virDomainMigrateGetMaxSpeed",
libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
--
1.7.1