From patchwork Wed Oct 13 17:10:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Bharadwaj X-Patchwork-Id: 67712 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 5F75D1007D2 for ; Thu, 14 Oct 2010 04:20:07 +1100 (EST) Received: from localhost ([127.0.0.1]:36589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P64zk-0008Cc-CV for incoming@patchwork.ozlabs.org; Wed, 13 Oct 2010 13:20:04 -0400 Received: from [140.186.70.92] (port=57324 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P64qH-0002I3-Sk for qemu-devel@nongnu.org; Wed, 13 Oct 2010 13:10:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P64qF-0005Tr-Fs for qemu-devel@nongnu.org; Wed, 13 Oct 2010 13:10:17 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:42125) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P64qE-0005TH-Vo for qemu-devel@nongnu.org; Wed, 13 Oct 2010 13:10:15 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp06.au.ibm.com (8.14.4/8.13.1) with ESMTP id o9DHA9Vw012954 for ; Thu, 14 Oct 2010 04:10:09 +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 o9DHADnC2003102 for ; Thu, 14 Oct 2010 04:10:13 +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 o9DHADW8030684 for ; Thu, 14 Oct 2010 04:10:13 +1100 Received: from localhost6.localdomain6 ([9.77.203.166]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9DHAAfC030655 for ; Thu, 14 Oct 2010 04:10:11 +1100 To: qemu-devel@nongnu.org From: Arun R Bharadwaj Date: Wed, 13 Oct 2010 22:40:07 +0530 Message-ID: <20101013171007.23885.42851.stgit@localhost6.localdomain6> In-Reply-To: <20101013165321.23885.81012.stgit@localhost6.localdomain6> References: <20101013165321.23885.81012.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 4/6] This patch converts v9fs_write() 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_write onto the helper threads belonging to the threadlets infrastructure. The handling of the v9fs_post_*write* calls is done from the io-thread context. Signed-off-by: Gautham R Shenoy Signed-off-by: Arun R Bharadwaj --- hw/virtio-9p.c | 63 ++++++++++++++++++++++++++++---------------------------- hw/virtio-9p.h | 5 ++++ 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index da185c3..5fb7dc4 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -2459,37 +2459,41 @@ out: return; } -static void v9fs_write_post_pwritev(V9fsState *s, V9fsWriteState *vs, - ssize_t err) +/************************ v9fs_write calls ************************/ + +static void v9fs_write_do_pwritev(ThreadletWork *work) +{ + V9fsWriteState *vs; + + vs = container_of(work, V9fsWriteState, work); + v9fs_do_pwritev(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_write_post_pwritev(void *opaque) { - if (err < 0) { + V9fsWriteState *vs = (V9fsWriteState *)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_pwritev(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_write_post_pwritev(s, vs, err); + v9fs_do_async_posix(&vs->work, v9fs_write_do_pwritev, &vs->post_fn, + v9fs_write_post_pwritev); return; } vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total); - 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); } @@ -2539,7 +2543,6 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu) { int32_t fid; V9fsWriteState *vs; - ssize_t err; vs = qemu_malloc(sizeof(*vs)); @@ -2548,19 +2551,20 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu) vs->sg = vs->iov; vs->total = 0; vs->len = 0; + vs->s = s; pdu_unmarshal(vs->pdu, vs->offset, "dqdv", &fid, &vs->off, &vs->count, vs->sg, &vs->cnt); vs->fidp = lookup_fid(s, fid); if (vs->fidp == NULL) { - err = -EINVAL; + vs->err = -EINVAL; goto out; } if (vs->fidp->fid_type == P9_FID_FILE) { if (vs->fidp->fs.fd == -1) { - err = -EINVAL; + vs->err = -EINVAL; goto out; } } else if (vs->fidp->fid_type == P9_FID_XATTR) { @@ -2570,21 +2574,18 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu) v9fs_xattr_write(s, vs); return; } else { - err = -EINVAL; + vs->err = -EINVAL; goto out; } vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt); if (vs->total <= vs->count) { - vs->len = v9fs_do_pwritev(s, vs->fidp->fs.fd, vs->sg, vs->cnt, vs->off); - if (vs->len > 0) { - vs->off += vs->len; - } - err = vs->len; - v9fs_write_post_pwritev(s, vs, err); + vs->err = vs->len; + v9fs_do_async_posix(&vs->work, v9fs_write_do_pwritev, &vs->post_fn, + v9fs_write_post_pwritev); } return; out: - complete_pdu(s, vs->pdu, err); + complete_pdu(vs->s, vs->pdu, vs->err); qemu_free(vs); } diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index fcea434..be87d5f 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -343,6 +343,11 @@ typedef struct V9fsWriteState { struct iovec iov[128]; /* FIXME: bad, bad, bad */ struct iovec *sg; int cnt; + V9fsState *s; + int err; + int v9fs_errno; + ThreadletWork work; + void (*post_fn)(void *arg); } V9fsWriteState; typedef struct V9fsRemoveState {