From patchwork Mon May 24 12:53:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautham R Shenoy X-Patchwork-Id: 53416 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 CCE38B7D12 for ; Mon, 24 May 2010 23:00:16 +1000 (EST) Received: from localhost ([127.0.0.1]:42524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGXGQ-0000Uk-2u for incoming@patchwork.ozlabs.org; Mon, 24 May 2010 09:00:14 -0400 Received: from [140.186.70.92] (port=44459 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGX9r-0004f0-O3 for qemu-devel@nongnu.org; Mon, 24 May 2010 08:53:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGX9m-00072c-5L for qemu-devel@nongnu.org; Mon, 24 May 2010 08:53:27 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:44310) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGX9k-00072Q-VI for qemu-devel@nongnu.org; Mon, 24 May 2010 08:53:22 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp06.au.ibm.com (8.14.3/8.13.1) with ESMTP id o4OCr67s010646 for ; Mon, 24 May 2010 22:53:06 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o4OCrJkN1613866 for ; Mon, 24 May 2010 22:53:19 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o4OCrJjx028228 for ; Mon, 24 May 2010 22:53:19 +1000 Received: from sofia.in.ibm.com ([9.124.35.40]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o4OCrII6028225; Mon, 24 May 2010 22:53:18 +1000 Received: from localhost.localdomain (localhost [IPv6:::1]) by sofia.in.ibm.com (Postfix) with ESMTP id 62B6CE4B35; Mon, 24 May 2010 18:23:18 +0530 (IST) To: Qemu-development List From: Gautham R Shenoy Date: Mon, 24 May 2010 18:23:18 +0530 Message-ID: <20100524125318.29646.59542.stgit@localhost.localdomain> In-Reply-To: <20100524125220.29646.62160.stgit@localhost.localdomain> References: <20100524125220.29646.62160.stgit@localhost.localdomain> User-Agent: StGit/0.15-51-gc750 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Anthony Liguori , Avi Kivity Subject: [Qemu-devel] [RFC/ PATCH 4/4] virtio-9p: convert lstat to use async 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 This patch converts v9fs_stat() to make use of the async infrastructure. Every call to v9fs_stat() is processed in the context of the vcpu thread before offloading the actual stat operation onto an async-thread. The post operation is handled in the context of the io-thread which in turn does the complete() operation for this particular v9fs_stat() operation. Signed-off-by: Gautham R Shenoy --- hw/virtio-9p.c | 34 ++++++++++++++++++++++------------ hw/virtio-9p.h | 4 ++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index f8f60d3..a57fffc 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1218,26 +1218,38 @@ out: v9fs_string_free(&aname); } -static void v9fs_stat_post_lstat(V9fsState *s, V9fsStatState *vs, int err) +static void v9fs_stat_post_lstat(void *opaque) { - if (err == -1) { - err = -errno; + V9fsStatState *vs = (V9fsStatState *)opaque; + + if (vs->err == -1) { + vs->err = -(vs->v9fs_errno); goto out; } - err = stat_to_v9stat(s, &vs->fidp->path, &vs->stbuf, &vs->v9stat); - if (err) { + vs->err = stat_to_v9stat(vs->s, &vs->fidp->path, &vs->stbuf, &vs->v9stat); + if (vs->err) { goto out; } vs->offset += pdu_marshal(vs->pdu, vs->offset, "wS", 0, &vs->v9stat); - err = vs->offset; + vs->err = vs->offset; out: - complete_pdu(s, vs->pdu, err); + complete_pdu(vs->s, vs->pdu, vs->err); v9fs_stat_free(&vs->v9stat); qemu_free(vs); } +static void v9fs_stat_do_lstat(struct work_item *work) +{ + V9fsStatState *vs = (V9fsStatState *)work->private; + + vs->err = v9fs_do_lstat(vs->s, &vs->fidp->path, &vs->stbuf); + vs->v9fs_errno = errno; + + v9fs_async_signal(vs->post_fn, vs); +} + static void v9fs_stat(V9fsState *s, V9fsPDU *pdu) { int32_t fid; @@ -1247,6 +1259,7 @@ static void v9fs_stat(V9fsState *s, V9fsPDU *pdu) vs = qemu_malloc(sizeof(*vs)); vs->pdu = pdu; vs->offset = 7; + vs->s = s; memset(&vs->v9stat, 0, sizeof(vs->v9stat)); @@ -1258,8 +1271,8 @@ static void v9fs_stat(V9fsState *s, V9fsPDU *pdu) goto out; } - err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf); - v9fs_stat_post_lstat(s, vs, err); + v9fs_do_async_posix(vs, v9fs_stat_do_lstat, &vs->post_fn, + v9fs_stat_post_lstat); return; out: @@ -2559,8 +2572,5 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) /* Create async queue. */ async_queue_init(&v9fs_async_struct.virtio_9p_aqueue, 10, 3); - (void)v9fs_do_async_posix; - (void)v9fs_async_signal; - return &s->vdev; } diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 992c765..b4a1d46 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -173,6 +173,10 @@ typedef struct V9fsStatState { V9fsStat v9stat; V9fsFidState *fidp; struct stat stbuf; + V9fsState *s; + int err; + int v9fs_errno; + void (*post_fn)(void *arg); } V9fsStatState; typedef struct V9fsWalkState {