qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Arun R Bharadwaj <arun@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 6/9] Convert open into 2nd threading model
Date: Thu, 14 Oct 2010 17:54:50 +0530	[thread overview]
Message-ID: <20101014122450.2238.90057.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20101014122217.2238.94995.stgit@localhost6.localdomain6>

From: Sripathi Kodi <sripathik@in.ibm.com>

Signed-off-by: Sripathi Kodi <sripathik@in.ibm.com>
---
 hw/virtio-9p.c |  115 +++++++++++++++++++++++---------------------------------
 hw/virtio-9p.h |    4 ++
 2 files changed, 51 insertions(+), 68 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 1f2fd9f..cad21fd 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1797,6 +1797,13 @@ out:
     v9fs_walk_complete(s, vs, err);
 }
 
+static void v9fs_open_do_complete(void *opaque)
+{
+    V9fsOpenState *vs = (V9fsOpenState *)opaque;
+    complete_pdu(vs->s, vs->pdu, vs->err);
+    qemu_free(vs);
+}
+
 static int32_t get_iounit(V9fsState *s, V9fsString *name)
 {
     struct statfs stbuf;
@@ -1817,61 +1824,37 @@ static int32_t get_iounit(V9fsState *s, V9fsString *name)
     return iounit;
 }
 
-static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err)
-{
-    if (vs->fidp->fs.dir == NULL) {
-        err = -errno;
-        goto out;
-    }
-    vs->fidp->fid_type = P9_FID_DIR;
-    vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
-    err = vs->offset;
-out:
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-
-}
-
-static void v9fs_open_post_getiounit(V9fsState *s, V9fsOpenState *vs)
-{
-    int err;
-    vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, vs->iounit);
-    err = vs->offset;
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
-static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
+static void v9fs_open_worker(ThreadletWork *work)
 {
-    if (vs->fidp->fs.fd == -1) {
-        err = -errno;
+    int flags;
+    V9fsOpenState *vs = container_of(work, V9fsOpenState, work);
+    vs->fidp = lookup_fid(vs->s, vs->fid);
+    if (vs->fidp == NULL) {
+        vs->err = -ENOENT;
         goto out;
     }
-    vs->fidp->fid_type = P9_FID_FILE;
-    vs->iounit = get_iounit(s, &vs->fidp->path);
-    v9fs_open_post_getiounit(s, vs);
-    return;
-out:
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
-static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
-{
-    int flags;
-
-    if (err) {
-        err = -errno;
+    BUG_ON(vs->fidp->fid_type != P9_FID_NONE);
+    qemu_rwmutex_rdlock(&global_rename_lock);
+    vs->err = v9fs_do_lstat(vs->s, &vs->fidp->path, &vs->stbuf);
+    if (vs->err) {
+        vs->err = -errno;
         goto out;
     }
 
     stat_to_qid(&vs->stbuf, &vs->qid);
 
     if (S_ISDIR(vs->stbuf.st_mode)) {
-        vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fidp->path);
-        v9fs_open_post_opendir(s, vs, err);
+        vs->fidp->fs.dir = v9fs_do_opendir(vs->s, &vs->fidp->path);
+
+        if (vs->fidp->fs.dir == NULL) {
+            vs->err = -errno;
+            goto out;
+        }
+        vs->fidp->fid_type = P9_FID_DIR;
+        vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
+        vs->err = vs->offset;
     } else {
-        if (s->proto_version == V9FS_PROTO_2000L) {
+        if (vs->s->proto_version == V9FS_PROTO_2000L) {
             flags = vs->mode;
             flags &= ~(O_NOCTTY | O_ASYNC | O_CREAT);
             /* Ignore direct disk access hint until the server supports it. */
@@ -1879,47 +1862,43 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
         } else {
             flags = omode_to_uflags(vs->mode);
         }
-        vs->fidp->fs.fd = v9fs_do_open(s, &vs->fidp->path, flags);
-        v9fs_open_post_open(s, vs, err);
+        vs->fidp->fs.fd = v9fs_do_open(vs->s, &vs->fidp->path, flags);
+
+        if (vs->fidp->fs.fd == -1) {
+            vs->err = -errno;
+            goto out;
+        }
+        vs->fidp->fid_type = P9_FID_FILE;
+        vs->iounit = get_iounit(vs->s, &vs->fidp->path);
+        vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid,
+                                                          vs->iounit);
+        vs->err = vs->offset;
     }
-    return;
 out:
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
+    qemu_rwmutex_unlock(&global_rename_lock);
+    v9fs_async_helper_done(v9fs_open_do_complete, vs);
 }
 
 static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
 {
-    int32_t fid;
     V9fsOpenState *vs;
-    ssize_t err = 0;
 
     vs = qemu_malloc(sizeof(*vs));
     vs->pdu = pdu;
     vs->offset = 7;
     vs->mode = 0;
+    vs->err = 0;
+    vs->s = s;
 
     if (s->proto_version == V9FS_PROTO_2000L) {
-        pdu_unmarshal(vs->pdu, vs->offset, "dd", &fid, &vs->mode);
+        pdu_unmarshal(vs->pdu, vs->offset, "dd", &vs->fid, &vs->mode);
     } else {
-        pdu_unmarshal(vs->pdu, vs->offset, "db", &fid, &vs->mode);
+        pdu_unmarshal(vs->pdu, vs->offset, "db", &vs->fid, &vs->mode);
     }
 
-    vs->fidp = lookup_fid(s, fid);
-    if (vs->fidp == NULL) {
-        err = -ENOENT;
-        goto out;
-    }
-
-    BUG_ON(vs->fidp->fid_type != P9_FID_NONE);
-
-    err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
-
-    v9fs_open_post_lstat(s, vs, err);
+    vs->work.func = v9fs_open_worker;
+    submit_threadlet(&vs->work);
     return;
-out:
-    complete_pdu(s, pdu, err);
-    qemu_free(vs);
 }
 
 static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err)
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 59f7a4e..1581bbe 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -306,6 +306,10 @@ typedef struct V9fsOpenState {
     V9fsQID qid;
     struct stat stbuf;
     int iounit;
+    V9fsState *s;
+    int32_t fid;
+    int32_t err;
+    ThreadletWork work;
 } V9fsOpenState;
 
 typedef struct V9fsReadState {

  parent reply	other threads:[~2010-10-14 12:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-14 12:23 [Qemu-devel] [RFC PATCH 0/9] Second threading model Arun R Bharadwaj
2010-10-14 12:23 ` [Qemu-devel] [PATCH 1/9] Add read-write lock to QEMU Arun R Bharadwaj
2010-10-14 12:23 ` [Qemu-devel] [PATCH 2/9] Introduce lock fid_list_lock to protect the fid list Arun R Bharadwaj
2010-10-14 12:24 ` [Qemu-devel] [PATCH 3/9] Global rename lock Arun R Bharadwaj
2010-10-14 12:24 ` [Qemu-devel] [PATCH 4/9] Convert stat into 2nd threading model Arun R Bharadwaj
2010-10-14 12:24 ` [Qemu-devel] [PATCH 5/9] Convert wstat " Arun R Bharadwaj
2010-10-14 12:24 ` Arun R Bharadwaj [this message]
2010-10-14 12:25 ` [Qemu-devel] [PATCH 7/9] Convert walk " Arun R Bharadwaj
2010-10-14 12:25 ` [Qemu-devel] [PATCH 8/9] Convert read " Arun R Bharadwaj
2010-10-14 12:25 ` [Qemu-devel] [PATCH 9/9] Convert write " Arun R Bharadwaj

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=20101014122450.2238.90057.stgit@localhost6.localdomain6 \
    --to=arun@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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).