All of lore.kernel.org
 help / color / mirror / Atom feed
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 25/29] hw/9pfs: Update v9fs_wstat to use coroutines
Date: Wed, 25 May 2011 16:53:13 -0700	[thread overview]
Message-ID: <1306367597-797-26-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 |  265 ++++++++++++--------------------------------------
 hw/9pfs/virtio-9p.h |   10 --
 2 files changed, 64 insertions(+), 211 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c4e9efb..b378fc8 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -103,40 +103,6 @@ static int v9fs_do_preadv(V9fsState *s, int fd, const struct iovec *iov,
     return s->ops->preadv(&s->ctx, fd, iov, iovcnt, offset);
 }
 
-static int v9fs_do_chmod(V9fsState *s, V9fsString *path, mode_t mode)
-{
-    FsCred cred;
-    cred_init(&cred);
-    cred.fc_mode = mode;
-    return s->ops->chmod(&s->ctx, path->data, &cred);
-}
-
-static int v9fs_do_truncate(V9fsState *s, V9fsString *path, off_t size)
-{
-    return s->ops->truncate(&s->ctx, path->data, size);
-}
-
-static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
-{
-    FsCred cred;
-    cred_init(&cred);
-    cred.fc_uid = uid;
-    cred.fc_gid = gid;
-
-    return s->ops->chown(&s->ctx, path->data, &cred);
-}
-
-static int v9fs_do_utimensat(V9fsState *s, V9fsString *path,
-                                           const struct timespec times[2])
-{
-    return s->ops->utimensat(&s->ctx, path->data, times);
-}
-
-static int v9fs_do_fsync(V9fsState *s, int fd, int datasync)
-{
-    return s->ops->fsync(&s->ctx, fd, datasync);
-}
-
 static void v9fs_string_init(V9fsString *str)
 {
     str->data = NULL;
@@ -2183,39 +2149,6 @@ out:
     complete_pdu(pdu->s, pdu, err);
 }
 
