[PATCH RFC 37/48] fdstream: Handle formatted messages separately

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

 



As described in the previous commit, we need to handle
communication with iohelper differently in some cases.
This patch creates function stubs for that.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/fdstream.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 71 insertions(+), 12 deletions(-)

diff --git a/src/fdstream.c b/src/fdstream.c
index 911fac0..8ab7cd5 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -399,6 +399,21 @@ virFDStreamAbort(virStreamPtr st)
     return virFDStreamCloseInt(st, true);
 }
 
+static ssize_t
+virFDStreamWriteInternal(virFDStreamDataPtr fdst,
+                         const char *bytes,
+                         size_t nbytes)
+{
+    if (fdst->formatted) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("sparse stream not supported"));
+        return -1;
+    } else {
+        return write(fdst->fd, bytes, nbytes);
+    }
+}
+
+
 static int virFDStreamWrite(virStreamPtr st, const char *bytes, size_t nbytes)
 {
     virFDStreamDataPtr fdst = st->privateData;
@@ -431,7 +446,7 @@ static int virFDStreamWrite(virStreamPtr st, const char *bytes, size_t nbytes)
     }
 
  retry:
-    ret = write(fdst->fd, bytes, nbytes);
+    ret = virFDStreamWriteInternal(fdst, bytes, nbytes);
     if (ret < 0) {
         VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
         if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -453,6 +468,21 @@ static int virFDStreamWrite(virStreamPtr st, const char *bytes, size_t nbytes)
 }
 
 
+static ssize_t
+virFDStreamReadInternal(virFDStreamDataPtr fdst,
+                        char *bytes,
+                        size_t nbytes)
+{
+    if (fdst->formatted) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("sparse stream not supported"));
+        return -1;
+    } else {
+        return read(fdst->fd, bytes, nbytes);
+    }
+}
+
+
 static int virFDStreamRead(virStreamPtr st, char *bytes, size_t nbytes)
 {
     virFDStreamDataPtr fdst = st->privateData;
@@ -483,7 +513,7 @@ static int virFDStreamRead(virStreamPtr st, char *bytes, size_t nbytes)
     }
 
  retry:
-    ret = read(fdst->fd, bytes, nbytes);
+    ret = virFDStreamReadInternal(fdst, bytes, nbytes);
     if (ret < 0) {
         VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
         if (errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -506,11 +536,26 @@ static int virFDStreamRead(virStreamPtr st, char *bytes, size_t nbytes)
 
 
 static int
+virFDStreamSkipInternal(virFDStreamDataPtr fdst,
+                        unsigned long long length)
+{
+    off_t off;
+    if (fdst->formatted) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("sparse stream not supported"));
+        return -1;
+    } else {
+        off = lseek(fdst->fd, length, SEEK_CUR);
+        return off == (off_t) -1 ? -1 : 0;
+    }
+}
+
+
+static int
 virFDStreamSkip(virStreamPtr st,
                 unsigned long long length)
 {
     virFDStreamDataPtr fdst = st->privateData;
-    off_t off;
     int ret = -1;
 
     virObjectLock(fdst);
@@ -520,15 +565,13 @@ virFDStreamSkip(virStreamPtr st,
                                  _("cannot write to stream"));
             goto cleanup;
         }
+    }
+
+    if (virFDStreamSkipInternal(fdst, length) < 0)
+        goto cleanup;
+
+    if (fdst->length)
         fdst->offset += length;
-    }
-
-    off = lseek(fdst->fd, length, SEEK_CUR);
-    if (off == (off_t) -1) {
-        virReportSystemError(errno, "%s",
-                             _("unable to seek"));
-        goto cleanup;
-    }
     ret = 0;
  cleanup:
     virObjectUnlock(fdst);
@@ -536,6 +579,22 @@ virFDStreamSkip(virStreamPtr st,
 }
 
 
+
+static int
+virFDStreamInDataInternal(virFDStreamDataPtr fdst,
+                          int *inData,
+                          unsigned long long *length)
+{
+    if (fdst->formatted) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("sparse stream not supported"));
+        return -1;
+    } else {
+        return virFileInData(fdst->fd, inData, length);
+    }
+}
+
+
 static int
 virFDStreamInData(virStreamPtr st,
                   int *inData,
@@ -545,7 +604,7 @@ virFDStreamInData(virStreamPtr st,
     int ret = -1;
 
     virObjectLock(fdst);
-    ret = virFileInData(fdst->fd, inData, length);
+    ret = virFDStreamInDataInternal(fdst, inData, length);
     virObjectUnlock(fdst);
     return ret;
 }
-- 
2.8.4

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