From nobody Fri May 16 11:03:24 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1495549717905890.3669914782093; Tue, 23 May 2017 07:28:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7215F81229; Tue, 23 May 2017 14:28:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EEA27D682; Tue, 23 May 2017 14:28:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 02B53180BAFA; Tue, 23 May 2017 14:28:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NEQKQe028662 for ; Tue, 23 May 2017 10:26:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 945EE7BB1D; Tue, 23 May 2017 14:26:20 +0000 (UTC) Received: from moe.brq.redhat.com (dhcp129-131.brq.redhat.com [10.34.129.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CECD7BCB1 for ; Tue, 23 May 2017 14:26:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7215F81229 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7215F81229 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 16:26:08 +0200 Message-Id: <1f42d8629f7fa516ebe8e02b74cbeba1e46aab4e.1495549496.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-python][PATCH v2 1/4] Implement virStreamSendHole/virStreamRecvHole X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 23 May 2017 14:28:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D ( '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 =20 '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 =3D libvirtmod.virStreamSend(self._o, data) if ret =3D=3D -1: raise libvirtError ('virStreamSend() failed') return ret + + def recvHole(self, flags =3D 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 =3D libvirtmod.virStreamRecvHole(self._o, flags) + if ret is None: raise libvirtError ('virStreamRecvHole() failed') + return ret + + def sendHole(self, length, flags =3D 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 =3D libvirtmod.virStreamSendHole(self._o, length, flags) + if ret =3D=3D -1: raise libvirtError('virStreamSendHole() failed') + return ret diff --git a/libvirt-override.c b/libvirt-override.c index a762941..a6ef49e 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)*/ =20 + +#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 =3D -1; + unsigned int flags; + int ret; + + if (!PyArg_ParseTuple(args, (char *) "OI:virStreamRecvHole", + &pyobj_stream, &flags)) + return NULL; + + stream =3D PyvirStream_Get(pyobj_stream); + + LIBVIRT_BEGIN_ALLOW_THREADS; + ret =3D virStreamRecvHole(stream, &length, flags); + LIBVIRT_END_ALLOW_THREADS; + + DEBUG("StreamRecvHole ret=3D%d length=3D%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 *) "OLI:virStreamSendHole", + &pyobj_stream, &length, &flags)) + return NULL; + + stream =3D PyvirStream_Get(pyobj_stream); + + LIBVIRT_BEGIN_ALLOW_THREADS; + ret =3D virStreamSendHole(stream, length, flags); + LIBVIRT_END_ALLOW_THREADS; + + DEBUG("StreamSendHole ret=3D%d\n", ret); + + return libvirt_intWrap(ret); +} + +#endif /* LIBVIR_CHECK_VERSION(3, 4, 0) */ + + /************************************************************************ * * * The registration stuff * @@ -9687,6 +9746,10 @@ static PyMethodDef libvirtMethods[] =3D { {(char *) "virConnectSecretEventRegisterAny", libvirt_virConnectSecret= EventRegisterAny, METH_VARARGS, NULL}, {(char *) "virConnectSecretEventDeregisterAny", libvirt_virConnectSecr= etEventDeregisterAny, 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} }; =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list