From patchwork Wed Oct 13 15:37:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Bharadwaj X-Patchwork-Id: 67695 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 4CFB11007D2 for ; Thu, 14 Oct 2010 02:56:00 +1100 (EST) Received: from localhost ([127.0.0.1]:51942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P63g1-0001Qp-Sz for incoming@patchwork.ozlabs.org; Wed, 13 Oct 2010 11:55:37 -0400 Received: from [140.186.70.92] (port=41115 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P63ZS-0005cL-Kq for qemu-devel@nongnu.org; Wed, 13 Oct 2010 11:48:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P63OG-0005IK-KB for qemu-devel@nongnu.org; Wed, 13 Oct 2010 11:37:17 -0400 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:50879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P63OF-0005Hk-Jg for qemu-devel@nongnu.org; Wed, 13 Oct 2010 11:37:16 -0400 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by e28smtp02.in.ibm.com (8.14.4/8.13.1) with ESMTP id o9DFbDmu010726 for ; Wed, 13 Oct 2010 21:07:13 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9DFbDYZ2572478 for ; Wed, 13 Oct 2010 21:07:13 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9DFbD14019207 for ; Wed, 13 Oct 2010 21:07:13 +0530 Received: from localhost6.localdomain6 ([9.77.201.21]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9DFb8Zf019053 for ; Wed, 13 Oct 2010 21:07:10 +0530 To: qemu-devel@nongnu.org From: Arun R Bharadwaj Date: Wed, 13 Oct 2010 21:07:06 +0530 Message-ID: <20101013153706.21873.29799.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 3/6] This patch converts v9fs_read() 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_read onto the helper threads belonging to the threadlets infrastructure. The handling of the v9fs_post_*read* calls is done from the io-thread context. Signed-off-by: Gautham R Shenoy Signed-off-by: Arun R Bharadwaj --- hw/virtio-9p.c | 218 +++++++++++++++++++++++++++++++++++++++++--------------- hw/virtio-9p.h | 5 + 2 files changed, 164 insertions(+), 59 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index cf7e012..da185c3 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -2037,33 +2037,136 @@ out: complete_pdu(s, pdu, err); } -static void v9fs_read_post_readdir(V9fsState *, V9fsReadState *, ssize_t); +/********************** v9fs_read calls ******************************/ +static void v9fs_read_do_preadv(ThreadletWork *work) +{ + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + v9fs_do_preadv(vs->s, vs->fidp->fs.fd, vs->sg, vs->cnt, vs->off); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_read_do_rewinddir(ThreadletWork *work) + { + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + v9fs_do_rewinddir(vs->s, vs->fidp->fs.dir); + vs->v9fs_errno = errno; -static void v9fs_read_post_seekdir(V9fsState *s, V9fsReadState *vs, ssize_t err) + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_read_do_lseek(ThreadletWork *work) { - if (err) { + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + vs->err = v9fs_do_lseek(vs->s, vs->fidp->fs.fd, vs->off, SEEK_SET); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_read_do_readv(ThreadletWork *work) +{ + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + do { + if (0) { + print_sg(vs->sg, vs->cnt); + } + vs->len = v9fs_do_readv(vs->s, vs->fidp->fs.fd, vs->sg, vs->cnt); + } while (vs->len == -1 && errno == EINTR); + vs->v9fs_errno = errno; + + if (vs->len == -1) { + vs->err = -vs->v9fs_errno; + } + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_read_do_telldir(ThreadletWork *work) +{ + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + vs->dir_pos = v9fs_do_telldir(vs->s, vs->fidp->fs.dir); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_read_do_readdir(ThreadletWork *work) +{ + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + vs->dent = v9fs_do_readdir(vs->s, vs->fidp->fs.dir); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_read_do_lstat(ThreadletWork *work) +{ + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + vs->err = v9fs_do_lstat(vs->s, &vs->name, &vs->stbuf); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + +static void v9fs_read_do_seekdir(ThreadletWork *work) +{ + V9fsReadState *vs; + + vs = container_of(work, V9fsReadState, work); + v9fs_do_seekdir(vs->s, vs->fidp->fs.dir, vs->dir_pos); + vs->v9fs_errno = errno; + + v9fs_async_helper_done(vs->post_fn, vs); +} + + + +static void v9fs_read_post_readdir(void *); + +static void v9fs_read_post_seekdir(void *opaque) +{ + V9fsReadState *vs = (V9fsReadState *)opaque; + + if (vs->err) { goto out; } v9fs_stat_free(&vs->v9stat); v9fs_string_free(&vs->name); vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count); vs->offset += vs->count; - 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); return; } -static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs, - ssize_t err) +static void v9fs_read_post_dir_lstat(void *opaque) { - if (err) { - err = -errno; + V9fsReadState *vs = (V9fsReadState *)opaque; + + if (vs->err) { + vs->err = -vs->v9fs_errno; goto out; } - err = stat_to_v9stat(s, &vs->name, &vs->stbuf, &vs->v9stat); - if (err) { + vs->err = stat_to_v9stat(vs->s, &vs->name, &vs->stbuf, &vs->v9stat); + if (vs->err) { goto out; } @@ -2071,26 +2174,28 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs, &vs->v9stat); if ((vs->len != (vs->v9stat.size + 2)) || ((vs->count + vs->len) > vs->max_count)) { - v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos); - v9fs_read_post_seekdir(s, vs, err); + v9fs_do_async_posix(&vs->work, v9fs_read_do_seekdir, &vs->post_fn, + v9fs_read_post_seekdir); return; } vs->count += vs->len; v9fs_stat_free(&vs->v9stat); v9fs_string_free(&vs->name); vs->dir_pos = vs->dent->d_off; - vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir); - v9fs_read_post_readdir(s, vs, err); + v9fs_do_async_posix(&vs->work, v9fs_read_do_readdir, &vs->post_fn, + v9fs_read_post_readdir); return; out: - v9fs_do_seekdir(s, vs->fidp->fs.dir, vs->dir_pos); - v9fs_read_post_seekdir(s, vs, err); + v9fs_do_async_posix(&vs->work, v9fs_read_do_seekdir, &vs->post_fn, + v9fs_read_post_seekdir); return; } -static void v9fs_read_post_readdir(V9fsState *s, V9fsReadState *vs, ssize_t err) +static void v9fs_read_post_readdir(void *opaque) { + V9fsReadState *vs = (V9fsReadState *)opaque; + if (vs->dent) { memset(&vs->v9stat, 0, sizeof(vs->v9stat)); v9fs_string_init(&vs->name); @@ -2098,64 +2203,61 @@ static void v9fs_read_post_readdir(V9fsState *s, V9fsReadState *vs, ssize_t err) vs->dent->d_name); err = v9fs_do_lstat(s, &vs->name, &vs->stbuf); v9fs_read_post_dir_lstat(s, vs, err); + v9fs_do_async_posix(&vs->work, v9fs_read_do_lstat, &vs->post_fn, + v9fs_read_post_dir_lstat); return; } vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count); vs->offset += vs->count; - err = vs->offset; - complete_pdu(s, vs->pdu, err); + vs->err = vs->offset; + complete_pdu(vs->s, vs->pdu, vs->err); qemu_free(vs); return; } -static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t err) +static void v9fs_read_post_telldir(void *opaque) { - vs->dent = v9fs_do_readdir(s, vs->fidp->fs.dir); - v9fs_read_post_readdir(s, vs, err); + V9fsReadState *vs = (V9fsReadState *)opaque; + + v9fs_do_async_posix(&vs->work, v9fs_read_do_readdir, &vs->post_fn, + v9fs_read_post_readdir); return; } -static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs, - ssize_t err) +static void v9fs_read_post_rewinddir(void *opaque) { - vs->dir_pos = v9fs_do_telldir(s, vs->fidp->fs.dir); - v9fs_read_post_telldir(s, vs, err); + V9fsReadState *vs = (V9fsReadState *)opaque; + + v9fs_do_async_posix(&vs->work, v9fs_read_do_telldir, &vs->post_fn, + v9fs_read_post_telldir); return; } -static void v9fs_read_post_preadv(V9fsState *s, V9fsReadState *vs, ssize_t err) +static void v9fs_read_post_preadv(void *opaque) { - if (err < 0) { + V9fsReadState *vs = (V9fsReadState *)opaque; + + if (vs->err < 0) { /* IO error return the error */ - err = -errno; + vs->err = -errno; goto out; + } else { + vs->off += vs->len; } vs->total += vs->len; vs->sg = adjust_sg(vs->sg, vs->len, &vs->cnt); if (vs->total < vs->count && vs->len > 0) { - do { - if (0) { - print_sg(vs->sg, vs->cnt); - } - vs->len = v9fs_do_preadv(s, vs->fidp->fs.fd, vs->sg, vs->cnt, - vs->off); - if (vs->len > 0) { - vs->off += vs->len; - } - } while (vs->len == -1 && errno == EINTR); - if (vs->len == -1) { - err = -errno; - } - v9fs_read_post_preadv(s, vs, err); + v9fs_do_async_posix(&vs->work, v9fs_read_do_preadv, &vs->post_fn, + v9fs_read_post_preadv); return; } vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total); vs->offset += vs->count; - 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); } @@ -2188,7 +2290,6 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu) { int32_t fid; V9fsReadState *vs; - ssize_t err = 0; vs = qemu_malloc(sizeof(*vs)); vs->pdu = pdu; @@ -2196,12 +2297,13 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu) vs->total = 0; vs->len = 0; vs->count = 0; + vs->s = s; pdu_unmarshal(vs->pdu, vs->offset, "dqd", &fid, &vs->off, &vs->count); vs->fidp = lookup_fid(s, fid); if (vs->fidp == NULL) { - err = -EINVAL; + vs->err = -EINVAL; goto out; } @@ -2209,32 +2311,30 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu) vs->max_count = vs->count; vs->count = 0; if (vs->off == 0) { - v9fs_do_rewinddir(s, vs->fidp->fs.dir); + v9fs_do_async_posix(&vs->work, v9fs_read_do_rewinddir, + &vs->post_fn, v9fs_read_post_rewinddir); + return; } - v9fs_read_post_rewinddir(s, vs, err); + v9fs_read_post_rewinddir(vs); return; } else if (vs->fidp->fid_type == P9_FID_FILE) { vs->sg = vs->iov; pdu_marshal(vs->pdu, vs->offset + 4, "v", vs->sg, &vs->cnt); vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt); if (vs->total <= vs->count) { - vs->len = v9fs_do_preadv(s, vs->fidp->fs.fd, vs->sg, vs->cnt, - vs->off); - if (vs->len > 0) { - vs->off += vs->len; - } - err = vs->len; - v9fs_read_post_preadv(s, vs, err); + vs->err = vs->len; + v9fs_do_async_posix(&vs->work, v9fs_read_do_preadv, + &vs->post_fn, v9fs_read_post_preadv); } return; } else if (vs->fidp->fid_type == P9_FID_XATTR) { v9fs_xattr_read(s, vs); return; } else { - err = -EINVAL; + vs->err = -EINVAL; } out: - complete_pdu(s, pdu, err); + complete_pdu(s, pdu, vs->err); qemu_free(vs); } diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 74d7b68..fcea434 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -325,6 +325,11 @@ typedef struct V9fsReadState { int32_t len; int32_t cnt; int32_t max_count; + V9fsState *s; + int err; + int v9fs_errno; + ThreadletWork work; + void (*post_fn)(void *arg); } V9fsReadState; typedef struct V9fsWriteState {