[libvirt] [RFC PATCH 5/5] Enable virDomainBlockIoThrottle in the python API

Lei Li lilei at linux.vnet.ibm.com
Mon Oct 10 13:45:13 UTC 2011


Signed-off-by: Zhi Yong Wu <wuzhy at linux.vnet.ibm.com>
---
 python/generator.py             |    1 +
 python/libvirt-override-api.xml |    9 ++++++++
 python/libvirt-override.c       |   43 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/python/generator.py b/python/generator.py
index 79558dd..bec9e83 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -413,6 +413,7 @@ skip_impl = (
     'virDomainGetBlockJobInfo',
     'virDomainMigrateGetMaxSpeed',
     'virDomainBlockStatsFlags',
+    'virDomainBlockIoThrottle',
 )
 
 qemu_skip_impl = (
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 3013e46..3044b33 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -369,5 +369,14 @@
       <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='virDomainBlockIoThrottle' file='python'>
+      <info>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='info' type='virDomainBlockIoThrottleInfoPtr' info='io throttle limits'/>
+      <arg name='reply' type='virDomainBlockIoThrottleInfoPtr' info='io throttle info'/>
+      <arg name='flags' type='unsigned int' info='1 on display, 1 on set.'/>
+      <return type='virDomainBlockIoThrottleInfo' 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 d65423d..767906a 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3150,6 +3150,48 @@ LIBVIRT_END_ALLOW_THREADS;
     return ret;
 }
 
+static PyObject *
+libvirt_virDomainBlockIoThrottle(PyObject *self ATTRIBUTE_UNUSED,
+                                 PyObject *args)
+{
+    virDomainPtr domain;
+    PyObject *pyobj_domain;
+    const char *disk;
+    unsigned int flags;
+    virDomainBlockIoThrottleInfo reply;
+    int c_ret;
+    PyObject *ret;
+
+    if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainBlockIoThrottle",
+                          &pyobj_domain, &disk, &flags))
+        return(NULL);
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_ret = virDomainBlockIoThrottle(domain, disk, NULL, &reply, flags);
+LIBVIRT_END_ALLOW_THREADS;
+
+    if (c_ret != 1)
+        return VIR_PY_NONE;
+
+    if ((ret = PyDict_New()) == NULL)
+        return VIR_PY_NONE;
+
+    PyDict_SetItem(ret, libvirt_constcharPtrWrap("bps"),
+                   libvirt_intWrap(reply.bps));
+    PyDict_SetItem(ret, libvirt_constcharPtrWrap("bps_rd"),
+                   libvirt_intWrap(reply.bps_rd));
+    PyDict_SetItem(ret, libvirt_constcharPtrWrap("bps_wr"),
+                   libvirt_intWrap(reply.bps_wr));
+    PyDict_SetItem(ret, libvirt_constcharPtrWrap("iops"),
+                   libvirt_intWrap(reply.iops));
+    PyDict_SetItem(ret, libvirt_constcharPtrWrap("iops_rd"),
+                   libvirt_intWrap(reply.iops_rd));
+    PyDict_SetItem(ret, libvirt_constcharPtrWrap("iops_wr"),
+                   libvirt_intWrap(reply.iops_wr));
+    return ret;
+}
+
 /*******************************************
  * Helper functions to avoid importing modules
  * for every callback
@@ -4739,6 +4781,7 @@ 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 *) "virDomainGetBlockIoThrottle", libvirt_virDomainBlockIoThrottle, METH_VARARGS, NULL},
     {(char *) "virDomainSendKey", libvirt_virDomainSendKey, METH_VARARGS, NULL},
     {(char *) "virDomainMigrateGetMaxSpeed", libvirt_virDomainMigrateGetMaxSpeed, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
-- 
1.7.1




More information about the libvir-list mailing list