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

[libvirt] [libvirt-python][PATCH 1/4] Implement virStreamSendHole/virStreamRecvHole



The return value for virStreamRecvHole is slightly different to
its C counterpart. In python, either it returns the hole size or
None if C API fails.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 generator.py                  |  2 ++
 libvirt-override-virStream.py | 21 +++++++++++++++
 libvirt-override.c            | 63 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+)

diff --git a/generator.py b/generator.py
index 5dfa73e..ca1df35 100755
--- a/generator.py
+++ b/generator.py
@@ -543,6 +543,8 @@ skip_function = (
     'virStreamSendAll', # Pure python libvirt-override-virStream.py
     'virStreamRecv', # overridden in libvirt-override-virStream.py
     'virStreamSend', # overridden in libvirt-override-virStream.py
+    'virStreamRecvHole', # overridden in libvirt-override-virStream.py
+    'virStreamSendHole', # overridden in libvirt-override-virStream.py
 
     'virConnectUnregisterCloseCallback', # overridden in virConnect.py
     'virConnectRegisterCloseCallback', # overridden in virConnect.py
diff --git a/libvirt-override-virStream.py b/libvirt-override-virStream.py
index 2e77cc7..62c1328 100644
--- a/libvirt-override-virStream.py
+++ b/libvirt-override-virStream.py
@@ -125,3 +125,24 @@
         ret = libvirtmod.virStreamSend(self._o, data)
         if ret == -1: raise libvirtError ('virStreamSend() failed')
         return ret
+
+    def recvHole(self, flags = 0):
+        """This method is used to determine the length in bytes
+        of the empty space to be created in a stream's target
+        file when uploading or downloading sparsely populated
+        files. This is the counterpart to sendHole.
+        """
+        ret = libvirtmod.virStreamRecvHole(self._o, flags)
+        if ret is None: raise libvirtError ('virStreamRecvHole() failed')
+        return ret
+
+    def sendHole(self, length, flags = 0):
+        """Rather than transmitting empty file space, this method
+        directs the stream target to create length bytes of empty
+        space.  This method would be used when uploading or
+        downloading sparsely populated files to avoid the
+        needless copy of empty file space.
+        """
+        ret = libvirtmod.virStreamSendHole(self._o, length, flags)
+        if ret == -1: raise libvirtError('virStreamSendHole() failed')
+        return ret
diff --git a/libvirt-override.c b/libvirt-override.c
index a762941..b5e11ed 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -9463,6 +9463,65 @@ libvirt_virConnectSecretEventDeregisterAny(PyObject *self ATTRIBUTE_UNUSED,
 }
 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0)*/
 
+
+#if LIBVIR_CHECK_VERSION(3, 4, 0)
+static PyObject *
+libvirt_virStreamRecvHole(PyObject *self ATTRIBUTE_UNUSED,
+                          PyObject *args)
+{
+    PyObject *pyobj_stream;
+    virStreamPtr stream;
+    long long length = -1;
+    unsigned int flags;
+    int ret;
+
+    if (!PyArg_ParseTuple(args, (char *) "OI:virStreamRecvHole",
+                          &pyobj_stream, &flags))
+        return NULL;
+
+    stream = PyvirStream_Get(pyobj_stream);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    ret = virStreamRecvHole(stream, &length, flags);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    DEBUG("StreamRecvHole ret=%d length=%lld\n", ret, length);
+
+    if (ret < 0)
+        return VIR_PY_NONE;
+
+    return libvirt_longlongWrap(length);
+}
+
+
+static PyObject *
+libvirt_virStreamSendHole(PyObject *self ATTRIBUTE_UNUSED,
+                          PyObject *args)
+{
+    PyObject *pyobj_stream;
+    virStreamPtr stream;
+    long long length;
+    unsigned int flags;
+    int ret;
+
+    if (!PyArg_ParseTuple(args, (char *) "OKI:virStreamSendHole",
+                          &pyobj_stream, &length, &flags))
+        return NULL;
+
+    stream = PyvirStream_Get(pyobj_stream);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    ret = virStreamSendHole(stream, length, flags);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    DEBUG("StreamSendHole ret=%d\n", ret);
+
+    return libvirt_intWrap(ret);
+}
+
+#endif /* LIBVIR_CHECK_VERSION(3, 4, 0) */
+
+
 /************************************************************************
  *									*
  *			The registration stuff				*
@@ -9687,6 +9746,10 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virConnectSecretEventRegisterAny", libvirt_virConnectSecretEventRegisterAny, METH_VARARGS, NULL},
     {(char *) "virConnectSecretEventDeregisterAny", libvirt_virConnectSecretEventDeregisterAny, METH_VARARGS, NULL},
 #endif /* LIBVIR_CHECK_VERSION(3, 0, 0) */
+#if LIBVIR_CHECK_VERSION(3, 4, 0)
+    {(char *) "virStreamRecvHole", libvirt_virStreamRecvHole, METH_VARARGS, NULL},
+    {(char *) "virStreamSendHole", libvirt_virStreamSendHole, METH_VARARGS, NULL},
+#endif /* LIBVIR_CHECK_VERSION(3, 4, 0) */
     {NULL, NULL, 0, NULL}
 };
 
-- 
2.13.0


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