From patchwork Thu Oct 14 12:24:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Bharadwaj X-Patchwork-Id: 67814 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 0964AB70F8 for ; Thu, 14 Oct 2010 23:31:22 +1100 (EST) Received: from localhost ([127.0.0.1]:54211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6Mxm-0004KL-89 for incoming@patchwork.ozlabs.org; Thu, 14 Oct 2010 08:31:14 -0400 Received: from [140.186.70.92] (port=52409 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P6Mrn-00082f-He for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:25:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6Mrm-0003dm-47 for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:25:03 -0400 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:35658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6Mrl-0003cj-3u for qemu-devel@nongnu.org; Thu, 14 Oct 2010 08:25:02 -0400 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by e28smtp06.in.ibm.com (8.14.4/8.13.1) with ESMTP id o9ECOx0Z026839 for ; Thu, 14 Oct 2010 17:54:59 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9ECOxIa2322472 for ; Thu, 14 Oct 2010 17:54:59 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9ECOxH8028472 for ; Thu, 14 Oct 2010 23:24:59 +1100 Received: from localhost6.localdomain6 ([9.77.206.195]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9ECOsSm028423 for ; Thu, 14 Oct 2010 23:24:56 +1100 To: qemu-devel@nongnu.org From: Arun R Bharadwaj Date: Thu, 14 Oct 2010 17:54:50 +0530 Message-ID: <20101014122450.2238.90057.stgit@localhost6.localdomain6> In-Reply-To: <20101014122217.2238.94995.stgit@localhost6.localdomain6> References: <20101014122217.2238.94995.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Subject: [Qemu-devel] [PATCH 6/9] Convert open into 2nd threading model 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: Sripathi Kodi Signed-off-by: Sripathi Kodi --- hw/virtio-9p.c | 115 +++++++++++++++++++++++--------------------------------- hw/virtio-9p.h | 4 ++ 2 files changed, 51 insertions(+), 68 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 1f2fd9f..cad21fd 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1797,6 +1797,13 @@ out: v9fs_walk_complete(s, vs, err); } +static void v9fs_open_do_complete(void *opaque) +{ + V9fsOpenState *vs = (V9fsOpenState *)opaque; + complete_pdu(vs->s, vs->pdu, vs->err); + qemu_free(vs); +} + static int32_t get_iounit(V9fsState *s, V9fsString *name) { struct statfs stbuf; @@ -1817,61 +1824,37 @@ static int32_t get_iounit(V9fsState *s, V9fsString *name) return iounit; } -static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err) -{ - if (vs->fidp->fs.dir == NULL) { - err = -errno; - goto out; - } - vs->fidp->fid_type = P9_FID_DIR; - 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_getiounit(V9fsState *s, V9fsOpenState *vs) -{ - int err; - vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, vs->iounit); - err = vs->offset; - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - -static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err) +static void v9fs_open_worker(ThreadletWork *work) { - if (vs->fidp->fs.fd == -1) { - err = -errno; + int flags; + V9fsOpenState *vs = container_of(work, V9fsOpenState, work); + vs->fidp = lookup_fid(vs->s, vs->fid); + if (vs->fidp == NULL) { + vs->err = -ENOENT; goto out; } - vs->fidp->fid_type = P9_FID_FILE; - vs->iounit = get_iounit(s, &vs->fidp->path); - v9fs_open_post_getiounit(s, vs); - return; -out: - complete_pdu(s, vs->pdu, err); - qemu_free(vs); -} - -static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err) -{ - int flags; - - if (err) { - err = -errno; + BUG_ON(vs->fidp->fid_type != P9_FID_NONE); + qemu_rwmutex_rdlock(&global_rename_lock); + vs->err = v9fs_do_lstat(vs->s, &vs->fidp->path, &vs->stbuf); + if (vs->err) { + vs->err = -errno; goto out; } stat_to_qid(&vs->stbuf, &vs->qid); if (S_ISDIR(vs->stbuf.st_mode)) { - vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fidp->path); - v9fs_open_post_opendir(s, vs, err); + vs->fidp->fs.dir = v9fs_do_opendir(vs->s, &vs->fidp->path); + + if (vs->fidp->fs.dir == NULL) { + vs->err = -errno; + goto out; + } + vs->fidp->fid_type = P9_FID_DIR; + vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0); + vs->err = vs->offset; } else { - if (s->proto_version == V9FS_PROTO_2000L) { + if (vs->s->proto_version == V9FS_PROTO_2000L) { flags = vs->mode; flags &= ~(O_NOCTTY | O_ASYNC | O_CREAT); /* Ignore direct disk access hint until the server supports it. */ @@ -1879,47 +1862,43 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err) } else { flags = omode_to_uflags(vs->mode); } - vs->fidp->fs.fd = v9fs_do_open(s, &vs->fidp->path, flags); - v9fs_open_post_open(s, vs, err); + vs->fidp->fs.fd = v9fs_do_open(vs->s, &vs->fidp->path, flags); + + if (vs->fidp->fs.fd == -1) { + vs->err = -errno; + goto out; + } + vs->fidp->fid_type = P9_FID_FILE; + vs->iounit = get_iounit(vs->s, &vs->fidp->path); + vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, + vs->iounit); + vs->err = vs->offset; } - return; out: - complete_pdu(s, vs->pdu, err); - qemu_free(vs); + qemu_rwmutex_unlock(&global_rename_lock); + v9fs_async_helper_done(v9fs_open_do_complete, vs); } static void v9fs_open(V9fsState *s, V9fsPDU *pdu) { - int32_t fid; V9fsOpenState *vs; - ssize_t err = 0; vs = qemu_malloc(sizeof(*vs)); vs->pdu = pdu; vs->offset = 7; vs->mode = 0; + vs->err = 0; + vs->s = s; if (s->proto_version == V9FS_PROTO_2000L) { - pdu_unmarshal(vs->pdu, vs->offset, "dd", &fid, &vs->mode); + pdu_unmarshal(vs->pdu, vs->offset, "dd", &vs->fid, &vs->mode); } else { - pdu_unmarshal(vs->pdu, vs->offset, "db", &fid, &vs->mode); + pdu_unmarshal(vs->pdu, vs->offset, "db", &vs->fid, &vs->mode); } - vs->fidp = lookup_fid(s, fid); - if (vs->fidp == NULL) { - err = -ENOENT; - goto out; - } - - BUG_ON(vs->fidp->fid_type != P9_FID_NONE); - - err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf); - - v9fs_open_post_lstat(s, vs, err); + vs->work.func = v9fs_open_worker; + submit_threadlet(&vs->work); return; -out: - complete_pdu(s, pdu, err); - qemu_free(vs); } static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err) diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 59f7a4e..1581bbe 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -306,6 +306,10 @@ typedef struct V9fsOpenState { V9fsQID qid; struct stat stbuf; int iounit; + V9fsState *s; + int32_t fid; + int32_t err; + ThreadletWork work; } V9fsOpenState; typedef struct V9fsReadState {