From patchwork Wed May 25 23:53:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jvrao X-Patchwork-Id: 97457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0120BB6F94 for ; Thu, 26 May 2011 09:57:01 +1000 (EST) Received: from localhost ([::1]:57965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNwg-0007Bm-EH for incoming@patchwork.ozlabs.org; Wed, 25 May 2011 19:56:58 -0400 Received: from eggs.gnu.org ([140.186.70.92]:49018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNtT-00084v-Jz for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPNtQ-0007Uy-KG for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:39 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:41321) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPNtQ-0007Ug-DT for qemu-devel@nongnu.org; Wed, 25 May 2011 19:53:36 -0400 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by e37.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p4PNobWJ028825 for ; Wed, 25 May 2011 17:50:37 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4PNrTl3351330 for ; Wed, 25 May 2011 17:53:29 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4PHr2th018383 for ; Wed, 25 May 2011 11:53:02 -0600 Received: from oc6675851006.ibm.com (dyn9041079012.austin.ibm.com [9.41.79.12]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p4PHqwLj018178; Wed, 25 May 2011 11:53:02 -0600 From: "Venkateswararao Jujjuri (JV)" To: qemu-devel@nongnu.org Date: Wed, 25 May 2011 16:53:00 -0700 Message-Id: <1306367597-797-13-git-send-email-jvrao@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1306367597-797-1-git-send-email-jvrao@linux.vnet.ibm.com> References: <1306367597-797-1-git-send-email-jvrao@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.110.158 Cc: "Venkateswararao Jujjuri \"" , stefanha@linux.vnet.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH 12/29] hw/9pfs: Update v9fs_walk to use coroutines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Aneesh Kumar K.V Signed-off-by: Aneesh Kumar K.V Signed-off-by: Venkateswararao Jujjuri " --- hw/9pfs/virtio-9p.c | 205 +++++++++++++++++---------------------------------- hw/9pfs/virtio-9p.h | 13 --- 2 files changed, 68 insertions(+), 150 deletions(-) diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index fea9de4..1eb32f6 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -1328,171 +1328,102 @@ out: complete_pdu(s, pdu, err); } -static void v9fs_walk_complete(V9fsState *s, V9fsWalkState *vs, int err) -{ - complete_pdu(s, vs->pdu, err); - - if (vs->nwnames && vs->nwnames <= P9_MAXWELEM) { - for (vs->name_idx = 0; vs->name_idx < vs->nwnames; vs->name_idx++) { - v9fs_string_free(&vs->wnames[vs->name_idx]); - } - - qemu_free(vs->wnames); - qemu_free(vs->qids); - } -} - -static void v9fs_walk_marshal(V9fsWalkState *vs) +static int v9fs_walk_marshal(V9fsPDU *pdu, uint16_t nwnames, V9fsQID *qids) { int i; - vs->offset = 7; - vs->offset += pdu_marshal(vs->pdu, vs->offset, "w", vs->nwnames); - - for (i = 0; i < vs->nwnames; i++) { - vs->offset += pdu_marshal(vs->pdu, vs->offset, "Q", &vs->qids[i]); - } -} - -static void v9fs_walk_post_newfid_lstat(V9fsState *s, V9fsWalkState *vs, - int err) -{ - if (err == -1) { - free_fid(s, vs->newfidp->fid); - v9fs_string_free(&vs->path); - err = -ENOENT; - goto out; - } - - stat_to_qid(&vs->stbuf, &vs->qids[vs->name_idx]); - - vs->name_idx++; - if (vs->name_idx < vs->nwnames) { - v9fs_string_sprintf(&vs->path, "%s/%s", vs->newfidp->path.data, - vs->wnames[vs->name_idx].data); - v9fs_string_copy(&vs->newfidp->path, &vs->path); - - err = v9fs_do_lstat(s, &vs->newfidp->path, &vs->stbuf); - v9fs_walk_post_newfid_lstat(s, vs, err); - return; + size_t offset = 7; + offset += pdu_marshal(pdu, offset, "w", nwnames); + for (i = 0; i < nwnames; i++) { + offset += pdu_marshal(pdu, offset, "Q", &qids[i]); } - - v9fs_string_free(&vs->path); - v9fs_walk_marshal(vs); - err = vs->offset; -out: - v9fs_walk_complete(s, vs, err); -} - -static void v9fs_walk_post_oldfid_lstat(V9fsState *s, V9fsWalkState *vs, - int err) -{ - if (err == -1) { - v9fs_string_free(&vs->path); - err = -ENOENT; - goto out; - } - - stat_to_qid(&vs->stbuf, &vs->qids[vs->name_idx]); - vs->name_idx++; - if (vs->name_idx < vs->nwnames) { - - v9fs_string_sprintf(&vs->path, "%s/%s", - vs->fidp->path.data, vs->wnames[vs->name_idx].data); - v9fs_string_copy(&vs->fidp->path, &vs->path); - - err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf); - v9fs_walk_post_oldfid_lstat(s, vs, err); - return; - } - - v9fs_string_free(&vs->path); - v9fs_walk_marshal(vs); - err = vs->offset; -out: - v9fs_walk_complete(s, vs, err); + return offset; } static void v9fs_walk(void *opaque) { + int name_idx; + V9fsQID *qids = NULL; + int i, err = 0; + V9fsString path; + uint16_t nwnames; + struct stat stbuf; + size_t offset = 7; + int32_t fid, newfid; + V9fsString *wnames = NULL; + V9fsFidState *fidp; + V9fsFidState *newfidp; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; - int32_t fid, newfid; - V9fsWalkState *vs; - int err = 0; - int i; - vs = qemu_malloc(sizeof(*vs)); - vs->pdu = pdu; - vs->wnames = NULL; - vs->qids = NULL; - vs->offset = 7; - - vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "ddw", &fid, - &newfid, &vs->nwnames); - - if (vs->nwnames && vs->nwnames <= P9_MAXWELEM) { - vs->wnames = qemu_mallocz(sizeof(vs->wnames[0]) * vs->nwnames); + offset += pdu_unmarshal(pdu, offset, "ddw", &fid, + &newfid, &nwnames); - vs->qids = qemu_mallocz(sizeof(vs->qids[0]) * vs->nwnames); + if (nwnames && nwnames <= P9_MAXWELEM) { + wnames = qemu_mallocz(sizeof(wnames[0]) * nwnames); + qids = qemu_mallocz(sizeof(qids[0]) * nwnames); - for (i = 0; i < vs->nwnames; i++) { - vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "s", - &vs->wnames[i]); + for (i = 0; i < nwnames; i++) { + offset += pdu_unmarshal(pdu, offset, "s", &wnames[i]); } - } else if (vs->nwnames > P9_MAXWELEM) { + + } else if (nwnames > P9_MAXWELEM) { err = -EINVAL; goto out; } - - vs->fidp = lookup_fid(s, fid); - if (vs->fidp == NULL) { + fidp = lookup_fid(s, fid); + if (fidp == NULL) { err = -ENOENT; goto out; } - - /* FIXME: is this really valid? */ if (fid == newfid) { - - BUG_ON(vs->fidp->fid_type != P9_FID_NONE); - v9fs_string_init(&vs->path); - vs->name_idx = 0; - - if (vs->name_idx < vs->nwnames) { - v9fs_string_sprintf(&vs->path, "%s/%s", - vs->fidp->path.data, vs->wnames[vs->name_idx].data); - v9fs_string_copy(&vs->fidp->path, &vs->path); - - err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf); - v9fs_walk_post_oldfid_lstat(s, vs, err); - return; + BUG_ON(fidp->fid_type != P9_FID_NONE); + v9fs_string_init(&path); + for (name_idx = 0; name_idx < nwnames; name_idx++) { + v9fs_string_sprintf(&path, "%s/%s", + fidp->path.data, wnames[name_idx].data); + v9fs_string_copy(&fidp->path, &path); + + err = v9fs_co_lstat(s, &fidp->path, &stbuf); + if (err < 0) { + v9fs_string_free(&path); + goto out; + } + stat_to_qid(&stbuf, &qids[name_idx]); } + v9fs_string_free(&path); } else { - vs->newfidp = alloc_fid(s, newfid); - if (vs->newfidp == NULL) { + newfidp = alloc_fid(s, newfid); + if (newfidp == NULL) { err = -EINVAL; goto out; } - - vs->newfidp->uid = vs->fidp->uid; - v9fs_string_init(&vs->path); - vs->name_idx = 0; - v9fs_string_copy(&vs->newfidp->path, &vs->fidp->path); - - if (vs->name_idx < vs->nwnames) { - v9fs_string_sprintf(&vs->path, "%s/%s", vs->newfidp->path.data, - vs->wnames[vs->name_idx].data); - v9fs_string_copy(&vs->newfidp->path, &vs->path); - - err = v9fs_do_lstat(s, &vs->newfidp->path, &vs->stbuf); - v9fs_walk_post_newfid_lstat(s, vs, err); - return; + newfidp->uid = fidp->uid; + v9fs_string_init(&path); + v9fs_string_copy(&newfidp->path, &fidp->path); + for (name_idx = 0; name_idx < nwnames; name_idx++) { + v9fs_string_sprintf(&path, "%s/%s", newfidp->path.data, + wnames[name_idx].data); + v9fs_string_copy(&newfidp->path, &path); + err = v9fs_co_lstat(s, &newfidp->path, &stbuf); + if (err < 0) { + free_fid(s, newfidp->fid); + v9fs_string_free(&path); + goto out; + } + stat_to_qid(&stbuf, &qids[name_idx]); } + v9fs_string_free(&path); } - - v9fs_walk_marshal(vs); - err = vs->offset; + err = v9fs_walk_marshal(pdu, nwnames, qids); out: - v9fs_walk_complete(s, vs, err); + complete_pdu(s, pdu, err); + if (nwnames && nwnames <= P9_MAXWELEM) { + for (name_idx = 0; name_idx < nwnames; name_idx++) { + v9fs_string_free(&wnames[name_idx]); + } + qemu_free(wnames); + qemu_free(qids); + } } static int32_t get_iounit(V9fsState *s, V9fsString *name) diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 97ceb72..3b585f0 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -267,19 +267,6 @@ typedef struct V9fsStatDotl { uint64_t st_data_version; } V9fsStatDotl; -typedef struct V9fsWalkState { - V9fsPDU *pdu; - size_t offset; - uint16_t nwnames; - int name_idx; - V9fsQID *qids; - V9fsFidState *fidp; - V9fsFidState *newfidp; - V9fsString path; - V9fsString *wnames; - struct stat stbuf; -} V9fsWalkState; - typedef struct V9fsOpenState { V9fsPDU *pdu; size_t offset;