Introduce virStreamRecvHole

This function is basically a counterpart for virStreamSendHole().
If one side of a stream called virStreamSendHole() the other
should call virStreamRecvHole() to get the size of the hole.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2016-05-20 15:03:11 +02:00
parent 69a573d010
commit b6aedd2f05
4 changed files with 55 additions and 0 deletions

View File

@ -54,6 +54,10 @@ int virStreamSendHole(virStreamPtr st,
long long length,
unsigned int flags);
int virStreamRecvHole(virStreamPtr,
long long *length,
unsigned int flags);
/**
* virStreamSourceFunc:

View File

@ -46,6 +46,11 @@ typedef int
long long length,
unsigned int flags);
typedef int
(*virDrvStreamRecvHole)(virStreamPtr st,
long long *length,
unsigned int flags);
typedef int
(*virDrvStreamEventAddCallback)(virStreamPtr stream,
int events,
@ -74,6 +79,7 @@ struct _virStreamDriver {
virDrvStreamRecv streamRecv;
virDrvStreamRecvFlags streamRecvFlags;
virDrvStreamSendHole streamSendHole;
virDrvStreamRecvHole streamRecvHole;
virDrvStreamEventAddCallback streamEventAddCallback;
virDrvStreamEventUpdateCallback streamEventUpdateCallback;
virDrvStreamEventRemoveCallback streamEventRemoveCallback;

View File

@ -405,6 +405,50 @@ virStreamSendHole(virStreamPtr stream,
}
/**
* virStreamRecvHole:
* @stream: pointer to the stream object
* @length: number of bytes to skip
* @flags: extra flags; not used yet, so callers should always pass 0
*
* This API 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 virStreamSendHole().
*
* Returns 0 on success,
* -1 on error or when there's currently no hole in the stream
*/
int
virStreamRecvHole(virStreamPtr stream,
long long *length,
unsigned int flags)
{
VIR_DEBUG("stream=%p, length=%p flags=%x",
stream, length, flags);
virResetLastError();
virCheckStreamReturn(stream, -1);
virCheckNonNullArgReturn(length, -1);
if (stream->driver &&
stream->driver->streamRecvHole) {
int ret;
ret = (stream->driver->streamRecvHole)(stream, length, flags);
if (ret < 0)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(stream->conn);
return -1;
}
/**
* virStreamSendAll:
* @stream: pointer to the stream object

View File

@ -762,6 +762,7 @@ LIBVIRT_3.1.0 {
LIBVIRT_3.4.0 {
global:
virStreamRecvFlags;
virStreamRecvHole;
virStreamSendHole;
} LIBVIRT_3.1.0;