[PATCH RFC 29/48] fdstream: Implement seek

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

 



Implement virStreamSkip and virStreamInData callbacks. These
callbacks do no magic, just skip a hole or detect whether we are
in a data section of a file or in a hole and how much bytes can
we read until section changes.

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

diff --git a/src/fdstream.c b/src/fdstream.c
index bebeac3..be94325 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -504,11 +504,59 @@ static int virFDStreamRead(virStreamPtr st, char *bytes, size_t nbytes)
 }
 
 
+static int
+virFDStreamSkip(virStreamPtr st,
+                unsigned long long length)
+{
+    virFDStreamDataPtr fdst = st->privateData;
+    off_t off;
+    int ret = -1;
+
+    virObjectLock(fdst);
+    if (fdst->length) {
+        if (fdst->offset + length > fdst->length) {
+            virReportSystemError(ENOSPC, "%s",
+                                 _("cannot write to stream"));
+            goto cleanup;
+        }
+        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);
+    return ret;
+}
+
+
+static int
+virFDStreamInData(virStreamPtr st,
+                  int *inData,
+                  unsigned long long *length)
+{
+    virFDStreamDataPtr fdst = st->privateData;
+    int ret = -1;
+
+    virObjectLock(fdst);
+    ret = virFileInData(fdst->fd, inData, length);
+    virObjectUnlock(fdst);
+    return ret;
+}
+
+
 static virStreamDriver virFDStreamDrv = {
     .streamSend = virFDStreamWrite,
     .streamRecv = virFDStreamRead,
     .streamFinish = virFDStreamClose,
     .streamAbort = virFDStreamAbort,
+    .streamSkip = virFDStreamSkip,
+    .streamInData = virFDStreamInData,
     .streamEventAddCallback = virFDStreamAddCallback,
     .streamEventUpdateCallback = virFDStreamUpdateCallback,
     .streamEventRemoveCallback = virFDStreamRemoveCallback
-- 
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]