From nobody Sat May 4 12:44:10 2024 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 1495551957338443.8842800004668; Tue, 23 May 2017 08:05:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5611672470; Tue, 23 May 2017 15:05:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02BB77EE77; Tue, 23 May 2017 15:05:51 +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 1A9954A48C; Tue, 23 May 2017 15:05:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NF5m2b002758 for ; Tue, 23 May 2017 11:05:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1451B78213; Tue, 23 May 2017 15:05:48 +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 8F8E2784B1 for ; Tue, 23 May 2017 15:05:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5611672470 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 5611672470 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 17:05:35 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-perl][PATCH 1/7] Fix send_all() callback helper 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 23 May 2017 15:05:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Sys::Virt::virStream->send_all() uses virStreamSendAll() under the hood. This function takes one callback to fill the send buffer with stream data. We have a C glue callback that eventually calls the perl one. However, there's a problem with the glue callback mangling the data as it mistakenly uses strcpy() instead of memcpy(). Signed-off-by: Michal Privoznik --- Changes | 1 + Virt.xs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 2e5bfe4..2e4a99e 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for perl module Sys::Virt 3.4.0 2017-06-00 =20 - Add LIST_CAP_MDEV & LIST_CAP_MDEV_TYPES constants + - Fix send_all() callback helper =20 3.3.0 2017-05-08 =20 diff --git a/Virt.xs b/Virt.xs index 9ccdc1f..a041c95 100644 --- a/Virt.xs +++ b/Virt.xs @@ -1948,7 +1948,7 @@ _stream_send_all_source(virStreamPtr st, const char *newdata =3D SvPV_nolen(datasv); if (ret > nbytes) ret =3D nbytes; - strncpy(data, newdata, nbytes); + memcpy(data, newdata, nbytes); } =20 FREETMPS; --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:44:10 2024 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 1495551963313158.13219585863135; Tue, 23 May 2017 08:06:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 871527249C; Tue, 23 May 2017 15:06:00 +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 43C127EE7E; Tue, 23 May 2017 15:06:00 +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 E064E180BAF8; Tue, 23 May 2017 15:05:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NF5ncP002767 for ; Tue, 23 May 2017 11:05:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 05A5878433; Tue, 23 May 2017 15:05:49 +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 80F4378213 for ; Tue, 23 May 2017 15:05:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 871527249C Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 871527249C From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 17:05:36 +0200 Message-Id: <049baec59426b87e4576133cb6ea68bb48d379ac.1495551923.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-perl][PATCH 2/7] Introduce flags to Stream::recv() 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 23 May 2017 15:06:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" At the same time register RECV_STOP_AT_HOLE constant. Signed-off-by: Michal Privoznik --- Changes | 2 ++ Virt.xs | 13 ++++++++++--- lib/Sys/Virt/Stream.pm | 20 ++++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Changes b/Changes index 2e4a99e..b4a493c 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,8 @@ Revision history for perl module Sys::Virt =20 - Add LIST_CAP_MDEV & LIST_CAP_MDEV_TYPES constants - Fix send_all() callback helper + - Introduce flags to Stream::recv() and + register RECV_STOP_AT_HOLE constant =20 3.3.0 2017-05-08 =20 diff --git a/Virt.xs b/Virt.xs index a041c95..498e711 100644 --- a/Virt.xs +++ b/Virt.xs @@ -7874,16 +7874,21 @@ send(st, data, nbytes) =20 =20 int -recv(st, data, nbytes) +recv(st, data, nbytes, flags=3D0) virStreamPtr st; SV *data; size_t nbytes; + unsigned int flags; PREINIT: char *rawdata; CODE: Newx(rawdata, nbytes, char); - if ((RETVAL =3D virStreamRecv(st, rawdata, nbytes)) < 0 && - RETVAL !=3D -2) { + if (flags) + RETVAL =3D virStreamRecvFlags(st, rawdata, nbytes, flags); + else + RETVAL =3D virStreamRecv(st, rawdata, nbytes); + + if (RETVAL !=3D -2 && RETVAL !=3D -3) { Safefree(rawdata); _croak_error(); } @@ -9010,6 +9015,8 @@ BOOT: REGISTER_CONSTANT(VIR_STREAM_EVENT_ERROR, EVENT_ERROR); REGISTER_CONSTANT(VIR_STREAM_EVENT_HANGUP, EVENT_HANGUP); =20 + REGISTER_CONSTANT(VIR_STREAM_RECV_STOP_AT_HOLE, RECV_STOP_AT_HOLE); + =20 =20 stash =3D gv_stashpv( "Sys::Virt::Error", TRUE ); diff --git a/lib/Sys/Virt/Stream.pm b/lib/Sys/Virt/Stream.pm index 4022c84..069895e 100644 --- a/lib/Sys/Virt/Stream.pm +++ b/lib/Sys/Virt/Stream.pm @@ -69,11 +69,23 @@ be called on any stream which has been activated Complete I/O on the stream. Either this function or C must be called on any stream which has been activated =20 -=3Ditem $rv =3D $st->recv($data, $nbytes) +=3Ditem $rv =3D $st->recv($data, $nbytes, $flags=3D0) =20 -Receive upto C<$nbytes> worth of data, copying into C<$data>. -Returns the number of bytes read, or -2 if I/O would block, -or -1 on error. +Receive up to C<$nbytes> worth of data, copying into C<$data>. +Returns the number of bytes read, or -3 if hole is reached and +C<$flags> contains RECV_STOP_AT_HOLE, or -2 if I/O would block, +or -1 on error. The C<$flags> parameter accepts the following +flags: + +=3Dover 4 + +=3Ditem Sys::Virt::Stream::RECV_STOP_AT_HOLE + +If this flag is set, the C function will stop reading from +stream if it has reached a hole. In that case, -3 is returned and +C should be called to get the hole size. + +=3Dback =20 =3Ditem $rv =3D $st->send($data, $nbytes) =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:44:10 2024 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 1495551967255365.2175720646652; Tue, 23 May 2017 08:06:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76CE980516; Tue, 23 May 2017 15:06:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BD4717C16; Tue, 23 May 2017 15:06:00 +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 E23224A491; Tue, 23 May 2017 15:05:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NF5nCc002778 for ; Tue, 23 May 2017 11:05:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id CB08278433; Tue, 23 May 2017 15:05:49 +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 52ABD78213 for ; Tue, 23 May 2017 15:05:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 76CE980516 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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 76CE980516 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 17:05:37 +0200 Message-Id: <2fb6f11c05af753f3e8c9b0fbc09be881d9ea541.1495551923.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-perl][PATCH 3/7] Introduce Stream::recvHole() and Stream::sendHole() 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 23 May 2017 15:06:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- Changes | 1 + Virt.xs | 28 ++++++++++++++++++++++++++++ lib/Sys/Virt/Stream.pm | 17 +++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/Changes b/Changes index b4a493c..c92c271 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,7 @@ Revision history for perl module Sys::Virt - Fix send_all() callback helper - Introduce flags to Stream::recv() and register RECV_STOP_AT_HOLE constant + - Introduce Stream::recvHole() and Stream::sendHole() =20 3.3.0 2017-05-08 =20 diff --git a/Virt.xs b/Virt.xs index 498e711..d112708 100644 --- a/Virt.xs +++ b/Virt.xs @@ -7900,6 +7900,34 @@ recv(st, data, nbytes, flags=3D0) RETVAL =20 =20 +SV * +recvHole(st, flags=3D0) + virStreamPtr st; + unsigned int flags; + PREINIT: + long long length; + CODE: + if (virStreamRecvHole(st, &length, flags) < 0) + _croak_error(); + + RETVAL =3D virt_newSVll(length); + OUTPUT: + RETVAL + + +void +sendHole(st, lengthSV, flags=3D0) + virStreamPtr st; + SV *lengthSV; + unsigned int flags; + PREINIT: + long long length; + PPCODE: + length =3D virt_SvIVll(lengthSV); + if (virStreamSendHole(st, length, flags) < 0) + _croak_error(); + + void send_all(stref, handler) SV *stref; diff --git a/lib/Sys/Virt/Stream.pm b/lib/Sys/Virt/Stream.pm index 069895e..5984fb6 100644 --- a/lib/Sys/Virt/Stream.pm +++ b/lib/Sys/Virt/Stream.pm @@ -93,6 +93,23 @@ Send upto C<$nbytes> worth of data, copying from C<$data= >. Returns the number of bytes sent, or -2 if I/O would block, or -1 on error. =20 +=3Ditem $rv =3D $st->recvHole($flags=3D0) + +Determine the amount of the empty space (in bytes) to be created +in a stream's target file when uploading or downloading sparsely +populated files. This is the counterpart to C. The +optional C<$flags> parameter is currently unused and defaults to +zero if omitted. + +=3Ditem $st->sendHole($length, $flags=3D0) + +Rather than transmitting empty file space, this method directs +the stream target to create C<$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. +The optional C<$flags> parameter is currently unused and defaults +to zero if omitted. + =3Ditem $st->recv_all($handler) =20 Receive all data available from the stream, invoking --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:44:10 2024 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 1495551967541552.8178670646392; Tue, 23 May 2017 08:06:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00F76448D7F; Tue, 23 May 2017 15:06:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86EEE71C31; Tue, 23 May 2017 15:06:04 +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 265AE4A492; Tue, 23 May 2017 15:06:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NF5oCQ002785 for ; Tue, 23 May 2017 11:05:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id AF1AD78213; Tue, 23 May 2017 15:05:50 +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 36A74784A2 for ; Tue, 23 May 2017 15:05:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00F76448D7F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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 00F76448D7F From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 17:05:38 +0200 Message-Id: <01d5a412067f4946c102f0cb7d0391e1992905c6.1495551923.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-perl][PATCH 4/7] Introduce Stream::sparse_recv_all() 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 23 May 2017 15:06:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- Changes | 1 + Virt.xs | 70 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ lib/Sys/Virt/Stream.pm | 14 ++++++++++ t/030-api-coverage.t | 1 + 4 files changed, 86 insertions(+) diff --git a/Changes b/Changes index c92c271..4c1e071 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,7 @@ Revision history for perl module Sys::Virt - Introduce flags to Stream::recv() and register RECV_STOP_AT_HOLE constant - Introduce Stream::recvHole() and Stream::sendHole() + - Introduce Stream::sparse_recv_all() =20 3.3.0 2017-05-08 =20 diff --git a/Virt.xs b/Virt.xs index d112708..002bd6a 100644 --- a/Virt.xs +++ b/Virt.xs @@ -2008,6 +2008,48 @@ _stream_recv_all_sink(virStreamPtr st, } =20 =20 +static int +_stream_sparse_recv_holeHandler(virStreamPtr st, + long long offset, + void *opaque) +{ + AV *av =3D opaque; + SV **self; + SV **holeHandler; + int rv; + int ret; + dSP; + + self =3D av_fetch(av, 0, 0); + holeHandler =3D av_fetch(av, 2, 0); + + SvREFCNT_inc(*self); + + ENTER; + SAVETMPS; + + PUSHMARK(SP); + XPUSHs(*self); + XPUSHs(sv_2mortal(virt_newSVll(offset))); + PUTBACK; + + rv =3D call_sv((SV*)*holeHandler, G_SCALAR); + + SPAGAIN; + + if (rv =3D=3D 1) { + ret =3D POPi; + } else { + ret =3D -1; + } + + FREETMPS; + LEAVE; + + return ret; +} + + MODULE =3D Sys::Virt PACKAGE =3D Sys::Virt =20 PROTOTYPES: ENABLE @@ -7972,6 +8014,34 @@ recv_all(stref, handler) SvREFCNT_dec(opaque); =20 =20 +void +sparse_recv_all(stref, handler, holeHandler) + SV *stref; + SV *handler; + SV *holeHandler; + PREINIT: + AV *opaque; + virStreamPtr st; + CODE: + st =3D (virStreamPtr)SvIV((SV*)SvRV(stref)); + + opaque =3D newAV(); + SvREFCNT_inc(stref); + SvREFCNT_inc(handler); + SvREFCNT_inc(holeHandler); + av_push(opaque, stref); + av_push(opaque, handler); + av_push(opaque, holeHandler); + + if (virStreamSparseRecvAll(st, + _stream_recv_all_sink, + _stream_sparse_recv_holeHandler, + opaque) < 0) + _croak_error(); + + SvREFCNT_dec(opaque); + + void add_callback(stref, events, cb) SV* stref; diff --git a/lib/Sys/Virt/Stream.pm b/lib/Sys/Virt/Stream.pm index 5984fb6..c32b957 100644 --- a/lib/Sys/Virt/Stream.pm +++ b/lib/Sys/Virt/Stream.pm @@ -130,6 +130,20 @@ data byte count desired. The function should return the number of bytes filled, 0 on end of file, or -1 upon error =20 +=3Ditem $st->sparse_recv_all($handler, $holeHandler) + +Receive all data available from the sparse stream, invoking +C<$handler> to process the data. The C<$handler> parameter must +be a function which expects three arguments, the C<$st> stream +object, a scalar containing the data received and a data byte +count. The function should return the number of bytes processed, +or -1 upon error. The second argument C<$holeHandler> is a +function which expects two arguments: the C<$st> stream and a +scalar, number describing the size of the hole in the stream (in +bytes). The C<$holeHandler> is expected to return a non-negative +number on success (usually 0) and a negative number (usually -1) +otherwise. + =3Ditem $st->add_callback($events, $coderef) =20 Register a callback to be invoked whenever the stream has diff --git a/t/030-api-coverage.t b/t/030-api-coverage.t index 3049713..6a281ba 100644 --- a/t/030-api-coverage.t +++ b/t/030-api-coverage.t @@ -114,6 +114,7 @@ virEventUpdateTimeoutFunc =20 virStreamEventCallback virStreamSinkFunc +virStreamSinkHoleFunc virStreamSourceFunc =20 virConnectCloseFunc --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:44:10 2024 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 1495551962848352.43906067731666; Tue, 23 May 2017 08:06:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1E1417AC63; Tue, 23 May 2017 15:05:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 781E45C8A5; Tue, 23 May 2017 15:05:56 +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 18C924A48D; Tue, 23 May 2017 15:05:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NF5r6P002800 for ; Tue, 23 May 2017 11:05:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2014A78213; Tue, 23 May 2017 15:05:53 +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 996C7784B9 for ; Tue, 23 May 2017 15:05:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B1E1417AC63 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 B1E1417AC63 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 17:05:39 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-perl][PATCH 5/7] Introduce Stream::sparse_send_all() 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 23 May 2017 15:05:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- Changes | 1 + Virt.xs | 124 +++++++++++++++++++++++++++++++++++++++++++++= ++++ lib/Sys/Virt/Stream.pm | 19 ++++++++ t/030-api-coverage.t | 2 + 4 files changed, 146 insertions(+) diff --git a/Changes b/Changes index 4c1e071..989b795 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,7 @@ Revision history for perl module Sys::Virt register RECV_STOP_AT_HOLE constant - Introduce Stream::recvHole() and Stream::sendHole() - Introduce Stream::sparse_recv_all() + - Introduce Stream::sparse_send_all() =20 3.3.0 2017-05-08 =20 diff --git a/Virt.xs b/Virt.xs index 002bd6a..fc282b8 100644 --- a/Virt.xs +++ b/Virt.xs @@ -1960,6 +1960,100 @@ _stream_send_all_source(virStreamPtr st, } =20 =20 +static int +_stream_sparse_send_all_holeHandler(virStreamPtr st, + int *inData, + long long *length, + void *opaque) +{ + AV *av =3D opaque; + SV **self; + SV **holeHandler; + SV *inDataSV; + SV *lengthSV; + int count; + int ret; + dSP; + + self =3D av_fetch(av, 0, 0); + holeHandler =3D av_fetch(av, 2, 0); + + SvREFCNT_inc(*self); + + ENTER; + SAVETMPS; + + PUSHMARK(SP); + XPUSHs(*self); + PUTBACK; + + count =3D call_sv((SV*)*holeHandler, G_ARRAY); + + SPAGAIN; + + if (count =3D=3D 2) { + /* @holeHandler returns (inData, length), but on a stack. + * Therefore the order is reversed. */ + lengthSV =3D POPs; + inDataSV =3D POPs; + *inData =3D virt_SvIVll(inDataSV); + *length =3D virt_SvIVll(lengthSV); + ret =3D 0; + } else { + ret =3D -1; + } + + PUTBACK; + FREETMPS; + LEAVE; + + return ret; +} + + +static int +_stream_sparse_send_all_skipHandler(virStreamPtr st, + long long length, + void *opaque) +{ + AV *av =3D opaque; + SV **self; + SV **skipHandler; + int rv; + int ret; + dSP; + + self =3D av_fetch(av, 0, 0); + skipHandler =3D av_fetch(av, 3, 0); + + SvREFCNT_inc(*self); + + ENTER; + SAVETMPS; + + PUSHMARK(SP); + XPUSHs(*self); + XPUSHs(sv_2mortal(virt_newSVll(length))); + PUTBACK; + + rv =3D call_sv((SV*)*skipHandler, G_SCALAR); + + SPAGAIN; + + if (rv =3D=3D 1) { + ret =3D POPi; + } else { + ret =3D -1; + } + + PUTBACK; + FREETMPS; + LEAVE; + + return ret; +} + + static int _stream_recv_all_sink(virStreamPtr st, const char *data, @@ -8041,6 +8135,36 @@ sparse_recv_all(stref, handler, holeHandler) =20 SvREFCNT_dec(opaque); =20 +void +sparse_send_all(stref, handler, holeHandler, skipHandler) + SV *stref; + SV *handler; + SV *holeHandler; + SV *skipHandler; + PREINIT: + AV *opaque; + virStreamPtr st; + CODE: + st =3D (virStreamPtr)SvIV((SV*)SvRV(stref)); + + opaque =3D newAV(); + SvREFCNT_inc(stref); + SvREFCNT_inc(handler); + SvREFCNT_inc(holeHandler); + SvREFCNT_inc(skipHandler); + av_push(opaque, stref); + av_push(opaque, handler); + av_push(opaque, holeHandler); + av_push(opaque, skipHandler); + + if (virStreamSparseSendAll(st, + _stream_send_all_source, + _stream_sparse_send_all_holeHandler, + _stream_sparse_send_all_skipHandler, + opaque) < 0) + _croak_error(); + + SvREFCNT_dec(opaque); =20 void add_callback(stref, events, cb) diff --git a/lib/Sys/Virt/Stream.pm b/lib/Sys/Virt/Stream.pm index c32b957..e3b25a5 100644 --- a/lib/Sys/Virt/Stream.pm +++ b/lib/Sys/Virt/Stream.pm @@ -144,6 +144,25 @@ bytes). The C<$holeHandler> is expected to return a no= n-negative number on success (usually 0) and a negative number (usually -1) otherwise. =20 +=3Ditem $st->sparse_send_all($handler, $holeHandler, $skipHandler) + +Send all data produced by C<$handler> to the stream. The +C<$handler> parameter must be a function which expects three +arguments, the C<$st> stream object, a scalar which must be +filled with data and a maximum data byte count desired. The +function should return the number of bytes filled, 0 on end of +file, or -1 upon error. The second argument C<$holeHandler> is a +function expecting just one argument C<$st> and returning an +array of two elements (C<$inData>, C<$sectionLen>) where +C<$inData> has zero or non-zero value if underlying file is in a +hole or data section respectively. The C<$sectionLen> then is the +number of remaining bytes in the current section in the +underlying file. Finally, the third C<$skipHandler> is a function +expecting two arguments C<$st> and C<$length> which moves cursor +in the underlying file for C<$length> bytes. The C<$skipHandler> +is expected to return a non-negative number on success (usually +0) and a negative number (usually -1) otherwise. + =3Ditem $st->add_callback($events, $coderef) =20 Register a callback to be invoked whenever the stream has diff --git a/t/030-api-coverage.t b/t/030-api-coverage.t index 6a281ba..95bbd11 100644 --- a/t/030-api-coverage.t +++ b/t/030-api-coverage.t @@ -116,6 +116,8 @@ virStreamEventCallback virStreamSinkFunc virStreamSinkHoleFunc virStreamSourceFunc +virStreamSourceHoleFunc +virStreamSourceSkipFunc =20 virConnectCloseFunc =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:44:10 2024 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 1495551969765707.0411292644148; Tue, 23 May 2017 08:06:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2AD53C04B941; Tue, 23 May 2017 15:06:06 +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 D71C680E96; Tue, 23 May 2017 15:06:05 +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 65539180BAF7; Tue, 23 May 2017 15:06:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NF5sUC002813 for ; Tue, 23 May 2017 11:05:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 42AC67849F; Tue, 23 May 2017 15:05:54 +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 BE188784A8 for ; Tue, 23 May 2017 15:05:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2AD53C04B941 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 2AD53C04B941 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 17:05:40 +0200 Message-Id: <3376ed9f7bca7c9ed73eead020abde1279f0a14d.1495551923.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-perl][PATCH 6/7] Register VOL_DOWNLOAD_SPARSE_STREAM & VOL_UPLOAD_SPARSE_STREAM constants 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 23 May 2017 15:06:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- Changes | 2 ++ Virt.xs | 4 ++++ lib/Sys/Virt/StorageVol.pm | 30 ++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 989b795..6c671c0 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,8 @@ Revision history for perl module Sys::Virt - Introduce Stream::recvHole() and Stream::sendHole() - Introduce Stream::sparse_recv_all() - Introduce Stream::sparse_send_all() + - Register VOL_DOWNLOAD_SPARSE_STREAM & + VOL_UPLOAD_SPARSE_STREAM constants =20 3.3.0 2017-05-08 =20 diff --git a/Virt.xs b/Virt.xs index fc282b8..663571c 100644 --- a/Virt.xs +++ b/Virt.xs @@ -9209,6 +9209,10 @@ BOOT: REGISTER_CONSTANT(VIR_STORAGE_VOL_USE_ALLOCATION, USE_ALLOCATION); REGISTER_CONSTANT(VIR_STORAGE_VOL_GET_PHYSICAL, GET_PHYSICAL); =20 + REGISTER_CONSTANT(VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM, VOL_DOWNLO= AD_SPARSE_STREAM); + + REGISTER_CONSTANT(VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM, VOL_UPLOAD_S= PARSE_STREAM); + stash =3D gv_stashpv( "Sys::Virt::Secret", TRUE ); REGISTER_CONSTANT(VIR_SECRET_USAGE_TYPE_NONE, USAGE_TYPE_NONE); REGISTER_CONSTANT(VIR_SECRET_USAGE_TYPE_VOLUME, USAGE_TYPE_VOLUME); diff --git a/lib/Sys/Virt/StorageVol.pm b/lib/Sys/Virt/StorageVol.pm index 42f10e8..82c3df2 100644 --- a/lib/Sys/Virt/StorageVol.pm +++ b/lib/Sys/Virt/StorageVol.pm @@ -141,17 +141,39 @@ Return the physical size in allocation =20 =3Dback =20 -=3Ditem $vol->download($st, $offset, $length); +=3Ditem $vol->download($st, $offset, $length, $flags=3D0); =20 Download data from C<$vol> using the stream C<$st>. If C<$offset> and C<$length> are non-zero, then restrict data to the specified -volume byte range. +volume byte range. The C<$flags> accept the following values: =20 -=3Ditem $vol->upload($st, $offset, $length); +=3Dover 4 + +=3Ditem Sys::Virt::StorageVol::VOL_DOWNLOAD_SPARSE_STREAM + +If this flag is is set in @flags effective transmission of holes +is enabled. This assumes using the stream C<$st> with combination of +C or C for honouring holes sent by server. + +=3Dback + +=3Ditem $vol->upload($st, $offset, $length, $flags=3D0); =20 Upload data to C<$vol> using the stream C<$st>. If C<$offset> and C<$length> are non-zero, then restrict data to the specified -volume byte range. +volume byte range. The C<$flags> accept the following values: + +=3Dover 4 + +=3Ditem Sys::Virt::StorageVol::VOL_UPLOAD_SPARSE_STREAM + +If this is set in C<$flags> effective transmission of holes is +enabled. This assumes using the stream C<$st> with combination of +C or C to preserve source file +sparseness. + +=3Dback =20 =3Dback =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:44:10 2024 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 1495551974538774.4920978466256; Tue, 23 May 2017 08:06:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E2DA80F95; Tue, 23 May 2017 15:06:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF49971C31; Tue, 23 May 2017 15:06:09 +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 880854A494; Tue, 23 May 2017 15:06:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4NF5t2T002822 for ; Tue, 23 May 2017 11:05:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14BFE78213; Tue, 23 May 2017 15:05:55 +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 90181784AB for ; Tue, 23 May 2017 15:05:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1E2DA80F95 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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 1E2DA80F95 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 23 May 2017 17:05:41 +0200 Message-Id: <47786dc28d0643b68992530b901f41293df7935b.1495551923.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-perl][PATCH 7/7] examples: Introduce vol-sparse.pl 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 23 May 2017 15:06:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- Changes | 1 + examples/vol-sparse.pl | 142 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 143 insertions(+) create mode 100755 examples/vol-sparse.pl diff --git a/Changes b/Changes index 6c671c0..3742a8c 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,7 @@ Revision history for perl module Sys::Virt - Introduce Stream::sparse_send_all() - Register VOL_DOWNLOAD_SPARSE_STREAM & VOL_UPLOAD_SPARSE_STREAM constants + - Add vol-sparse.pl example =20 3.3.0 2017-05-08 =20 diff --git a/examples/vol-sparse.pl b/examples/vol-sparse.pl new file mode 100755 index 0000000..b99b57f --- /dev/null +++ b/examples/vol-sparse.pl @@ -0,0 +1,142 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Sys::Virt; +use Fcntl; + +my $FILE; + +sub downloadHandler { + my $st =3D shift; + my $data =3D shift; + my $nbytes =3D shift; + return syswrite FILE, $data, $nbytes; +} + +sub downloadHoleHandler { + my $st =3D shift; + my $offset =3D shift; + my $pos =3D sysseek FILE, $offset, Fcntl::SEEK_CUR or die "Unable to s= eek in $FILE: $!"; + truncate FILE, $pos; +} + + +sub download { + my $vol =3D shift; + my $st =3D shift; + my $filename =3D shift; + my $offset =3D 0; + my $length =3D 0; + + open FILE, ">$filename" or die "unable to create $filename: $!"; + eval { + $vol->download($st, $offset, $length, Sys::Virt::StorageVol::VOL_D= OWNLOAD_SPARSE_STREAM); + $st->sparse_recv_all(\&downloadHandler, \&downloadHoleHandler); + $st->finish(); + }; + if ($@) { + unlink $filename if $@; + close FILE; + die $@; + } + + close FILE or die "cannot save $filename: $!" +} + +sub uploadHandler { + my $st =3D $_[0]; + my $nbytes =3D $_[2]; + return sysread FILE, $_[1], $nbytes; +} + +sub uploadHoleHandler { + my $st =3D shift; + my $inData; + my $sectionLen; + + # HACK, Perl lacks SEEK_DATA and SEEK_HOLE. + my $SEEK_DATA =3D 3; + my $SEEK_HOLE =3D 4; + + my $cur =3D sysseek FILE, 0, Fcntl::SEEK_CUR; + eval { + my $data =3D sysseek FILE, $cur, $SEEK_DATA; + # There are three options: + # 1) $data =3D=3D $cur; $cur is in data + # 2) $data > $cur; $cur is in a hole, next data at $data + # 3) $data < 0; either $cur is in trailing hole, or $cur is beyond= EOF. + + if (!defined($data)) { + # case 3 + $inData =3D 0; + my $end =3D sysseek FILE, 0, Fcntl::SEEK_END or die "Unable to= get EOF position: $!"; + $sectionLen =3D $end - $cur; + } elsif ($data > $cur) { + #case 2 + $inData =3D 0; + $sectionLen =3D $data - $cur; + } else { + #case 1 + my $hole =3D sysseek FILE, $data, $SEEK_HOLE; + if (!defined($hole) or $hole eq $data) { + die "Blah"; + } + $inData =3D 1; + $sectionLen =3D $hole - $data; + } + }; + + # reposition file back + sysseek FILE, $cur, Fcntl::SEEK_SET; + + return ($inData, $sectionLen); +} + +sub uploadSkipHandler { + my $st =3D shift; + my $offset =3D shift; + print("uploadSkipHandler: $offset\n"); + sysseek FILE, $offset, Fcntl::SEEK_CUR or die "Unable to seek in $FILE= "; +} + +sub upload { + my $vol =3D shift; + my $st =3D shift; + my $filename =3D shift; + my $offset =3D 0; + my $length =3D 0; + + open FILE, "<$filename" or die "unable to open $filename: $!"; + eval { + $vol->upload($st, $offset, $length, Sys::Virt::StorageVol::VOL_UPL= OAD_SPARSE_STREAM); + $st->sparse_send_all(\&uploadHandler, \&uploadHoleHandler, \&uploa= dSkipHandler); + $st->finish(); + }; + if ($@) { + close FILE; + die $@; + } + + close FILE or die "cannot close $filename: $!" +} + +die "syntax: $0 URI --download/--upload VOLUME FILE" unless int(@ARGV) =3D= =3D 4; + +my $uri =3D shift @ARGV; +my $action =3D shift @ARGV; +my $volpath =3D shift @ARGV; +my $filename =3D shift @ARGV; + +my $c =3D Sys::Virt->new(uri =3D> $uri) or die "Unable to connect to $uri"; +my $vol =3D $c->get_storage_volume_by_key($volpath) or die "No such volume= "; +my $st =3D $c->new_stream(); + +if ($action eq "--download") { + download($vol, $st, $filename); +} elsif ($action eq "--upload") { + upload($vol, $st, $filename); +} else { + die "unknown action $action"; +} --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list