From patchwork Wed Mar 3 19:01:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 46860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8702CB7C09 for ; Thu, 4 Mar 2010 06:14:24 +1100 (EST) Received: from localhost ([127.0.0.1]:52876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmtzX-00037X-Bq for incoming@patchwork.ozlabs.org; Wed, 03 Mar 2010 14:12:19 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NmtpE-0007Fz-EE for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:40 -0500 Received: from [199.232.76.173] (port=60451 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmtpD-0007EF-5D for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:39 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NmtpA-0001Yo-Ao for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:38 -0500 Received: from e38.co.us.ibm.com ([32.97.110.159]:33634) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Nmtp9-0001YE-9r for qemu-devel@nongnu.org; Wed, 03 Mar 2010 14:01:35 -0500 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by e38.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o23Itsfn011013 for ; Wed, 3 Mar 2010 11:55:54 -0700 Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o23J1LY5042800 for ; Wed, 3 Mar 2010 12:01:22 -0700 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o23J3hrf009953 for ; Wed, 3 Mar 2010 12:03:44 -0700 Received: from localhost.localdomain (sig-9-76-214-227.mts.ibm.com [9.76.214.227]) by d03av06.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o23J3daF009640; Wed, 3 Mar 2010 12:03:43 -0700 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 3 Mar 2010 13:01:03 -0600 Message-Id: <1267642874-15001-8-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1267642874-15001-1-git-send-email-aliguori@us.ibm.com> References: <1267642874-15001-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Anthony Liguori , "Aneesh Kumar K.V" , Gautham R Shenoy Subject: [Qemu-devel] [PATCH 06/17] virtio-9p: Implement P9_TOPEN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 | 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); }