Patchwork [-V4,16/26,virtio-9p] qemu: virtio-9p: Implement LOPEN

login
register
mail settings
Submitter jvrao
Date Aug. 29, 2010, 7:02 p.m.
Message ID <1283108572-20228-17-git-send-email-jvrao@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/62960/
State New
Headers show

Comments

jvrao - Aug. 29, 2010, 7:02 p.m.
From: M. Mohan Kumar <mohan@in.ibm.com>

Implement 9p2000.L version of open(LOPEN) interface in qemu 9p server.

For LOPEN, no need to convert the flags to and from 9p mode to VFS mode.

Synopsis:

    size[4] Tlopen tag[2] fid[4] mode[4]

    size[4] Rlopen tag[2] qid[13] iounit[4]

Current qemu 9p server does not support following flags:
    O_NOCTTY, O_NONBLOCK, O_ASYNC & O_CLOEXEC

[Fix mode format - jvrao@linux.vnet.ibm.com]

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
---
 hw/virtio-9p.c |   32 ++++++++++++++++++++++++++++----
 hw/virtio-9p.h |    4 +++-
 2 files changed, 31 insertions(+), 5 deletions(-)

Patch

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 88dd496..deeacbd 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1621,8 +1621,19 @@  out:
     qemu_free(vs);
 }
 
+static inline int valid_flags(int flag)
+{
+    if (flag & O_NOCTTY || flag & O_NONBLOCK || flag & O_ASYNC ||
+            flag & O_CLOEXEC)
+        return 0;
+    else
+        return 1;
+}
+
 static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
 {
+    int flags;
+
     if (err) {
         err = -errno;
         goto out;
@@ -1634,8 +1645,16 @@  static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
         vs->fidp->dir = v9fs_do_opendir(s, &vs->fidp->path);
         v9fs_open_post_opendir(s, vs, err);
     } else {
-        vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path,
-                                    omode_to_uflags(vs->mode));
+        if (s->proto_version == V9FS_PROTO_2000L) {
+            if (!valid_flags(vs->mode)) {
+                err = -EINVAL;
+                goto out;
+            }
+            flags = vs->mode;
+        } else {
+            flags = omode_to_uflags(vs->mode);
+        }
+        vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path, flags);
         v9fs_open_post_open(s, vs, err);
     }
     return;
@@ -1650,12 +1669,16 @@  static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
     V9fsOpenState *vs;
     ssize_t err = 0;
 
-
     vs = qemu_malloc(sizeof(*vs));
     vs->pdu = pdu;
     vs->offset = 7;
+    vs->mode = 0;
 
-    pdu_unmarshal(vs->pdu, vs->offset, "db", &fid, &vs->mode);
+    if (s->proto_version == V9FS_PROTO_2000L) {
+        pdu_unmarshal(vs->pdu, vs->offset, "dd", &fid, &vs->mode);
+    } else {
+        pdu_unmarshal(vs->pdu, vs->offset, "db", &fid, &vs->mode);
+    }
 
     vs->fidp = lookup_fid(s, fid);
     if (vs->fidp == NULL) {
@@ -3076,6 +3099,7 @@  static pdu_handler_t *pdu_handlers[] = {
     [P9_TRENAME] = v9fs_rename,
     [P9_TMKDIR] = v9fs_mkdir,
     [P9_TVERSION] = v9fs_version,
+    [P9_TLOPEN] = v9fs_open,
     [P9_TATTACH] = v9fs_attach,
     [P9_TSTAT] = v9fs_stat,
     [P9_TWALK] = v9fs_walk,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 4d179b7..cd7c67e 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -15,6 +15,8 @@ 
 enum {
     P9_TSTATFS = 8,
     P9_RSTATFS,
+    P9_TLOPEN = 12,
+    P9_RLOPEN,
     P9_TLCREATE = 14,
     P9_RLCREATE,
     P9_TSYMLINK = 16,
@@ -259,7 +261,7 @@  typedef struct V9fsWalkState {
 typedef struct V9fsOpenState {
     V9fsPDU *pdu;
     size_t offset;
-    int8_t mode;
+    int32_t mode;
     V9fsFidState *fidp;
     V9fsQID qid;
     struct stat stbuf;