Re: [PATCH v3 09/31] Introduce virStreamSparseSendAll

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

 




On 05/16/2017 10:03 AM, Michal Privoznik wrote:
> This is just a wrapper over new function that have been just
> introduced: virStreamSendHole() . It's very similar to
> virStreamSendAll() except it handles sparse streams well.
> 
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  include/libvirt/libvirt-stream.h |  65 +++++++++++++++-
>  src/libvirt-stream.c             | 159 +++++++++++++++++++++++++++++++++++++++
>  src/libvirt_public.syms          |   1 +
>  3 files changed, 222 insertions(+), 3 deletions(-)
> 

[...]

> diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
> index 6bf4c4f29..4cbe5eee1 100644
> --- a/src/libvirt-stream.c
> +++ b/src/libvirt-stream.c
> @@ -574,6 +574,165 @@ virStreamSendAll(virStreamPtr stream,
>  }
>  
>  
> +/**
> + * virStreamSparseSendAll:
> + * @stream: pointer to the stream object
> + * @handler: source callback for reading data from application
> + * @holeHandler: source callback for determining holes
> + * @skipHandler: skip holes as reported by @holeHandler
> + * @opaque: application defined data
> + *
> + * Send the entire data stream, reading the data from the
> + * requested data source. This is simply a convenient alternative
> + * to virStreamSend, for apps that do blocking-I/O.
> + *
> + * An example using this with a hypothetical file upload
> + * API looks like
> + *
> + *   int mysource(virStreamPtr st, char *buf, int nbytes, void *opaque) {
> + *       int *fd = opaque;
> + *
> + *       return read(*fd, buf, nbytes);
> + *   }
> + *
> + *   int myskip(virStreamPtr st, long long offset, void *opaque) {
> + *       int *fd = opaque;
> + *
> + *       return lseek(*fd, offset, SEEK_CUR) == (off_t) -1 ? -1 : 0;
> + *   }

Similar notations here regarding "long long" values that are being used
in/for lseek() which expects "off_t"...

> + *
> + *   int myindata(virStreamPtr st, int *inData,
> + *                long long *offset, void *opaque) {
> + *       int *fd = opaque;
> + *
> + *       if (@fd in hole) {
> + *           *inData = 0;
> + *           *offset = holeSize;
> + *       } else {
> + *           *inData = 1;
> + *           *offset = dataSize;
> + *       }
> + *
> + *       return 0;
> + *   }
> + *
> + *   virStreamPtr st = virStreamNew(conn, 0);
> + *   int fd = open("demo.iso", O_RDONLY);
> + *
> + *   virConnectUploadFile(conn, st);

^^ This doesn't exist either and is a straight copy from
virStreamSendAll... Should it also have the "Sparse" though?

Reviewed-by: John Ferlan <jferlan@xxxxxxxxxx>


John

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux