From nobody Sun Feb 8 23:26:51 2026 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