From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NuqAH-00072P-2e for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:13 -0400 Received: from [140.186.70.92] (port=50368 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuqA8-0006yI-06 for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuqA4-00053t-My for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:03 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:51574) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuqA3-00053c-Tn for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:00 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp07.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2PGhwhB030021 for ; Fri, 26 Mar 2010 03:43:58 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2PGbuG71319144 for ; Fri, 26 Mar 2010 03:37:56 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2PGhvKu031101 for ; Fri, 26 Mar 2010 03:43:58 +1100 From: "Aneesh Kumar K.V" Date: Thu, 25 Mar 2010 22:13:14 +0530 Message-Id: <1269535420-31206-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com> In-Reply-To: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH -V3 06/32] virtio-9p: Implement P9_TOPEN List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: ericvh@gmail.com, aliguori@us.ibm.com, "Aneesh Kumar K.V" , Gautham R Shenoy From: Anthony Liguori Signed-off-by: Anthony Liguori Signed-off-by: Gautham R Shenoy Signed-off-by: Aneesh Kumar K.V --- hw/virtio-9p-local.c | 12 ++++ hw/virtio-9p.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 151 insertions(+), 6 deletions(-) diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c index 409f5b0..d8cb70d 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 784d399..f1df0b9 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; @@ -910,15 +920,138 @@ 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(V9fsState *s, V9fsPDU *pdu) -{ if (debug_9p_pdu) - pprint_pdu(pdu); +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) +{ + + 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); } static void v9fs_read(V9fsState *s, V9fsPDU *pdu) -- 1.7.0.2.323.g0d092