-static void v9fs_wstat_post_truncate(V9fsState *s, V9fsWstatState *vs, int err)
-{
-    if (err < 0) {
-        goto out;
-    }
-
-    err = vs->offset;
-
-out:
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
-static void v9fs_wstat_post_rename(V9fsState *s, V9fsWstatState *vs, int err)
-{
-    if (err < 0) {
-        goto out;
-    }
-    if (vs->v9stat.length != -1) {
-        if (v9fs_do_truncate(s, &vs->fidp->path, vs->v9stat.length) < 0) {
-            err = -errno;
-        }
-    }
-    v9fs_wstat_post_truncate(s, vs, err);
-    return;
-
-out:
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
 static int v9fs_complete_rename(V9fsState *s, V9fsFidState *fidp,
                                 int32_t newdirfid, V9fsString *name)
 {
@@ -2284,24 +2217,6 @@ out:
     return err;
 }
 
-static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
-{
-    if (err < 0) {
-        goto out;
-    }
-
-    if (vs->v9stat.name.size != 0) {
-        err = v9fs_complete_rename(s, vs->fidp, -1, &vs->v9stat.name);
-    }
-    v9fs_wstat_post_rename(s, vs, err);
-    return;
-
-out:
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
 static void v9fs_rename(void *opaque)
 {
     int32_t fid;
@@ -2333,143 +2248,91 @@ out:
     v9fs_string_free(&name);
 }
 
-static void v9fs_wstat_post_utime(V9fsState *s, V9fsWstatState *vs, int err)
+static void v9fs_wstat(void *opaque)
 {
-    if (err < 0) {
-        goto out;
-    }
-
-    if (vs->v9stat.n_gid != -1 || vs->v9stat.n_uid != -1) {
-        if (v9fs_do_chown(s, &vs->fidp->path, vs->v9stat.n_uid,
-                    vs->v9stat.n_gid)) {
-            err = -errno;
-        }
-    }
-    v9fs_wstat_post_chown(s, vs, err);
-    return;
+    int32_t fid;
+    int err = 0;
+    int16_t unused;
+    V9fsStat v9stat;
+    size_t offset = 7;
+    struct stat stbuf;
+    V9fsFidState *fidp;
+    V9fsPDU *pdu = opaque;
+    V9fsState *s = pdu->s;
 
-out:
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
+    pdu_unmarshal(pdu, offset, "dwS", &fid, &unused, &v9stat);
 
-static void v9fs_wstat_post_chmod(V9fsState *s, V9fsWstatState *vs, int err)
-{
-    if (err < 0) {
+    fidp = lookup_fid(s, fid);
+    if (fidp == NULL) {
+        err = -EINVAL;
         goto out;
     }
-
-    if (vs->v9stat.mtime != -1 || vs->v9stat.atime != -1) {
+    /* do we need to sync the file? */
+    if (donttouch_stat(&v9stat)) {
+        err = v9fs_co_fsync(s, fidp, 0);
+        goto out;
+    }
+    if (v9stat.mode != -1) {
+        uint32_t v9_mode;
+        err = v9fs_co_lstat(s, &fidp->path, &stbuf);
+        if (err < 0) {
+            goto out;
+        }
+        v9_mode = stat_to_v9mode(&stbuf);
+        if ((v9stat.mode & P9_STAT_MODE_TYPE_BITS) !=
+            (v9_mode & P9_STAT_MODE_TYPE_BITS)) {
+            /* Attempting to change the type */
+            err = -EIO;
+            goto out;
+        }
+        err = v9fs_co_chmod(s, &fidp->path,
+                            v9mode_to_mode(v9stat.mode,
+                                           &v9stat.extension));
+        if (err < 0) {
+            goto out;
+        }
+    }
+    if (v9stat.mtime != -1 || v9stat.atime != -1) {
         struct timespec times[2];
-        if (vs->v9stat.atime != -1) {
-            times[0].tv_sec = vs->v9stat.atime;
+        if (v9stat.atime != -1) {
+            times[0].tv_sec = v9stat.atime;
             times[0].tv_nsec = 0;
         } else {
             times[0].tv_nsec = UTIME_OMIT;
         }
-        if (vs->v9stat.mtime != -1) {
-            times[1].tv_sec = vs->v9stat.mtime;
+        if (v9stat.mtime != -1) {
+            times[1].tv_sec = v9stat.mtime;
             times[1].tv_nsec = 0;
         } else {
             times[1].tv_nsec = UTIME_OMIT;
         }
-
-        if (v9fs_do_utimensat(s, &vs->fidp->path, times)) {
-            err = -errno;
+        err = v9fs_co_utimensat(s, &fidp->path, times);
+        if (err < 0) {
+            goto out;
         }
     }
-
-    v9fs_wstat_post_utime(s, vs, err);
-    return;
-
-out:
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
-static void v9fs_wstat_post_fsync(V9fsState *s, V9fsWstatState *vs, int err)
-{
-    if (err == -1) {
-        err = -errno;
-    }
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
-static void v9fs_wstat_post_lstat(V9fsState *s, V9fsWstatState *vs, int err)
-{
-    uint32_t v9_mode;
-
-    if (err == -1) {
-        err = -errno;
-        goto out;
-    }
-
-    v9_mode = stat_to_v9mode(&vs->stbuf);
-
-    if ((vs->v9stat.mode & P9_STAT_MODE_TYPE_BITS) !=
-        (v9_mode & P9_STAT_MODE_TYPE_BITS)) {
-            /* Attempting to change the type */
-            err = -EIO;
+    if (v9stat.n_gid != -1 || v9stat.n_uid != -1) {
+        err = v9fs_co_chown(s, &fidp->path, v9stat.n_uid, v9stat.n_gid);
+        if (err < 0) {
             goto out;
+        }
     }
-
-    if (v9fs_do_chmod(s, &vs->fidp->path, v9mode_to_mode(vs->v9stat.mode,
-                    &vs->v9stat.extension))) {
-            err = -errno;
-     }
-    v9fs_wstat_post_chmod(s, vs, err);
-    return;
-
-out:
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
-}
-
-static void v9fs_wstat(void *opaque)
-{
-    V9fsPDU *pdu = opaque;
-    V9fsState *s = pdu->s;
-    int32_t fid;
-    V9fsWstatState *vs;
-    int err = 0;
-
-    vs = qemu_malloc(sizeof(*vs));
-    vs->pdu = pdu;
-    vs->offset = 7;
-
-    pdu_unmarshal(pdu, vs->offset, "dwS", &fid, &vs->unused, &vs->v9stat);
-
-    vs->fidp = lookup_fid(s, fid);
-    if (vs->fidp == NULL) {
-        err = -EINVAL;
-        goto out;
-    }
-
-    /* do we need to sync the file? */
-    if (donttouch_stat(&vs->v9stat)) {
-        err = v9fs_do_fsync(s, vs->fidp->fs.fd, 0);
-        v9fs_wstat_post_fsync(s, vs, err);
-        return;
+    if (v9stat.name.size != 0) {
+        err = v9fs_complete_rename(s, fidp, -1, &v9stat.name);
+        if (err < 0) {
+            goto out;
+        }
     }
-
-    if (vs->v9stat.mode != -1) {
-        err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
-        v9fs_wstat_post_lstat(s, vs, err);
-        return;
+    if (v9stat.length != -1) {
+        err = v9fs_co_truncate(s, &fidp->path, v9stat.length);
+        if (err < 0) {
+            goto out;
+        }
     }
-
-    v9fs_wstat_post_chmod(s, vs, err);
-    return;
-
+    err = offset;
 out:
-    v9fs_stat_free(&vs->v9stat);
-    complete_pdu(s, vs->pdu, err);
-    qemu_free(vs);
+    v9fs_stat_free(&v9stat);
+    complete_pdu(s, pdu, err);
 }
 
 static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 29f3184..1d8c1b1 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -295,16 +295,6 @@ typedef struct V9fsWriteState {
     int cnt;
 } V9fsWriteState;
 
-typedef struct V9fsWstatState
-{
-    V9fsPDU *pdu;
-    size_t offset;
-    int16_t unused;
-    V9fsStat v9stat;
-    V9fsFidState *fidp;
-    struct stat stbuf;
-} V9fsWstatState;
-
 typedef struct V9fsIattr
 {
     int32_t valid;
-- 
1.7.1

  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 ` [Qemu-devel] [PATCH 12/29] hw/9pfs: Update v9fs_walk " Venkateswararao Jujjuri (JV)
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 ` Venkateswararao Jujjuri (JV) [this message]
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-26-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.