[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/17] virtio-9p: Implement P9_TOPEN
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 06/17] virtio-9p: Implement P9_TOPEN |
Date: |
Wed, 3 Mar 2010 13:01:03 -0600 |
Signed-off-by: Anthony Liguori <address@hidden>
Signed-off-by: Gautham R Shenoy <address@hidden>
Signed-off-by: Aneesh Kumar K.V <address@hidden>
---
hw/virtio-9p-local.c | 12 ++++
hw/virtio-9p.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 149 insertions(+), 4 deletions(-)
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index ac0dce5..803b0ea 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -88,12 +88,24 @@ static int local_closedir(void *opaque, DIR *dir)
return closedir(dir);
}
+static int local_open(void *opaque, const char *path, int flags)
+{
+ return open(rpath(path), flags);
+}
+
+static DIR *local_opendir(void *opaque, const char *path)
+{
+ return opendir(rpath(path));
+}
+
static V9fsPosixFileOperations ops = {
.lstat = local_lstat,
.setuid = local_setuid,
.readlink = local_readlink,
.close = local_close,
.closedir = local_closedir,
+ .open = local_open,
+ .opendir = local_opendir,
};
V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 685646a..7709e4c 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -127,6 +127,16 @@ static int posix_closedir(V9fsState *s, DIR *dir)
return s->ops->closedir(s->ops->opaque, dir);
}
+static int posix_open(V9fsState *s, V9fsString *path, int flags)
+{
+ return s->ops->open(s->ops->opaque, path->data, flags);
+}
+
+static DIR *posix_opendir(V9fsState *s, V9fsString *path)
+{
+ return s->ops->opendir(s->ops->opaque, path->data);
+}
+
static void v9fs_string_init(V9fsString *str)
{
str->data = NULL;
@@ -912,14 +922,137 @@ out:
v9fs_walk_complete(s, vs, err);
}
-static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu)
+typedef struct V9fsOpenState {
+ V9fsPDU *pdu;
+ size_t offset;
+ int32_t fid;
+ int8_t mode;
+ V9fsFidState *fidp;
+ V9fsQID qid;
+ struct stat stbuf;
+
+} V9fsOpenState;
+
+enum {
+ Oread = 0x00,
+ Owrite = 0x01,
+ Ordwr = 0x02,
+ Oexec = 0x03,
+ Oexcl = 0x04,
+ Otrunc = 0x10,
+ Orexec = 0x20,
+ Orclose = 0x40,
+ Oappend = 0x80,
+};
+
+static int omode_to_uflags(int8_t mode)
{
- if (debug_9p_pdu)
- pprint_pdu(pdu);
+ int ret = 0;
+
+ switch (mode & 3) {
+ case Oread:
+ ret = O_RDONLY;
+ break;
+ case Ordwr:
+ ret = O_RDWR;
+ break;
+ case Owrite:
+ ret = O_WRONLY;
+ break;
+ case Oexec:
+ ret = O_RDONLY;
+ break;
+ }
+
+ if (mode & Otrunc)
+ ret |= O_TRUNC;
+
+ if (mode & Oappend)
+ ret |= O_APPEND;
+
+ if (mode & Oexcl)
+ ret |= O_EXCL;
+
+ return ret;
+}
+
+static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err)
+{
+ if (vs->fidp->dir == NULL) {
+ err = -errno;
+ goto out;
+ }
+
+ vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
+ err = vs->offset;
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+
+}
+
+static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
+{
+ if (vs->fidp->fd == -1) {
+ err = -errno;
+ goto out;
+ }
+
+ vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
+ err = vs->offset;
+out:
+ complete_pdu(s, vs->pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
+{
+ BUG_ON(err == -1);
+
+ stat_to_qid(&vs->stbuf, &vs->qid);
+
+ if (S_ISDIR(vs->stbuf.st_mode)) {
+ vs->fidp->dir = posix_opendir(s, &vs->fidp->path);
+ v9fs_open_post_opendir(s, vs, err);
+ } else {
+ vs->fidp->fd = posix_open(s, &vs->fidp->path,
+ omode_to_uflags(vs->mode));
+ v9fs_open_post_open(s, vs, err);
+ }
+
}
static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
-{ if (debug_9p_pdu)
+{
+
+ V9fsOpenState *vs;
+ ssize_t err = 0;
+
+
+ vs = qemu_malloc(sizeof(*vs));
+ vs->pdu = pdu;
+ vs->offset = 7;
+
+ pdu_unmarshal(vs->pdu, vs->offset, "db", &vs->fid, &vs->mode);
+
+ vs->fidp = lookup_fid(s, vs->fid);
+ if (vs->fidp == NULL) {
+ err = -ENOENT;
+ goto out;
+ }
+
+ err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
+
+ v9fs_open_post_lstat(s, vs, err);
+ return;
+out:
+ complete_pdu(s, pdu, err);
+ qemu_free(vs);
+}
+
+static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu)
+{
+ if (debug_9p_pdu)
pprint_pdu(pdu);
}
--
1.6.5.2
[Qemu-devel] [PATCH 02/17] vrtio-9p: Implement P9_TVERSION for 9P, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 08/17] virtio-9p: Implement P9_TCLUNK, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 01/17] vitio-9p: Add a virtio 9p device to qemu, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 06/17] virtio-9p: Implement P9_TOPEN,
Anthony Liguori <=
[Qemu-devel] [PATCH 05/17] virtio-9p: Implement P9_TWALK, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 03/17] virtio-9p: Implement P9_TATTACH, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 16/17] virtio-9p: Add support for hardlink, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 07/17] virtio-9p: Implement P9_TREAD, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 14/17] virtio-9p: Add multiple mount point support, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 17/17] Implement sync support in 9p server, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 11/17] virtio-9p: Implement P9_TWSTAT, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 00/17][RFC] virtio-9p: paravirtual filesystem passthrough, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 13/17] virtio-9p: Implement P9_TFLUSH, Anthony Liguori, 2010/03/03
[Qemu-devel] [PATCH 09/17] virtio-9p: Implement P9_TWRITE, Anthony Liguori, 2010/03/03