mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
Introduce virStreamInData
This is just an internal API, that calls corresponding function in stream driver. This function will set @data = 1 if the underlying file is in data section, or @data = 0 if it is in a hole. At any rate, @length is set to number of bytes remaining in the section the file currently is. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
a524951091
commit
84b5079232
@ -51,6 +51,11 @@ typedef int
|
||||
long long *length,
|
||||
unsigned int flags);
|
||||
|
||||
typedef int
|
||||
(*virDrvStreamInData)(virStreamPtr st,
|
||||
int *data,
|
||||
long long *length);
|
||||
|
||||
typedef int
|
||||
(*virDrvStreamEventAddCallback)(virStreamPtr stream,
|
||||
int events,
|
||||
@ -80,6 +85,7 @@ struct _virStreamDriver {
|
||||
virDrvStreamRecvFlags streamRecvFlags;
|
||||
virDrvStreamSendHole streamSendHole;
|
||||
virDrvStreamRecvHole streamRecvHole;
|
||||
virDrvStreamInData streamInData;
|
||||
virDrvStreamEventAddCallback streamEventAddCallback;
|
||||
virDrvStreamEventUpdateCallback streamEventUpdateCallback;
|
||||
virDrvStreamEventRemoveCallback streamEventRemoveCallback;
|
||||
|
@ -481,6 +481,54 @@ virStreamRecvHole(virStreamPtr stream,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStreamInData:
|
||||
* @stream: stream
|
||||
* @data: are we in data or hole
|
||||
* @length: length to next section
|
||||
*
|
||||
* This function checks the underlying stream (typically a file)
|
||||
* to learn whether the current stream position lies within a
|
||||
* data section or a hole. Upon return @data is set to a nonzero
|
||||
* value if former is the case, or to zero if @stream is in a
|
||||
* hole. Moreover, @length is updated to tell caller how many
|
||||
* bytes can be read from @stream until current section changes
|
||||
* (from data to a hole or vice versa).
|
||||
*
|
||||
* NB: there's an implicit hole at EOF. In this situation this
|
||||
* function should set @data = false, @length = 0 and return 0.
|
||||
*
|
||||
* To sum it up:
|
||||
*
|
||||
* data section: @data = true, @length > 0
|
||||
* hole: @data = false, @length > 0
|
||||
* EOF: @data = false, @length = 0
|
||||
*
|
||||
* Returns 0 on success,
|
||||
* -1 otherwise
|
||||
*/
|
||||
int
|
||||
virStreamInData(virStreamPtr stream,
|
||||
int *data,
|
||||
long long *length)
|
||||
{
|
||||
VIR_DEBUG("stream=%p, data=%p, length=%p", stream, data, length);
|
||||
|
||||
virResetLastError();
|
||||
virCheckNonNullArgReturn(data, -1);
|
||||
virCheckNonNullArgReturn(length, -1);
|
||||
|
||||
if (stream->driver->streamInData) {
|
||||
int ret;
|
||||
ret = (stream->driver->streamInData)(stream, data, length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
virReportUnsupportedError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStreamSendAll:
|
||||
* @stream: pointer to the stream object
|
||||
|
@ -294,4 +294,8 @@ virTypedParameterValidateSet(virConnectPtr conn,
|
||||
virTypedParameterPtr params,
|
||||
int nparams);
|
||||
|
||||
int virStreamInData(virStreamPtr stream,
|
||||
int *data,
|
||||
long long *length);
|
||||
|
||||
#endif
|
||||
|
@ -1124,6 +1124,7 @@ virStateCleanup;
|
||||
virStateInitialize;
|
||||
virStateReload;
|
||||
virStateStop;
|
||||
virStreamInData;
|
||||
|
||||
|
||||
# locking/domain_lock.h
|
||||
|
Loading…
Reference in New Issue
Block a user