[PATCH 17/27] daemonStreamHandleRead: Wire up seekable stream

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

 



Whenever client is able to receive some data from stream
daemonStreamHandleRead is called. But now the behaviour of this
function needs to be changed a bit. Previously it just read data
from underlying file (of chardev or whatever) and sent those
through the stream to client. This model will not work any longer
because it does not differentiate whether underlying file is in
data or hole section. Therefore, at the beginning of this
function add code that checks this situation and acts
accordingly.
So after the this, when wanting to send some data we always check
whether we are not in a hole and if so, skip it an inform client
about its size.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 daemon/stream.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/daemon/stream.c b/daemon/stream.c
index 1a7d334..5bf6f23 100644
--- a/daemon/stream.c
+++ b/daemon/stream.c
@@ -766,6 +766,8 @@ daemonStreamHandleRead(virNetServerClientPtr client,
     size_t bufferLen = VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX;
     int ret = -1;
     int rv;
+    int inData = 0;
+    unsigned long long offset;
 
     VIR_DEBUG("client=%p, stream=%p tx=%d closed=%d",
               client, stream, stream->tx, stream->closed);
@@ -790,6 +792,54 @@ daemonStreamHandleRead(virNetServerClientPtr client,
     if (!(msg = virNetMessageNew(false)))
         goto cleanup;
 
+    if (stream->seekable) {
+        /* Handle skip. We want to send some data to the client. But we might
+         * be in a hole. Seek to next data. But if we are in data already, just
+         * carry on. */
+
+        rv = virStreamInData(stream->st, &inData, &offset);
+        VIR_DEBUG("rv=%d inData=%d offset=%llu", rv, inData, offset);
+
+        if (rv < 0) {
+            if (virNetServerProgramSendStreamError(remoteProgram,
+                                                   client,
+                                                   msg,
+                                                   &rerr,
+                                                   stream->procedure,
+                                                   stream->serial) < 0)
+                goto cleanup;
+            msg = NULL;
+
+            /* We're done with this call */
+            goto done;
+        } else {
+            if (!inData && offset) {
+                stream->tx = false;
+                msg->cb = daemonStreamMessageFinished;
+                msg->opaque = stream;
+                stream->refs++;
+                if (virNetServerProgramSendStreamSkip(remoteProgram,
+                                                      client,
+                                                      msg,
+                                                      stream->procedure,
+                                                      stream->serial,
+                                                      offset) < 0)
+                    goto cleanup;
+
+                msg = NULL;
+
+                /* We have successfully sent stream skip to the  other side.
+                 * To keep streams in sync seek locally too. */
+                virStreamSkipCallback(stream->st, offset);
+                /* We're done with this call */
+                goto done;
+            }
+        }
+
+        if (offset < bufferLen)
+            bufferLen = offset;
+    }
+
     rv = virStreamRecv(stream->st, buffer, bufferLen);
     if (rv == -2) {
         /* Should never get this, since we're only called when we know
@@ -821,6 +871,7 @@ daemonStreamHandleRead(virNetServerClientPtr client,
         msg = NULL;
     }
 
+ done:
     ret = 0;
  cleanup:
     VIR_FREE(buffer);
-- 
2.8.1

--
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]