From patchwork Wed Oct 13 15:37:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Bharadwaj X-Patchwork-Id: 67697 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 16D6A1007D2 for ; Thu, 14 Oct 2010 02:59:39 +1100 (EST) Received: from localhost ([127.0.0.1]:52588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P63h0-000286-5N for incoming@patchwork.ozlabs.org; Wed, 13 Oct 2010 11:56:38 -0400 Received: from [140.186.70.92] (port=40904 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P63ZL-0005Xu-9z for qemu-devel@nongnu.org; Wed, 13 Oct 2010 11:48:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P63P8-0005Sp-Iv for qemu-devel@nongnu.org; Wed, 13 Oct 2010 11:38:11 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:47020) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P63P7-0005Se-Qm for qemu-devel@nongnu.org; Wed, 13 Oct 2010 11:38:10 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp08.au.ibm.com (8.14.4/8.13.1) with ESMTP id o9DFc82t018571 for ; Thu, 14 Oct 2010 02:38:08 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9DFc82c3203202 for ; Thu, 14 Oct 2010 02:38:08 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9DFc83c008791 for ; Thu, 14 Oct 2010 02:38:08 +1100 Received: from localhost6.localdomain6 ([9.77.201.21]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9DFboIP008235 for ; Thu, 14 Oct 2010 02:37:59 +1100 To: qemu-devel@nongnu.org From: Arun R Bharadwaj Date: Wed, 13 Oct 2010 21:07:42 +0530 Message-ID: <20101013153742.21873.5347.stgit@localhost6.localdomain6> In-Reply-To: <20101013153402.21873.3175.stgit@localhost6.localdomain6> References: <20101013153402.21873.3175.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 5/6] This patch converts v9fs_open() to make use of the threadlets infrastructure. 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: Gautham R Shenoy This patch offloads all the blocking calls invoked for v9fs_open onto the helper threads belonging to the threadlets infrastructure. The handling of the v9fs_post_*open* calls is done from the io-thread context. Signed-off-by: Gautham R Shenoy --- hw/virtio-9p.c | 86 +++++++++++++++++++++++++++++++++++++++++--------------- hw/virtio-9p.h | 5 +++ 2 files changed, 68 insertions(+), 23 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 5fb7dc4..75d4be3 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1777,6 +1777,41 @@ out: v9fs_walk_complete(s, vs, err); } +/********************* v9fs_open calls *********************************/ +static void v9fs_open_do_lstat(ThreadletWork *work) +{ + V9fsOpenState *vs; + + vs = container_of(work, V9fsOpenState, work); + vs->err = v9fs_do_lstat(vs->s, &vs->fidp->path, &vs->stbuf); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_open_do_opendir(ThreadletWork *work) +{ + V9fsOpenState *vs; + + vs = container_of(work, V9fsOpenState, work); + vs->fidp->fs.dir = v9fs_do_opendir(vs->s, &vs->fidp->path); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_open_do_open(ThreadletWork *work) +{ + V9fsOpenState *vs; + + vs = container_of(work, V9fsOpenState, work); + vs->fidp->fs.fd = v9fs_do_open(vs->s, &vs->fidp->path, + omode_to_uflags(vs->mode)); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + static int32_t get_iounit(V9fsState *s, V9fsString *name) { struct statfs stbuf; @@ -1797,17 +1832,19 @@ static int32_t get_iounit(V9fsState *s, V9fsString *name) return iounit; } -static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err) +static void v9fs_open_post_opendir(void *opaque) { + V9fsOpenState *vs = (V9fsOpenState *)opaque; + if (vs->fidp->fs.dir == NULL) { - err = -errno; + vs->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; + vs->err = vs->offset; out: - complete_pdu(s, vs->pdu, err); + complete_pdu(vs->s, vs->pdu, vs->err); qemu_free(vs); } @@ -1821,35 +1858,39 @@ static void v9fs_open_post_getiounit(V9fsState *s, V9fsOpenState *vs) qemu_free(vs); } -static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err) +static void v9fs_open_post_open(void *opaque) { + V9fsOpenState *vs = (V9fsOpenState *)opaque; + if (vs->fidp->fs.fd == -1) { - err = -errno; + vs->err = -errno; goto out; } vs->fidp->fid_type = P9_FID_FILE; - vs->iounit = get_iounit(s, &vs->fidp->path); - v9fs_open_post_getiounit(s, vs); + /* FIXME: Need a new state here */ + vs->iounit = get_iounit(vs->s, &vs->fidp->path); + v9fs_open_post_getiounit(vs->s, vs); return; out: - complete_pdu(s, vs->pdu, err); + complete_pdu(vs->s, vs->pdu, vs->err); qemu_free(vs); } -static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err) +static void v9fs_open_post_lstat(void *opaque) { + V9fsOpenState *vs = (V9fsOpenState *)opaque; int flags; - if (err) { - err = -errno; + 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); + v9fs_do_async_posix(&vs->work, v9fs_open_do_opendir, &vs->post_fn, + v9fs_open_post_opendir); } else { if (s->proto_version == V9FS_PROTO_2000L) { flags = vs->mode; @@ -1859,12 +1900,12 @@ 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); + v9fs_do_async_posix(&vs->work, v9fs_open_do_open, &vs->post_fn, + v9fs_open_post_open); } return; out: - complete_pdu(s, vs->pdu, err); + complete_pdu(vs->s, vs->pdu, vs->err); qemu_free(vs); } @@ -1872,12 +1913,12 @@ 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->s = s; if (s->proto_version == V9FS_PROTO_2000L) { pdu_unmarshal(vs->pdu, vs->offset, "dd", &fid, &vs->mode); @@ -1887,18 +1928,17 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu) vs->fidp = lookup_fid(s, fid); if (vs->fidp == NULL) { - err = -ENOENT; + vs->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); + v9fs_do_async_posix(&vs->work, v9fs_open_do_lstat, &vs->post_fn, + v9fs_open_post_lstat); return; out: - complete_pdu(s, pdu, err); + complete_pdu(vs->s, pdu, vs->err); qemu_free(vs); } diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index be87d5f..294de83 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -306,6 +306,11 @@ typedef struct V9fsOpenState { V9fsQID qid; struct stat stbuf; int iounit; + V9fsState *s; + int err; + int v9fs_errno; + ThreadletWork work; + void (*post_fn)(void *arg); } V9fsOpenState; typedef struct V9fsReadState {