This flag will create a virStream that will use sparse APIs instead of those meant for regular, dense streams. Therefore we must check for stream (non-)sparseness and deny API meant for one or another type. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- include/libvirt/libvirt-stream.h | 1 + src/internal.h | 20 ++++++++++++++++++++ src/libvirt-stream.c | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/include/libvirt/libvirt-stream.h b/include/libvirt/libvirt-stream.h index 5a2bde3..f05e703 100644 --- a/include/libvirt/libvirt-stream.h +++ b/include/libvirt/libvirt-stream.h @@ -31,6 +31,7 @@ typedef enum { VIR_STREAM_NONBLOCK = (1 << 0), + VIR_STREAM_SPARSE = (1 << 1), } virStreamFlags; virStreamPtr virStreamNew(virConnectPtr conn, diff --git a/src/internal.h b/src/internal.h index db26fb0..b99d9fd 100644 --- a/src/internal.h +++ b/src/internal.h @@ -493,6 +493,26 @@ goto label; \ } \ } while (0) +# define virCheckStreamSparseReturn(flags, retval) \ + do { \ + if (!((flags) & VIR_STREAM_SPARSE)) { \ + virReportInvalidArg(flags, \ + _("%s function is not supported " \ + "with sparse streams"), \ + __FUNCTION__); \ + return retval; \ + } \ + } while (0) +# define virCheckStreamNonSparseReturn(flags, retval) \ + do { \ + if ((flags) & VIR_STREAM_SPARSE) { \ + virReportInvalidArg(flags, \ + _("%s function is not supported " \ + "on dense streams"), \ + __FUNCTION__); \ + return retval; \ + } \ + } while(0) diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c index 1df188c..5c6b83f 100644 --- a/src/libvirt-stream.c +++ b/src/libvirt-stream.c @@ -171,6 +171,7 @@ virStreamSend(virStreamPtr stream, virCheckStreamReturn(stream, -1); virCheckNonNullArgGoto(data, error); + virCheckStreamSparseReturn(stream->flags, -1); if (stream->driver && stream->driver->streamSend) { @@ -223,6 +224,7 @@ virStreamSendOffset(virStreamPtr stream, virCheckStreamReturn(stream, -1); virCheckNonNullArgGoto(data, error); + virCheckStreamNonSparseReturn(stream->flags, -1); if (stream->driver && stream->driver->streamSendOffset) { @@ -316,6 +318,7 @@ virStreamRecv(virStreamPtr stream, virCheckStreamReturn(stream, -1); virCheckNonNullArgGoto(data, error); + virCheckStreamSparseReturn(stream->flags, -1); if (stream->driver && stream->driver->streamRecv) { @@ -377,6 +380,7 @@ virStreamRecvOffset(virStreamPtr stream, virCheckStreamReturn(stream, -1); virCheckNonNullArgGoto(offset, error); virCheckNonNullArgGoto(data, error); + virCheckStreamNonSparseReturn(stream->flags, -1); if (stream->driver && stream->driver->streamRecvOffset) { @@ -451,6 +455,7 @@ virStreamSendAll(virStreamPtr stream, virCheckStreamReturn(stream, -1); virCheckNonNullArgGoto(handler, cleanup); + virCheckStreamSparseReturn(stream->flags, -1); if (stream->flags & VIR_STREAM_NONBLOCK) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -544,6 +549,7 @@ virStreamRecvAll(virStreamPtr stream, virCheckStreamReturn(stream, -1); virCheckNonNullArgGoto(handler, cleanup); + virCheckStreamSparseReturn(stream->flags, -1); if (stream->flags & VIR_STREAM_NONBLOCK) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", -- 2.4.10 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list