From patchwork Tue Mar 16 09:15:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 47822 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 1E8E3B7D73 for ; Tue, 16 Mar 2010 20:45:07 +1100 (EST) Received: from localhost ([127.0.0.1]:50461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrTIu-00035O-U4 for incoming@patchwork.ozlabs.org; Tue, 16 Mar 2010 05:43:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NrSsZ-0001ut-M8 for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:15:59 -0400 Received: from [199.232.76.173] (port=57558 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NrSsY-0001u0-5V for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:15:58 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NrSsW-0000gJ-Ek for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:15:57 -0400 Received: from mx20.gnu.org ([199.232.41.8]:47221) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NrSsV-0000au-JA for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:15:55 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NrSsT-0001XR-GQ for qemu-devel@nongnu.org; Tue, 16 Mar 2010 05:15:54 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp03.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2G9CXdI030489 for ; Tue, 16 Mar 2010 20:12:33 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2G99p14999562 for ; Tue, 16 Mar 2010 20:09:51 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2G9FfbC005840 for ; Tue, 16 Mar 2010 20:15:41 +1100 Received: from localhost.localdomain ([9.124.214.164]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2G9FRvD005290; Tue, 16 Mar 2010 20:15:39 +1100 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Tue, 16 Mar 2010 14:45:04 +0530 Message-Id: <1268730920-14584-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.2.273.gc2413 In-Reply-To: <1268730920-14584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1268730920-14584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-detected-operating-system: by mx20.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: ericvh@gmail.com, aliguori@us.ibm.com, "Aneesh Kumar K.V" , Gautham R Shenoy Subject: [Qemu-devel] [PATCH -v2 06/22] 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 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)