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

[libvirt] [PATCH v3 17/31] virnetclientstream: Introduce virNetClientStreamSendHole



While the previous commit implemented a helper for sending a
STREAM_HOLE packet for daemon, this is a client's counterpart.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/libvirt_remote.syms      |  1 +
 src/rpc/virnetclientstream.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
 src/rpc/virnetclientstream.h |  5 ++++
 3 files changed, 60 insertions(+)

diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms
index bb6a8d465..186d2c622 100644
--- a/src/libvirt_remote.syms
+++ b/src/libvirt_remote.syms
@@ -53,6 +53,7 @@ virNetClientStreamNew;
 virNetClientStreamQueuePacket;
 virNetClientStreamRaiseError;
 virNetClientStreamRecvPacket;
+virNetClientStreamSendHole;
 virNetClientStreamSendPacket;
 virNetClientStreamSetError;
 
diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c
index 4c27f308e..9005e6be9 100644
--- a/src/rpc/virnetclientstream.c
+++ b/src/rpc/virnetclientstream.c
@@ -429,6 +429,60 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
 }
 
 
+int
+virNetClientStreamSendHole(virNetClientStreamPtr st,
+                           virNetClientPtr client,
+                           long long length,
+                           unsigned int flags)
+{
+    virNetMessagePtr msg = NULL;
+    virNetStreamHole data;
+    int ret = -1;
+
+    VIR_DEBUG("st=%p length=%llu", st, length);
+
+    if (!st->allowSkip) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("Skipping is not supported with this stream"));
+        return -1;
+    }
+
+    memset(&data, 0, sizeof(data));
+    data.length = length;
+    data.flags = flags;
+
+    if (!(msg = virNetMessageNew(false)))
+        return -1;
+
+    virObjectLock(st);
+
+    msg->header.prog = virNetClientProgramGetProgram(st->prog);
+    msg->header.vers = virNetClientProgramGetVersion(st->prog);
+    msg->header.status = VIR_NET_CONTINUE;
+    msg->header.type = VIR_NET_STREAM_HOLE;
+    msg->header.serial = st->serial;
+    msg->header.proc = st->proc;
+
+    virObjectUnlock(st);
+
+    if (virNetMessageEncodeHeader(msg) < 0)
+        goto cleanup;
+
+    if (virNetMessageEncodePayload(msg,
+                                   (xdrproc_t) xdr_virNetStreamHole,
+                                   &data) < 0)
+        goto cleanup;
+
+    if (virNetClientSendNoReply(client, msg) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    virNetMessageFree(msg);
+    return ret;
+}
+
+
 int virNetClientStreamEventAddCallback(virNetClientStreamPtr st,
                                        int events,
                                        virNetClientStreamEventCallback cb,
diff --git a/src/rpc/virnetclientstream.h b/src/rpc/virnetclientstream.h
index f3bc0672b..c25c69bb1 100644
--- a/src/rpc/virnetclientstream.h
+++ b/src/rpc/virnetclientstream.h
@@ -61,6 +61,11 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
                                  size_t nbytes,
                                  bool nonblock);
 
+int virNetClientStreamSendHole(virNetClientStreamPtr st,
+                               virNetClientPtr client,
+                               long long length,
+                               unsigned int flags);
+
 int virNetClientStreamEventAddCallback(virNetClientStreamPtr st,
                                        int events,
                                        virNetClientStreamEventCallback cb,
-- 
2.13.0


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