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

[PATCH 14/29] tools/xenlogd: add 9pfs read request support



Add the read request of the 9pfs protocol.

For now support only reading plain files (no directories).

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/xenlogd/io.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/tools/xenlogd/io.c b/tools/xenlogd/io.c
index 6b4692ca67..b3f9f96bcc 100644
--- a/tools/xenlogd/io.c
+++ b/tools/xenlogd/io.c
@@ -32,6 +32,7 @@
 #define P9_CMD_WALK       110
 #define P9_CMD_OPEN       112
 #define P9_CMD_CREATE     114
+#define P9_CMD_READ       116
 #define P9_CMD_WRITE      118
 #define P9_CMD_CLUNK      120
 #define P9_CMD_STAT       124
@@ -1011,6 +1012,61 @@ static void p9_create(device *device, struct p9_header 
*hdr)
     fill_buffer(device, hdr->cmd + 1, hdr->tag, "QU", &qid, &iounit);
 }
 
+static void p9_read(device *device, struct p9_header *hdr)
+{
+    uint32_t fid;
+    uint64_t off;
+    unsigned int len;
+    uint32_t count;
+    void *buf;
+    struct p9_fid *fidp;
+    int ret;
+
+    ret = fill_data(device, "ULU", &fid, &off, &count);
+    if ( ret != 3 )
+    {
+        p9_error(device, hdr->tag, EINVAL);
+        return;
+    }
+
+    fidp = find_fid(device, fid);
+    if ( !fidp || !fidp->opened )
+    {
+        p9_error(device, hdr->tag, EBADF);
+        return;
+    }
+
+    if ( fidp->isdir )
+    {
+        p9_error(device, hdr->tag, EOPNOTSUPP);
+        return;
+    }
+    else
+    {
+        len = count;
+        buf = device->buffer + sizeof(*hdr) + sizeof(uint32_t);
+
+        while ( len != 0 )
+        {
+            ret = pread(fidp->fd, buf, len, off);
+            if ( ret <= 0 )
+                break;
+            len -= ret;
+            buf += ret;
+            off += ret;
+        }
+        if ( ret && len == count )
+        {
+            p9_error(device, hdr->tag, errno);
+            return;
+        }
+
+        buf = device->buffer + sizeof(*hdr) + sizeof(uint32_t);
+        len = count - len;
+        fill_buffer(device, hdr->cmd + 1, hdr->tag, "D", &len, buf);
+    }
+}
+
 static void p9_write(device *device, struct p9_header *hdr)
 {
     uint32_t fid;
@@ -1228,6 +1284,10 @@ void *io_thread(void *arg)
                 p9_create(device, &hdr);
                 break;
 
+            case P9_CMD_READ:
+                p9_read(device, &hdr);
+                break;
+
             case P9_CMD_WRITE:
                 p9_write(device, &hdr);
                 break;
-- 
2.35.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.