From nobody Mon Feb 9 03:20:02 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 1494943701481557.7200002747174; Tue, 16 May 2017 07:08:21 -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 52AEC796FE; Tue, 16 May 2017 14:07:42 +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 A47D276616; Tue, 16 May 2017 14:07:33 +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 C9E1A180BAFB; Tue, 16 May 2017 14:07:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4GE4NIp027703 for ; Tue, 16 May 2017 10:04:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 74B48860F0; Tue, 16 May 2017 14:04:23 +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 F1A0362926 for ; Tue, 16 May 2017 14:04:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 52AEC796FE 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 52AEC796FE From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 16 May 2017 16:03:45 +0200 Message-Id: <44419eab5acbc2087472322d9af40ff3994c1b81.1494943031.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 05/31] Introduce virStreamSendHole 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.25]); Tue, 16 May 2017 14:08:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This API is used to tell the other side of the stream to skip some bytes in the stream. This can be used to create a sparse file on the receiving side of a stream. It takes @length argument, which says how big the hole is. This skipping is done from the current point of stream. Since our streams are not rewindable like regular files, we don't need @whence argument like seek(2) has. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- include/libvirt/libvirt-stream.h | 4 +++ src/driver-stream.h | 6 ++++ src/libvirt-stream.c | 61 ++++++++++++++++++++++++++++++++++++= ++++ src/libvirt_public.syms | 1 + 4 files changed, 72 insertions(+) diff --git a/include/libvirt/libvirt-stream.h b/include/libvirt/libvirt-str= eam.h index bee25168b..14c9af142 100644 --- a/include/libvirt/libvirt-stream.h +++ b/include/libvirt/libvirt-stream.h @@ -50,6 +50,10 @@ int virStreamRecvFlags(virStreamPtr st, size_t nbytes, unsigned int flags); =20 +int virStreamSendHole(virStreamPtr st, + long long length, + unsigned int flags); + =20 /** * virStreamSourceFunc: diff --git a/src/driver-stream.h b/src/driver-stream.h index d4b048018..0a5201431 100644 --- a/src/driver-stream.h +++ b/src/driver-stream.h @@ -41,6 +41,11 @@ typedef int size_t nbytes, unsigned int flags); =20 +typedef int +(*virDrvStreamSendHole)(virStreamPtr st, + long long length, + unsigned int flags); + typedef int (*virDrvStreamEventAddCallback)(virStreamPtr stream, int events, @@ -68,6 +73,7 @@ struct _virStreamDriver { virDrvStreamSend streamSend; virDrvStreamRecv streamRecv; virDrvStreamRecvFlags streamRecvFlags; + virDrvStreamSendHole streamSendHole; virDrvStreamEventAddCallback streamEventAddCallback; virDrvStreamEventUpdateCallback streamEventUpdateCallback; virDrvStreamEventRemoveCallback streamEventRemoveCallback; diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c index 7535deb3c..a09896dcd 100644 --- a/src/libvirt-stream.c +++ b/src/libvirt-stream.c @@ -344,6 +344,67 @@ virStreamRecvFlags(virStreamPtr stream, } =20 =20 +/** + * virStreamSendHole: + * @stream: pointer to the stream object + * @length: number of bytes to skip + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Rather than transmitting empty file space, this API directs + * the @stream target to create @length bytes of empty space. + * This API would be used when uploading or downloading sparsely + * populated files to avoid the needless copy of empty file + * space. + * + * An example using this with a hypothetical file upload API + * looks like: + * + * virStream st; + * + * while (1) { + * char buf[4096]; + * size_t len; + * if (..in hole...) { + * ..get hole size... + * virStreamSendHole(st, len, 0); + * } else { + * ...read len bytes... + * virStreamSend(st, buf, len); + * } + * } + * + * Returns 0 on success, + * -1 error + */ +int +virStreamSendHole(virStreamPtr stream, + long long length, + unsigned int flags) +{ + VIR_DEBUG("stream=3D%p, length=3D%lld flags=3D%x", + stream, length, flags); + + virResetLastError(); + + virCheckStreamReturn(stream, -1); + + if (stream->driver && + stream->driver->streamSendHole) { + int ret; + ret =3D (stream->driver->streamSendHole)(stream, length, flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(stream->conn); + return -1; +} + + /** * virStreamSendAll: * @stream: pointer to the stream object diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index d50b36a24..3be7cc6a0 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -762,6 +762,7 @@ LIBVIRT_3.1.0 { LIBVIRT_3.4.0 { global: virStreamRecvFlags; + virStreamSendHole; } LIBVIRT_3.1.0; =20 # .... define new API here using predicted next version number .... --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list