From: "Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Venkateswararao Jujjuri \"" <jvrao@linux.vnet.ibm.com>,
stefanha@linux.vnet.ibm.com,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 12/29] hw/9pfs: Update v9fs_walk to use coroutines
Date: Wed, 25 May 2011 16:53:00 -0700 [thread overview]
Message-ID: <1306367597-797-13-git-send-email-jvrao@linux.vnet.ibm.com> (raw)
In-Reply-To: <1306367597-797-1-git-send-email-jvrao@linux.vnet.ibm.com>
From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri "<jvrao@linux.vnet.ibm.com>
---
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;
--
1.7.1
next prev parent reply other threads:[~2011-05-25 23:53 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-25 23:52 [Qemu-devel] [0/29] Second batch of VirtFS routines converted to coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 01/29] hw/9pfs: Add yeild support to rename coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 02/29] hw/9pfs: Update vfs_rename to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 03/29] hw/9pfs: Add yeild support for fstat coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 04/29] hw/9pfs: Update v9fs_lock to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 05/29] hw/9pfs: Update v9fs_getlock " Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 06/29] hw/9pfs: Add yield support for open and opendir coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 07/29] hw/9pfs: Update v9fs_open to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 08/29] [virtio-9p] Remove post functions for v9fs_lcreate Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 09/29] [virtio-9p] clean up v9fs_lcreate Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 10/29] [PATCH] [virtio-9p] coroutine and threading for open2 Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 11/29] hw/9pfs: Update v9fs_stat to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` Venkateswararao Jujjuri (JV) [this message]
2011-05-25 23:53 ` [Qemu-devel] [PATCH 13/29] hw/9pfs: Add yeild support for clunk related coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 14/29] hw/9pfs: Update v9fs_clunk to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 15/29] hw/9pfs: Add yield support for fsync coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 16/29] hw/9pfs: Update v9fs_fsync to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 17/29] [virtio-9p] Remove post functions for v9fs_create Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 18/29] [virtio-9p] clean up v9fs_create Rearrange the code Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 19/29] [virtio-9p] Remove post functions for v9fs_symlink Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 20/29] [virtio-9p] clean up v9fs_symlink Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 21/29] [virtio-9p] coroutine and threading for v9fs_do_symlink Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 22/29] [virtio-9p] coroutine and threading for v9fs_do_link Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 23/29] hw/9pfs: Add yield support for pwritev coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 24/29] hw/9pfs: Update v9fs_write to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 25/29] hw/9pfs: Update v9fs_wstat " Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 26/29] hw/9pfs: Update v9fs_attach " Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 27/29] hw/9pfs: Add yield support for preadv coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 28/29] hw/9pfs: Update v9fs_read to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 29/29] use readdir_r instead of readdir for reentrancy Venkateswararao Jujjuri (JV)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1306367597-797-13-git-send-email-jvrao@linux.vnet.ibm.com \
--to=jvrao@linux.vnet.ibm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).