[Qemu-devel] [PATCH 02/29] hw/9pfs: Update vfs_rename to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

I guess TRENAME 9p operation needs an update. The 9p op should
more similar renameat. Otherwise anything other than path cannot track
the fid.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  134 --
 hw/9pfs/virtio-9p.h |9 
 2 files changed, 54 insertions(+), 89 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f5b7f89..42e260d 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -190,12 +190,6 @@ 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_rename(V9fsState *s, V9fsString *oldpath,
-V9fsString *newpath)
-{
-return s-ops-rename(s-ctx, oldpath-data, newpath-data);
-}
-
 static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
 {
 FsCred cred;
@@ -2634,84 +2628,74 @@ out:
 qemu_free(vs);
 }
 
-static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs)
+static int v9fs_complete_rename(V9fsState *s, V9fsFidState *fidp,
+int32_t newdirfid, V9fsString *name)
 {
+char *end;
 int err = 0;
 char *old_name, *new_name;
-char *end;
 
-if (vs-newdirfid != -1) {
+if (newdirfid != -1) {
 V9fsFidState *dirfidp;
-dirfidp = lookup_fid(s, vs-newdirfid);
-
+dirfidp = lookup_fid(s, newdirfid);
 if (dirfidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
 BUG_ON(dirfidp-fid_type != P9_FID_NONE);
 
-new_name = qemu_mallocz(dirfidp-path.size + vs-name.size + 2);
+new_name = qemu_mallocz(dirfidp-path.size + name-size + 2);
 
 strcpy(new_name, dirfidp-path.data);
 strcat(new_name, /);
-strcat(new_name + dirfidp-path.size, vs-name.data);
+strcat(new_name + dirfidp-path.size, name-data);
 } else {
-old_name = vs-fidp-path.data;
+old_name = fidp-path.data;
 end = strrchr(old_name, '/');
 if (end) {
 end++;
 } else {
 end = old_name;
 }
-new_name = qemu_mallocz(end - old_name + vs-name.size + 1);
+new_name = qemu_mallocz(end - old_name + name-size + 1);
 
 strncat(new_name, old_name, end - old_name);
-strncat(new_name + (end - old_name), vs-name.data, vs-name.size);
+strncat(new_name + (end - old_name), name-data, name-size);
 }
 
-v9fs_string_free(vs-name);
-vs-name.data = qemu_strdup(new_name);
-vs-name.size = strlen(new_name);
+v9fs_string_free(name);
+name-data = qemu_strdup(new_name);
+name-size = strlen(new_name);
 
-if (strcmp(new_name, vs-fidp-path.data) != 0) {
-if (v9fs_do_rename(s, vs-fidp-path, vs-name)) {
-err = -errno;
-} else {
-V9fsFidState *fidp;
-/*
-* Fixup fid's pointing to the old name to
-* start pointing to the new name
-*/
-for (fidp = s-fid_list; fidp; fidp = fidp-next) {
-if (vs-fidp == fidp) {
-/*
-* we replace name of this fid towards the end so
-* that our below v9fs_path_is_ancestor check will
-* work
-*/
-continue;
-}
-if (v9fs_path_is_ancestor(vs-fidp-path, fidp-path)) {
-/* replace the name */
-v9fs_fix_path(fidp-path, vs-name,
-  strlen(vs-fidp-path.data));
-}
+if (strcmp(new_name, fidp-path.data) != 0) {
+err = v9fs_co_rename(s, fidp-path, name);
+if (err  0) {
+goto out;
+}
+V9fsFidState *tfidp;
+/*
+ * Fixup fid's pointing to the old name to
+ * start pointing to the new name
+ */
+for (tfidp = s-fid_list; tfidp; tfidp = tfidp-next) {
+if (fidp == tfidp) {
+/*
+ * we replace name of this fid towards the end
+ * so that our below strcmp will work
+ */
+continue;
+}
+if (v9fs_path_is_ancestor(fidp-path, tfidp-path)) {
+/* replace the name */
+v9fs_fix_path(tfidp-path, name, strlen(fidp-path.data));
 }
-v9fs_string_copy(vs-fidp-path, vs-name);
 }
+v9fs_string_copy(fidp-path, name);
 }
 out:
-v9fs_string_free(vs-name);
 return err;
 }
 
-static void v9fs_rename_post_rename(V9fsState *s, V9fsRenameState *vs, int err)
-{
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
 static void v9fs_wstat_post_chown(V9fsState *s

[Qemu-devel] [PATCH 06/29] hw/9pfs: Add yield support for open and opendir coroutine

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/codir.c  |   16 
 hw/9pfs/cofile.c |   16 
 hw/9pfs/virtio-9p-coth.h |2 ++
 3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 28f2ad7..bc6a105 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -83,3 +83,19 @@ int v9fs_co_mkdir(V9fsState *s, char *name, mode_t mode, 
uid_t uid, gid_t gid)
 });
 return err;
 }
+
+int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+fidp-fs.dir = s-ops-opendir(s-ctx, fidp-path.data);
+if (!fidp-fs.dir) {
+err = -errno;
+} else {
+err = 0;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index e400b86..4a3ca21 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -44,3 +44,19 @@ int v9fs_co_fstat(V9fsState *s, int fd, struct stat *stbuf)
 });
 return err;
 }
+
+int v9fs_co_open(V9fsState *s, V9fsFidState *fidp, int flags)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+fidp-fs.fd = s-ops-open(s-ctx, fidp-path.data, flags);
+if (fidp-fs.fd == -1) {
+err = -errno;
+} else {
+err = 0;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 88070d3..1df7063 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -77,4 +77,6 @@ extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, 
gid_t);
 extern int v9fs_co_remove(V9fsState *, V9fsString *);
 extern int v9fs_co_rename(V9fsState *, V9fsString *, V9fsString *);
 extern int v9fs_co_fstat(V9fsState *, int, struct stat *);
+extern int v9fs_co_opendir(V9fsState *, V9fsFidState *);
+extern int v9fs_co_open(V9fsState *, V9fsFidState *, int);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 01/29] hw/9pfs: Add yeild support to rename coroutine

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   14 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 8fbfe73..473ce53 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -155,3 +155,17 @@ int v9fs_co_remove(V9fsState *s, V9fsString *path)
 });
 return err;
 }
+
+int v9fs_co_rename(V9fsState *s, V9fsString *oldpath, V9fsString *newpath)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-rename(s-ctx, oldpath-data, newpath-data);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 60795c4..11272d3 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -75,4 +75,5 @@ extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
  gid_t, dev_t, mode_t);
 extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
 extern int v9fs_co_remove(V9fsState *, V9fsString *);
+extern int v9fs_co_rename(V9fsState *, V9fsString *, V9fsString *);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 05/29] hw/9pfs: Update v9fs_getlock to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   42 +++---
 hw/9pfs/virtio-9p.h |9 -
 2 files changed, 19 insertions(+), 32 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 1729422..e6032cd 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3052,42 +3052,38 @@ out:
  * When a TGETLOCK request comes, always return success because all lock
  * handling is done by client's VFS layer.
  */
-
 static void v9fs_getlock(void *opaque)
 {
+size_t offset = 7;
+struct stat stbuf;
+V9fsFidState *fidp;
+V9fsGetlock *glock;
+int32_t fid, err = 0;
 V9fsPDU *pdu = opaque;
 V9fsState *s = pdu-s;
-int32_t fid, err = 0;
-V9fsGetlockState *vs;
 
-vs = qemu_mallocz(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-vs-glock = qemu_malloc(sizeof(*vs-glock));
-pdu_unmarshal(vs-pdu, vs-offset, dbqqds, fid, vs-glock-type,
-vs-glock-start, vs-glock-length, vs-glock-proc_id,
-   vs-glock-client_id);
+glock = qemu_malloc(sizeof(*glock));
+pdu_unmarshal(pdu, offset, dbqqds, fid, glock-type,
+  glock-start, glock-length, glock-proc_id,
+  glock-client_id);
 
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
-err = v9fs_do_fstat(s, vs-fidp-fs.fd, vs-stbuf);
+err = v9fs_co_fstat(s, fidp-fs.fd, stbuf);
 if (err  0) {
-err = -errno;
 goto out;
 }
-vs-glock-type = F_UNLCK;
-vs-offset += pdu_marshal(vs-pdu, vs-offset, bqqds, vs-glock-type,
-vs-glock-start, vs-glock-length, vs-glock-proc_id,
-   vs-glock-client_id);
+glock-type = F_UNLCK;
+offset += pdu_marshal(pdu, offset, bqqds, glock-type,
+  glock-start, glock-length, glock-proc_id,
+  glock-client_id);
+err = offset;
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs-glock);
-qemu_free(vs);
+complete_pdu(s, pdu, err);
+qemu_free(glock);
 }
 
 static void v9fs_mkdir(void *opaque)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 0c1e3ee..edf3413 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -412,15 +412,6 @@ typedef struct V9fsGetlock
 V9fsString client_id;
 } V9fsGetlock;
 
-typedef struct V9fsGetlockState
-{
-V9fsPDU *pdu;
-size_t offset;
-struct stat stbuf;
-V9fsFidState *fidp;
-V9fsGetlock *glock;
-} V9fsGetlockState;
-
 size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
   size_t offset, size_t size, int pack);
 
-- 
1.7.1




[Qemu-devel] [PATCH 09/29] [virtio-9p] clean up v9fs_lcreate

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsLcreateState
and additional malloc()s.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   63 --
 hw/9pfs/virtio-9p.h |   11 -
 2 files changed, 30 insertions(+), 44 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index a43a58f..49de67c 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1610,63 +1610,60 @@ out:
 
 static void v9fs_lcreate(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int32_t dfid, flags, mode;
 gid_t gid;
-V9fsLcreateState *vs;
 ssize_t err = 0;
+ssize_t offset = 7;
+V9fsString fullname;
+V9fsString name;
+V9fsFidState *fidp;
+struct stat stbuf;
+V9fsQID qid;
+int32_t iounit;
+V9fsPDU *pdu = opaque;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-v9fs_string_init(vs-fullname);
+v9fs_string_init(fullname);
 
-pdu_unmarshal(vs-pdu, vs-offset, dsddd, dfid, vs-name, flags,
-mode, gid);
+pdu_unmarshal(pdu, offset, dsddd, dfid, name, flags,
+  mode, gid);
 
-vs-fidp = lookup_fid(s, dfid);
-if (vs-fidp == NULL) {
+fidp = lookup_fid(pdu-s, dfid);
+if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
 
-v9fs_string_sprintf(vs-fullname, %s/%s, vs-fidp-path.data,
-vs-name.data);
+v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
 
 /* Ignore direct disk access hint until the server supports it. */
 flags = ~O_DIRECT;
 
-vs-fidp-fs.fd = v9fs_do_open2(s, vs-fullname.data, vs-fidp-uid,
-gid, flags, mode);
-if (vs-fidp-fs.fd == -1) {
+fidp-fs.fd = v9fs_do_open2(pdu-s, fullname.data, fidp-uid,
+gid, flags, mode);
+if (fidp-fs.fd == -1) {
 err = -errno;
 goto out;
 }
+fidp-fid_type = P9_FID_FILE;
+iounit =  get_iounit(pdu-s, fullname);
 
-vs-fidp-fid_type = P9_FID_FILE;
-vs-iounit =  get_iounit(s, vs-fullname);
-
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+err = v9fs_do_lstat(pdu-s, fullname, stbuf);
 if (err == 0) {
-v9fs_string_copy(vs-fidp-path, vs-fullname);
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Qd, vs-qid,
-vs-iounit);
-err = vs-offset;
+v9fs_string_copy(fidp-path, fullname);
+stat_to_qid(stbuf, qid);
+offset += pdu_marshal(pdu, offset, Qd, qid, iounit);
+err = offset;
 } else {
-vs-fidp-fid_type = P9_FID_NONE; /*TODO:Why are we keeping this fid?*/
+fidp-fid_type = P9_FID_NONE; /*TODO:Why are we keeping this fid?*/
 err = -errno;
-if (vs-fidp-fs.fd  0) {
-close(vs-fidp-fs.fd);
+if (fidp-fs.fd  0) {
+close(fidp-fs.fd);
 }
 }
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-v9fs_string_free(vs-fullname);
-qemu_free(vs);
+complete_pdu(pdu-s, pdu, err);
+v9fs_string_free(name);
+v9fs_string_free(fullname);
 }
 
 static void v9fs_post_do_fsync(V9fsState *s, V9fsPDU *pdu, int err)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index edf3413..97ceb72 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -236,17 +236,6 @@ typedef struct V9fsCreateState {
 int iounit;
 } V9fsCreateState;
 
-typedef struct V9fsLcreateState {
-V9fsPDU *pdu;
-size_t offset;
-V9fsFidState *fidp;
-V9fsQID qid;
-int32_t iounit;
-struct stat stbuf;
-V9fsString name;
-V9fsString fullname;
-} V9fsLcreateState;
-
 typedef struct V9fsStatState {
 V9fsPDU *pdu;
 size_t offset;
-- 
1.7.1




[Qemu-devel] [PATCH 03/29] hw/9pfs: Add yeild support for fstat coroutine

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofile.c |   14 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index a4c0ae7..e400b86 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -30,3 +30,17 @@ int v9fs_co_lstat(V9fsState *s, V9fsString *path, struct 
stat *stbuf)
 });
 return err;
 }
+
+int v9fs_co_fstat(V9fsState *s, int fd, struct stat *stbuf)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-fstat(s-ctx, fd, stbuf);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 11272d3..88070d3 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -76,4 +76,5 @@ extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
 extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
 extern int v9fs_co_remove(V9fsState *, V9fsString *);
 extern int v9fs_co_rename(V9fsState *, V9fsString *, V9fsString *);
+extern int v9fs_co_fstat(V9fsState *, int, struct stat *);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 07/29] hw/9pfs: Update v9fs_open to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  143 +++---
 1 files changed, 43 insertions(+), 100 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index e6032cd..2cb406b 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -92,11 +92,6 @@ static int v9fs_do_closedir(V9fsState *s, DIR *dir)
 return s-ops-closedir(s-ctx, dir);
 }
 
-static int v9fs_do_open(V9fsState *s, V9fsString *path, int flags)
-{
-return s-ops-open(s-ctx, path-data, flags);
-}
-
 static DIR *v9fs_do_opendir(V9fsState *s, V9fsString *path)
 {
 return s-ops-opendir(s-ctx, path-data);
@@ -211,11 +206,6 @@ static int v9fs_do_fsync(V9fsState *s, int fd, int 
datasync)
 return s-ops-fsync(s-ctx, fd, datasync);
 }
 
-static int v9fs_do_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf)
-{
-return s-ops-statfs(s-ctx, path-data, stbuf);
-}
-
 static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path,
  V9fsString *xattr_name,
  void *value, size_t size, int flags)
@@ -1547,122 +1537,75 @@ static int32_t get_iounit(V9fsState *s, V9fsString 
*name)
  * iounit should be multiples of f_bsize (host filesystem block size
  * and as well as less than (client msize - P9_IOHDRSZ))
  */
-if (!v9fs_do_statfs(s, name, stbuf)) {
+if (!v9fs_co_statfs(s, name, stbuf)) {
 iounit = stbuf.f_bsize;
 iounit *= (s-msize - P9_IOHDRSZ)/stbuf.f_bsize;
 }
-
 if (!iounit) {
 iounit = s-msize - P9_IOHDRSZ;
 }
 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)
+static void v9fs_open(void *opaque)
 {
-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);
-}
+int flags;
+int iounit;
+int32_t fid;
+int32_t mode;
+V9fsQID qid;
+ssize_t err = 0;
+size_t offset = 7;
+struct stat stbuf;
+V9fsFidState *fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
-{
-if (vs-fidp-fs.fd == -1) {
-err = -errno;
+if (s-proto_version == V9FS_PROTO_2000L) {
+pdu_unmarshal(pdu, offset, dd, fid, mode);
+} else {
+pdu_unmarshal(pdu, offset, db, fid, mode);
+}
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+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;
+BUG_ON(fidp-fid_type != P9_FID_NONE);
 
-if (err) {
-err = -errno;
+err = v9fs_co_lstat(s, fidp-path, stbuf);
+if (err  0) {
 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);
+stat_to_qid(stbuf, qid);
+if (S_ISDIR(stbuf.st_mode)) {
+err = v9fs_co_opendir(s, fidp);
+if (err  0) {
+goto out;
+}
+fidp-fid_type = P9_FID_DIR;
+offset += pdu_marshal(pdu, offset, Qd, qid, 0);
+err = offset;
 } else {
 if (s-proto_version == V9FS_PROTO_2000L) {
-flags = vs-mode;
+flags = mode;
 flags = ~(O_NOCTTY | O_ASYNC | O_CREAT);
 /* Ignore direct disk access hint until the server supports it. */
 flags = ~O_DIRECT;
 } else {
-flags = omode_to_uflags(vs-mode);
+flags = omode_to_uflags(mode);
 }
-vs-fidp-fs.fd = v9fs_do_open(s, vs-fidp-path, flags);
-v9fs_open_post_open(s, vs, err);
-}
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_open(void *opaque)
-{
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
-int32_t fid;
-V9fsOpenState *vs;
-ssize_t err = 0;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-vs-mode = 0;
-
-if (s-proto_version == V9FS_PROTO_2000L) {
-pdu_unmarshal(vs-pdu, vs-offset, dd, fid, vs-mode);
-} else {
-pdu_unmarshal(vs

[Qemu-devel] [PATCH 14/29] hw/9pfs: Update v9fs_clunk to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   43 +++
 1 files changed, 7 insertions(+), 36 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 1eb32f6..0227694 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -82,16 +82,6 @@ static int v9fs_do_lstat(V9fsState *s, V9fsString *path, 
struct stat *stbuf)
 return s-ops-lstat(s-ctx, path-data, stbuf);
 }
 
-static int v9fs_do_close(V9fsState *s, int fd)
-{
-return s-ops-close(s-ctx, fd);
-}
-
-static int v9fs_do_closedir(V9fsState *s, DIR *dir)
-{
-return s-ops-closedir(s-ctx, dir);
-}
-
 static DIR *v9fs_do_opendir(V9fsState *s, V9fsString *path)
 {
 return s-ops-opendir(s-ctx, path-data);
@@ -192,22 +182,6 @@ static int v9fs_do_fsync(V9fsState *s, int fd, int 
datasync)
 return s-ops-fsync(s-ctx, fd, datasync);
 }
 
-static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path,
- V9fsString *xattr_name,
- void *value, size_t size, int flags)
-{
-return s-ops-lsetxattr(s-ctx, path-data,
- xattr_name-data, value, size, flags);
-}
-
-static int v9fs_do_lremovexattr(V9fsState *s, V9fsString *path,
-V9fsString *xattr_name)
-{
-return s-ops-lremovexattr(s-ctx, path-data,
-xattr_name-data);
-}
-
-
 static void v9fs_string_init(V9fsString *str)
 {
 str-data = NULL;
@@ -414,12 +388,12 @@ static int v9fs_xattr_fid_clunk(V9fsState *s, 
V9fsFidState *fidp)
 goto free_out;
 }
 if (fidp-fs.xattr.len) {
-retval = v9fs_do_lsetxattr(s, fidp-path, fidp-fs.xattr.name,
+retval = v9fs_co_lsetxattr(s, fidp-path, fidp-fs.xattr.name,
fidp-fs.xattr.value,
fidp-fs.xattr.len,
fidp-fs.xattr.flags);
 } else {
-retval = v9fs_do_lremovexattr(s, fidp-path, fidp-fs.xattr.name);
+retval = v9fs_co_lremovexattr(s, fidp-path, fidp-fs.xattr.name);
 }
 free_out:
 v9fs_string_free(fidp-fs.xattr.name);
@@ -449,15 +423,14 @@ static int free_fid(V9fsState *s, int32_t fid)
 *fidpp = fidp-next;
 
 if (fidp-fid_type == P9_FID_FILE) {
-v9fs_do_close(s, fidp-fs.fd);
+retval = v9fs_co_close(s, fidp);
 } else if (fidp-fid_type == P9_FID_DIR) {
-v9fs_do_closedir(s, fidp-fs.dir);
+retval = v9fs_co_closedir(s, fidp);
 } else if (fidp-fid_type == P9_FID_XATTR) {
 retval = v9fs_xattr_fid_clunk(s, fidp);
 }
 v9fs_string_free(fidp-path);
 qemu_free(fidp);
-
 return retval;
 }
 
@@ -1591,19 +1564,17 @@ static void v9fs_fsync(void *opaque)
 
 static void v9fs_clunk(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+int err;
 int32_t fid;
 size_t offset = 7;
-int err;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
 pdu_unmarshal(pdu, offset, d, fid);
-
 err = free_fid(s, fid);
 if (err  0) {
 goto out;
 }
-
 offset = 7;
 err = offset;
 out:
-- 
1.7.1




[Qemu-devel] [0/29] Second batch of VirtFS routines converted to coroutines.

2011-05-25 Thread Venkateswararao Jujjuri (JV)
This is the continuation of my previous series converting rest of 9p 
functions to coroutines.

http://lists.gnu.org/archive/html/qemu-devel/2011-05/msg01756.html

Once coroutines makes into upstream, all these patches can go in
making virtfs completely asynchronous.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com





[Qemu-devel] [PATCH 22/29] [virtio-9p] coroutine and threading for v9fs_do_link

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofile.c |   14 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   17 -
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 26dd636..52eec2a 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -113,3 +113,17 @@ int v9fs_co_fsync(V9fsState *s, V9fsFidState *fidp, int 
datasync)
 });
 return err;
 }
+
+int v9fs_co_link(V9fsState *s, V9fsString *oldpath, V9fsString *newpath)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-link(s-ctx, oldpath-data, newpath-data);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index e394933..17ffd76 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -88,4 +88,5 @@ extern int v9fs_co_close(V9fsState *, V9fsFidState *);
 extern int v9fs_co_fsync(V9fsState *, V9fsFidState *, int);
 extern int v9fs_co_symlink(V9fsState *, V9fsFidState *, const char *,
const char *, gid_t);
+extern int v9fs_co_link(V9fsState *, V9fsString *, V9fsString *);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index cb11ee6..7fa253c 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -117,11 +117,6 @@ static int v9fs_do_chmod(V9fsState *s, V9fsString *path, 
mode_t mode)
 return s-ops-chmod(s-ctx, path-data, cred);
 }
 
-static int v9fs_do_link(V9fsState *s, V9fsString *oldpath, V9fsString *newpath)
-{
-return s-ops-link(s-ctx, oldpath-data, newpath-data);
-}
-
 static int v9fs_do_truncate(V9fsState *s, V9fsString *path, off_t size)
 {
 return s-ops-truncate(s-ctx, path-data, size);
@@ -2030,9 +2025,8 @@ static void v9fs_create(void *opaque)
 err = -EINVAL;
 goto out;
 }
-err = v9fs_do_link(pdu-s, nfidp-path, fullname);
+err = v9fs_co_link(pdu-s, nfidp-path, fullname);
 if (err  0) {
-err = -errno;
 goto out;
 }
 } else if (perm  P9_STAT_MODE_DEVICE) {
@@ -2172,22 +2166,19 @@ static void v9fs_link(void *opaque)
 
 dfidp = lookup_fid(s, dfid);
 if (dfidp == NULL) {
-err = -errno;
+err = -ENOENT;
 goto out;
 }
 
 oldfidp = lookup_fid(s, oldfid);
 if (oldfidp == NULL) {
-err = -errno;
+err = -ENOENT;
 goto out;
 }
 
 v9fs_string_sprintf(fullname, %s/%s, dfidp-path.data, name.data);
 err = offset;
-err = v9fs_do_link(s, oldfidp-path, fullname);
-if (err) {
-err = -errno;
-}
+err = v9fs_co_link(s, oldfidp-path, fullname);
 v9fs_string_free(fullname);
 
 out:
-- 
1.7.1




[Qemu-devel] [PATCH 10/29] [PATCH] [virtio-9p] coroutine and threading for open2

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofile.c |   21 +
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   45 +
 3 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 4a3ca21..4b0d96c 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -60,3 +60,24 @@ int v9fs_co_open(V9fsState *s, V9fsFidState *fidp, int flags)
 });
 return err;
 }
+
+int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, char *fullname, gid_t gid,
+  int flags, int mode)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_mode = mode  0;
+cred.fc_uid = fidp-uid;
+cred.fc_gid = gid;
+v9fs_co_run_in_worker(
+{
+fidp-fs.fd = s-ops-open2(s-ctx, fullname, flags, cred);
+err = 0;
+if (fidp-fs.fd == -1) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 1df7063..f9610b9 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -79,4 +79,5 @@ extern int v9fs_co_rename(V9fsState *, V9fsString *, 
V9fsString *);
 extern int v9fs_co_fstat(V9fsState *, int, struct stat *);
 extern int v9fs_co_opendir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_open(V9fsState *, V9fsFidState *, int);
+extern int v9fs_co_open2(V9fsState *, V9fsFidState *, char *, gid_t, int, int);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 49de67c..f535134 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -149,20 +149,6 @@ static int v9fs_do_fstat(V9fsState *s, int fd, struct stat 
*stbuf)
 return s-ops-fstat(s-ctx, fd, stbuf);
 }
 
-static int v9fs_do_open2(V9fsState *s, char *fullname, uid_t uid, gid_t gid,
-int flags, int mode)
-{
-FsCred cred;
-
-cred_init(cred);
-cred.fc_uid = uid;
-cred.fc_gid = gid;
-cred.fc_mode = mode  0;
-flags = flags;
-
-return s-ops-open2(s-ctx, fullname, flags, cred);
-}
-
 static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp,
 const char *oldpath, const char *newpath, gid_t gid)
 {
@@ -1632,34 +1618,30 @@ static void v9fs_lcreate(void *opaque)
 err = -ENOENT;
 goto out;
 }
-
 v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
 
 /* Ignore direct disk access hint until the server supports it. */
 flags = ~O_DIRECT;
 
-fidp-fs.fd = v9fs_do_open2(pdu-s, fullname.data, fidp-uid,
-gid, flags, mode);
-if (fidp-fs.fd == -1) {
-err = -errno;
+err = v9fs_co_open2(pdu-s, fidp, fullname.data, gid, flags, mode);
+if (err  0) {
 goto out;
 }
 fidp-fid_type = P9_FID_FILE;
 iounit =  get_iounit(pdu-s, fullname);
 
-err = v9fs_do_lstat(pdu-s, fullname, stbuf);
-if (err == 0) {
-v9fs_string_copy(fidp-path, fullname);
-stat_to_qid(stbuf, qid);
-offset += pdu_marshal(pdu, offset, Qd, qid, iounit);
-err = offset;
-} else {
-fidp-fid_type = P9_FID_NONE; /*TODO:Why are we keeping this fid?*/
-err = -errno;
+err = v9fs_co_lstat(pdu-s, fullname, stbuf);
+if (err  0) {
+fidp-fid_type = P9_FID_NONE;
 if (fidp-fs.fd  0) {
 close(fidp-fs.fd);
 }
+goto out;
 }
+v9fs_string_copy(fidp-path, fullname);
+stat_to_qid(stbuf, qid);
+offset += pdu_marshal(pdu, offset, Qd, qid, iounit);
+err = offset;
 out:
 complete_pdu(pdu-s, pdu, err);
 v9fs_string_free(name);
@@ -2240,8 +,7 @@ static void v9fs_create_post_fstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 
 static void v9fs_create_post_open2(V9fsState *s, V9fsCreateState *vs, int err)
 {
-if (vs-fidp-fs.fd == -1) {
-err = -errno;
+if (err  0) {
 goto out;
 }
 vs-fidp-fid_type = P9_FID_FILE;
@@ -2316,8 +2297,8 @@ static void v9fs_create_post_lstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 0, vs-fidp-uid, -1);
 v9fs_post_create(s, vs, err);
 } else {
-vs-fidp-fs.fd = v9fs_do_open2(s, vs-fullname.data, vs-fidp-uid,
--1, omode_to_uflags(vs-mode)|O_CREAT, vs-perm);
+err = v9fs_co_open2(s, vs-fidp, vs-fullname.data, -1,
+omode_to_uflags(vs-mode)|O_CREAT, vs-perm);
 
 v9fs_create_post_open2(s, vs, err);
 }
-- 
1.7.1




[Qemu-devel] [PATCH 16/29] hw/9pfs: Update v9fs_fsync to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   24 
 1 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0227694..d1733ca 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1533,33 +1533,25 @@ out:
 v9fs_string_free(fullname);
 }
 
-static void v9fs_post_do_fsync(V9fsState *s, V9fsPDU *pdu, int err)
-{
-if (err == -1) {
-err = -errno;
-}
-complete_pdu(s, pdu, err);
-}
-
 static void v9fs_fsync(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+int err;
 int32_t fid;
+int datasync;
 size_t offset = 7;
 V9fsFidState *fidp;
-int datasync;
-int err;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
 pdu_unmarshal(pdu, offset, dd, fid, datasync);
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
-v9fs_post_do_fsync(s, pdu, err);
-return;
+goto out;
 }
-err = v9fs_do_fsync(s, fidp-fs.fd, datasync);
-v9fs_post_do_fsync(s, pdu, err);
+err = v9fs_co_fsync(s, fidp, datasync);
+out:
+complete_pdu(s, pdu, err);
 }
 
 static void v9fs_clunk(void *opaque)
-- 
1.7.1




[Qemu-devel] [PATCH 04/29] hw/9pfs: Update v9fs_lock to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   44 
 hw/9pfs/virtio-9p.h |   10 --
 2 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 42e260d..1729422 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3009,47 +3009,43 @@ out:
  * do any thing in * qemu 9p server side lock code path.
  * So when a TLOCK request comes, always return success
  */
-
 static void v9fs_lock(void *opaque)
 {
+int8_t status;
+V9fsFlock *flock;
+size_t offset = 7;
+struct stat stbuf;
+V9fsFidState *fidp;
+int32_t fid, err = 0;
 V9fsPDU *pdu = opaque;
 V9fsState *s = pdu-s;
-int32_t fid, err = 0;
-V9fsLockState *vs;
-
-vs = qemu_mallocz(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-vs-flock = qemu_malloc(sizeof(*vs-flock));
-pdu_unmarshal(vs-pdu, vs-offset, dbdqqds, fid, vs-flock-type,
-vs-flock-flags, vs-flock-start, vs-flock-length,
-vs-flock-proc_id, vs-flock-client_id);
 
-vs-status = P9_LOCK_ERROR;
+flock = qemu_malloc(sizeof(*flock));
+pdu_unmarshal(pdu, offset, dbdqqds, fid, flock-type,
+  flock-flags, flock-start, flock-length,
+  flock-proc_id, flock-client_id);
+status = P9_LOCK_ERROR;
 
 /* We support only block flag now (that too ignored currently) */
-if (vs-flock-flags  ~P9_LOCK_FLAGS_BLOCK) {
+if (flock-flags  ~P9_LOCK_FLAGS_BLOCK) {
 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;
 }
-
-err = v9fs_do_fstat(s, vs-fidp-fs.fd, vs-stbuf);
+err = v9fs_co_fstat(s, fidp-fs.fd, stbuf);
 if (err  0) {
-err = -errno;
 goto out;
 }
-vs-status = P9_LOCK_SUCCESS;
+status = P9_LOCK_SUCCESS;
 out:
-vs-offset += pdu_marshal(vs-pdu, vs-offset, b, vs-status);
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs-flock);
-qemu_free(vs);
+err = offset;
+err += pdu_marshal(pdu, offset, b, status);
+complete_pdu(s, pdu, err);
+qemu_free(flock);
 }
 
 /*
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 46d79da..0c1e3ee 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -403,16 +403,6 @@ typedef struct V9fsFlock
 V9fsString client_id;
 } V9fsFlock;
 
-typedef struct V9fsLockState
-{
-V9fsPDU *pdu;
-size_t offset;
-int8_t status;
-struct stat stbuf;
-V9fsFidState *fidp;
-V9fsFlock *flock;
-} V9fsLockState;
-
 typedef struct V9fsGetlock
 {
 uint8_t type;
-- 
1.7.1




[Qemu-devel] [PATCH 12/29] hw/9pfs: Update v9fs_walk to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@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

[Qemu-devel] [PATCH 19/29] [virtio-9p] Remove post functions for v9fs_symlink

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   47 +++
 1 files changed, 15 insertions(+), 32 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 9976516..8702319 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2117,33 +2117,6 @@ out:
v9fs_string_free(fullname);
 }
 
-static void v9fs_post_symlink(V9fsState *s, V9fsSymlinkState *vs, int err)
-{
-if (err == 0) {
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
-} else {
-err = -errno;
-}
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-v9fs_string_free(vs-symname);
-v9fs_string_free(vs-fullname);
-qemu_free(vs);
-}
-
-static void v9fs_symlink_post_do_symlink(V9fsState *s, V9fsSymlinkState *vs,
-int err)
-{
-if (err) {
-goto out;
-}
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-out:
-v9fs_post_symlink(s, vs, err);
-}
-
 static void v9fs_symlink(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -2169,16 +2142,26 @@ static void v9fs_symlink(void *opaque)
 }
 
 v9fs_string_sprintf(vs-fullname, %s/%s, vs-dfidp-path.data,
-vs-name.data);
+vs-name.data);
 err = v9fs_do_symlink(s, vs-dfidp, vs-symname.data,
-vs-fullname.data, gid);
-v9fs_symlink_post_do_symlink(s, vs, err);
-return;
-
+  vs-fullname.data, gid);
+if (err  0) {
+err = -errno;
+goto out;
+}
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+if (err == 0) {
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
+err = vs-offset;
+} else {
+err = -errno;
+}
 out:
 complete_pdu(s, vs-pdu, err);
 v9fs_string_free(vs-name);
 v9fs_string_free(vs-symname);
+v9fs_string_free(vs-fullname);
 qemu_free(vs);
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 26/29] hw/9pfs: Update v9fs_attach to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   13 -
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index b378fc8..06a71fb 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -402,11 +402,10 @@ static int fid_to_qid(V9fsState *s, V9fsFidState *fidp, 
V9fsQID *qidp)
 struct stat stbuf;
 int err;
 
-err = v9fs_do_lstat(s, fidp-path, stbuf);
-if (err) {
+err = v9fs_co_lstat(s, fidp-path, stbuf);
+if (err  0) {
 return err;
 }
-
 stat_to_qid(stbuf, qidp);
 return 0;
 }
@@ -1032,8 +1031,8 @@ static void v9fs_attach(void *opaque)
 int32_t fid, afid, n_uname;
 V9fsString uname, aname;
 V9fsFidState *fidp;
-V9fsQID qid;
 size_t offset = 7;
+V9fsQID qid;
 ssize_t err;
 
 pdu_unmarshal(pdu, offset, ddssd, fid, afid, uname, aname, n_uname);
@@ -1043,19 +1042,15 @@ static void v9fs_attach(void *opaque)
 err = -EINVAL;
 goto out;
 }
-
 fidp-uid = n_uname;
-
 v9fs_string_sprintf(fidp-path, %s, /);
 err = fid_to_qid(s, fidp, qid);
-if (err) {
+if (err  0) {
 err = -EINVAL;
 free_fid(s, fid);
 goto out;
 }
-
 offset += pdu_marshal(pdu, offset, Q, qid);
-
 err = offset;
 out:
 complete_pdu(s, pdu, err);
-- 
1.7.1




[Qemu-devel] [PATCH 17/29] [virtio-9p] Remove post functions for v9fs_create

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  229 ---
 1 files changed, 72 insertions(+), 157 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index d1733ca..14eefac 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -134,11 +134,6 @@ static int v9fs_do_mknod(V9fsState *s, char *name,
 return s-ops-mknod(s-ctx, name, cred);
 }
 
-static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf)
-{
-return s-ops-fstat(s-ctx, fd, stbuf);
-}
-
 static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp,
 const char *oldpath, const char *newpath, gid_t gid)
 {
@@ -2005,137 +2000,66 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_create_post_getiounit(V9fsState *s, V9fsCreateState *vs)
-{
-int err;
-v9fs_string_copy(vs-fidp-path, vs-fullname);
-stat_to_qid(vs-stbuf, vs-qid);
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Qd, vs-qid, vs-iounit);
-err = vs-offset;
-
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-v9fs_string_free(vs-extension);
-v9fs_string_free(vs-fullname);
-qemu_free(vs);
-}
-
-static void v9fs_post_create(V9fsState *s, V9fsCreateState *vs, int err)
-{
-if (err == 0) {
-vs-iounit = get_iounit(s, vs-fidp-path);
-v9fs_create_post_getiounit(s, vs);
-return;
-}
-
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-v9fs_string_free(vs-extension);
-v9fs_string_free(vs-fullname);
-qemu_free(vs);
-}
-
-static void v9fs_create_post_perms(V9fsState *s, V9fsCreateState *vs, int err)
-{
-if (err) {
-err = -errno;
-}
-v9fs_post_create(s, vs, err);
-}
-
-static void v9fs_create_post_opendir(V9fsState *s, V9fsCreateState *vs,
-int err)
+static void v9fs_create(void *opaque)
 {
-if (!vs-fidp-fs.dir) {
-err = -errno;
-}
-vs-fidp-fid_type = P9_FID_DIR;
-v9fs_post_create(s, vs, err);
-}
+int err = 0;
+int32_t fid;
+V9fsCreateState *vs;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-static void v9fs_create_post_dir_lstat(V9fsState *s, V9fsCreateState *vs,
-int err)
-{
-if (err) {
-err = -errno;
-goto out;
-}
+vs = qemu_malloc(sizeof(*vs));
+vs-pdu = pdu;
+vs-offset = 7;
 
-vs-fidp-fs.dir = v9fs_do_opendir(s, vs-fullname);
-v9fs_create_post_opendir(s, vs, err);
-return;
+v9fs_string_init(vs-fullname);
 
-out:
-v9fs_post_create(s, vs, err);
-}
+pdu_unmarshal(vs-pdu, vs-offset, dsdbs, fid, vs-name,
+vs-perm, vs-mode, vs-extension);
 
-static void v9fs_create_post_mkdir(V9fsState *s, V9fsCreateState *vs, int err)
-{
-if (err  0) {
+vs-fidp = lookup_fid(s, fid);
+if (vs-fidp == NULL) {
+err = -EINVAL;
 goto out;
 }
 
+v9fs_string_sprintf(vs-fullname, %s/%s, vs-fidp-path.data,
+vs-name.data);
 err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-v9fs_create_post_dir_lstat(s, vs, err);
-return;
-
-out:
-v9fs_post_create(s, vs, err);
-}
-
-static void v9fs_create_post_fstat(V9fsState *s, V9fsCreateState *vs, int err)
-{
-if (err) {
-vs-fidp-fid_type = P9_FID_NONE;
-close(vs-fidp-fs.fd);
-err = -errno;
-}
-v9fs_post_create(s, vs, err);
-return;
-}
-
-static void v9fs_create_post_open2(V9fsState *s, V9fsCreateState *vs, int err)
-{
-if (err  0) {
-goto out;
-}
-vs-fidp-fid_type = P9_FID_FILE;
-err = v9fs_do_fstat(s, vs-fidp-fs.fd, vs-stbuf);
-v9fs_create_post_fstat(s, vs, err);
-
-return;
-
-out:
-v9fs_post_create(s, vs, err);
-
-}
-
-static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err)
-{
-
 if (err == 0 || errno != ENOENT) {
 err = -errno;
 goto out;
 }
-
 if (vs-perm  P9_STAT_MODE_DIR) {
 err = v9fs_co_mkdir(s, vs-fullname.data, vs-perm  0777,
 vs-fidp-uid, -1);
-v9fs_create_post_mkdir(s, vs, err);
+if (!err) {
+vs-fidp-fs.dir = v9fs_do_opendir(s, vs-fullname);
+}
+if (err  0 || !vs-fidp-fs.dir) {
+err = -errno;
+vs-fidp-fid_type = P9_FID_NONE;
+}
+vs-fidp-fid_type = P9_FID_DIR;
 } else if (vs-perm  P9_STAT_MODE_SYMLINK) {
 err = v9fs_do_symlink(s, vs-fidp, vs-extension.data,
 vs-fullname.data, -1);
-v9fs_create_post_perms(s, vs, err);
+if (err  0) {
+err = -errno;
+goto out;
+}
 } else if (vs-perm  P9_STAT_MODE_LINK) {
 int32_t nfid = atoi(vs-extension.data);
 V9fsFidState *nfidp = lookup_fid(s, nfid);
 if (nfidp == NULL

[Qemu-devel] [PATCH 20/29] [virtio-9p] clean up v9fs_symlink

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsSymlinkState
and additional malloc()s.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   45 +
 hw/9pfs/virtio-9p.h |   12 
 2 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 8702319..1e6c2b8 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2120,49 +2120,46 @@ out:
 static void v9fs_symlink(void *opaque)
 {
 V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+V9fsString name;
+V9fsString symname;
+V9fsString fullname;
+V9fsFidState *dfidp;
+V9fsQID qid;
+struct stat stbuf;
 int32_t dfid;
-V9fsSymlinkState *vs;
 int err = 0;
 gid_t gid;
+size_t offset = 7;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-v9fs_string_init(vs-fullname);
+v9fs_string_init(fullname);
 
-pdu_unmarshal(vs-pdu, vs-offset, dssd, dfid, vs-name,
-vs-symname, gid);
+pdu_unmarshal(pdu, offset, dssd, dfid, name, symname, gid);
 
-vs-dfidp = lookup_fid(s, dfid);
-if (vs-dfidp == NULL) {
+dfidp = lookup_fid(pdu-s, dfid);
+if (dfidp == NULL) {
 err = -EINVAL;
 goto out;
 }
 
-v9fs_string_sprintf(vs-fullname, %s/%s, vs-dfidp-path.data,
-vs-name.data);
-err = v9fs_do_symlink(s, vs-dfidp, vs-symname.data,
-  vs-fullname.data, gid);
+v9fs_string_sprintf(fullname, %s/%s, dfidp-path.data, name.data);
+err = v9fs_do_symlink(pdu-s, dfidp, symname.data, fullname.data, gid);
 if (err  0) {
 err = -errno;
 goto out;
 }
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+err = v9fs_do_lstat(pdu-s, fullname, stbuf);
 if (err == 0) {
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
+stat_to_qid(stbuf, qid);
+offset += pdu_marshal(pdu, offset, Q, qid);
+err = offset;
 } else {
 err = -errno;
 }
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-v9fs_string_free(vs-symname);
-v9fs_string_free(vs-fullname);
-qemu_free(vs);
+complete_pdu(pdu-s, pdu, err);
+v9fs_string_free(name);
+v9fs_string_free(symname);
+v9fs_string_free(fullname);
 }
 
 static void v9fs_flush(void *opaque)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index e7d87d9..29f3184 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -305,18 +305,6 @@ typedef struct V9fsWstatState
 struct stat stbuf;
 } V9fsWstatState;
 
-typedef struct V9fsSymlinkState
-{
-V9fsPDU *pdu;
-size_t offset;
-V9fsString name;
-V9fsString symname;
-V9fsString fullname;
-V9fsFidState *dfidp;
-V9fsQID qid;
-struct stat stbuf;
-} V9fsSymlinkState;
-
 typedef struct V9fsIattr
 {
 int32_t valid;
-- 
1.7.1




[Qemu-devel] [PATCH 11/29] hw/9pfs: Update v9fs_stat to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   61 +-
 1 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f535134..fea9de4 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1169,56 +1169,37 @@ out:
 v9fs_string_free(aname);
 }
 
-static void v9fs_stat_post_lstat(V9fsState *s, V9fsStatState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-err = stat_to_v9stat(s, vs-fidp-path, vs-stbuf, vs-v9stat);
-if (err) {
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, wS, 0, vs-v9stat);
-err = vs-offset;
-
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_stat_free(vs-v9stat);
-qemu_free(vs);
-}
-
 static void v9fs_stat(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int32_t fid;
-V9fsStatState *vs;
+V9fsStat v9stat;
 ssize_t err = 0;
+size_t offset = 7;
+struct stat stbuf;
+V9fsFidState *fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-memset(vs-v9stat, 0, sizeof(vs-v9stat));
-
-pdu_unmarshal(vs-pdu, vs-offset, d, fid);
+pdu_unmarshal(pdu, offset, d, fid);
 
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
-err = v9fs_do_lstat(s, vs-fidp-path, vs-stbuf);
-v9fs_stat_post_lstat(s, vs, err);
-return;
-
+err = v9fs_co_lstat(s, fidp-path, stbuf);
+if (err  0) {
+goto out;
+}
+err = stat_to_v9stat(s, fidp-path, stbuf, v9stat);
+if (err  0) {
+goto out;
+}
+offset += pdu_marshal(pdu, offset, wS, 0, v9stat);
+err = offset;
+v9fs_stat_free(v9stat);
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_stat_free(vs-v9stat);
-qemu_free(vs);
+complete_pdu(s, pdu, err);
 }
 
 static void v9fs_getattr(void *opaque)
-- 
1.7.1




[Qemu-devel] [PATCH 18/29] [virtio-9p] clean up v9fs_create Rearrange the code

2011-05-25 Thread Venkateswararao Jujjuri (JV)
so that we can avoid V9fsCreateState and additional malloc()s.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  149 ++-
 hw/9pfs/virtio-9p.h |   14 -
 2 files changed, 65 insertions(+), 98 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 14eefac..9976516 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -82,11 +82,6 @@ static int v9fs_do_lstat(V9fsState *s, V9fsString *path, 
struct stat *stbuf)
 return s-ops-lstat(s-ctx, path-data, stbuf);
 }
 
-static DIR *v9fs_do_opendir(V9fsState *s, V9fsString *path)
-{
-return s-ops-opendir(s-ctx, path-data);
-}
-
 static void v9fs_do_rewinddir(V9fsState *s, DIR *dir)
 {
 return s-ops-rewinddir(s-ctx, dir);
@@ -122,18 +117,6 @@ static int v9fs_do_chmod(V9fsState *s, V9fsString *path, 
mode_t mode)
 return s-ops-chmod(s-ctx, path-data, cred);
 }
 
-static int v9fs_do_mknod(V9fsState *s, char *name,
-mode_t mode, dev_t dev, uid_t uid, gid_t gid)
-{
-FsCred cred;
-cred_init(cred);
-cred.fc_uid = uid;
-cred.fc_gid = gid;
-cred.fc_mode = mode;
-cred.fc_rdev = dev;
-return s-ops-mknod(s-ctx, name, cred);
-}
-
 static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp,
 const char *oldpath, const char *newpath, gid_t gid)
 {
@@ -2002,71 +1985,75 @@ out:
 
 static void v9fs_create(void *opaque)
 {
-int err = 0;
 int32_t fid;
-V9fsCreateState *vs;
+int err = 0;
+size_t offset = 7;
+V9fsFidState *fidp;
+V9fsQID qid;
+int32_t perm;
+int8_t mode;
+struct stat stbuf;
+V9fsString name;
+V9fsString extension;
+V9fsString fullname;
+int iounit;
 V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
 
-v9fs_string_init(vs-fullname);
+v9fs_string_init(fullname);
 
-pdu_unmarshal(vs-pdu, vs-offset, dsdbs, fid, vs-name,
-vs-perm, vs-mode, vs-extension);
+pdu_unmarshal(pdu, offset, dsdbs, fid, name,
+  perm, mode, extension);
 
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
+fidp = lookup_fid(pdu-s, fid);
+if (fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
 
-v9fs_string_sprintf(vs-fullname, %s/%s, vs-fidp-path.data,
-vs-name.data);
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-if (err == 0 || errno != ENOENT) {
-err = -errno;
+v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
+err = v9fs_co_lstat(pdu-s, fullname, stbuf);
+if (!err) {
+err = -EEXIST;
+goto out;
+} else if (err != -ENOENT) {
 goto out;
 }
-if (vs-perm  P9_STAT_MODE_DIR) {
-err = v9fs_co_mkdir(s, vs-fullname.data, vs-perm  0777,
-vs-fidp-uid, -1);
-if (!err) {
-vs-fidp-fs.dir = v9fs_do_opendir(s, vs-fullname);
+if (perm  P9_STAT_MODE_DIR) {
+err = v9fs_co_mkdir(pdu-s, fullname.data, perm  0777,
+fidp-uid, -1);
+if (err  0) {
+goto out;
 }
-if (err  0 || !vs-fidp-fs.dir) {
-err = -errno;
-vs-fidp-fid_type = P9_FID_NONE;
+err = v9fs_co_opendir(pdu-s, fidp);
+if (err  0) {
+goto out;
 }
-vs-fidp-fid_type = P9_FID_DIR;
-} else if (vs-perm  P9_STAT_MODE_SYMLINK) {
-err = v9fs_do_symlink(s, vs-fidp, vs-extension.data,
-vs-fullname.data, -1);
+fidp-fid_type = P9_FID_DIR;
+} else if (perm  P9_STAT_MODE_SYMLINK) {
+err = v9fs_do_symlink(pdu-s, fidp, extension.data,
+  fullname.data, -1);
 if (err  0) {
 err = -errno;
 goto out;
 }
-} else if (vs-perm  P9_STAT_MODE_LINK) {
-int32_t nfid = atoi(vs-extension.data);
-V9fsFidState *nfidp = lookup_fid(s, nfid);
+} else if (perm  P9_STAT_MODE_LINK) {
+int32_t nfid = atoi(extension.data);
+V9fsFidState *nfidp = lookup_fid(pdu-s, nfid);
 if (nfidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-err = v9fs_do_link(s, nfidp-path, vs-fullname);
+err = v9fs_do_link(pdu-s, nfidp-path, fullname);
 if (err  0) {
 err = -errno;
 goto out;
 }
-} else if (vs-perm  P9_STAT_MODE_DEVICE) {
+} else if (perm  P9_STAT_MODE_DEVICE) {
 char ctype;
 uint32_t major, minor;
 mode_t nmode = 0;
 
-if (sscanf(vs-extension.data, %c %u %u, ctype, major,
-minor) != 3) {
+if (sscanf(extension.data, %c %u %u, ctype, major, minor) != 3) {
 err = -errno;
 goto out;
 }
@@ -2083,57 +2070,51 @@ static void

[Qemu-devel] [PATCH 21/29] [virtio-9p] coroutine and threading for v9fs_do_symlink

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   20 
 hw/9pfs/virtio-9p-coth.h |2 ++
 hw/9pfs/virtio-9p.c  |   31 ---
 3 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 473ce53..60468bc 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -169,3 +169,23 @@ int v9fs_co_rename(V9fsState *s, V9fsString *oldpath, 
V9fsString *newpath)
 });
 return err;
 }
+
+int v9fs_co_symlink(V9fsState *s, V9fsFidState *fidp,
+const char *oldpath, const char *newpath, gid_t gid)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_uid = fidp-uid;
+cred.fc_gid = gid;
+cred.fc_mode = 0777;
+v9fs_co_run_in_worker(
+{
+err = s-ops-symlink(s-ctx, oldpath, newpath, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index a3881f3..e394933 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -86,4 +86,6 @@ extern int v9fs_co_lremovexattr(V9fsState *, V9fsString *, 
V9fsString *);
 extern int v9fs_co_closedir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_close(V9fsState *, V9fsFidState *);
 extern int v9fs_co_fsync(V9fsState *, V9fsFidState *, int);
+extern int v9fs_co_symlink(V9fsState *, V9fsFidState *, const char *,
+   const char *, gid_t);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 1e6c2b8..cb11ee6 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -117,18 +117,6 @@ static int v9fs_do_chmod(V9fsState *s, V9fsString *path, 
mode_t mode)
 return s-ops-chmod(s-ctx, path-data, cred);
 }
 
-static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp,
-const char *oldpath, const char *newpath, gid_t gid)
-{
-FsCred cred;
-cred_init(cred);
-cred.fc_uid = fidp-uid;
-cred.fc_gid = gid;
-cred.fc_mode = 0777;
-
-return s-ops-symlink(s-ctx, oldpath, newpath, cred);
-}
-
 static int v9fs_do_link(V9fsState *s, V9fsString *oldpath, V9fsString *newpath)
 {
 return s-ops-link(s-ctx, oldpath-data, newpath-data);
@@ -2030,10 +2018,9 @@ static void v9fs_create(void *opaque)
 }
 fidp-fid_type = P9_FID_DIR;
 } else if (perm  P9_STAT_MODE_SYMLINK) {
-err = v9fs_do_symlink(pdu-s, fidp, extension.data,
+err = v9fs_co_symlink(pdu-s, fidp, extension.data,
   fullname.data, -1);
 if (err  0) {
-err = -errno;
 goto out;
 }
 } else if (perm  P9_STAT_MODE_LINK) {
@@ -2142,19 +2129,17 @@ static void v9fs_symlink(void *opaque)
 }
 
 v9fs_string_sprintf(fullname, %s/%s, dfidp-path.data, name.data);
-err = v9fs_do_symlink(pdu-s, dfidp, symname.data, fullname.data, gid);
+err = v9fs_co_symlink(pdu-s, dfidp, symname.data, fullname.data, gid);
 if (err  0) {
-err = -errno;
 goto out;
 }
-err = v9fs_do_lstat(pdu-s, fullname, stbuf);
-if (err == 0) {
-stat_to_qid(stbuf, qid);
-offset += pdu_marshal(pdu, offset, Q, qid);
-err = offset;
-} else {
-err = -errno;
+err = v9fs_co_lstat(pdu-s, fullname, stbuf);
+if (err  0) {
+goto out;
 }
+stat_to_qid(stbuf, qid);
+offset += pdu_marshal(pdu, offset, Q, qid);
+err = offset;
 out:
 complete_pdu(pdu-s, pdu, err);
 v9fs_string_free(name);
-- 
1.7.1




[Qemu-devel] [PATCH 27/29] hw/9pfs: Add yield support for preadv coroutine

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofile.c |   17 +
 hw/9pfs/virtio-9p-coth.h |2 ++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index e0d032d..e388146 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -144,3 +144,20 @@ int v9fs_co_pwritev(V9fsState *s, V9fsFidState *fidp,
 });
 return err;
 }
+
+int v9fs_co_preadv(V9fsState *s, V9fsFidState *fidp,
+   struct iovec *iov, int iovcnt, int64_t offset)
+{
+int fd;
+int err;
+
+fd = fidp-fs.fd;
+v9fs_co_run_in_worker(
+{
+err = s-ops-preadv(s-ctx, fd, iov, iovcnt, offset);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index fa408f8..5fa2972 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -91,4 +91,6 @@ extern int v9fs_co_symlink(V9fsState *, V9fsFidState *, const 
char *,
 extern int v9fs_co_link(V9fsState *, V9fsString *, V9fsString *);
 extern int v9fs_co_pwritev(V9fsState *, V9fsFidState *,
struct iovec *, int, int64_t);
+extern int v9fs_co_preadv(V9fsState *, V9fsFidState *,
+  struct iovec *, int, int64_t);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 13/29] hw/9pfs: Add yeild support for clunk related coroutine

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include lsetxattr, lremovexattr, closedir and close.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/codir.c  |   16 
 hw/9pfs/cofile.c |   16 
 hw/9pfs/coxattr.c|   34 ++
 hw/9pfs/virtio-9p-coth.h |5 +
 4 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index bc6a105..0c31db3 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -99,3 +99,19 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp)
 });
 return err;
 }
+
+int v9fs_co_closedir(V9fsState *s, V9fsFidState *fidp)
+{
+int err;
+DIR *dir;
+
+dir = fidp-fs.dir;
+v9fs_co_run_in_worker(
+{
+err = s-ops-closedir(s-ctx, dir);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 4b0d96c..e552999 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -81,3 +81,19 @@ int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, char 
*fullname, gid_t gid,
 });
 return err;
 }
+
+int v9fs_co_close(V9fsState *s, V9fsFidState *fidp)
+{
+int fd;
+int err;
+
+fd = fidp-fs.fd;
+v9fs_co_run_in_worker(
+{
+err = s-ops-close(s-ctx, fd);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/coxattr.c b/hw/9pfs/coxattr.c
index 2fba2c9..a289389 100644
--- a/hw/9pfs/coxattr.c
+++ b/hw/9pfs/coxattr.c
@@ -48,3 +48,37 @@ int v9fs_co_lgetxattr(V9fsState *s, V9fsString *path,
 });
 return err;
 }
+
+int v9fs_co_lsetxattr(V9fsState *s, V9fsString *path,
+  V9fsString *xattr_name, void *value,
+  size_t size, int flags)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-lsetxattr(s-ctx, path-data,
+xattr_name-data, value,
+size, flags);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_lremovexattr(V9fsState *s, V9fsString *path,
+ V9fsString *xattr_name)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-lremovexattr(s-ctx, path-data,
+   xattr_name-data);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index f9610b9..5d7dfd7 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -80,4 +80,9 @@ extern int v9fs_co_fstat(V9fsState *, int, struct stat *);
 extern int v9fs_co_opendir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_open(V9fsState *, V9fsFidState *, int);
 extern int v9fs_co_open2(V9fsState *, V9fsFidState *, char *, gid_t, int, int);
+extern int v9fs_co_lsetxattr(V9fsState *, V9fsString *, V9fsString *,
+ void *, size_t, int);
+extern int v9fs_co_lremovexattr(V9fsState *, V9fsString *, V9fsString *);
+extern int v9fs_co_closedir(V9fsState *, V9fsFidState *);
+extern int v9fs_co_close(V9fsState *, V9fsFidState *);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 24/29] hw/9pfs: Update v9fs_write to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  147 --
 1 files changed, 59 insertions(+), 88 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 7fa253c..c4e9efb 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -103,12 +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_pwritev(V9fsState *s, int fd, const struct iovec *iov,
-   int iovcnt, int64_t offset)
-{
-return s-ops-pwritev(s-ctx, fd, iov, iovcnt, offset);
-}
-
 static int v9fs_do_chmod(V9fsState *s, V9fsString *path, mode_t mode)
 {
 FsCred cred;
@@ -1835,51 +1829,21 @@ out:
 complete_pdu(s, pdu, retval);
 }
 
-static void v9fs_write_post_pwritev(V9fsState *s, V9fsWriteState *vs,
-   ssize_t err)
-{
-if (err   0) {
-/* IO error return the error */
-err = -errno;
-goto out;
-}
-vs-total += vs-len;
-vs-sg = adjust_sg(vs-sg, vs-len, vs-cnt);
-if (vs-total  vs-count  vs-len  0) {
-do {
-if (0) {
-print_sg(vs-sg, vs-cnt);
-}
-vs-len = v9fs_do_pwritev(s, vs-fidp-fs.fd, vs-sg, vs-cnt,
-  vs-off);
-if (vs-len  0) {
-vs-off += vs-len;
-}
-} while (vs-len == -1  errno == EINTR);
-if (vs-len == -1) {
-err  = -errno;
-}
-v9fs_write_post_pwritev(s, vs, err);
-return;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-total);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_xattr_write(V9fsState *s, V9fsWriteState *vs)
+static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
+int64_t off, int32_t count,
+struct iovec *sg, int cnt)
 {
 int i, to_copy;
 ssize_t err = 0;
 int write_count;
 int64_t xattr_len;
+size_t offset = 7;
 
-xattr_len = vs-fidp-fs.xattr.len;
-write_count = xattr_len - vs-off;
-if (write_count  vs-count) {
-write_count = vs-count;
+
+xattr_len = fidp-fs.xattr.len;
+write_count = xattr_len - off;
+if (write_count  count) {
+write_count = count;
 } else if (write_count  0) {
 /*
  * write beyond XATTR value len specified in
@@ -1888,82 +1852,89 @@ static void v9fs_xattr_write(V9fsState *s, 
V9fsWriteState *vs)
 err = -ENOSPC;
 goto out;
 }
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, write_count);
-err = vs-offset;
-vs-fidp-fs.xattr.copied_len += write_count;
+offset += pdu_marshal(pdu, offset, d, write_count);
+err = offset;
+fidp-fs.xattr.copied_len += write_count;
 /*
  * Now copy the content from sg list
  */
-for (i = 0; i  vs-cnt; i++) {
-if (write_count  vs-sg[i].iov_len) {
-to_copy = vs-sg[i].iov_len;
+for (i = 0; i  cnt; i++) {
+if (write_count  sg[i].iov_len) {
+to_copy = sg[i].iov_len;
 } else {
 to_copy = write_count;
 }
-memcpy((char *)vs-fidp-fs.xattr.value + vs-off,
-   vs-sg[i].iov_base, to_copy);
+memcpy((char *)fidp-fs.xattr.value + off, sg[i].iov_base, to_copy);
 /* updating vs-off since we are not using below */
-vs-off += to_copy;
+off += to_copy;
 write_count -= to_copy;
 }
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+return err;
 }
 
 static void v9fs_write(void *opaque)
 {
+int cnt;
+ssize_t err;
+int32_t fid;
+int64_t off;
+int32_t count;
+int32_t len = 0;
+int32_t total = 0;
+size_t offset = 7;
+V9fsFidState *fidp;
+struct iovec iov[128]; /* FIXME: bad, bad, bad */
+struct iovec *sg = iov;
 V9fsPDU *pdu = opaque;
 V9fsState *s = pdu-s;
-int32_t fid;
-V9fsWriteState *vs;
-ssize_t err;
 
-vs = qemu_malloc(sizeof(*vs));
+pdu_unmarshal(pdu, offset, dqdv, fid, off, count, sg, cnt);
 
-vs-pdu = pdu;
-vs-offset = 7;
-vs-sg = vs-iov;
-vs-total = 0;
-vs-len = 0;
-
-pdu_unmarshal(vs-pdu, vs-offset, dqdv, fid, vs-off, vs-count,
-  vs-sg, vs-cnt);
-
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-
-if (vs-fidp-fid_type == P9_FID_FILE) {
-if (vs-fidp-fs.fd == -1) {
+if (fidp-fid_type == P9_FID_FILE) {
+if (fidp-fs.fd == -1) {
 err = -EINVAL;
 goto out;
 }
-} else if (vs-fidp

[Qemu-devel] [PATCH 08/29] [virtio-9p] Remove post functions for v9fs_lcreate

2011-05-25 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   79 +++---
 1 files changed, 24 insertions(+), 55 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 2cb406b..a43a58f 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1608,57 +1608,6 @@ out:
 complete_pdu(s, pdu, err);
 }
 
-static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err)
-{
-if (err == 0) {
-v9fs_string_copy(vs-fidp-path, vs-fullname);
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Qd, vs-qid,
-vs-iounit);
-err = vs-offset;
-} else {
-vs-fidp-fid_type = P9_FID_NONE;
-err = -errno;
-if (vs-fidp-fs.fd  0) {
-close(vs-fidp-fs.fd);
-}
-}
-
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-v9fs_string_free(vs-fullname);
-qemu_free(vs);
-}
-
-static void v9fs_lcreate_post_get_iounit(V9fsState *s, V9fsLcreateState *vs,
-int err)
-{
-if (err) {
-err = -errno;
-goto out;
-}
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-
-out:
-v9fs_post_lcreate(s, vs, err);
-}
-
-static void v9fs_lcreate_post_do_open2(V9fsState *s, V9fsLcreateState *vs,
-int err)
-{
-if (vs-fidp-fs.fd == -1) {
-err = -errno;
-goto out;
-}
-vs-fidp-fid_type = P9_FID_FILE;
-vs-iounit =  get_iounit(s, vs-fullname);
-v9fs_lcreate_post_get_iounit(s, vs, err);
-return;
-
-out:
-v9fs_post_lcreate(s, vs, err);
-}
-
 static void v9fs_lcreate(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -1684,19 +1633,39 @@ static void v9fs_lcreate(void *opaque)
 }
 
 v9fs_string_sprintf(vs-fullname, %s/%s, vs-fidp-path.data,
- vs-name.data);
+vs-name.data);
 
 /* Ignore direct disk access hint until the server supports it. */
 flags = ~O_DIRECT;
 
 vs-fidp-fs.fd = v9fs_do_open2(s, vs-fullname.data, vs-fidp-uid,
-gid, flags, mode);
-v9fs_lcreate_post_do_open2(s, vs, err);
-return;
+gid, flags, mode);
+if (vs-fidp-fs.fd == -1) {
+err = -errno;
+goto out;
+}
 
+vs-fidp-fid_type = P9_FID_FILE;
+vs-iounit =  get_iounit(s, vs-fullname);
+
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+if (err == 0) {
+v9fs_string_copy(vs-fidp-path, vs-fullname);
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Qd, vs-qid,
+vs-iounit);
+err = vs-offset;
+} else {
+vs-fidp-fid_type = P9_FID_NONE; /*TODO:Why are we keeping this fid?*/
+err = -errno;
+if (vs-fidp-fs.fd  0) {
+close(vs-fidp-fs.fd);
+}
+}
 out:
 complete_pdu(s, vs-pdu, err);
 v9fs_string_free(vs-name);
+v9fs_string_free(vs-fullname);
 qemu_free(vs);
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 25/29] hw/9pfs: Update v9fs_wstat to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@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

[Qemu-devel] [PATCH 29/29] use readdir_r instead of readdir for reentrancy

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Harsh Prateek Bora ha...@linux.vnet.ibm.com

This patch is created on top of Aneesh's coroutine work.
LTP test for readdir passed.

Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 fsdev/file-op-9p.h|2 +-
 hw/9pfs/codir.c   |7 ---
 hw/9pfs/virtio-9p-coth.h  |4 ++--
 hw/9pfs/virtio-9p-local.c |7 ---
 hw/9pfs/virtio-9p.c   |   22 --
 5 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index af9daf7..1eda342 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -78,7 +78,7 @@ typedef struct FileOperations
 int (*open2)(FsContext *, const char *, int, FsCred *);
 void (*rewinddir)(FsContext *, DIR *);
 off_t (*telldir)(FsContext *, DIR *);
-struct dirent *(*readdir)(FsContext *, DIR *);
+int (*readdir_r)(FsContext *, DIR *, struct dirent *, struct dirent **);
 void (*seekdir)(FsContext *, DIR *, off_t);
 ssize_t (*preadv)(FsContext *, int, const struct iovec *, int, off_t);
 ssize_t (*pwritev)(FsContext *, int, const struct iovec *, int, off_t);
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 0c31db3..783d279 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -17,7 +17,8 @@
 #include qemu-coroutine.h
 #include virtio-9p-coth.h
 
-int v9fs_co_readdir(V9fsState *s, V9fsFidState *fidp, struct dirent **dent)
+int v9fs_co_readdir_r(V9fsState *s, V9fsFidState *fidp, struct dirent *dent,
+  struct dirent **result)
 {
 int err;
 
@@ -25,8 +26,8 @@ int v9fs_co_readdir(V9fsState *s, V9fsFidState *fidp, struct 
dirent **dent)
 {
 errno = 0;
 /*FIXME!! need to switch to readdir_r */
-*dent = s-ops-readdir(s-ctx, fidp-fs.dir);
-if (!*dent  errno) {
+err = s-ops-readdir_r(s-ctx, fidp-fs.dir, dent, result);
+if (!*result  errno) {
 err = -errno;
 } else {
 err = 0;
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 5fa2972..48defb7 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -57,8 +57,8 @@ typedef struct V9fsThPool {
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
 extern int v9fs_co_readlink(V9fsState *, V9fsString *, V9fsString *);
-extern int v9fs_co_readdir(V9fsState *, V9fsFidState *,
-   struct dirent **);
+extern int v9fs_co_readdir_r(V9fsState *, V9fsFidState *,
+   struct dirent *, struct dirent **result);
 extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
 extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
index 77904c3..61cbf8d 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -165,9 +165,10 @@ static off_t local_telldir(FsContext *ctx, DIR *dir)
 return telldir(dir);
 }
 
-static struct dirent *local_readdir(FsContext *ctx, DIR *dir)
+static int local_readdir_r(FsContext *ctx, DIR *dir, struct dirent *entry,
+ struct dirent **result)
 {
-return readdir(dir);
+return readdir_r(dir, entry, result);
 }
 
 static void local_seekdir(FsContext *ctx, DIR *dir, off_t off)
@@ -532,7 +533,7 @@ FileOperations local_ops = {
 .opendir = local_opendir,
 .rewinddir = local_rewinddir,
 .telldir = local_telldir,
-.readdir = local_readdir,
+.readdir_r = local_readdir_r,
 .seekdir = local_seekdir,
 .preadv = local_preadv,
 .pwritev = local_pwritev,
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 4c084fa..b48bb13 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1496,17 +1496,20 @@ static int v9fs_do_readdir_with_stat(V9fsState *s, 
V9fsPDU *pdu,
 int32_t count = 0;
 struct stat stbuf;
 off_t saved_dir_pos;
-struct dirent *dent;
+struct dirent *dent, *result;
 
 /* save the directory position */
 saved_dir_pos = v9fs_co_telldir(s, fidp);
 if (saved_dir_pos  0) {
 return saved_dir_pos;
 }
+
+dent = qemu_malloc(sizeof(struct dirent));
+
 while (1) {
 v9fs_string_init(name);
-err = v9fs_co_readdir(s, fidp, dent);
-if (err || !dent) {
+err = v9fs_co_readdir_r(s, fidp, dent, result);
+if (err || !result) {
 break;
 }
 v9fs_string_sprintf(name, %s/%s, fidp-path.data, dent-d_name);
@@ -1525,6 +1528,7 @@ static int v9fs_do_readdir_with_stat(V9fsState *s, 
V9fsPDU *pdu,
 v9fs_co_seekdir(s, fidp, saved_dir_pos);
 v9fs_stat_free(v9stat);
 v9fs_string_free(name);
+qemu_free(dent);
 return count;
 }
 count += len;
@@ -1533,6 +1537,7 @@ static int

[Qemu-devel] [PATCH 28/29] hw/9pfs: Update v9fs_read to use coroutines

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  314 +++
 1 files changed, 117 insertions(+), 197 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 06a71fb..4c084fa 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -77,32 +77,6 @@ void cred_init(FsCred *credp)
 credp-fc_rdev = -1;
 }
 
-static int v9fs_do_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
-{
-return s-ops-lstat(s-ctx, path-data, stbuf);
-}
-
-static void v9fs_do_rewinddir(V9fsState *s, DIR *dir)
-{
-return s-ops-rewinddir(s-ctx, dir);
-}
-
-static off_t v9fs_do_telldir(V9fsState *s, DIR *dir)
-{
-return s-ops-telldir(s-ctx, dir);
-}
-
-static void v9fs_do_seekdir(V9fsState *s, DIR *dir, off_t off)
-{
-return s-ops-seekdir(s-ctx, dir, off);
-}
-
-static int v9fs_do_preadv(V9fsState *s, int fd, const struct iovec *iov,
-int iovcnt, int64_t offset)
-{
-return s-ops-preadv(s-ctx, fd, iov, iovcnt, offset);
-}
-
 static void v9fs_string_init(V9fsString *str)
 {
 str-data = NULL;
@@ -1489,207 +1463,153 @@ out:
 complete_pdu(s, pdu, err);
 }
 
-static void v9fs_read_post_readdir(V9fsState *, V9fsReadState *, ssize_t);
-
-static void v9fs_read_post_seekdir(V9fsState *s, V9fsReadState *vs, ssize_t 
err)
-{
-if (err) {
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count;
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_stat_free(vs-v9stat);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_read_post_dir_lstat(V9fsState *s, V9fsReadState *vs,
-ssize_t err)
+static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu,
+   V9fsFidState *fidp, int64_t off, int32_t max_count)
 {
-if (err) {
-err = -errno;
-goto out;
-}
-err = stat_to_v9stat(s, vs-name, vs-stbuf, vs-v9stat);
-if (err) {
-goto out;
-}
-
-vs-len = pdu_marshal(vs-pdu, vs-offset + 4 + vs-count, S,
-vs-v9stat);
-if ((vs-len != (vs-v9stat.size + 2)) ||
-((vs-count + vs-len)  vs-max_count)) {
-v9fs_do_seekdir(s, vs-fidp-fs.dir, vs-dir_pos);
-v9fs_read_post_seekdir(s, vs, err);
-return;
-}
-vs-count += vs-len;
-v9fs_stat_free(vs-v9stat);
-v9fs_string_free(vs-name);
-vs-dir_pos = vs-dent-d_off;
-v9fs_co_readdir(s, vs-fidp, vs-dent);
-v9fs_read_post_readdir(s, vs, err);
-return;
-out:
-v9fs_do_seekdir(s, vs-fidp-fs.dir, vs-dir_pos);
-v9fs_read_post_seekdir(s, vs, err);
-return;
-
-}
+size_t offset = 7;
+int read_count;
+int64_t xattr_len;
 
-static void v9fs_read_post_readdir(V9fsState *s, V9fsReadState *vs, ssize_t 
err)
-{
-if (vs-dent) {
-memset(vs-v9stat, 0, sizeof(vs-v9stat));
-v9fs_string_init(vs-name);
-v9fs_string_sprintf(vs-name, %s/%s, vs-fidp-path.data,
-vs-dent-d_name);
-err = v9fs_do_lstat(s, vs-name, vs-stbuf);
-v9fs_read_post_dir_lstat(s, vs, err);
-return;
+xattr_len = fidp-fs.xattr.len;
+read_count = xattr_len - off;
+if (read_count  max_count) {
+read_count = max_count;
+} else if (read_count  0) {
+/*
+ * read beyond XATTR value
+ */
+read_count = 0;
 }
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count;
-err = vs-offset;
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t 
err)
-{
-v9fs_co_readdir(s, vs-fidp, vs-dent);
-v9fs_read_post_readdir(s, vs, err);
-return;
+offset += pdu_marshal(pdu, offset, d, read_count);
+offset += pdu_pack(pdu, offset,
+   ((char *)fidp-fs.xattr.value) + off,
+   read_count);
+return offset;
 }
 
-static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs,
-   ssize_t err)
+static int v9fs_do_readdir_with_stat(V9fsState *s, V9fsPDU *pdu,
+ V9fsFidState *fidp, int32_t max_count)
 {
-vs-dir_pos = v9fs_do_telldir(s, vs-fidp-fs.dir);
-v9fs_read_post_telldir(s, vs, err);
-return;
-}
+V9fsString name;
+V9fsStat v9stat;
+int len, err = 0;
+int32_t count = 0;
+struct stat stbuf;
+off_t saved_dir_pos;
+struct dirent *dent;
 
-static void v9fs_read_post_preadv(V9fsState *s, V9fsReadState *vs, ssize_t err)
-{
-if (err   0) {
-/* IO error return the error */
-err = -errno;
-goto out;
+/* save the directory

[Qemu-devel] [PATCH 15/29] hw/9pfs: Add yield support for fsync coroutine

2011-05-25 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofile.c |   16 
 hw/9pfs/virtio-9p-coth.h |1 +
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index e552999..26dd636 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -97,3 +97,19 @@ int v9fs_co_close(V9fsState *s, V9fsFidState *fidp)
 });
 return err;
 }
+
+int v9fs_co_fsync(V9fsState *s, V9fsFidState *fidp, int datasync)
+{
+int fd;
+int err;
+
+fd = fidp-fs.fd;
+v9fs_co_run_in_worker(
+{
+err = s-ops-fsync(s-ctx, fd, datasync);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 5d7dfd7..a3881f3 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -85,4 +85,5 @@ extern int v9fs_co_lsetxattr(V9fsState *, V9fsString *, 
V9fsString *,
 extern int v9fs_co_lremovexattr(V9fsState *, V9fsString *, V9fsString *);
 extern int v9fs_co_closedir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_close(V9fsState *, V9fsFidState *);
+extern int v9fs_co_fsync(V9fsState *, V9fsFidState *, int);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 0/24] Async threading for VirtFS using glib threads coroutines.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Anthony's  Add hard build dependency on glib patch and 
Kevin/Stefan's coroutine effort is a prerequisite.

Changes from V2
--
o Addressed all minor review comments.
o Merged two patches to avoid confusion with readlink argument.

Changes from V1
---
o Redesigned to use bh as per Stefan's suggestion. 
  This made the code very simple but is little less performant compared to V1.
  Anthony suggested to go-in with cleaner code and design (This version) and
  deal with the performance later.
  Just to put in perspective:
  Sequential Writes of creating 1GB files using ffsb
  o Write size 8k 
  With bh: 66.9MB/sec
  Without bh (marshalling routines): 74.9 MB/sec

  o Write size 128k
  With bh: 117MB/sec
  Without bh (marshalling routines): 122MB/sec

o Addressed all review comments.

o Using readdir_r is currently being worked on. Will add as a patch on top.

This patch set contains:
 - Converting all 9pfs calls into coroutines. 
 - Each 9P operation will be modified for:
- Remove post* functions. These are our call back functions which makes 
  the code very hard to read. Now with coroutines, we can achieve the same 
  state machine model with nice sequential code flow.
- Move errno access near to the local_syscall()
- Introduce asynchronous threading

This series has the basic infrastructure and few routines like 
mkdir,monod,unlink,readdir,xattr,lstat, etc converted. 
Currently we are working on converting and testing other 9P operations also 
into this model and those patches will follow shortly.

Removing callback functions made some of the patches little lengthy. 
Here is the git tree for the reviewer convenience. 

http://repo.or.cz/w/qemu/aliguori/jvrao.git/shortlog/refs/heads/9p-coroutine-bh-round1-v3

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com






[Qemu-devel] [V3 03/24] [virtio-9p] Remove post functions for v9fs_readlink.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
In the process of preparation for coroutine threads, remove all post functions
and make the function more readable.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   29 +
 1 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 15bfea7..d931a7a 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1950,13 +1950,13 @@ static void v9fs_read_post_seekdir(V9fsState *s, 
V9fsReadState *vs, ssize_t err)
 if (err) {
 goto out;
 }
-v9fs_stat_free(vs-v9stat);
-v9fs_string_free(vs-name);
 vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
 vs-offset += vs-count;
 err = vs-offset;
 out:
 complete_pdu(s, vs-pdu, err);
+v9fs_stat_free(vs-v9stat);
+v9fs_string_free(vs-name);
 qemu_free(vs);
 return;
 }
@@ -3583,21 +3583,6 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_readlink_post_readlink(V9fsState *s, V9fsReadLinkState *vs,
-int err)
-{
-if (err  0) {
-err = -errno;
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-target);
-qemu_free(vs);
-}
-
 static void v9fs_readlink(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -3612,7 +3597,6 @@ static void v9fs_readlink(void *opaque)
 vs-offset = 7;
 
 pdu_unmarshal(vs-pdu, vs-offset, d, fid);
-
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
@@ -3621,10 +3605,15 @@ static void v9fs_readlink(void *opaque)
 
 v9fs_string_init(vs-target);
 err = v9fs_do_readlink(s, fidp-path, vs-target);
-v9fs_readlink_post_readlink(s, vs, err);
-return;
+if (err  0) {
+err = -errno;
+goto out;
+}
+vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
+err = vs-offset;
 out:
 complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-target);
 qemu_free(vs);
 }
 
-- 
1.7.1




[Qemu-devel] [V3 06/24] [virtio-9p] Remove post functions for v9fs_mkdir.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   52 --
 1 files changed, 13 insertions(+), 39 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 3e0d933..f2794d4 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3308,40 +3308,6 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_mkdir_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_mkdir_post_mkdir(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-v9fs_mkdir_post_lstat(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_mkdir(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -3359,19 +3325,27 @@ static void v9fs_mkdir(void *opaque)
 
 v9fs_string_init(vs-fullname);
 pdu_unmarshal(vs-pdu, vs-offset, dsdd, fid, vs-name, mode,
-gid);
+  gid);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
 v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
 err = v9fs_do_mkdir(s, vs-fullname.data, mode, fidp-uid, gid);
-v9fs_mkdir_post_mkdir(s, vs, err);
-return;
-
+if (err == -1) {
+err = -errno;
+goto out;
+}
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+if (err == -1) {
+err = -errno;
+goto out;
+}
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
+err = vs-offset;
 out:
 complete_pdu(s, vs-pdu, err);
 v9fs_string_free(vs-fullname);
-- 
1.7.1




[Qemu-devel] [V3 10/24] hw/9pfs: Add yield support to statfs coroutine

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   14 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 3e5f4c7..b4ae372 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -41,3 +41,17 @@ int v9fs_co_readlink(V9fsState *s, V9fsString *path, 
V9fsString *buf)
 buf-data = tbuf.data;
 return err;
 }
+
+int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-statfs(s-ctx, path-data, stbuf);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 9aa5953..5d9dc0f 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -62,4 +62,5 @@ extern int v9fs_co_readdir(V9fsState *, V9fsFidState *,
 extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
 extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
+extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 02/24] [virtio-9p] Change all pdu handlers to coroutines.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
This patch changes the top level handlers to coroutines and sets the base.
It will be followed up with series of patches to convert all filesystem
calls to threaded coroutines pushing all blocking clals in VirtFS out
of vcpu threads.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |  139 +++---
 hw/9pfs/virtio-9p.h  |4 +-
 3 files changed, 99 insertions(+), 45 deletions(-)

diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 8445d29..9388f9b 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -17,6 +17,7 @@
 
 #include qemu-thread.h
 #include qemu-coroutine.h
+#include virtio-9p.h
 #include glib.h
 
 typedef struct V9fsThPool {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index ec97b10..15bfea7 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -19,6 +19,7 @@
 #include fsdev/qemu-fsdev.h
 #include virtio-9p-debug.h
 #include virtio-9p-xattr.h
+#include virtio-9p-coth.h
 
 int debug_9p_pdu;
 
@@ -1192,8 +1193,10 @@ static void v9fs_fix_path(V9fsString *dst, V9fsString 
*src, int len)
 v9fs_string_free(str);
 }
 
-static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_version(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 V9fsString version;
 size_t offset = 7;
 
@@ -1211,10 +1214,13 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
 complete_pdu(s, pdu, offset);
 
 v9fs_string_free(version);
+return;
 }
 
-static void v9fs_attach(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_attach(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid, afid, n_uname;
 V9fsString uname, aname;
 V9fsFidState *fidp;
@@ -1269,8 +1275,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_stat(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_stat(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsStatState *vs;
 ssize_t err = 0;
@@ -1316,8 +1324,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_getattr(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_getattr(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsStatStateDotl *vs;
 ssize_t err = 0;
@@ -1465,8 +1475,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_setattr(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_setattr(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsSetattrState *vs;
 int err = 0;
@@ -1579,8 +1591,10 @@ out:
 v9fs_walk_complete(s, vs, err);
 }
 
-static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_walk(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid, newfid;
 V9fsWalkState *vs;
 int err = 0;
@@ -1751,8 +1765,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_open(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsOpenState *vs;
 ssize_t err = 0;
@@ -1836,8 +1852,10 @@ out:
 v9fs_post_lcreate(s, vs, err);
 }
 
-static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_lcreate(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t dfid, flags, mode;
 gid_t gid;
 V9fsLcreateState *vs;
@@ -1883,8 +1901,10 @@ static void v9fs_post_do_fsync(V9fsState *s, V9fsPDU 
*pdu, int err)
 complete_pdu(s, pdu, err);
 }
 
-static void v9fs_fsync(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_fsync(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 size_t offset = 7;
 V9fsFidState *fidp;
@@ -1902,8 +1922,10 @@ static void v9fs_fsync(V9fsState *s, V9fsPDU *pdu)
 v9fs_post_do_fsync(s, pdu, err);
 }
 
-static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_clunk(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 size_t offset = 7;
 int err;
@@ -2068,8 +2090,10 @@ static void v9fs_xattr_read(V9fsState *s, V9fsReadState 
*vs)
 qemu_free(vs);
 }
 
-static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_read(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsReadState *vs;
 ssize_t err = 0;
@@ -2207,8 +2231,10 @@ static void v9fs_readdir_post_setdir(V9fsState *s, 
V9fsReadDirState *vs)
 return;
 }
 
-static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_readdir(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsReadDirState *vs;
 ssize_t err = 0;
@@ -2240,7 +2266,6 @@ static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu)
 out:
 complete_pdu(s, pdu, err);
 qemu_free(vs);
-return;
 }
 
 static void v9fs_write_post_pwritev(V9fsState *s

[Qemu-devel] [V3 05/24] [virtio-9p] coroutines for readlink

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/cofs.c   |   43 +++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   27 ---
 hw/9pfs/virtio-9p.h  |2 +-
 5 files changed, 50 insertions(+), 25 deletions(-)
 create mode 100644 hw/9pfs/cofs.c

diff --git a/Makefile.objs b/Makefile.objs
index 96f6a24..36005bb 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
new file mode 100644
index 000..3e5f4c7
--- /dev/null
+++ b/hw/9pfs/cofs.c
@@ -0,0 +1,43 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
+{
+int err;
+ssize_t len;
+V9fsString tbuf;
+
+v9fs_string_init(tbuf);
+tbuf.data = qemu_malloc(PATH_MAX);
+v9fs_co_run_in_worker(
+{
+len = s-ops-readlink(s-ctx, path-data,
+   tbuf.data, PATH_MAX - 1);
+if (len  -1) {
+tbuf.size = len;
+tbuf.data[len] = 0;
+err = 0;
+} else {
+err = -errno;
+}
+});
+buf-size = tbuf.size;
+buf-data = tbuf.data;
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 9388f9b..94c5147 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -56,4 +56,5 @@ typedef struct V9fsThPool {
 
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
+extern int v9fs_co_readlink(V9fsState *, V9fsString *, V9fsString *);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 4efbbca..3e0d933 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -82,21 +82,6 @@ static int v9fs_do_lstat(V9fsState *s, V9fsString *path, 
struct stat *stbuf)
 return s-ops-lstat(s-ctx, path-data, stbuf);
 }
 
-static ssize_t v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString 
*buf)
-{
-ssize_t len;
-
-buf-data = qemu_malloc(1024);
-
-len = s-ops-readlink(s-ctx, path-data, buf-data, 1024 - 1);
-if (len  -1) {
-buf-size = len;
-buf-data[len] = 0;
-}
-
-return len;
-}
-
 static int v9fs_do_close(V9fsState *s, int fd)
 {
 return s-ops-close(s-ctx, fd);
@@ -291,7 +276,7 @@ static int v9fs_do_lremovexattr(V9fsState *s, V9fsString 
*path,
 }
 
 
-static void v9fs_string_init(V9fsString *str)
+void v9fs_string_init(V9fsString *str)
 {
 str-data = NULL;
 str-size = 0;
@@ -1055,13 +1040,10 @@ static int stat_to_v9stat(V9fsState *s, V9fsString 
*name,
 v9fs_string_null(v9stat-extension);
 
 if (v9stat-mode  P9_STAT_MODE_SYMLINK) {
-err = v9fs_do_readlink(s, name, v9stat-extension);
-if (err == -1) {
-err = -errno;
+err = v9fs_co_readlink(s, name, v9stat-extension);
+if (err  0) {
 return err;
 }
-v9stat-extension.data[err] = 0;
-v9stat-extension.size = err;
 } else if (v9stat-mode  P9_STAT_MODE_DEVICE) {
 v9fs_string_sprintf(v9stat-extension, %c %u %u,
 S_ISCHR(stbuf-st_mode) ? 'c' : 'b',
@@ -3600,9 +3582,8 @@ static void v9fs_readlink(void *opaque)
 }
 
 v9fs_string_init(target);
-err = v9fs_do_readlink(pdu-s, fidp-path, target);
+err = v9fs_co_readlink(pdu-s, fidp-path, target);
 if (err  0) {
-err = -errno;
 goto out;
 }
 offset += pdu_marshal(pdu, offset, s, target);
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index e95b63d..78d45b5 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -505,5 +505,5 @@ static inline size_t do_pdu_unpack(void *dst, struct iovec 
*sg, int sg_count,
 }
 
 extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
-
+void v9fs_string_init(V9fsString *str);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 04/24] [virtio-9p] clean up v9fs_readlink.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsReadLinkState.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   25 ++---
 hw/9pfs/virtio-9p.h |7 ---
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index d931a7a..4efbbca 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3586,35 +3586,30 @@ out:
 static void v9fs_readlink(void *opaque)
 {
 V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+size_t offset = 7;
+V9fsString target;
 int32_t fid;
-V9fsReadLinkState *vs;
 int err = 0;
 V9fsFidState *fidp;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, d, fid);
-fidp = lookup_fid(s, fid);
+pdu_unmarshal(pdu, offset, d, fid);
+fidp = lookup_fid(pdu-s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
 
-v9fs_string_init(vs-target);
-err = v9fs_do_readlink(s, fidp-path, vs-target);
+v9fs_string_init(target);
+err = v9fs_do_readlink(pdu-s, fidp-path, target);
 if (err  0) {
 err = -errno;
 goto out;
 }
-vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
-err = vs-offset;
+offset += pdu_marshal(pdu, offset, s, target);
+err = offset;
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-target);
-qemu_free(vs);
+v9fs_string_free(target);
+complete_pdu(pdu-s, pdu, err);
 }
 
 static CoroutineEntry *pdu_co_handlers[] = {
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index fb1e465..e95b63d 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -495,13 +495,6 @@ typedef struct V9fsGetlockState
 V9fsGetlock *glock;
 } V9fsGetlockState;
 
-typedef struct V9fsReadLinkState
-{
-V9fsPDU *pdu;
-size_t offset;
-V9fsString target;
-} V9fsReadLinkState;
-
 size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
   size_t offset, size_t size, int pack);
 
-- 
1.7.1




[Qemu-devel] [V3 01/24] [virtio-9p] Add infrastructure to support glib threads and coroutines.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
This patch is originally made by Arun Bharadwaj for glib support.
Later Harsh Prateek Bora added coroutines support.
This version implemented with suggestions from
Stefan Hajnoczi stefa...@linux.vnet.ibm.com.

Signed-off-by: Arun R Bharadwaj a...@linux.vnet.ibm.com
Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs  |2 +
 hw/9pfs/virtio-9p-coth.c   |   93 
 hw/9pfs/virtio-9p-coth.h   |   58 +++
 hw/9pfs/virtio-9p-device.c |7 ++-
 4 files changed, 158 insertions(+), 2 deletions(-)
 create mode 100644 hw/9pfs/virtio-9p-coth.c
 create mode 100644 hw/9pfs/virtio-9p-coth.h

diff --git a/Makefile.objs b/Makefile.objs
index 3873f10..96f6a24 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,8 +297,10 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
+$(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
 
 ##
diff --git a/hw/9pfs/virtio-9p-coth.c b/hw/9pfs/virtio-9p-coth.c
new file mode 100644
index 000..e61b656
--- /dev/null
+++ b/hw/9pfs/virtio-9p-coth.c
@@ -0,0 +1,93 @@
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Harsh Prateek Bora ha...@linux.vnet.ibm.com
+ *  Venkateswararao Jujjuri(JV) jv...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include qemu-char.h
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+/* v9fs glib thread pool */
+static V9fsThPool v9fs_pool;
+
+void co_run_in_worker_bh(void *opaque)
+{
+Coroutine *co = opaque;
+g_thread_pool_push(v9fs_pool.pool, co, NULL);
+}
+
+static void v9fs_qemu_process_req_done(void *arg)
+{
+char byte;
+ssize_t len;
+Coroutine *co;
+
+do {
+len = read(v9fs_pool.rfd, byte, sizeof(byte));
+} while (len == -1   errno == EINTR);
+
+while ((co = g_async_queue_try_pop(v9fs_pool.completed)) != NULL) {
+qemu_coroutine_enter(co, NULL);
+}
+}
+
+static void v9fs_thread_routine(gpointer data, gpointer user_data)
+{
+ssize_t len;
+char byte = 0;
+Coroutine *co = data;
+
+qemu_coroutine_enter(co, NULL);
+
+g_async_queue_push(v9fs_pool.completed, co);
+do {
+len = write(v9fs_pool.wfd, byte, sizeof(byte));
+} while (len == -1  errno == EINTR);
+}
+
+int v9fs_init_worker_threads(void)
+{
+int notifier_fds[2];
+V9fsThPool *p = v9fs_pool;
+
+/* init thread system if not already initialized */
+if (!g_thread_get_initialized()) {
+g_thread_init(NULL);
+}
+
+if (qemu_pipe(notifier_fds) == -1) {
+return -1;
+}
+
+p-pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL);
+if (!p-pool) {
+return -1;
+}
+p-completed = g_async_queue_new();
+if (!p-completed) {
+/*
+ * We are going to terminate.
+ * So don't worry about cleanup
+ */
+return -1;
+}
+p-rfd = notifier_fds[0];
+p-wfd = notifier_fds[1];
+
+fcntl(p-rfd, F_SETFL, O_NONBLOCK);
+fcntl(p-wfd, F_SETFL, O_NONBLOCK);
+
+qemu_set_fd_handler(p-rfd, v9fs_qemu_process_req_done, NULL, NULL);
+return 0;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
new file mode 100644
index 000..8445d29
--- /dev/null
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -0,0 +1,58 @@
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Harsh Prateek Bora ha...@linux.vnet.ibm.com
+ *  Venkateswararao Jujjuri(JV) jv...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef _QEMU_VIRTIO_9P_COTH_H
+#define _QEMU_VIRTIO_9P_COTH_H
+
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include glib.h
+
+typedef struct V9fsThPool {
+int rfd;
+int wfd;
+GThreadPool *pool;
+GAsyncQueue *completed;
+} V9fsThPool;
+
+/*
+ * we want to use bottom half because we want to make sure the below
+ * sequence of events.
+ *
+ *   1. Yield the coroutine in the QEMU thread.
+ *   2. Submit the coroutine to a worker thread.
+ *   3. Enter the coroutine in the worker thread.
+ * we cannot swap step 1 and 2, because that would imply worker thread
+ * can enter coroutine while step1 is still running
+ */
+#define v9fs_co_run_in_worker(code_block)   \
+do

[Qemu-devel] [V3 14/24] hw/9pfs: Add yield support to setattr related coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include chmod, utimensat, chown and truncate.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   64 ++
 hw/9pfs/virtio-9p-coth.h |4 +++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index b4ae372..2a94707 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -55,3 +55,67 @@ int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct 
statfs *stbuf)
 });
 return err;
 }
+
+int v9fs_co_chmod(V9fsState *s, V9fsString *path, mode_t mode)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_mode = mode;
+v9fs_co_run_in_worker(
+{
+err = s-ops-chmod(s-ctx, path-data, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_utimensat(V9fsState *s, V9fsString *path,
+  struct timespec times[2])
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-utimensat(s-ctx, path-data, times);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_uid = uid;
+cred.fc_gid = gid;
+v9fs_co_run_in_worker(
+{
+err = s-ops-chown(s-ctx, path-data, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t size)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-truncate(s-ctx, path-data, size);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 3538d91..09f232a 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -64,4 +64,8 @@ extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, 
off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
 extern int v9fs_co_lstat(V9fsState *, V9fsString *, struct stat *);
+extern int v9fs_co_chmod(V9fsState *, V9fsString *, mode_t);
+extern int v9fs_co_utimensat(V9fsState *, V9fsString *, struct timespec [2]);
+extern int v9fs_co_chown(V9fsState *, V9fsString *, uid_t, gid_t);
+extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 08/24] hw/9pfs: Add yield support for readdir related coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include readdir, telldir, seekdir, rewinddir.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/codir.c  |   66 ++
 hw/9pfs/virtio-9p-coth.h |5 +++
 3 files changed, 72 insertions(+), 1 deletions(-)
 create mode 100644 hw/9pfs/codir.c

diff --git a/Makefile.objs b/Makefile.objs
index 36005bb..614bcaf 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
new file mode 100644
index 000..47b10df
--- /dev/null
+++ b/hw/9pfs/codir.c
@@ -0,0 +1,66 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_readdir(V9fsState *s, V9fsFidState *fidp, struct dirent **dent)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+errno = 0;
+/*FIXME!! need to switch to readdir_r */
+*dent = s-ops-readdir(s-ctx, fidp-fs.dir);
+if (!*dent  errno) {
+err = -errno;
+} else {
+err = 0;
+}
+});
+return err;
+}
+
+off_t v9fs_co_telldir(V9fsState *s, V9fsFidState *fidp)
+{
+off_t err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-telldir(s-ctx, fidp-fs.dir);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+void v9fs_co_seekdir(V9fsState *s, V9fsFidState *fidp, off_t offset)
+{
+v9fs_co_run_in_worker(
+{
+s-ops-seekdir(s-ctx, fidp-fs.dir, offset);
+});
+}
+
+void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
+{
+v9fs_co_run_in_worker(
+{
+s-ops-rewinddir(s-ctx, fidp-fs.dir);
+});
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 94c5147..9aa5953 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -57,4 +57,9 @@ typedef struct V9fsThPool {
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
 extern int v9fs_co_readlink(V9fsState *, V9fsString *, V9fsString *);
+extern int v9fs_co_readdir(V9fsState *, V9fsFidState *,
+   struct dirent **);
+extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
+extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
+extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 09/24] hw/9pfs: Update v9fs_readdir to use coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  173 +--
 1 files changed, 72 insertions(+), 101 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 54976c4..f48cc47 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -112,11 +112,6 @@ static off_t v9fs_do_telldir(V9fsState *s, DIR *dir)
 return s-ops-telldir(s-ctx, dir);
 }
 
-static struct dirent *v9fs_do_readdir(V9fsState *s, DIR *dir)
-{
-return s-ops-readdir(s-ctx, dir);
-}
-
 static void v9fs_do_seekdir(V9fsState *s, DIR *dir, off_t off)
 {
 return s-ops-seekdir(s-ctx, dir, off);
@@ -1967,7 +1962,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, 
V9fsReadState *vs,
 v9fs_stat_free(vs-v9stat);
 v9fs_string_free(vs-name);
 vs-dir_pos = vs-dent-d_off;
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
+v9fs_co_readdir(s, vs-fidp, vs-dent);
 v9fs_read_post_readdir(s, vs, err);
 return;
 out:
@@ -1999,7 +1994,7 @@ static void v9fs_read_post_readdir(V9fsState *s, 
V9fsReadState *vs, ssize_t err)
 
 static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t 
err)
 {
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
+v9fs_co_readdir(s, vs-fidp, vs-dent);
 v9fs_read_post_readdir(s, vs, err);
 return;
 }
@@ -2128,126 +2123,102 @@ out:
 qemu_free(vs);
 }
 
-typedef struct V9fsReadDirState {
-V9fsPDU *pdu;
-V9fsFidState *fidp;
-V9fsQID qid;
-off_t saved_dir_pos;
-struct dirent *dent;
-int32_t count;
-int32_t max_count;
-size_t offset;
-int64_t initial_offset;
-V9fsString name;
-} V9fsReadDirState;
-
-static void v9fs_readdir_post_seekdir(V9fsState *s, V9fsReadDirState *vs)
+static size_t v9fs_readdir_data_size(V9fsString *name)
 {
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count;
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
-return;
+/*
+ * Size of each dirent on the wire: size of qid (13) + size of offset (8)
+ * size of type (1) + size of name.size (2) + strlen(name.data)
+ */
+return 24 + v9fs_string_size(name);
 }
 
-/* Size of each dirent on the wire: size of qid (13) + size of offset (8)
- * size of type (1) + size of name.size (2) + strlen(name.data)
- */
-#define V9_READDIR_DATA_SZ (24 + strlen(vs-name.data))
-
-static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs)
+static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu,
+   V9fsFidState *fidp, int32_t max_count)
 {
-int len;
 size_t size;
+V9fsQID qid;
+V9fsString name;
+int len, err = 0;
+int32_t count = 0;
+off_t saved_dir_pos;
+struct dirent *dent;
 
-if (vs-dent) {
-v9fs_string_init(vs-name);
-v9fs_string_sprintf(vs-name, %s, vs-dent-d_name);
-
-if ((vs-count + V9_READDIR_DATA_SZ)  vs-max_count) {
+/* save the directory position */
+saved_dir_pos = v9fs_co_telldir(s, fidp);
+if (saved_dir_pos  0) {
+return saved_dir_pos;
+}
+while (1) {
+err = v9fs_co_readdir(s, fidp, dent);
+if (err || !dent) {
+break;
+}
+v9fs_string_init(name);
+v9fs_string_sprintf(name, %s, dent-d_name);
+if ((count + v9fs_readdir_data_size(name))  max_count) {
 /* Ran out of buffer. Set dir back to old position and return */
-v9fs_do_seekdir(s, vs-fidp-fs.dir, vs-saved_dir_pos);
-v9fs_readdir_post_seekdir(s, vs);
-return;
+v9fs_co_seekdir(s, fidp, saved_dir_pos);
+v9fs_string_free(name);
+return count;
 }
-
-/* Fill up just the path field of qid because the client uses
+/*
+ * Fill up just the path field of qid because the client uses
  * only that. To fill the entire qid structure we will have
  * to stat each dirent found, which is expensive
  */
-size = MIN(sizeof(vs-dent-d_ino), sizeof(vs-qid.path));
-memcpy(vs-qid.path, vs-dent-d_ino, size);
+size = MIN(sizeof(dent-d_ino), sizeof(qid.path));
+memcpy(qid.path, dent-d_ino, size);
 /* Fill the other fields with dummy values */
-vs-qid.type = 0;
-vs-qid.version = 0;
-
-len = pdu_marshal(vs-pdu, vs-offset+4+vs-count, Qqbs,
-  vs-qid, vs-dent-d_off,
-  vs-dent-d_type, vs-name);
-vs-count += len;
-v9fs_string_free(vs-name);
-vs-saved_dir_pos = vs-dent-d_off;
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
-v9fs_readdir_post_readdir(s, vs);
-return;
-}
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count

[Qemu-devel] [V3 24/24] [virtio-9p] coroutine and threading for remove/unlink

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   14 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   11 ++-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 293e377..70d1273 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -140,3 +140,17 @@ int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t 
uid,
 });
 return err;
 }
+
+int v9fs_co_remove(V9fsState *s, V9fsString *path)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-remove(s-ctx, path-data);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 96e88d8..60795c4 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -74,4 +74,5 @@ extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
 extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
  gid_t, dev_t, mode_t);
 extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
+extern int v9fs_co_remove(V9fsState *, V9fsString *);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 7327b3b..a5f0590 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -212,11 +212,6 @@ static int v9fs_do_utimensat(V9fsState *s, V9fsString 
*path,
 return s-ops-utimensat(s-ctx, path-data, times);
 }
 
-static int v9fs_do_remove(V9fsState *s, V9fsString *path)
-{
-return s-ops-remove(s-ctx, path-data);
-}
-
 static int v9fs_do_fsync(V9fsState *s, int fd, int datasync)
 {
 return s-ops-fsync(s-ctx, fd, datasync);
@@ -2595,10 +2590,8 @@ static void v9fs_remove(void *opaque)
 err = -EINVAL;
 goto out;
 }
-err = v9fs_do_remove(pdu-s, fidp-path);
-if (err  0) {
-err = -errno;
-} else {
+err = v9fs_co_remove(pdu-s, fidp-path);
+if (!err) {
 err = offset;
 }
 
-- 
1.7.1




[Qemu-devel] [V3 07/24] [virtio-9p] clean up v9fs_mkdir.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsMkState and additional malloc()s.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   38 +-
 1 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f2794d4..54976c4 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3311,46 +3311,42 @@ out:
 static void v9fs_mkdir(void *opaque)
 {
 V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+size_t offset = 7;
 int32_t fid;
-V9fsMkState *vs;
-int err = 0;
+struct stat stbuf;
+V9fsString name, fullname;
+V9fsQID qid;
 V9fsFidState *fidp;
 gid_t gid;
 int mode;
+int err = 0;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-v9fs_string_init(vs-fullname);
-pdu_unmarshal(vs-pdu, vs-offset, dsdd, fid, vs-name, mode,
-  gid);
+v9fs_string_init(fullname);
+pdu_unmarshal(pdu, offset, dsdd, fid, name, mode, gid);
 
-fidp = lookup_fid(s, fid);
+fidp = lookup_fid(pdu-s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
-err = v9fs_do_mkdir(s, vs-fullname.data, mode, fidp-uid, gid);
+v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
+err = v9fs_do_mkdir(pdu-s, fullname.data, mode, fidp-uid, gid);
 if (err == -1) {
 err = -errno;
 goto out;
 }
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+err = v9fs_do_lstat(pdu-s, fullname, stbuf);
 if (err == -1) {
 err = -errno;
 goto out;
 }
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
+stat_to_qid(stbuf, qid);
+offset += pdu_marshal(pdu, offset, Q, qid);
+err = offset;
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
+complete_pdu(pdu-s, pdu, err);
+v9fs_string_free(fullname);
+v9fs_string_free(name);
 }
 
 static void v9fs_post_xattr_getvalue(V9fsState *s, V9fsXattrState *vs, int err)
-- 
1.7.1




[Qemu-devel] [V3 13/24] hw/9pfs: Update v9fs_getattr to use coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   57 +--
 hw/9pfs/virtio-9p.h |8 ---
 2 files changed, 19 insertions(+), 46 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f83fe5a..4e9d73a 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1087,7 +1087,7 @@ static int stat_to_v9stat(V9fsState *s, V9fsString *name,
 
 
 static void stat_to_v9stat_dotl(V9fsState *s, const struct stat *stbuf,
-V9fsStatDotl *v9lstat)
+V9fsStatDotl *v9lstat)
 {
 memset(v9lstat, 0, sizeof(*v9lstat));
 
@@ -1284,57 +1284,38 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_getattr_post_lstat(V9fsState *s, V9fsStatStateDotl *vs,
-int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_v9stat_dotl(s, vs-stbuf, vs-v9stat_dotl);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, A, vs-v9stat_dotl);
-err = vs-offset;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
 static void v9fs_getattr(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int32_t fid;
-V9fsStatStateDotl *vs;
-ssize_t err = 0;
+size_t offset = 7;
+ssize_t retval = 0;
+struct stat stbuf;
 V9fsFidState *fidp;
 uint64_t request_mask;
+V9fsStatDotl v9stat_dotl;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-memset(vs-v9stat_dotl, 0, sizeof(vs-v9stat_dotl));
-
-pdu_unmarshal(vs-pdu, vs-offset, dq, fid, request_mask);
+pdu_unmarshal(pdu, offset, dq, fid, request_mask);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
-err = -ENOENT;
+retval = -ENOENT;
 goto out;
 }
-
-/* Currently we only support BASIC fields in stat, so there is no
+/*
+ * Currently we only support BASIC fields in stat, so there is no
  * need to look at request_mask.
  */
-err = v9fs_do_lstat(s, fidp-path, vs-stbuf);
-v9fs_getattr_post_lstat(s, vs, err);
-return;
-
+retval = v9fs_co_lstat(s, fidp-path, stbuf);
+if (retval  0) {
+goto out;
+}
+stat_to_v9stat_dotl(s, stbuf, v9stat_dotl);
+retval = offset;
+retval += pdu_marshal(pdu, offset, A, v9stat_dotl);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(s, pdu, retval);
 }
 
 /* From Linux kernel code */
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 22651cd..9747ee9 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -278,14 +278,6 @@ typedef struct V9fsStatDotl {
 uint64_t st_data_version;
 } V9fsStatDotl;
 
-typedef struct V9fsStatStateDotl {
-V9fsPDU *pdu;
-size_t offset;
-V9fsStatDotl v9stat_dotl;
-struct stat stbuf;
-} V9fsStatStateDotl;
-
-
 typedef struct V9fsWalkState {
 V9fsPDU *pdu;
 size_t offset;
-- 
1.7.1




[Qemu-devel] [V3 12/24] hw/9pfs: Add yield support to lstat coroutine

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/cofile.c |   32 
 hw/9pfs/virtio-9p-coth.h |1 +
 3 files changed, 34 insertions(+), 1 deletions(-)
 create mode 100644 hw/9pfs/cofile.c

diff --git a/Makefile.objs b/Makefile.objs
index 614bcaf..83d30bd 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
new file mode 100644
index 000..a4c0ae7
--- /dev/null
+++ b/hw/9pfs/cofile.c
@@ -0,0 +1,32 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-lstat(s-ctx, path-data, stbuf);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 5d9dc0f..3538d91 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -63,4 +63,5 @@ extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
 extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
+extern int v9fs_co_lstat(V9fsState *, V9fsString *, struct stat *);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 11/24] hw/9pfs: Update v9fs_statfs to use coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   92 --
 hw/9pfs/virtio-9p.h |   22 
 2 files changed, 44 insertions(+), 70 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f48cc47..f83fe5a 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3037,79 +3037,75 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_statfs_post_statfs(V9fsState *s, V9fsStatfsState *vs, int err)
-{
+static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
+{
+uint32_t f_type;
+uint32_t f_bsize;
+uint64_t f_blocks;
+uint64_t f_bfree;
+uint64_t f_bavail;
+uint64_t f_files;
+uint64_t f_ffree;
+uint64_t fsid_val;
+uint32_t f_namelen;
+size_t offset = 7;
 int32_t bsize_factor;
 
-if (err) {
-err = -errno;
-goto out;
-}
-
 /*
  * compute bsize factor based on host file system block size
  * and client msize
  */
-bsize_factor = (s-msize - P9_IOHDRSZ)/vs-stbuf.f_bsize;
+bsize_factor = (s-msize - P9_IOHDRSZ)/stbuf-f_bsize;
 if (!bsize_factor) {
 bsize_factor = 1;
 }
-vs-v9statfs.f_type = vs-stbuf.f_type;
-vs-v9statfs.f_bsize = vs-stbuf.f_bsize;
-vs-v9statfs.f_bsize *= bsize_factor;
+f_type  = stbuf-f_type;
+f_bsize = stbuf-f_bsize;
+f_bsize *= bsize_factor;
 /*
  * f_bsize is adjusted(multiplied) by bsize factor, so we need to
  * adjust(divide) the number of blocks, free blocks and available
  * blocks by bsize factor
  */
-vs-v9statfs.f_blocks = vs-stbuf.f_blocks/bsize_factor;
-vs-v9statfs.f_bfree = vs-stbuf.f_bfree/bsize_factor;
-vs-v9statfs.f_bavail = vs-stbuf.f_bavail/bsize_factor;
-vs-v9statfs.f_files = vs-stbuf.f_files;
-vs-v9statfs.f_ffree = vs-stbuf.f_ffree;
-vs-v9statfs.fsid_val = (unsigned int) vs-stbuf.f_fsid.__val[0] |
-   (unsigned long long)vs-stbuf.f_fsid.__val[1]  32;
-vs-v9statfs.f_namelen = vs-stbuf.f_namelen;
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, ddqqd,
- vs-v9statfs.f_type, vs-v9statfs.f_bsize, vs-v9statfs.f_blocks,
- vs-v9statfs.f_bfree, vs-v9statfs.f_bavail, vs-v9statfs.f_files,
- vs-v9statfs.f_ffree, vs-v9statfs.fsid_val,
- vs-v9statfs.f_namelen);
+f_blocks = stbuf-f_blocks/bsize_factor;
+f_bfree  = stbuf-f_bfree/bsize_factor;
+f_bavail = stbuf-f_bavail/bsize_factor;
+f_files  = stbuf-f_files;
+f_ffree  = stbuf-f_ffree;
+fsid_val = (unsigned int) stbuf-f_fsid.__val[0] |
+   (unsigned long long)stbuf-f_fsid.__val[1]  32;
+f_namelen = stbuf-f_namelen;
 
-out:
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
+return pdu_marshal(pdu, offset, ddqqd,
+   f_type, f_bsize, f_blocks, f_bfree,
+   f_bavail, f_files, f_ffree,
+   fsid_val, f_namelen);
 }
 
 static void v9fs_statfs(void *opaque)
 {
+int32_t fid;
+ssize_t retval = 0;
+size_t offset = 7;
+V9fsFidState *fidp;
+struct statfs stbuf;
 V9fsPDU *pdu = opaque;
 V9fsState *s = pdu-s;
-V9fsStatfsState *vs;
-ssize_t err = 0;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-memset(vs-v9statfs, 0, sizeof(vs-v9statfs));
-
-pdu_unmarshal(vs-pdu, vs-offset, d, vs-fid);
-
-vs-fidp = lookup_fid(s, vs-fid);
-if (vs-fidp == NULL) {
-err = -ENOENT;
+pdu_unmarshal(pdu, offset, d, fid);
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+retval = -ENOENT;
 goto out;
 }
-
-err = v9fs_do_statfs(s, vs-fidp-path, vs-stbuf);
-v9fs_statfs_post_statfs(s, vs, err);
-return;
-
+retval = v9fs_co_statfs(s, fidp-path, stbuf);
+if (retval  0) {
+goto out;
+}
+retval = offset;
+retval += v9fs_fill_statfs(s, pdu, stbuf);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(s, pdu, retval);
 return;
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 78d45b5..22651cd 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -398,28 +398,6 @@ struct virtio_9p_config
 uint8_t tag[0];
 } __attribute__((packed));
 
-typedef struct V9fsStatfs
-{
-uint32_t f_type;
-uint32_t f_bsize;
-uint64_t f_blocks;
-uint64_t f_bfree;
-uint64_t f_bavail;
-uint64_t f_files;
-uint64_t f_ffree;
-uint64_t fsid_val;
-uint32_t f_namelen;
-} V9fsStatfs;
-
-typedef struct V9fsStatfsState {
-V9fsPDU *pdu;
-size_t offset;
-int32_t fid;
-V9fsStatfs v9statfs;
-V9fsFidState *fidp;
-struct statfs stbuf;
-} V9fsStatfsState;
-
 typedef struct V9fsMkState {
 V9fsPDU *pdu;
 size_t offset;
-- 
1.7.1




[Qemu-devel] [V3 16/24] hw/9pfs: Add yield support to xattr related coroutine

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include llistxattr and lgetxattr.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|1 +
 hw/9pfs/coxattr.c|   50 ++
 hw/9pfs/virtio-9p-coth.h |3 ++
 3 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 hw/9pfs/coxattr.c

diff --git a/Makefile.objs b/Makefile.objs
index 83d30bd..98a345b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -298,6 +298,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
+9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/coxattr.c b/hw/9pfs/coxattr.c
new file mode 100644
index 000..2fba2c9
--- /dev/null
+++ b/hw/9pfs/coxattr.c
@@ -0,0 +1,50 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_llistxattr(V9fsState *s, V9fsString *path, void *value, size_t 
size)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-llistxattr(s-ctx, path-data, value, size);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_lgetxattr(V9fsState *s, V9fsString *path,
+  V9fsString *xattr_name,
+  void *value, size_t size)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-lgetxattr(s-ctx, path-data,
+xattr_name-data,
+value, size);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 09f232a..eb0c99a 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -68,4 +68,7 @@ extern int v9fs_co_chmod(V9fsState *, V9fsString *, mode_t);
 extern int v9fs_co_utimensat(V9fsState *, V9fsString *, struct timespec [2]);
 extern int v9fs_co_chown(V9fsState *, V9fsString *, uid_t, gid_t);
 extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
+extern int v9fs_co_llistxattr(V9fsState *, V9fsString *, void *, size_t);
+extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
+ V9fsString *, void *, size_t);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 18/24] hw/9pfs: Update v9fs_xattrcreate to use coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   53 +--
 hw/9pfs/virtio-9p.h |   11 --
 2 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 5336b8b..112b0f7 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3317,43 +3317,42 @@ out:
 
 static void v9fs_xattrcreate(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int flags;
 int32_t fid;
+int64_t size;
 ssize_t err = 0;
-V9fsXattrState *vs;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
+V9fsString name;
+size_t offset = 7;
+V9fsFidState *file_fidp;
+V9fsFidState *xattr_fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-pdu_unmarshal(vs-pdu, vs-offset, dsqd,
-  fid, vs-name, vs-size, flags);
+pdu_unmarshal(pdu, offset, dsqd,
+  fid, name, size, flags);
 
-vs-file_fidp = lookup_fid(s, fid);
-if (vs-file_fidp == NULL) {
+file_fidp = lookup_fid(s, fid);
+if (file_fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-
 /* Make the file fid point to xattr */
-vs-xattr_fidp = vs-file_fidp;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = 0;
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fs.xattr.flags = flags;
-v9fs_string_init(vs-xattr_fidp-fs.xattr.name);
-v9fs_string_copy(vs-xattr_fidp-fs.xattr.name, vs-name);
-if (vs-size)
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-else
-vs-xattr_fidp-fs.xattr.value = NULL;
-
+xattr_fidp = file_fidp;
+xattr_fidp-fid_type = P9_FID_XATTR;
+xattr_fidp-fs.xattr.copied_len = 0;
+xattr_fidp-fs.xattr.len = size;
+xattr_fidp-fs.xattr.flags = flags;
+v9fs_string_init(xattr_fidp-fs.xattr.name);
+v9fs_string_copy(xattr_fidp-fs.xattr.name, name);
+if (size) {
+xattr_fidp-fs.xattr.value = qemu_malloc(size);
+} else {
+xattr_fidp-fs.xattr.value = NULL;
+}
+err = offset;
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
+complete_pdu(s, pdu, err);
+v9fs_string_free(name);
 }
 
 static void v9fs_readlink(void *opaque)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 2976433..d57d5ae 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -399,17 +399,6 @@ typedef struct V9fsRenameState {
 V9fsString name;
 } V9fsRenameState;
 
-typedef struct V9fsXattrState
-{
-V9fsPDU *pdu;
-size_t offset;
-V9fsFidState *file_fidp;
-V9fsFidState *xattr_fidp;
-V9fsString name;
-int64_t size;
-int flags;
-void *value;
-} V9fsXattrState;
 
 #define P9_LOCK_SUCCESS 0
 #define P9_LOCK_BLOCKED 1
-- 
1.7.1




[Qemu-devel] [V3 15/24] hw/9pfs: Update v9fs_setattr to use coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  163 +--
 hw/9pfs/virtio-9p.h |8 ---
 2 files changed, 54 insertions(+), 117 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 4e9d73a..0f965b5 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1330,139 +1330,84 @@ out:
 #define ATTR_ATIME_SET  (1  7)
 #define ATTR_MTIME_SET  (1  8)
 
-static void v9fs_setattr_post_truncate(V9fsState *s, V9fsSetattrState *vs,
-  int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-err = vs-offset;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_chown(V9fsState *s, V9fsSetattrState *vs, int 
err)
+static void v9fs_setattr(void *opaque)
 {
-if (err == -1) {
-err = -errno;
-goto out;
-}
+int err = 0;
+int32_t fid;
+V9fsFidState *fidp;
+size_t offset = 7;
+V9fsIattr v9iattr;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-if (vs-v9iattr.valid  (ATTR_SIZE)) {
-err = v9fs_do_truncate(s, vs-fidp-path, vs-v9iattr.size);
-}
-v9fs_setattr_post_truncate(s, vs, err);
-return;
+pdu_unmarshal(pdu, offset, dI, fid, v9iattr);
 
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_utimensat(V9fsState *s, V9fsSetattrState *vs,
-   int err)
-{
-if (err == -1) {
-err = -errno;
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+err = -EINVAL;
 goto out;
 }
-
-/* If the only valid entry in iattr is ctime we can call
- * chown(-1,-1) to update the ctime of the file
- */
-if ((vs-v9iattr.valid  (ATTR_UID | ATTR_GID)) ||
-((vs-v9iattr.valid  ATTR_CTIME)
- !((vs-v9iattr.valid  ATTR_MASK)  ~ATTR_CTIME))) {
-if (!(vs-v9iattr.valid  ATTR_UID)) {
-vs-v9iattr.uid = -1;
-}
-if (!(vs-v9iattr.valid  ATTR_GID)) {
-vs-v9iattr.gid = -1;
+if (v9iattr.valid  ATTR_MODE) {
+err = v9fs_co_chmod(s, fidp-path, v9iattr.mode);
+if (err  0) {
+goto out;
 }
-err = v9fs_do_chown(s, vs-fidp-path, vs-v9iattr.uid,
-vs-v9iattr.gid);
 }
-v9fs_setattr_post_chown(s, vs, err);
-return;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_chmod(V9fsState *s, V9fsSetattrState *vs, int 
err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-if (vs-v9iattr.valid  (ATTR_ATIME | ATTR_MTIME)) {
+if (v9iattr.valid  (ATTR_ATIME | ATTR_MTIME)) {
 struct timespec times[2];
-if (vs-v9iattr.valid  ATTR_ATIME) {
-if (vs-v9iattr.valid  ATTR_ATIME_SET) {
-times[0].tv_sec = vs-v9iattr.atime_sec;
-times[0].tv_nsec = vs-v9iattr.atime_nsec;
+if (v9iattr.valid  ATTR_ATIME) {
+if (v9iattr.valid  ATTR_ATIME_SET) {
+times[0].tv_sec = v9iattr.atime_sec;
+times[0].tv_nsec = v9iattr.atime_nsec;
 } else {
 times[0].tv_nsec = UTIME_NOW;
 }
 } else {
 times[0].tv_nsec = UTIME_OMIT;
 }
-
-if (vs-v9iattr.valid  ATTR_MTIME) {
-if (vs-v9iattr.valid  ATTR_MTIME_SET) {
-times[1].tv_sec = vs-v9iattr.mtime_sec;
-times[1].tv_nsec = vs-v9iattr.mtime_nsec;
+if (v9iattr.valid  ATTR_MTIME) {
+if (v9iattr.valid  ATTR_MTIME_SET) {
+times[1].tv_sec = v9iattr.mtime_sec;
+times[1].tv_nsec = v9iattr.mtime_nsec;
 } else {
 times[1].tv_nsec = UTIME_NOW;
 }
 } else {
 times[1].tv_nsec = UTIME_OMIT;
 }
-err = v9fs_do_utimensat(s, vs-fidp-path, times);
+err = v9fs_co_utimensat(s, fidp-path, times);
+if (err  0) {
+goto out;
+}
 }
-v9fs_setattr_post_utimensat(s, vs, err);
-return;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr(void *opaque)
-{
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
-int32_t fid;
-V9fsSetattrState *vs;
-int err = 0;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(pdu, vs-offset, dI, fid, vs-v9iattr);
-
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
-err = -EINVAL;
-goto out;
+/*
+ * If the only valid entry in iattr is ctime we can call
+ * chown(-1,-1) to update

[Qemu-devel] [V3 20/24] hw/9pfs: Update v9fs_mknod to use coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   88 +-
 1 files changed, 30 insertions(+), 58 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 112b0f7..80da9c6 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3020,77 +3020,49 @@ out:
 return;
 }
 
-static void v9fs_mknod_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_mknod_post_mknod(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-v9fs_mknod_post_lstat(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_mknod(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+
+int mode;
+gid_t gid;
 int32_t fid;
-V9fsMkState *vs;
+V9fsQID qid;
 int err = 0;
-V9fsFidState *fidp;
-gid_t gid;
-int mode;
 int major, minor;
+size_t offset = 7;
+V9fsString name;
+struct stat stbuf;
+V9fsString fullname;
+V9fsFidState *fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-v9fs_string_init(vs-fullname);
-pdu_unmarshal(vs-pdu, vs-offset, ds, fid, vs-name, mode,
-major, minor, gid);
+v9fs_string_init(fullname);
+pdu_unmarshal(pdu, offset, ds, fid, name, mode,
+  major, minor, gid);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
-v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
-err = v9fs_do_mknod(s, vs-fullname.data, mode, makedev(major, minor),
-fidp-uid, gid);
-v9fs_mknod_post_mknod(s, vs, err);
-return;
-
+v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
+err = v9fs_co_mknod(s, fullname, fidp-uid, gid,
+makedev(major, minor), mode);
+if (err  0) {
+goto out;
+}
+err = v9fs_co_lstat(s, fullname, stbuf);
+if (err  0) {
+goto out;
+}
+stat_to_qid(stbuf, qid);
+err = offset;
+err += pdu_marshal(pdu, offset, Q, qid);
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
+complete_pdu(s, pdu, err);
+v9fs_string_free(fullname);
+v9fs_string_free(name);
 }
 
 /*
-- 
1.7.1




[Qemu-devel] [V3 23/24] [virtio-9p] clean up v9fs_remove.

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsRemoveState
and additional malloc()s.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   25 ++---
 hw/9pfs/virtio-9p.h |6 --
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 1e860c6..7327b3b 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2582,35 +2582,30 @@ out:
 
 static void v9fs_remove(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int32_t fid;
-V9fsRemoveState *vs;
 int err = 0;
+size_t offset = 7;
+V9fsFidState *fidp;
+V9fsPDU *pdu = opaque;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, d, fid);
+pdu_unmarshal(pdu, offset, d, fid);
 
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
+fidp = lookup_fid(pdu-s, fid);
+if (fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-err = v9fs_do_remove(s, vs-fidp-path);
+err = v9fs_do_remove(pdu-s, fidp-path);
 if (err  0) {
 err = -errno;
 } else {
-err = vs-offset;
+err = offset;
 }
 
 /* For TREMOVE we need to clunk the fid even on failed remove */
-free_fid(s, vs-fidp-fid);
+free_fid(pdu-s, fidp-fid);
 out:
-complete_pdu(s, pdu, err);
-qemu_free(vs);
+complete_pdu(pdu-s, pdu, err);
 }
 
 static void v9fs_wstat_post_truncate(V9fsState *s, V9fsWstatState *vs, int err)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index d57d5ae..837ce67 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -333,12 +333,6 @@ typedef struct V9fsWriteState {
 int cnt;
 } V9fsWriteState;
 
-typedef struct V9fsRemoveState {
-V9fsPDU *pdu;
-size_t offset;
-V9fsFidState *fidp;
-} V9fsRemoveState;
-
 typedef struct V9fsWstatState
 {
 V9fsPDU *pdu;
-- 
1.7.1




[Qemu-devel] [V3 21/24] [virtio-9p] coroutine and threading for mkdir

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/codir.c  |   19 +++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   28 ++--
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 47b10df..28f2ad7 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -64,3 +64,22 @@ void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
 s-ops-rewinddir(s-ctx, fidp-fs.dir);
 });
 }
+
+int v9fs_co_mkdir(V9fsState *s, char *name, mode_t mode, uid_t uid, gid_t gid)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_mode = mode;
+cred.fc_uid = uid;
+cred.fc_gid = gid;
+v9fs_co_run_in_worker(
+{
+err = s-ops-mkdir(s-ctx, name, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index d023683..96e88d8 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -73,4 +73,5 @@ extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
  V9fsString *, void *, size_t);
 extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
  gid_t, dev_t, mode_t);
+extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 80da9c6..8dd6f7d 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -149,19 +149,6 @@ static int v9fs_do_mknod(V9fsState *s, char *name,
 return s-ops-mknod(s-ctx, name, cred);
 }
 
-static int v9fs_do_mkdir(V9fsState *s, char *name, mode_t mode,
-uid_t uid, gid_t gid)
-{
-FsCred cred;
-
-cred_init(cred);
-cred.fc_uid = uid;
-cred.fc_gid = gid;
-cred.fc_mode = mode;
-
-return s-ops-mkdir(s-ctx, name, cred);
-}
-
 static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf)
 {
 return s-ops-fstat(s-ctx, fd, stbuf);
@@ -2330,8 +2317,7 @@ out:
 
 static void v9fs_create_post_mkdir(V9fsState *s, V9fsCreateState *vs, int err)
 {
-if (err) {
-err = -errno;
+if (err  0) {
 goto out;
 }
 
@@ -2380,7 +2366,7 @@ static void v9fs_create_post_lstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 }
 
 if (vs-perm  P9_STAT_MODE_DIR) {
-err = v9fs_do_mkdir(s, vs-fullname.data, vs-perm  0777,
+err = v9fs_co_mkdir(s, vs-fullname.data, vs-perm  0777,
 vs-fidp-uid, -1);
 v9fs_create_post_mkdir(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_SYMLINK) {
@@ -3180,14 +3166,12 @@ static void v9fs_mkdir(void *opaque)
 goto out;
 }
 v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
-err = v9fs_do_mkdir(pdu-s, fullname.data, mode, fidp-uid, gid);
-if (err == -1) {
-err = -errno;
+err = v9fs_co_mkdir(pdu-s, fullname.data, mode, fidp-uid, gid);
+if (err  0) {
 goto out;
 }
-err = v9fs_do_lstat(pdu-s, fullname, stbuf);
-if (err == -1) {
-err = -errno;
+err = v9fs_co_lstat(pdu-s, fullname, stbuf);
+if (err  0) {
 goto out;
 }
 stat_to_qid(stbuf, qid);
-- 
1.7.1




[Qemu-devel] [V3 17/24] hw/9pfs: Update v9fs_xattrwalk to coroutines

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  198 ---
 1 files changed, 63 insertions(+), 135 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0f965b5..5336b8b 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -240,21 +240,6 @@ static int v9fs_do_statfs(V9fsState *s, V9fsString *path, 
struct statfs *stbuf)
 return s-ops-statfs(s-ctx, path-data, stbuf);
 }
 
-static ssize_t v9fs_do_lgetxattr(V9fsState *s, V9fsString *path,
- V9fsString *xattr_name,
- void *value, size_t size)
-{
-return s-ops-lgetxattr(s-ctx, path-data,
- xattr_name-data, value, size);
-}
-
-static ssize_t v9fs_do_llistxattr(V9fsState *s, V9fsString *path,
-  void *value, size_t size)
-{
-return s-ops-llistxattr(s-ctx, path-data,
-  value, size);
-}
-
 static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path,
  V9fsString *xattr_name,
  void *value, size_t size, int flags)
@@ -3242,149 +3227,92 @@ out:
 v9fs_string_free(name);
 }
 
-static void v9fs_post_xattr_getvalue(V9fsState *s, V9fsXattrState *vs, int err)
-{
-
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, q, vs-size);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_post_xattr_check(V9fsState *s, V9fsXattrState *vs, ssize_t 
err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-/*
- * Read the xattr value
- */
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = -1;
-if (vs-size) {
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-err = v9fs_do_lgetxattr(s, vs-xattr_fidp-path,
-vs-name, vs-xattr_fidp-fs.xattr.value,
-vs-xattr_fidp-fs.xattr.len);
-}
-v9fs_post_xattr_getvalue(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_post_lxattr_getvalue(V9fsState *s,
-  V9fsXattrState *vs, int err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, q, vs-size);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_post_lxattr_check(V9fsState *s,
-   V9fsXattrState *vs, ssize_t err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-/*
- * Read the xattr value
- */
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = -1;
-if (vs-size) {
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-err = v9fs_do_llistxattr(s, vs-xattr_fidp-path,
- vs-xattr_fidp-fs.xattr.value,
- vs-xattr_fidp-fs.xattr.len);
-}
-v9fs_post_lxattr_getvalue(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_xattrwalk(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+int64_t size;
+V9fsString name;
 ssize_t err = 0;
-V9fsXattrState *vs;
+size_t offset = 7;
 int32_t fid, newfid;
+V9fsFidState *file_fidp;
+V9fsFidState *xattr_fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, dds, fid, newfid, vs-name);
-vs-file_fidp = lookup_fid(s, fid);
-if (vs-file_fidp == NULL) {
+pdu_unmarshal(pdu, offset, dds, fid, newfid, name);
+file_fidp = lookup_fid(s, fid);
+if (file_fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
-vs-xattr_fidp = alloc_fid(s, newfid);
-if (vs-xattr_fidp == NULL) {
+xattr_fidp = alloc_fid(s, newfid);
+if (xattr_fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-
-v9fs_string_copy(vs-xattr_fidp-path, vs-file_fidp-path);
-if (vs-name.data[0] == 0) {
+v9fs_string_copy(xattr_fidp-path, file_fidp-path);
+if (name.data[0] == 0

[Qemu-devel] [V3 19/24] hw/9pfs: Add yield support to mknod coroutine

2011-05-18 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   21 +
 hw/9pfs/virtio-9p-coth.h |2 ++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 2a94707..293e377 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -119,3 +119,24 @@ int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t 
size)
 });
 return err;
 }
+
+int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t uid,
+  gid_t gid, dev_t dev, mode_t mode)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_uid  = uid;
+cred.fc_gid  = gid;
+cred.fc_mode = mode;
+cred.fc_rdev = dev;
+v9fs_co_run_in_worker(
+{
+err = s-ops-mknod(s-ctx, path-data, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index eb0c99a..d023683 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -71,4 +71,6 @@ extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
 extern int v9fs_co_llistxattr(V9fsState *, V9fsString *, void *, size_t);
 extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
  V9fsString *, void *, size_t);
+extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
+ gid_t, dev_t, mode_t);
 #endif
-- 
1.7.1




[Qemu-devel] [V3 22/24] [virtio-9p] Remove post functions for v9fs_remove

2011-05-18 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   26 +++---
 1 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 8dd6f7d..1e860c6 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2580,22 +2580,6 @@ out:
 complete_pdu(s, pdu, err);
 }
 
-static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs,
-int err)
-{
-if (err  0) {
-err = -errno;
-} else {
-err = vs-offset;
-}
-
-/* For TREMOVE we need to clunk the fid even on failed remove */
-free_fid(s, vs-fidp-fid);
-
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
 static void v9fs_remove(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -2615,11 +2599,15 @@ static void v9fs_remove(void *opaque)
 err = -EINVAL;
 goto out;
 }
-
 err = v9fs_do_remove(s, vs-fidp-path);
-v9fs_remove_post_remove(s, vs, err);
-return;
+if (err  0) {
+err = -errno;
+} else {
+err = vs-offset;
+}
 
+/* For TREMOVE we need to clunk the fid even on failed remove */
+free_fid(s, vs-fidp-fid);
 out:
 complete_pdu(s, pdu, err);
 qemu_free(vs);
-- 
1.7.1




[Qemu-devel] [V2 05/25] [virtio-9p] Move errno into v9fs_do_readlink

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   32 
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index e0e7eed..cc22a1f 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -82,19 +82,21 @@ static int v9fs_do_lstat(V9fsState *s, V9fsString *path, 
struct stat *stbuf)
 return s-ops-lstat(s-ctx, path-data, stbuf);
 }
 
-static ssize_t v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString 
*buf)
+static int v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString *buf,
+ssize_t *len)
 {
-ssize_t len;
-
+int err;
 buf-data = qemu_malloc(1024);
 
-len = s-ops-readlink(s-ctx, path-data, buf-data, 1024 - 1);
-if (len  -1) {
-buf-size = len;
-buf-data[len] = 0;
+*len = s-ops-readlink(s-ctx, path-data, buf-data, 1024 - 1);
+if (*len  -1) {
+buf-size = *len;
+buf-data[*len] = 0;
+err = 0;
+} else {
+err = -errno;
 }
-
-return len;
+return err;
 }
 
 static int v9fs_do_close(V9fsState *s, int fd)
@@ -1055,13 +1057,11 @@ static int stat_to_v9stat(V9fsState *s, V9fsString 
*name,
 v9fs_string_null(v9stat-extension);
 
 if (v9stat-mode  P9_STAT_MODE_SYMLINK) {
-err = v9fs_do_readlink(s, name, v9stat-extension);
-if (err == -1) {
-err = -errno;
+ssize_t symlink_len;
+err = v9fs_do_readlink(s, name, v9stat-extension, symlink_len);
+if (err  0) {
 return err;
 }
-v9stat-extension.data[err] = 0;
-v9stat-extension.size = err;
 } else if (v9stat-mode  P9_STAT_MODE_DEVICE) {
 v9fs_string_sprintf(v9stat-extension, %c %u %u,
 S_ISCHR(stbuf-st_mode) ? 'c' : 'b',
@@ -3591,6 +3591,7 @@ static void v9fs_readlink(void *opaque)
 int32_t fid;
 int err = 0;
 V9fsFidState *fidp;
+ssize_t symlink_len;
 
 pdu_unmarshal(pdu, offset, d, fid);
 fidp = lookup_fid(pdu-s, fid);
@@ -3600,9 +3601,8 @@ static void v9fs_readlink(void *opaque)
 }
 
 v9fs_string_init(target);
-err = v9fs_do_readlink(pdu-s, fidp-path, target);
+err = v9fs_do_readlink(pdu-s, fidp-path, target, symlink_len);
 if (err  0) {
-err = -errno;
 goto out;
 }
 offset += pdu_marshal(pdu, offset, s, target);
-- 
1.7.1




[Qemu-devel] [V2 03/25] [virtio-9p] Remove post functions for v9fs_readlink.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
In the process of preparation for coroutine threads, remove all post functions
and make the function more readable.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   25 +++--
 1 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 15bfea7..06da2c9 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3583,21 +3583,6 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_readlink_post_readlink(V9fsState *s, V9fsReadLinkState *vs,
-int err)
-{
-if (err  0) {
-err = -errno;
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-target);
-qemu_free(vs);
-}
-
 static void v9fs_readlink(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -3612,7 +3597,6 @@ static void v9fs_readlink(void *opaque)
 vs-offset = 7;
 
 pdu_unmarshal(vs-pdu, vs-offset, d, fid);
-
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
@@ -3621,8 +3605,13 @@ static void v9fs_readlink(void *opaque)
 
 v9fs_string_init(vs-target);
 err = v9fs_do_readlink(s, fidp-path, vs-target);
-v9fs_readlink_post_readlink(s, vs, err);
-return;
+if (err  0) {
+err = -errno;
+goto out;
+}
+vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
+err = vs-offset;
+v9fs_string_free(vs-target);
 out:
 complete_pdu(s, vs-pdu, err);
 qemu_free(vs);
-- 
1.7.1




[Qemu-devel] [V2 09/25] hw/9pfs: Add yield support for readdir related coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include readdir, telldir, seekdir, rewinddir.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/codir.c  |   68 ++
 hw/9pfs/virtio-9p-coth.h |5 +++
 3 files changed, 74 insertions(+), 1 deletions(-)
 create mode 100644 hw/9pfs/codir.c

diff --git a/Makefile.objs b/Makefile.objs
index 36005bb..614bcaf 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
new file mode 100644
index 000..885f7d0
--- /dev/null
+++ b/hw/9pfs/codir.c
@@ -0,0 +1,68 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_readdir(V9fsState *s, V9fsFidState *fidp, struct dirent **dent)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+errno = 0;
+/*FIXME!! need to switch to readdir_r */
+*dent = s-ops-readdir(s-ctx, fidp-fs.dir);
+if (!*dent  errno) {
+err = -errno;
+} else {
+err = 0;
+}
+});
+return err;
+}
+
+off_t v9fs_co_telldir(V9fsState *s, V9fsFidState *fidp)
+{
+off_t err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-telldir(s-ctx, fidp-fs.dir);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+void v9fs_co_seekdir(V9fsState *s, V9fsFidState *fidp, off_t offset)
+{
+v9fs_co_run_in_worker(
+{
+s-ops-seekdir(s-ctx, fidp-fs.dir, offset);
+});
+return;
+}
+
+void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
+{
+v9fs_co_run_in_worker(
+{
+s-ops-rewinddir(s-ctx, fidp-fs.dir);
+});
+return;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 94c5147..9aa5953 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -57,4 +57,9 @@ typedef struct V9fsThPool {
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
 extern int v9fs_co_readlink(V9fsState *, V9fsString *, V9fsString *);
+extern int v9fs_co_readdir(V9fsState *, V9fsFidState *,
+   struct dirent **);
+extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
+extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
+extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 #endif
-- 
1.7.1




[Qemu-devel] [V2 12/25] hw/9pfs: Update v9fs_statfs to use coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   92 --
 hw/9pfs/virtio-9p.h |   22 
 2 files changed, 44 insertions(+), 70 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 6ae4fe4..9523970 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3034,79 +3034,75 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_statfs_post_statfs(V9fsState *s, V9fsStatfsState *vs, int err)
-{
+static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
+{
+uint32_t f_type;
+uint32_t f_bsize;
+uint64_t f_blocks;
+uint64_t f_bfree;
+uint64_t f_bavail;
+uint64_t f_files;
+uint64_t f_ffree;
+uint64_t fsid_val;
+uint32_t f_namelen;
+size_t offset = 7;
 int32_t bsize_factor;
 
-if (err) {
-err = -errno;
-goto out;
-}
-
 /*
  * compute bsize factor based on host file system block size
  * and client msize
  */
-bsize_factor = (s-msize - P9_IOHDRSZ)/vs-stbuf.f_bsize;
+bsize_factor = (s-msize - P9_IOHDRSZ)/stbuf-f_bsize;
 if (!bsize_factor) {
 bsize_factor = 1;
 }
-vs-v9statfs.f_type = vs-stbuf.f_type;
-vs-v9statfs.f_bsize = vs-stbuf.f_bsize;
-vs-v9statfs.f_bsize *= bsize_factor;
+f_type  = stbuf-f_type;
+f_bsize = stbuf-f_bsize;
+f_bsize *= bsize_factor;
 /*
  * f_bsize is adjusted(multiplied) by bsize factor, so we need to
  * adjust(divide) the number of blocks, free blocks and available
  * blocks by bsize factor
  */
-vs-v9statfs.f_blocks = vs-stbuf.f_blocks/bsize_factor;
-vs-v9statfs.f_bfree = vs-stbuf.f_bfree/bsize_factor;
-vs-v9statfs.f_bavail = vs-stbuf.f_bavail/bsize_factor;
-vs-v9statfs.f_files = vs-stbuf.f_files;
-vs-v9statfs.f_ffree = vs-stbuf.f_ffree;
-vs-v9statfs.fsid_val = (unsigned int) vs-stbuf.f_fsid.__val[0] |
-   (unsigned long long)vs-stbuf.f_fsid.__val[1]  32;
-vs-v9statfs.f_namelen = vs-stbuf.f_namelen;
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, ddqqd,
- vs-v9statfs.f_type, vs-v9statfs.f_bsize, vs-v9statfs.f_blocks,
- vs-v9statfs.f_bfree, vs-v9statfs.f_bavail, vs-v9statfs.f_files,
- vs-v9statfs.f_ffree, vs-v9statfs.fsid_val,
- vs-v9statfs.f_namelen);
+f_blocks = stbuf-f_blocks/bsize_factor;
+f_bfree  = stbuf-f_bfree/bsize_factor;
+f_bavail = stbuf-f_bavail/bsize_factor;
+f_files  = stbuf-f_files;
+f_ffree  = stbuf-f_ffree;
+fsid_val = (unsigned int) stbuf-f_fsid.__val[0] |
+   (unsigned long long)stbuf-f_fsid.__val[1]  32;
+f_namelen = stbuf-f_namelen;
 
-out:
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
+return pdu_marshal(pdu, offset, ddqqd,
+   f_type, f_bsize, f_blocks, f_bfree,
+   f_bavail, f_files, f_ffree,
+   fsid_val, f_namelen);
 }
 
 static void v9fs_statfs(void *opaque)
 {
+int32_t fid;
+ssize_t retval = 0;
+size_t offset = 7;
+V9fsFidState *fidp;
+struct statfs stbuf;
 V9fsPDU *pdu = opaque;
 V9fsState *s = pdu-s;
-V9fsStatfsState *vs;
-ssize_t err = 0;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-memset(vs-v9statfs, 0, sizeof(vs-v9statfs));
-
-pdu_unmarshal(vs-pdu, vs-offset, d, vs-fid);
-
-vs-fidp = lookup_fid(s, vs-fid);
-if (vs-fidp == NULL) {
-err = -ENOENT;
+pdu_unmarshal(pdu, offset, d, fid);
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+retval = -ENOENT;
 goto out;
 }
-
-err = v9fs_do_statfs(s, vs-fidp-path, vs-stbuf);
-v9fs_statfs_post_statfs(s, vs, err);
-return;
-
+retval = v9fs_co_statfs(s, fidp-path, stbuf);
+if (retval  0) {
+goto out;
+}
+retval = offset;
+retval += v9fs_fill_statfs(s, pdu, stbuf);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(s, pdu, retval);
 return;
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index c6f2649..a7e4ff2 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -398,28 +398,6 @@ struct virtio_9p_config
 uint8_t tag[0];
 } __attribute__((packed));
 
-typedef struct V9fsStatfs
-{
-uint32_t f_type;
-uint32_t f_bsize;
-uint64_t f_blocks;
-uint64_t f_bfree;
-uint64_t f_bavail;
-uint64_t f_files;
-uint64_t f_ffree;
-uint64_t fsid_val;
-uint32_t f_namelen;
-} V9fsStatfs;
-
-typedef struct V9fsStatfsState {
-V9fsPDU *pdu;
-size_t offset;
-int32_t fid;
-V9fsStatfs v9statfs;
-V9fsFidState *fidp;
-struct statfs stbuf;
-} V9fsStatfsState;
-
 typedef struct V9fsMkState {
 V9fsPDU *pdu;
 size_t offset;
-- 
1.7.1




[Qemu-devel] [V2 14/25] hw/9pfs: Update v9fs_getattr to use coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   57 +--
 hw/9pfs/virtio-9p.h |8 ---
 2 files changed, 19 insertions(+), 46 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 9523970..936e97f 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1087,7 +1087,7 @@ static int stat_to_v9stat(V9fsState *s, V9fsString *name,
 
 
 static void stat_to_v9stat_dotl(V9fsState *s, const struct stat *stbuf,
-V9fsStatDotl *v9lstat)
+V9fsStatDotl *v9lstat)
 {
 memset(v9lstat, 0, sizeof(*v9lstat));
 
@@ -1284,57 +1284,38 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_getattr_post_lstat(V9fsState *s, V9fsStatStateDotl *vs,
-int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_v9stat_dotl(s, vs-stbuf, vs-v9stat_dotl);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, A, vs-v9stat_dotl);
-err = vs-offset;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
 static void v9fs_getattr(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int32_t fid;
-V9fsStatStateDotl *vs;
-ssize_t err = 0;
+size_t offset = 7;
+ssize_t retval = 0;
+struct stat stbuf;
 V9fsFidState *fidp;
 uint64_t request_mask;
+V9fsStatDotl v9stat_dotl;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-memset(vs-v9stat_dotl, 0, sizeof(vs-v9stat_dotl));
-
-pdu_unmarshal(vs-pdu, vs-offset, dq, fid, request_mask);
+pdu_unmarshal(pdu, offset, dq, fid, request_mask);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
-err = -ENOENT;
+retval = -ENOENT;
 goto out;
 }
-
-/* Currently we only support BASIC fields in stat, so there is no
+/*
+ * Currently we only support BASIC fields in stat, so there is no
  * need to look at request_mask.
  */
-err = v9fs_do_lstat(s, fidp-path, vs-stbuf);
-v9fs_getattr_post_lstat(s, vs, err);
-return;
-
+retval = v9fs_co_lstat(s, fidp-path, stbuf);
+if (retval  0) {
+goto out;
+}
+stat_to_v9stat_dotl(s, stbuf, v9stat_dotl);
+retval = offset;
+retval += pdu_marshal(pdu, offset, A, v9stat_dotl);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(s, pdu, retval);
 }
 
 /* From Linux kernel code */
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index a7e4ff2..debc64a 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -278,14 +278,6 @@ typedef struct V9fsStatDotl {
 uint64_t st_data_version;
 } V9fsStatDotl;
 
-typedef struct V9fsStatStateDotl {
-V9fsPDU *pdu;
-size_t offset;
-V9fsStatDotl v9stat_dotl;
-struct stat stbuf;
-} V9fsStatStateDotl;
-
-
 typedef struct V9fsWalkState {
 V9fsPDU *pdu;
 size_t offset;
-- 
1.7.1




[Qemu-devel] [V2 0/25] Async threading for VirtFS using glib threads coroutines.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
VirtFS (fileserver base on 9P) performs many blocking system calls in the 
vCPU context. This effort is to move the blocking calls out of vCPU/IO 
thread context, into asynchronous threads.

Anthony's  Add hard build dependency on glib patch and 
Kevin/Stefan's coroutine effort is a prerequisite.

Changes from V1
---
o Redesigned to use bh as per Stefan's suggestion. 
  This made the code very simple but is little less performant compared to V1.
  Anthony suggested to go-in with cleaner code and design (This version) and
  deal with the performance later.
  Just to put in perspective:
  Sequential Writes of creating 1GB files using ffsb
  o Write size 8k 
  With bh: 66.9MB/sec
  Without bh (marshalling routines): 74.9 MB/sec

  o Write size 128k
  With bh: 117MB/sec
  Without bh (marshalling routines): 122MB/sec

o Addressed all review comments.

o Using readdir_r is currently being worked on. Will add as a patch on top.

This patch set contains:
 - Converting all 9pfs calls into coroutines. 
 - Each 9P operation will be modified for:
- Remove post* functions. These are our call back functions which makes 
  the code very hard to read. Now with coroutines, we can achieve the same 
  state machine model with nice sequential code flow.
- Move errno access near to the local_syscall()
- Introduce asynchronous threading

This series has the basic infrastructure and few routines like 
mkdir,monod,unlink,readdir,xattr,lstat, etc converted. 
Currently we are working on converting and testing other 9P operations also 
into this model and those patches will follow shortly.

Removing callback functions made some of the patches little lengthy. 
Here is the git tree for the reviewer convenience. 

http://repo.or.cz/w/qemu/aliguori/jvrao.git/shortlog/refs/heads/9p-coroutine-bh-round1

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com




[Qemu-devel] [V2 10/25] hw/9pfs: Update v9fs_readdir to use coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  170 +--
 1 files changed, 69 insertions(+), 101 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 40c8b31..6ae4fe4 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -112,11 +112,6 @@ static off_t v9fs_do_telldir(V9fsState *s, DIR *dir)
 return s-ops-telldir(s-ctx, dir);
 }
 
-static struct dirent *v9fs_do_readdir(V9fsState *s, DIR *dir)
-{
-return s-ops-readdir(s-ctx, dir);
-}
-
 static void v9fs_do_seekdir(V9fsState *s, DIR *dir, off_t off)
 {
 return s-ops-seekdir(s-ctx, dir, off);
@@ -1967,7 +1962,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, 
V9fsReadState *vs,
 v9fs_stat_free(vs-v9stat);
 v9fs_string_free(vs-name);
 vs-dir_pos = vs-dent-d_off;
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
+v9fs_co_readdir(s, vs-fidp, vs-dent);
 v9fs_read_post_readdir(s, vs, err);
 return;
 out:
@@ -1999,7 +1994,7 @@ static void v9fs_read_post_readdir(V9fsState *s, 
V9fsReadState *vs, ssize_t err)
 
 static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t 
err)
 {
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
+v9fs_co_readdir(s, vs-fidp, vs-dent);
 v9fs_read_post_readdir(s, vs, err);
 return;
 }
@@ -2128,126 +2123,99 @@ out:
 qemu_free(vs);
 }
 
-typedef struct V9fsReadDirState {
-V9fsPDU *pdu;
-V9fsFidState *fidp;
-V9fsQID qid;
-off_t saved_dir_pos;
-struct dirent *dent;
-int32_t count;
-int32_t max_count;
-size_t offset;
-int64_t initial_offset;
-V9fsString name;
-} V9fsReadDirState;
-
-static void v9fs_readdir_post_seekdir(V9fsState *s, V9fsReadDirState *vs)
-{
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count;
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
-return;
-}
-
-/* Size of each dirent on the wire: size of qid (13) + size of offset (8)
+/*
+ * Size of each dirent on the wire: size of qid (13) + size of offset (8)
  * size of type (1) + size of name.size (2) + strlen(name.data)
  */
-#define V9_READDIR_DATA_SZ (24 + strlen(vs-name.data))
+#define V9_READDIR_DATA_SZ (24 + strlen(name.data))
 
-static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs)
+static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu,
+   V9fsFidState *fidp, int32_t max_count)
 {
-int len;
 size_t size;
+V9fsQID qid;
+V9fsString name;
+int len, err = 0;
+int32_t count = 0;
+off_t saved_dir_pos;
+struct dirent *dent;
 
-if (vs-dent) {
-v9fs_string_init(vs-name);
-v9fs_string_sprintf(vs-name, %s, vs-dent-d_name);
-
-if ((vs-count + V9_READDIR_DATA_SZ)  vs-max_count) {
+/* save the directory position */
+saved_dir_pos = v9fs_co_telldir(s, fidp);
+if (saved_dir_pos  0) {
+return saved_dir_pos;
+}
+while (1) {
+err = v9fs_co_readdir(s, fidp, dent);
+if (err || !dent) {
+break;
+}
+v9fs_string_init(name);
+v9fs_string_sprintf(name, %s, dent-d_name);
+if ((count + V9_READDIR_DATA_SZ)  max_count) {
 /* Ran out of buffer. Set dir back to old position and return */
-v9fs_do_seekdir(s, vs-fidp-fs.dir, vs-saved_dir_pos);
-v9fs_readdir_post_seekdir(s, vs);
-return;
+v9fs_co_seekdir(s, fidp, saved_dir_pos);
+v9fs_string_free(name);
+return count;
 }
-
-/* Fill up just the path field of qid because the client uses
+/*
+ * Fill up just the path field of qid because the client uses
  * only that. To fill the entire qid structure we will have
  * to stat each dirent found, which is expensive
  */
-size = MIN(sizeof(vs-dent-d_ino), sizeof(vs-qid.path));
-memcpy(vs-qid.path, vs-dent-d_ino, size);
+size = MIN(sizeof(dent-d_ino), sizeof(qid.path));
+memcpy(qid.path, dent-d_ino, size);
 /* Fill the other fields with dummy values */
-vs-qid.type = 0;
-vs-qid.version = 0;
-
-len = pdu_marshal(vs-pdu, vs-offset+4+vs-count, Qqbs,
-  vs-qid, vs-dent-d_off,
-  vs-dent-d_type, vs-name);
-vs-count += len;
-v9fs_string_free(vs-name);
-vs-saved_dir_pos = vs-dent-d_off;
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
-v9fs_readdir_post_readdir(s, vs);
-return;
-}
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count;
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_readdir_post_telldir(V9fsState *s, V9fsReadDirState *vs

[Qemu-devel] [V2 13/25] hw/9pfs: Add yield support to lstat coroutine

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/cofile.c |   32 
 hw/9pfs/virtio-9p-coth.h |1 +
 3 files changed, 34 insertions(+), 1 deletions(-)
 create mode 100644 hw/9pfs/cofile.c

diff --git a/Makefile.objs b/Makefile.objs
index 614bcaf..83d30bd 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
new file mode 100644
index 000..a4c0ae7
--- /dev/null
+++ b/hw/9pfs/cofile.c
@@ -0,0 +1,32 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-lstat(s-ctx, path-data, stbuf);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 5d9dc0f..3538d91 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -63,4 +63,5 @@ extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
 extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
+extern int v9fs_co_lstat(V9fsState *, V9fsString *, struct stat *);
 #endif
-- 
1.7.1




[Qemu-devel] [V2 08/25] [virtio-9p] clean up v9fs_mkdir.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsMkState and additional malloc()s.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   38 +-
 1 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 82e5490..40c8b31 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3311,46 +3311,42 @@ out:
 static void v9fs_mkdir(void *opaque)
 {
 V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+size_t offset = 7;
 int32_t fid;
-V9fsMkState *vs;
-int err = 0;
+struct stat stbuf;
+V9fsString name, fullname;
+V9fsQID qid;
 V9fsFidState *fidp;
 gid_t gid;
 int mode;
+int err = 0;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-v9fs_string_init(vs-fullname);
-pdu_unmarshal(vs-pdu, vs-offset, dsdd, fid, vs-name, mode,
-  gid);
+v9fs_string_init(fullname);
+pdu_unmarshal(pdu, offset, dsdd, fid, name, mode, gid);
 
-fidp = lookup_fid(s, fid);
+fidp = lookup_fid(pdu-s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
-err = v9fs_do_mkdir(s, vs-fullname.data, mode, fidp-uid, gid);
+v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
+err = v9fs_do_mkdir(pdu-s, fullname.data, mode, fidp-uid, gid);
 if (err == -1) {
 err = -errno;
 goto out;
 }
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+err = v9fs_do_lstat(pdu-s, fullname, stbuf);
 if (err == -1) {
 err = -errno;
 goto out;
 }
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
+stat_to_qid(stbuf, qid);
+offset += pdu_marshal(pdu, offset, Q, qid);
+err = offset;
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
+complete_pdu(pdu-s, pdu, err);
+v9fs_string_free(fullname);
+v9fs_string_free(name);
 }
 
 static void v9fs_post_xattr_getvalue(V9fsState *s, V9fsXattrState *vs, int err)
-- 
1.7.1




[Qemu-devel] [V2 19/25] hw/9pfs: Update v9fs_xattrcreate to use coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   53 +--
 hw/9pfs/virtio-9p.h |   11 --
 2 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index dc220f9..46577c0 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3314,43 +3314,42 @@ out:
 
 static void v9fs_xattrcreate(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int flags;
 int32_t fid;
+int64_t size;
 ssize_t err = 0;
-V9fsXattrState *vs;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
+V9fsString name;
+size_t offset = 7;
+V9fsFidState *file_fidp;
+V9fsFidState *xattr_fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-pdu_unmarshal(vs-pdu, vs-offset, dsqd,
-  fid, vs-name, vs-size, flags);
+pdu_unmarshal(pdu, offset, dsqd,
+  fid, name, size, flags);
 
-vs-file_fidp = lookup_fid(s, fid);
-if (vs-file_fidp == NULL) {
+file_fidp = lookup_fid(s, fid);
+if (file_fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-
 /* Make the file fid point to xattr */
-vs-xattr_fidp = vs-file_fidp;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = 0;
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fs.xattr.flags = flags;
-v9fs_string_init(vs-xattr_fidp-fs.xattr.name);
-v9fs_string_copy(vs-xattr_fidp-fs.xattr.name, vs-name);
-if (vs-size)
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-else
-vs-xattr_fidp-fs.xattr.value = NULL;
-
+xattr_fidp = file_fidp;
+xattr_fidp-fid_type = P9_FID_XATTR;
+xattr_fidp-fs.xattr.copied_len = 0;
+xattr_fidp-fs.xattr.len = size;
+xattr_fidp-fs.xattr.flags = flags;
+v9fs_string_init(xattr_fidp-fs.xattr.name);
+v9fs_string_copy(xattr_fidp-fs.xattr.name, name);
+if (size) {
+xattr_fidp-fs.xattr.value = qemu_malloc(size);
+} else {
+xattr_fidp-fs.xattr.value = NULL;
+}
+err = offset;
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
+complete_pdu(s, pdu, err);
+v9fs_string_free(name);
 }
 
 static void v9fs_readlink(void *opaque)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 2298d9c..ffbb3b8 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -399,17 +399,6 @@ typedef struct V9fsRenameState {
 V9fsString name;
 } V9fsRenameState;
 
-typedef struct V9fsXattrState
-{
-V9fsPDU *pdu;
-size_t offset;
-V9fsFidState *file_fidp;
-V9fsFidState *xattr_fidp;
-V9fsString name;
-int64_t size;
-int flags;
-void *value;
-} V9fsXattrState;
 
 #define P9_LOCK_SUCCESS 0
 #define P9_LOCK_BLOCKED 1
-- 
1.7.1




[Qemu-devel] [V2 18/25] hw/9pfs: Update v9fs_xattrwalk to coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  198 ---
 1 files changed, 63 insertions(+), 135 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f7e1980..dc220f9 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -240,21 +240,6 @@ static int v9fs_do_statfs(V9fsState *s, V9fsString *path, 
struct statfs *stbuf)
 return s-ops-statfs(s-ctx, path-data, stbuf);
 }
 
-static ssize_t v9fs_do_lgetxattr(V9fsState *s, V9fsString *path,
- V9fsString *xattr_name,
- void *value, size_t size)
-{
-return s-ops-lgetxattr(s-ctx, path-data,
- xattr_name-data, value, size);
-}
-
-static ssize_t v9fs_do_llistxattr(V9fsState *s, V9fsString *path,
-  void *value, size_t size)
-{
-return s-ops-llistxattr(s-ctx, path-data,
-  value, size);
-}
-
 static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path,
  V9fsString *xattr_name,
  void *value, size_t size, int flags)
@@ -3239,149 +3224,92 @@ out:
 v9fs_string_free(name);
 }
 
-static void v9fs_post_xattr_getvalue(V9fsState *s, V9fsXattrState *vs, int err)
-{
-
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, q, vs-size);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_post_xattr_check(V9fsState *s, V9fsXattrState *vs, ssize_t 
err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-/*
- * Read the xattr value
- */
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = -1;
-if (vs-size) {
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-err = v9fs_do_lgetxattr(s, vs-xattr_fidp-path,
-vs-name, vs-xattr_fidp-fs.xattr.value,
-vs-xattr_fidp-fs.xattr.len);
-}
-v9fs_post_xattr_getvalue(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_post_lxattr_getvalue(V9fsState *s,
-  V9fsXattrState *vs, int err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, q, vs-size);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_post_lxattr_check(V9fsState *s,
-   V9fsXattrState *vs, ssize_t err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-/*
- * Read the xattr value
- */
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = -1;
-if (vs-size) {
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-err = v9fs_do_llistxattr(s, vs-xattr_fidp-path,
- vs-xattr_fidp-fs.xattr.value,
- vs-xattr_fidp-fs.xattr.len);
-}
-v9fs_post_lxattr_getvalue(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_xattrwalk(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+int64_t size;
+V9fsString name;
 ssize_t err = 0;
-V9fsXattrState *vs;
+size_t offset = 7;
 int32_t fid, newfid;
+V9fsFidState *file_fidp;
+V9fsFidState *xattr_fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, dds, fid, newfid, vs-name);
-vs-file_fidp = lookup_fid(s, fid);
-if (vs-file_fidp == NULL) {
+pdu_unmarshal(pdu, offset, dds, fid, newfid, name);
+file_fidp = lookup_fid(s, fid);
+if (file_fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
-vs-xattr_fidp = alloc_fid(s, newfid);
-if (vs-xattr_fidp == NULL) {
+xattr_fidp = alloc_fid(s, newfid);
+if (xattr_fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-
-v9fs_string_copy(vs-xattr_fidp-path, vs-file_fidp-path);
-if (vs-name.data[0] == 0) {
+v9fs_string_copy(xattr_fidp-path, file_fidp-path);
+if (name.data[0] == 0

[Qemu-devel] [V2 11/25] hw/9pfs: Add yield support to statfs coroutine

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   14 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 6d94673..f79564b 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -40,3 +40,17 @@ int v9fs_co_readlink(V9fsState *s, V9fsString *path, 
V9fsString *buf)
 buf-data = tbuf.data;
 return err;
 }
+
+int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-statfs(s-ctx, path-data, stbuf);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 9aa5953..5d9dc0f 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -62,4 +62,5 @@ extern int v9fs_co_readdir(V9fsState *, V9fsFidState *,
 extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
 extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
+extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
 #endif
-- 
1.7.1




[Qemu-devel] [V2 07/25] [virtio-9p] Remove post functions for v9fs_mkdir.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   52 --
 1 files changed, 13 insertions(+), 39 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 25831c3..82e5490 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3308,40 +3308,6 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_mkdir_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_mkdir_post_mkdir(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-v9fs_mkdir_post_lstat(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_mkdir(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -3359,19 +3325,27 @@ static void v9fs_mkdir(void *opaque)
 
 v9fs_string_init(vs-fullname);
 pdu_unmarshal(vs-pdu, vs-offset, dsdd, fid, vs-name, mode,
-gid);
+  gid);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
 v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
 err = v9fs_do_mkdir(s, vs-fullname.data, mode, fidp-uid, gid);
-v9fs_mkdir_post_mkdir(s, vs, err);
-return;
-
+if (err == -1) {
+err = -errno;
+goto out;
+}
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+if (err == -1) {
+err = -errno;
+goto out;
+}
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
+err = vs-offset;
 out:
 complete_pdu(s, vs-pdu, err);
 v9fs_string_free(vs-fullname);
-- 
1.7.1




[Qemu-devel] [V2 02/25] [virtio-9p] Change all pdu handlers to coroutines.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
This patch changes the top level handlers to coroutines and sets the base.
It will be followed up with series of patches to convert all filesystem
calls to threaded coroutines pushing all blocking clals in VirtFS out
of vcpu threads.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |  139 +++---
 hw/9pfs/virtio-9p.h  |4 +-
 3 files changed, 99 insertions(+), 45 deletions(-)

diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 8445d29..9388f9b 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -17,6 +17,7 @@
 
 #include qemu-thread.h
 #include qemu-coroutine.h
+#include virtio-9p.h
 #include glib.h
 
 typedef struct V9fsThPool {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index ec97b10..15bfea7 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -19,6 +19,7 @@
 #include fsdev/qemu-fsdev.h
 #include virtio-9p-debug.h
 #include virtio-9p-xattr.h
+#include virtio-9p-coth.h
 
 int debug_9p_pdu;
 
@@ -1192,8 +1193,10 @@ static void v9fs_fix_path(V9fsString *dst, V9fsString 
*src, int len)
 v9fs_string_free(str);
 }
 
-static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_version(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 V9fsString version;
 size_t offset = 7;
 
@@ -1211,10 +1214,13 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
 complete_pdu(s, pdu, offset);
 
 v9fs_string_free(version);
+return;
 }
 
-static void v9fs_attach(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_attach(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid, afid, n_uname;
 V9fsString uname, aname;
 V9fsFidState *fidp;
@@ -1269,8 +1275,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_stat(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_stat(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsStatState *vs;
 ssize_t err = 0;
@@ -1316,8 +1324,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_getattr(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_getattr(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsStatStateDotl *vs;
 ssize_t err = 0;
@@ -1465,8 +1475,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_setattr(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_setattr(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsSetattrState *vs;
 int err = 0;
@@ -1579,8 +1591,10 @@ out:
 v9fs_walk_complete(s, vs, err);
 }
 
-static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_walk(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid, newfid;
 V9fsWalkState *vs;
 int err = 0;
@@ -1751,8 +1765,10 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_open(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsOpenState *vs;
 ssize_t err = 0;
@@ -1836,8 +1852,10 @@ out:
 v9fs_post_lcreate(s, vs, err);
 }
 
-static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_lcreate(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t dfid, flags, mode;
 gid_t gid;
 V9fsLcreateState *vs;
@@ -1883,8 +1901,10 @@ static void v9fs_post_do_fsync(V9fsState *s, V9fsPDU 
*pdu, int err)
 complete_pdu(s, pdu, err);
 }
 
-static void v9fs_fsync(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_fsync(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 size_t offset = 7;
 V9fsFidState *fidp;
@@ -1902,8 +1922,10 @@ static void v9fs_fsync(V9fsState *s, V9fsPDU *pdu)
 v9fs_post_do_fsync(s, pdu, err);
 }
 
-static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_clunk(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 size_t offset = 7;
 int err;
@@ -2068,8 +2090,10 @@ static void v9fs_xattr_read(V9fsState *s, V9fsReadState 
*vs)
 qemu_free(vs);
 }
 
-static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_read(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsReadState *vs;
 ssize_t err = 0;
@@ -2207,8 +2231,10 @@ static void v9fs_readdir_post_setdir(V9fsState *s, 
V9fsReadDirState *vs)
 return;
 }
 
-static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_readdir(void *opaque)
 {
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 int32_t fid;
 V9fsReadDirState *vs;
 ssize_t err = 0;
@@ -2240,7 +2266,6 @@ static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu)
 out:
 complete_pdu(s, pdu, err);
 qemu_free(vs);
-return;
 }
 
 static void v9fs_write_post_pwritev(V9fsState *s

[Qemu-devel] [V2 16/25] hw/9pfs: Update v9fs_setattr to use coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  163 +--
 hw/9pfs/virtio-9p.h |8 ---
 2 files changed, 54 insertions(+), 117 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 936e97f..f7e1980 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1330,139 +1330,84 @@ out:
 #define ATTR_ATIME_SET  (1  7)
 #define ATTR_MTIME_SET  (1  8)
 
-static void v9fs_setattr_post_truncate(V9fsState *s, V9fsSetattrState *vs,
-  int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-err = vs-offset;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_chown(V9fsState *s, V9fsSetattrState *vs, int 
err)
+static void v9fs_setattr(void *opaque)
 {
-if (err == -1) {
-err = -errno;
-goto out;
-}
+int err = 0;
+int32_t fid;
+V9fsFidState *fidp;
+size_t offset = 7;
+V9fsIattr v9iattr;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-if (vs-v9iattr.valid  (ATTR_SIZE)) {
-err = v9fs_do_truncate(s, vs-fidp-path, vs-v9iattr.size);
-}
-v9fs_setattr_post_truncate(s, vs, err);
-return;
+pdu_unmarshal(pdu, offset, dI, fid, v9iattr);
 
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_utimensat(V9fsState *s, V9fsSetattrState *vs,
-   int err)
-{
-if (err == -1) {
-err = -errno;
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+err = -EINVAL;
 goto out;
 }
-
-/* If the only valid entry in iattr is ctime we can call
- * chown(-1,-1) to update the ctime of the file
- */
-if ((vs-v9iattr.valid  (ATTR_UID | ATTR_GID)) ||
-((vs-v9iattr.valid  ATTR_CTIME)
- !((vs-v9iattr.valid  ATTR_MASK)  ~ATTR_CTIME))) {
-if (!(vs-v9iattr.valid  ATTR_UID)) {
-vs-v9iattr.uid = -1;
-}
-if (!(vs-v9iattr.valid  ATTR_GID)) {
-vs-v9iattr.gid = -1;
+if (v9iattr.valid  ATTR_MODE) {
+err = v9fs_co_chmod(s, fidp-path, v9iattr.mode);
+if (err  0) {
+goto out;
 }
-err = v9fs_do_chown(s, vs-fidp-path, vs-v9iattr.uid,
-vs-v9iattr.gid);
 }
-v9fs_setattr_post_chown(s, vs, err);
-return;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_chmod(V9fsState *s, V9fsSetattrState *vs, int 
err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-if (vs-v9iattr.valid  (ATTR_ATIME | ATTR_MTIME)) {
+if (v9iattr.valid  (ATTR_ATIME | ATTR_MTIME)) {
 struct timespec times[2];
-if (vs-v9iattr.valid  ATTR_ATIME) {
-if (vs-v9iattr.valid  ATTR_ATIME_SET) {
-times[0].tv_sec = vs-v9iattr.atime_sec;
-times[0].tv_nsec = vs-v9iattr.atime_nsec;
+if (v9iattr.valid  ATTR_ATIME) {
+if (v9iattr.valid  ATTR_ATIME_SET) {
+times[0].tv_sec = v9iattr.atime_sec;
+times[0].tv_nsec = v9iattr.atime_nsec;
 } else {
 times[0].tv_nsec = UTIME_NOW;
 }
 } else {
 times[0].tv_nsec = UTIME_OMIT;
 }
-
-if (vs-v9iattr.valid  ATTR_MTIME) {
-if (vs-v9iattr.valid  ATTR_MTIME_SET) {
-times[1].tv_sec = vs-v9iattr.mtime_sec;
-times[1].tv_nsec = vs-v9iattr.mtime_nsec;
+if (v9iattr.valid  ATTR_MTIME) {
+if (v9iattr.valid  ATTR_MTIME_SET) {
+times[1].tv_sec = v9iattr.mtime_sec;
+times[1].tv_nsec = v9iattr.mtime_nsec;
 } else {
 times[1].tv_nsec = UTIME_NOW;
 }
 } else {
 times[1].tv_nsec = UTIME_OMIT;
 }
-err = v9fs_do_utimensat(s, vs-fidp-path, times);
+err = v9fs_co_utimensat(s, fidp-path, times);
+if (err  0) {
+goto out;
+}
 }
-v9fs_setattr_post_utimensat(s, vs, err);
-return;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr(void *opaque)
-{
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
-int32_t fid;
-V9fsSetattrState *vs;
-int err = 0;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(pdu, vs-offset, dI, fid, vs-v9iattr);
-
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
-err = -EINVAL;
-goto out;
+/*
+ * If the only valid entry in iattr is ctime we can call
+ * chown(-1,-1) to update

[Qemu-devel] [V2 06/25] [virtio-9p] coroutines for readlink

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/cofs.c   |   42 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   27 ---
 hw/9pfs/virtio-9p.h  |3 ++-
 5 files changed, 50 insertions(+), 25 deletions(-)
 create mode 100644 hw/9pfs/cofs.c

diff --git a/Makefile.objs b/Makefile.objs
index 96f6a24..36005bb 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
new file mode 100644
index 000..6d94673
--- /dev/null
+++ b/hw/9pfs/cofs.c
@@ -0,0 +1,42 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
+{
+int err;
+ssize_t len;
+V9fsString tbuf;
+
+tbuf.data = qemu_malloc(PATH_MAX);
+v9fs_co_run_in_worker(
+{
+len = s-ops-readlink(s-ctx, path-data,
+   tbuf.data, PATH_MAX - 1);
+if (len  -1) {
+tbuf.size = len;
+tbuf.data[len] = 0;
+err = 0;
+} else {
+err = -errno;
+}
+});
+buf-size = tbuf.size;
+buf-data = tbuf.data;
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 9388f9b..94c5147 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -56,4 +56,5 @@ typedef struct V9fsThPool {
 
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
+extern int v9fs_co_readlink(V9fsState *, V9fsString *, V9fsString *);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index cc22a1f..25831c3 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -82,23 +82,6 @@ static int v9fs_do_lstat(V9fsState *s, V9fsString *path, 
struct stat *stbuf)
 return s-ops-lstat(s-ctx, path-data, stbuf);
 }
 
-static int v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString *buf,
-ssize_t *len)
-{
-int err;
-buf-data = qemu_malloc(1024);
-
-*len = s-ops-readlink(s-ctx, path-data, buf-data, 1024 - 1);
-if (*len  -1) {
-buf-size = *len;
-buf-data[*len] = 0;
-err = 0;
-} else {
-err = -errno;
-}
-return err;
-}
-
 static int v9fs_do_close(V9fsState *s, int fd)
 {
 return s-ops-close(s-ctx, fd);
@@ -299,7 +282,7 @@ static void v9fs_string_init(V9fsString *str)
 str-size = 0;
 }
 
-static void v9fs_string_free(V9fsString *str)
+void v9fs_string_free(V9fsString *str)
 {
 qemu_free(str-data);
 str-data = NULL;
@@ -421,7 +404,7 @@ v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)
 str-size = err;
 }
 
-static void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
+void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs)
 {
 v9fs_string_free(lhs);
 v9fs_string_sprintf(lhs, %s, rhs-data);
@@ -1057,8 +1040,7 @@ static int stat_to_v9stat(V9fsState *s, V9fsString *name,
 v9fs_string_null(v9stat-extension);
 
 if (v9stat-mode  P9_STAT_MODE_SYMLINK) {
-ssize_t symlink_len;
-err = v9fs_do_readlink(s, name, v9stat-extension, symlink_len);
+err = v9fs_co_readlink(s, name, v9stat-extension);
 if (err  0) {
 return err;
 }
@@ -3591,7 +3573,6 @@ static void v9fs_readlink(void *opaque)
 int32_t fid;
 int err = 0;
 V9fsFidState *fidp;
-ssize_t symlink_len;
 
 pdu_unmarshal(pdu, offset, d, fid);
 fidp = lookup_fid(pdu-s, fid);
@@ -3601,7 +3582,7 @@ static void v9fs_readlink(void *opaque)
 }
 
 v9fs_string_init(target);
-err = v9fs_do_readlink(pdu-s, fidp-path, target, symlink_len);
+err = v9fs_co_readlink(pdu-s, fidp-path, target);
 if (err  0) {
 goto out;
 }
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index e95b63d..c6f2649 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -505,5 +505,6 @@ static inline size_t do_pdu_unpack(void *dst, struct iovec 
*sg, int sg_count,
 }
 
 extern void handle_9p_output(VirtIODevice *vdev

[Qemu-devel] [V2 17/25] hw/9pfs: Add yield support to xattr related coroutine

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include llistxattr and lgetxattr.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|1 +
 hw/9pfs/coxattr.c|   50 ++
 hw/9pfs/virtio-9p-coth.h |3 ++
 3 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 hw/9pfs/coxattr.c

diff --git a/Makefile.objs b/Makefile.objs
index 83d30bd..98a345b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -298,6 +298,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
+9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/coxattr.c b/hw/9pfs/coxattr.c
new file mode 100644
index 000..2fba2c9
--- /dev/null
+++ b/hw/9pfs/coxattr.c
@@ -0,0 +1,50 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+int v9fs_co_llistxattr(V9fsState *s, V9fsString *path, void *value, size_t 
size)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-llistxattr(s-ctx, path-data, value, size);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_lgetxattr(V9fsState *s, V9fsString *path,
+  V9fsString *xattr_name,
+  void *value, size_t size)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-lgetxattr(s-ctx, path-data,
+xattr_name-data,
+value, size);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 09f232a..eb0c99a 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -68,4 +68,7 @@ extern int v9fs_co_chmod(V9fsState *, V9fsString *, mode_t);
 extern int v9fs_co_utimensat(V9fsState *, V9fsString *, struct timespec [2]);
 extern int v9fs_co_chown(V9fsState *, V9fsString *, uid_t, gid_t);
 extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
+extern int v9fs_co_llistxattr(V9fsState *, V9fsString *, void *, size_t);
+extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
+ V9fsString *, void *, size_t);
 #endif
-- 
1.7.1




[Qemu-devel] [V2 15/25] hw/9pfs: Add yield support to setattr related coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include chmod, utimensat, chown and truncate.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   64 ++
 hw/9pfs/virtio-9p-coth.h |4 +++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index f79564b..4297788 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -54,3 +54,67 @@ int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct 
statfs *stbuf)
 });
 return err;
 }
+
+int v9fs_co_chmod(V9fsState *s, V9fsString *path, mode_t mode)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_mode = mode;
+v9fs_co_run_in_worker(
+{
+err = s-ops-chmod(s-ctx, path-data, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_utimensat(V9fsState *s, V9fsString *path,
+  struct timespec times[2])
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-utimensat(s-ctx, path-data, times);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_uid = uid;
+cred.fc_gid = gid;
+v9fs_co_run_in_worker(
+{
+err = s-ops-chown(s-ctx, path-data, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
+
+int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t size)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-truncate(s-ctx, path-data, size);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 3538d91..09f232a 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -64,4 +64,8 @@ extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, 
off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
 extern int v9fs_co_lstat(V9fsState *, V9fsString *, struct stat *);
+extern int v9fs_co_chmod(V9fsState *, V9fsString *, mode_t);
+extern int v9fs_co_utimensat(V9fsState *, V9fsString *, struct timespec [2]);
+extern int v9fs_co_chown(V9fsState *, V9fsString *, uid_t, gid_t);
+extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
 #endif
-- 
1.7.1




[Qemu-devel] [V2 22/25] [virtio-9p] coroutine and threading for mkdir

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/codir.c  |   19 +++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   28 ++--
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 885f7d0..4ccf94f 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -66,3 +66,22 @@ void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
 });
 return;
 }
+
+int v9fs_co_mkdir(V9fsState *s, char *name, mode_t mode, uid_t uid, gid_t gid)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_mode = mode;
+cred.fc_uid = uid;
+cred.fc_gid = gid;
+v9fs_co_run_in_worker(
+{
+err = s-ops-mkdir(s-ctx, name, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index d023683..96e88d8 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -73,4 +73,5 @@ extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
  V9fsString *, void *, size_t);
 extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
  gid_t, dev_t, mode_t);
+extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 3f4d449..89fe652 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -149,19 +149,6 @@ static int v9fs_do_mknod(V9fsState *s, char *name,
 return s-ops-mknod(s-ctx, name, cred);
 }
 
-static int v9fs_do_mkdir(V9fsState *s, char *name, mode_t mode,
-uid_t uid, gid_t gid)
-{
-FsCred cred;
-
-cred_init(cred);
-cred.fc_uid = uid;
-cred.fc_gid = gid;
-cred.fc_mode = mode;
-
-return s-ops-mkdir(s-ctx, name, cred);
-}
-
 static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf)
 {
 return s-ops-fstat(s-ctx, fd, stbuf);
@@ -2327,8 +2314,7 @@ out:
 
 static void v9fs_create_post_mkdir(V9fsState *s, V9fsCreateState *vs, int err)
 {
-if (err) {
-err = -errno;
+if (err  0) {
 goto out;
 }
 
@@ -2377,7 +2363,7 @@ static void v9fs_create_post_lstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 }
 
 if (vs-perm  P9_STAT_MODE_DIR) {
-err = v9fs_do_mkdir(s, vs-fullname.data, vs-perm  0777,
+err = v9fs_co_mkdir(s, vs-fullname.data, vs-perm  0777,
 vs-fidp-uid, -1);
 v9fs_create_post_mkdir(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_SYMLINK) {
@@ -3177,14 +3163,12 @@ static void v9fs_mkdir(void *opaque)
 goto out;
 }
 v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
-err = v9fs_do_mkdir(pdu-s, fullname.data, mode, fidp-uid, gid);
-if (err == -1) {
-err = -errno;
+err = v9fs_co_mkdir(pdu-s, fullname.data, mode, fidp-uid, gid);
+if (err  0) {
 goto out;
 }
-err = v9fs_do_lstat(pdu-s, fullname, stbuf);
-if (err == -1) {
-err = -errno;
+err = v9fs_co_lstat(pdu-s, fullname, stbuf);
+if (err  0) {
 goto out;
 }
 stat_to_qid(stbuf, qid);
-- 
1.7.1




[Qemu-devel] [V2 04/25] [virtio-9p] clean up v9fs_readlink.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsReadLinkState.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   25 ++---
 hw/9pfs/virtio-9p.h |7 ---
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 06da2c9..e0e7eed 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3586,35 +3586,30 @@ out:
 static void v9fs_readlink(void *opaque)
 {
 V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+size_t offset = 7;
+V9fsString target;
 int32_t fid;
-V9fsReadLinkState *vs;
 int err = 0;
 V9fsFidState *fidp;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, d, fid);
-fidp = lookup_fid(s, fid);
+pdu_unmarshal(pdu, offset, d, fid);
+fidp = lookup_fid(pdu-s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
 
-v9fs_string_init(vs-target);
-err = v9fs_do_readlink(s, fidp-path, vs-target);
+v9fs_string_init(target);
+err = v9fs_do_readlink(pdu-s, fidp-path, target);
 if (err  0) {
 err = -errno;
 goto out;
 }
-vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
-err = vs-offset;
-v9fs_string_free(vs-target);
+offset += pdu_marshal(pdu, offset, s, target);
+err = offset;
+v9fs_string_free(target);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(pdu-s, pdu, err);
 }
 
 static CoroutineEntry *pdu_co_handlers[] = {
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index fb1e465..e95b63d 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -495,13 +495,6 @@ typedef struct V9fsGetlockState
 V9fsGetlock *glock;
 } V9fsGetlockState;
 
-typedef struct V9fsReadLinkState
-{
-V9fsPDU *pdu;
-size_t offset;
-V9fsString target;
-} V9fsReadLinkState;
-
 size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
   size_t offset, size_t size, int pack);
 
-- 
1.7.1




[Qemu-devel] [V2 25/25] [virtio-9p] coroutine and threading for remove/unlink

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   14 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   11 ++-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index af7b78e..af17077 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -139,3 +139,17 @@ int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t 
uid,
 });
 return err;
 }
+
+int v9fs_co_remove(V9fsState *s, V9fsString *path)
+{
+int err;
+
+v9fs_co_run_in_worker(
+{
+err = s-ops-remove(s-ctx, path-data);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 96e88d8..60795c4 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -74,4 +74,5 @@ extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
 extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
  gid_t, dev_t, mode_t);
 extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
+extern int v9fs_co_remove(V9fsState *, V9fsString *);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index ce45f00..0dba63d 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -212,11 +212,6 @@ static int v9fs_do_utimensat(V9fsState *s, V9fsString 
*path,
 return s-ops-utimensat(s-ctx, path-data, times);
 }
 
-static int v9fs_do_remove(V9fsState *s, V9fsString *path)
-{
-return s-ops-remove(s-ctx, path-data);
-}
-
 static int v9fs_do_fsync(V9fsState *s, int fd, int datasync)
 {
 return s-ops-fsync(s-ctx, fd, datasync);
@@ -2592,10 +2587,8 @@ static void v9fs_remove(void *opaque)
 err = -EINVAL;
 goto out;
 }
-err = v9fs_do_remove(pdu-s, fidp-path);
-if (err  0) {
-err = -errno;
-} else {
+err = v9fs_co_remove(pdu-s, fidp-path);
+if (!err) {
 err = offset;
 }
 
-- 
1.7.1




[Qemu-devel] [V2 21/25] hw/9pfs: Update v9fs_mknod to use coroutines

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   88 +-
 1 files changed, 30 insertions(+), 58 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 46577c0..3f4d449 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3017,77 +3017,49 @@ out:
 return;
 }
 
-static void v9fs_mknod_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_mknod_post_mknod(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-v9fs_mknod_post_lstat(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_mknod(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
+
+int mode;
+gid_t gid;
 int32_t fid;
-V9fsMkState *vs;
+V9fsQID qid;
 int err = 0;
-V9fsFidState *fidp;
-gid_t gid;
-int mode;
 int major, minor;
+size_t offset = 7;
+V9fsString name;
+struct stat stbuf;
+V9fsString fullname;
+V9fsFidState *fidp;
+V9fsPDU *pdu = opaque;
+V9fsState *s = pdu-s;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-v9fs_string_init(vs-fullname);
-pdu_unmarshal(vs-pdu, vs-offset, ds, fid, vs-name, mode,
-major, minor, gid);
+v9fs_string_init(fullname);
+pdu_unmarshal(pdu, offset, ds, fid, name, mode,
+  major, minor, gid);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
-v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
-err = v9fs_do_mknod(s, vs-fullname.data, mode, makedev(major, minor),
-fidp-uid, gid);
-v9fs_mknod_post_mknod(s, vs, err);
-return;
-
+v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
+err = v9fs_co_mknod(s, fullname, fidp-uid, gid,
+makedev(major, minor), mode);
+if (err  0) {
+goto out;
+}
+err = v9fs_co_lstat(s, fullname, stbuf);
+if (err  0) {
+goto out;
+}
+stat_to_qid(stbuf, qid);
+err = offset;
+err += pdu_marshal(pdu, offset, Q, qid);
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
+complete_pdu(s, pdu, err);
+v9fs_string_free(fullname);
+v9fs_string_free(name);
 }
 
 /*
-- 
1.7.1




[Qemu-devel] [V2 23/25] [virtio-9p] Remove post functions for v9fs_remove

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   26 +++---
 1 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 89fe652..a79ec72 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2577,22 +2577,6 @@ out:
 complete_pdu(s, pdu, err);
 }
 
-static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs,
-int err)
-{
-if (err  0) {
-err = -errno;
-} else {
-err = vs-offset;
-}
-
-/* For TREMOVE we need to clunk the fid even on failed remove */
-free_fid(s, vs-fidp-fid);
-
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
 static void v9fs_remove(void *opaque)
 {
 V9fsPDU *pdu = opaque;
@@ -2612,11 +2596,15 @@ static void v9fs_remove(void *opaque)
 err = -EINVAL;
 goto out;
 }
-
 err = v9fs_do_remove(s, vs-fidp-path);
-v9fs_remove_post_remove(s, vs, err);
-return;
+if (err  0) {
+err = -errno;
+} else {
+err = vs-offset;
+}
 
+/* For TREMOVE we need to clunk the fid even on failed remove */
+free_fid(s, vs-fidp-fid);
 out:
 complete_pdu(s, pdu, err);
 qemu_free(vs);
-- 
1.7.1




[Qemu-devel] [V2 20/25] hw/9pfs: Add yield support to mknod coroutine

2011-05-17 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   21 +
 hw/9pfs/virtio-9p-coth.h |2 ++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 4297788..af7b78e 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -118,3 +118,24 @@ int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t 
size)
 });
 return err;
 }
+
+int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t uid,
+  gid_t gid, dev_t dev, mode_t mode)
+{
+int err;
+FsCred cred;
+
+cred_init(cred);
+cred.fc_uid  = uid;
+cred.fc_gid  = gid;
+cred.fc_mode = mode;
+cred.fc_rdev = dev;
+v9fs_co_run_in_worker(
+{
+err = s-ops-mknod(s-ctx, path-data, cred);
+if (err  0) {
+err = -errno;
+}
+});
+return err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index eb0c99a..d023683 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -71,4 +71,6 @@ extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
 extern int v9fs_co_llistxattr(V9fsState *, V9fsString *, void *, size_t);
 extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
  V9fsString *, void *, size_t);
+extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
+ gid_t, dev_t, mode_t);
 #endif
-- 
1.7.1




[Qemu-devel] [V2 01/25] [virtio-9p] Add infrastructure to support glib threads and coroutines.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
This patch is originally made by Arun Bharadwaj for glib support.
Later Harsh Prateek Bora added coroutines support.
This version implemented with suggestions from
Stefan Hajnoczi stefa...@linux.vnet.ibm.com.

Signed-off-by: Arun R Bharadwaj a...@linux.vnet.ibm.com
Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs  |2 +
 hw/9pfs/virtio-9p-coth.c   |   93 
 hw/9pfs/virtio-9p-coth.h   |   58 +++
 hw/9pfs/virtio-9p-device.c |7 ++-
 4 files changed, 158 insertions(+), 2 deletions(-)
 create mode 100644 hw/9pfs/virtio-9p-coth.c
 create mode 100644 hw/9pfs/virtio-9p-coth.h

diff --git a/Makefile.objs b/Makefile.objs
index 3873f10..96f6a24 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,8 +297,10 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
+$(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
 
 ##
diff --git a/hw/9pfs/virtio-9p-coth.c b/hw/9pfs/virtio-9p-coth.c
new file mode 100644
index 000..e61b656
--- /dev/null
+++ b/hw/9pfs/virtio-9p-coth.c
@@ -0,0 +1,93 @@
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Harsh Prateek Bora ha...@linux.vnet.ibm.com
+ *  Venkateswararao Jujjuri(JV) jv...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include qemu-char.h
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+/* v9fs glib thread pool */
+static V9fsThPool v9fs_pool;
+
+void co_run_in_worker_bh(void *opaque)
+{
+Coroutine *co = opaque;
+g_thread_pool_push(v9fs_pool.pool, co, NULL);
+}
+
+static void v9fs_qemu_process_req_done(void *arg)
+{
+char byte;
+ssize_t len;
+Coroutine *co;
+
+do {
+len = read(v9fs_pool.rfd, byte, sizeof(byte));
+} while (len == -1   errno == EINTR);
+
+while ((co = g_async_queue_try_pop(v9fs_pool.completed)) != NULL) {
+qemu_coroutine_enter(co, NULL);
+}
+}
+
+static void v9fs_thread_routine(gpointer data, gpointer user_data)
+{
+ssize_t len;
+char byte = 0;
+Coroutine *co = data;
+
+qemu_coroutine_enter(co, NULL);
+
+g_async_queue_push(v9fs_pool.completed, co);
+do {
+len = write(v9fs_pool.wfd, byte, sizeof(byte));
+} while (len == -1  errno == EINTR);
+}
+
+int v9fs_init_worker_threads(void)
+{
+int notifier_fds[2];
+V9fsThPool *p = v9fs_pool;
+
+/* init thread system if not already initialized */
+if (!g_thread_get_initialized()) {
+g_thread_init(NULL);
+}
+
+if (qemu_pipe(notifier_fds) == -1) {
+return -1;
+}
+
+p-pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL);
+if (!p-pool) {
+return -1;
+}
+p-completed = g_async_queue_new();
+if (!p-completed) {
+/*
+ * We are going to terminate.
+ * So don't worry about cleanup
+ */
+return -1;
+}
+p-rfd = notifier_fds[0];
+p-wfd = notifier_fds[1];
+
+fcntl(p-rfd, F_SETFL, O_NONBLOCK);
+fcntl(p-wfd, F_SETFL, O_NONBLOCK);
+
+qemu_set_fd_handler(p-rfd, v9fs_qemu_process_req_done, NULL, NULL);
+return 0;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
new file mode 100644
index 000..8445d29
--- /dev/null
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -0,0 +1,58 @@
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Harsh Prateek Bora ha...@linux.vnet.ibm.com
+ *  Venkateswararao Jujjuri(JV) jv...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef _QEMU_VIRTIO_9P_COTH_H
+#define _QEMU_VIRTIO_9P_COTH_H
+
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include glib.h
+
+typedef struct V9fsThPool {
+int rfd;
+int wfd;
+GThreadPool *pool;
+GAsyncQueue *completed;
+} V9fsThPool;
+
+/*
+ * we want to use bottom half because we want to make sure the below
+ * sequence of events.
+ *
+ *   1. Yield the coroutine in the QEMU thread.
+ *   2. Submit the coroutine to a worker thread.
+ *   3. Enter the coroutine in the worker thread.
+ * we cannot swap step 1 and 2, because that would imply worker thread
+ * can enter coroutine while step1 is still running
+ */
+#define v9fs_co_run_in_worker(code_block)   \
+do

[Qemu-devel] [V2 24/25] [virtio-9p] clean up v9fs_remove.

2011-05-17 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsRemoveState
and additional malloc()s.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   25 ++---
 hw/9pfs/virtio-9p.h |6 --
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index a79ec72..ce45f00 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2579,35 +2579,30 @@ out:
 
 static void v9fs_remove(void *opaque)
 {
-V9fsPDU *pdu = opaque;
-V9fsState *s = pdu-s;
 int32_t fid;
-V9fsRemoveState *vs;
 int err = 0;
+size_t offset = 7;
+V9fsFidState *fidp;
+V9fsPDU *pdu = opaque;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, d, fid);
+pdu_unmarshal(pdu, offset, d, fid);
 
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
+fidp = lookup_fid(pdu-s, fid);
+if (fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-err = v9fs_do_remove(s, vs-fidp-path);
+err = v9fs_do_remove(pdu-s, fidp-path);
 if (err  0) {
 err = -errno;
 } else {
-err = vs-offset;
+err = offset;
 }
 
 /* For TREMOVE we need to clunk the fid even on failed remove */
-free_fid(s, vs-fidp-fid);
+free_fid(pdu-s, fidp-fid);
 out:
-complete_pdu(s, pdu, err);
-qemu_free(vs);
+complete_pdu(pdu-s, pdu, err);
 }
 
 static void v9fs_wstat_post_truncate(V9fsState *s, V9fsWstatState *vs, int err)
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index ffbb3b8..b693f74 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -333,12 +333,6 @@ typedef struct V9fsWriteState {
 int cnt;
 } V9fsWriteState;
 
-typedef struct V9fsRemoveState {
-V9fsPDU *pdu;
-size_t offset;
-V9fsFidState *fidp;
-} V9fsRemoveState;
-
 typedef struct V9fsWstatState
 {
 V9fsPDU *pdu;
-- 
1.7.1




[Qemu-devel] [PATCH 05/25] [virtio-9p] Move errno into v9fs_do_readlink

2011-05-12 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   32 
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c4d903a..a748c34 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -82,19 +82,21 @@ static int v9fs_do_lstat(V9fsState *s, V9fsString *path, 
struct stat *stbuf)
 return s-ops-lstat(s-ctx, path-data, stbuf);
 }
 
-static ssize_t v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString 
*buf)
+static int v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString *buf,
+ssize_t *len)
 {
-ssize_t len;
-
+int err;
 buf-data = qemu_malloc(1024);
 
-len = s-ops-readlink(s-ctx, path-data, buf-data, 1024 - 1);
-if (len  -1) {
-buf-size = len;
-buf-data[len] = 0;
+*len = s-ops-readlink(s-ctx, path-data, buf-data, 1024 - 1);
+if (*len  -1) {
+buf-size = *len;
+buf-data[*len] = 0;
+err = 0;
+} else {
+err = -errno;
 }
-
-return len;
+return err;
 }
 
 static int v9fs_do_close(V9fsState *s, int fd)
@@ -1055,13 +1057,11 @@ static int stat_to_v9stat(V9fsState *s, V9fsString 
*name,
 v9fs_string_null(v9stat-extension);
 
 if (v9stat-mode  P9_STAT_MODE_SYMLINK) {
-err = v9fs_do_readlink(s, name, v9stat-extension);
-if (err == -1) {
-err = -errno;
+ssize_t symlink_len;
+err = v9fs_do_readlink(s, name, v9stat-extension, symlink_len);
+if (err  0) {
 return err;
 }
-v9stat-extension.data[err] = 0;
-v9stat-extension.size = err;
 } else if (v9stat-mode  P9_STAT_MODE_DEVICE) {
 v9fs_string_sprintf(v9stat-extension, %c %u %u,
 S_ISCHR(stbuf-st_mode) ? 'c' : 'b',
@@ -3645,6 +3645,7 @@ static void v9fs_readlink(void *opaque)
 int32_t fid;
 int err = 0;
 V9fsFidState *fidp;
+ssize_t symlink_len;
 
 pdu_unmarshal(copdu-pdu, offset, d, fid);
 fidp = lookup_fid(copdu-s, fid);
@@ -3654,9 +3655,8 @@ static void v9fs_readlink(void *opaque)
 }
 
 v9fs_string_init(target);
-err = v9fs_do_readlink(copdu-s, fidp-path, target);
+err = v9fs_do_readlink(copdu-s, fidp-path, target, symlink_len);
 if (err  0) {
-err = -errno;
 goto out;
 }
 offset += pdu_marshal(copdu-pdu, offset, s, target);
-- 
1.7.1




[Qemu-devel] [PATCH 03/25] [virtio-9p] Remove post functions for v9fs_readlink.

2011-05-12 Thread Venkateswararao Jujjuri (JV)
In the process of preparation for coroutine threads, remove all post functions
and make the function more readable.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   25 +++--
 1 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index e308e9b..0b38868 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3637,21 +3637,6 @@ out:
 qemu_free(copdu);
 }
 
-static void v9fs_readlink_post_readlink(V9fsState *s, V9fsReadLinkState *vs,
-int err)
-{
-if (err  0) {
-err = -errno;
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-target);
-qemu_free(vs);
-}
-
 static void v9fs_readlink(void *opaque)
 {
 V9fsCoPdu *copdu = opaque;
@@ -3667,7 +3652,6 @@ static void v9fs_readlink(void *opaque)
 vs-offset = 7;
 
 pdu_unmarshal(vs-pdu, vs-offset, d, fid);
-
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
@@ -3676,8 +3660,13 @@ static void v9fs_readlink(void *opaque)
 
 v9fs_string_init(vs-target);
 err = v9fs_do_readlink(s, fidp-path, vs-target);
-v9fs_readlink_post_readlink(s, vs, err);
-return;
+if (err  0) {
+err = -errno;
+goto out;
+}
+vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
+err = vs-offset;
+v9fs_string_free(vs-target);
 out:
 complete_pdu(s, vs-pdu, err);
 qemu_free(vs);
-- 
1.7.1




[Qemu-devel] [PATCH 04/25] [virtio-9p] clean up v9fs_readlink.

2011-05-12 Thread Venkateswararao Jujjuri (JV)
Rearrange the code so that we can avoid V9fsReadLinkState.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   26 ++
 hw/9pfs/virtio-9p.h |7 ---
 2 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 0b38868..c4d903a 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3640,36 +3640,30 @@ out:
 static void v9fs_readlink(void *opaque)
 {
 V9fsCoPdu *copdu = opaque;
-V9fsState *s = copdu-s;
-V9fsPDU *pdu = copdu-pdu;
+size_t offset = 7;
+V9fsString target;
 int32_t fid;
-V9fsReadLinkState *vs;
 int err = 0;
 V9fsFidState *fidp;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, d, fid);
-fidp = lookup_fid(s, fid);
+pdu_unmarshal(copdu-pdu, offset, d, fid);
+fidp = lookup_fid(copdu-s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
 
-v9fs_string_init(vs-target);
-err = v9fs_do_readlink(s, fidp-path, vs-target);
+v9fs_string_init(target);
+err = v9fs_do_readlink(copdu-s, fidp-path, target);
 if (err  0) {
 err = -errno;
 goto out;
 }
-vs-offset += pdu_marshal(vs-pdu, vs-offset, s, vs-target);
-err = vs-offset;
-v9fs_string_free(vs-target);
+offset += pdu_marshal(copdu-pdu, offset, s, target);
+err = offset;
+v9fs_string_free(target);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(copdu-s, copdu-pdu, err);
 qemu_free(copdu);
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 5021da8..bf8f64b 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -493,13 +493,6 @@ typedef struct V9fsGetlockState
 V9fsGetlock *glock;
 } V9fsGetlockState;
 
-typedef struct V9fsReadLinkState
-{
-V9fsPDU *pdu;
-size_t offset;
-V9fsString target;
-} V9fsReadLinkState;
-
 size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
   size_t offset, size_t size, int pack);
 
-- 
1.7.1




[Qemu-devel] [PATCH 02/25] [virtio-9p] Change all pdu handlers to coroutines.

2011-05-12 Thread Venkateswararao Jujjuri (JV)
This patch changes the top level handlers to coroutines and sets the base.
It will be followed up with series of patches to convert all filesystem
calls to threaded coroutines pushing all blocking clals in VirtFS out
of vcpu threads.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p-coth.h |7 ++
 hw/9pfs/virtio-9p.c  |  194 --
 hw/9pfs/virtio-9p.h  |2 +-
 3 files changed, 161 insertions(+), 42 deletions(-)

diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index fdc44f6..2ec1401 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -17,6 +17,7 @@
 
 #include qemu-thread.h
 #include qemu-coroutine.h
+#include virtio-9p.h
 #include glib.h
 
 typedef struct V9fsRequest {
@@ -34,6 +35,12 @@ typedef struct V9fsThPool {
 int wfd;
 } V9fsThPool;
 
+typedef struct V9fsCoPdu {
+V9fsPDU *pdu;
+V9fsState *s;
+Coroutine *coroutine;
+} V9fsCoPdu;
+
 /* v9fs glib thread pool */
 extern V9fsThPool v9fs_pool;
 
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index ec97b10..e308e9b 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -19,6 +19,7 @@
 #include fsdev/qemu-fsdev.h
 #include virtio-9p-debug.h
 #include virtio-9p-xattr.h
+#include virtio-9p-coth.h
 
 int debug_9p_pdu;
 
@@ -1192,8 +1193,11 @@ static void v9fs_fix_path(V9fsString *dst, V9fsString 
*src, int len)
 v9fs_string_free(str);
 }
 
-static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_version(void *opaque)
 {
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 V9fsString version;
 size_t offset = 7;
 
@@ -1211,10 +1215,15 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
 complete_pdu(s, pdu, offset);
 
 v9fs_string_free(version);
+qemu_free(copdu);
+return;
 }
 
-static void v9fs_attach(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_attach(void *opaque)
 {
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 int32_t fid, afid, n_uname;
 V9fsString uname, aname;
 V9fsFidState *fidp;
@@ -1247,6 +1256,7 @@ out:
 complete_pdu(s, pdu, err);
 v9fs_string_free(uname);
 v9fs_string_free(aname);
+qemu_free(copdu);
 }
 
 static void v9fs_stat_post_lstat(V9fsState *s, V9fsStatState *vs, int err)
@@ -1269,8 +1279,11 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_stat(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_stat(void *opaque)
 {
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 int32_t fid;
 V9fsStatState *vs;
 ssize_t err = 0;
@@ -1297,6 +1310,7 @@ out:
 complete_pdu(s, vs-pdu, err);
 v9fs_stat_free(vs-v9stat);
 qemu_free(vs);
+qemu_free(copdu);
 }
 
 static void v9fs_getattr_post_lstat(V9fsState *s, V9fsStatStateDotl *vs,
@@ -1316,8 +1330,11 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_getattr(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_getattr(void *opaque)
 {
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 int32_t fid;
 V9fsStatStateDotl *vs;
 ssize_t err = 0;
@@ -1348,6 +1365,7 @@ static void v9fs_getattr(V9fsState *s, V9fsPDU *pdu)
 out:
 complete_pdu(s, vs-pdu, err);
 qemu_free(vs);
+qemu_free(copdu);
 }
 
 /* From Linux kernel code */
@@ -1465,8 +1483,11 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_setattr(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_setattr(void *opaque)
 {
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 int32_t fid;
 V9fsSetattrState *vs;
 int err = 0;
@@ -1493,6 +1514,7 @@ static void v9fs_setattr(V9fsState *s, V9fsPDU *pdu)
 out:
 complete_pdu(s, vs-pdu, err);
 qemu_free(vs);
+qemu_free(copdu);
 }
 
 static void v9fs_walk_complete(V9fsState *s, V9fsWalkState *vs, int err)
@@ -1579,8 +1601,11 @@ out:
 v9fs_walk_complete(s, vs, err);
 }
 
-static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_walk(void *opaque)
 {
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 int32_t fid, newfid;
 V9fsWalkState *vs;
 int err = 0;
@@ -1658,6 +1683,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
 err = vs-offset;
 out:
 v9fs_walk_complete(s, vs, err);
+qemu_free(copdu);
 }
 
 static int32_t get_iounit(V9fsState *s, V9fsString *name)
@@ -1751,8 +1777,11 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_open(void *opaque)
 {
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 int32_t fid;
 V9fsOpenState *vs;
 ssize_t err = 0;
@@ -1783,6 +1812,7 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
 out:
 complete_pdu(s, pdu, err);
 qemu_free(vs);
+qemu_free(copdu);
 }
 
 static void v9fs_post_lcreate

[Qemu-devel] [0/25] Async threading for VirtFS using glib threads coroutines.

2011-05-12 Thread Venkateswararao Jujjuri (JV)
VirtFS (fileserver base on 9P) performs many blocking system calls in the 
vCPU context. This effort is to move the blocking calls out of vCPU/IO 
thread context, into asynchronous threads.

Anthony's  Add hard build dependency on glib patch and 
Kevin/Stefan's coroutine effort is a prerequisite.

This patch set contains:
 - Converting all 9pfs calls into coroutines. 
 - Each 9P operation will be modified for:
- Remove post* functions. These are our call back functions which makes 
  the code very hard to read. Now with coroutines, we can achieve the same 
  state machine model with nice sequential code flow.
- Move errno access near to the local_syscall()
- Introduce asynchronous threading

This series has the basic infrastructure and few routines like 
mkdir,monod,unlink,readdir,xattr,lstat, etc converted. 
Currently we are working on converting and testing other 9P operations also 
into this model and those patches will follow shortly.

Removing callback functions made some of the patches little lengthy. 
Here is the git tree for the reviewer convenience. 

http://repo.or.cz/w/qemu/aliguori/jvrao.git/shortlog/refs/heads/9p-coroutines-round1
 

-Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com







[Qemu-devel] [PATCH 14/25] hw/9pfs: Update v9fs_getattr to use coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   59 +-
 hw/9pfs/virtio-9p.h |8 ---
 2 files changed, 20 insertions(+), 47 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 86e9482..fa2bb1f 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1088,7 +1088,7 @@ static int stat_to_v9stat(V9fsState *s, V9fsString *name,
 
 
 static void stat_to_v9stat_dotl(V9fsState *s, const struct stat *stbuf,
-V9fsStatDotl *v9lstat)
+V9fsStatDotl *v9lstat)
 {
 memset(v9lstat, 0, sizeof(*v9lstat));
 
@@ -1291,58 +1291,39 @@ out:
 qemu_free(copdu);
 }
 
-static void v9fs_getattr_post_lstat(V9fsState *s, V9fsStatStateDotl *vs,
-int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_v9stat_dotl(s, vs-stbuf, vs-v9stat_dotl);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, A, vs-v9stat_dotl);
-err = vs-offset;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
 static void v9fs_getattr(void *opaque)
 {
-V9fsCoPdu *copdu = opaque;
-V9fsState *s = copdu-s;
-V9fsPDU *pdu = copdu-pdu;
 int32_t fid;
-V9fsStatStateDotl *vs;
-ssize_t err = 0;
+size_t offset = 7;
+ssize_t retval = 0;
+struct stat stbuf;
 V9fsFidState *fidp;
 uint64_t request_mask;
+V9fsStatDotl v9stat_dotl;
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-memset(vs-v9stat_dotl, 0, sizeof(vs-v9stat_dotl));
-
-pdu_unmarshal(vs-pdu, vs-offset, dq, fid, request_mask);
+pdu_unmarshal(pdu, offset, dq, fid, request_mask);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
-err = -ENOENT;
+retval = -ENOENT;
 goto out;
 }
-
-/* Currently we only support BASIC fields in stat, so there is no
+/*
+ * Currently we only support BASIC fields in stat, so there is no
  * need to look at request_mask.
  */
-err = v9fs_do_lstat(s, fidp-path, vs-stbuf);
-v9fs_getattr_post_lstat(s, vs, err);
-return;
-
+retval = v9fs_co_lstat(s, fidp-path, stbuf);
+if (retval  0) {
+goto out;
+}
+stat_to_v9stat_dotl(s, stbuf, v9stat_dotl);
+retval = offset;
+retval += pdu_marshal(pdu, offset, A, v9stat_dotl);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(s, pdu, retval);
 qemu_free(copdu);
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index ee8cb79..7e4bea0 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -276,14 +276,6 @@ typedef struct V9fsStatDotl {
 uint64_t st_data_version;
 } V9fsStatDotl;
 
-typedef struct V9fsStatStateDotl {
-V9fsPDU *pdu;
-size_t offset;
-V9fsStatDotl v9stat_dotl;
-struct stat stbuf;
-} V9fsStatStateDotl;
-
-
 typedef struct V9fsWalkState {
 V9fsPDU *pdu;
 size_t offset;
-- 
1.7.1




[Qemu-devel] [PATCH 07/25] [virtio-9p] Remove post functions for v9fs_mkdir.

2011-05-12 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   52 --
 1 files changed, 13 insertions(+), 39 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 7ef6ad8..af0143d 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3357,40 +3357,6 @@ out:
 qemu_free(copdu);
 }
 
-static void v9fs_mkdir_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-stat_to_qid(vs-stbuf, vs-qid);
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_mkdir_post_mkdir(V9fsState *s, V9fsMkState *vs, int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
-v9fs_mkdir_post_lstat(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-fullname);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_mkdir(void *opaque)
 {
 V9fsCoPdu *copdu = opaque;
@@ -3409,19 +3375,27 @@ static void v9fs_mkdir(void *opaque)
 
 v9fs_string_init(vs-fullname);
 pdu_unmarshal(vs-pdu, vs-offset, dsdd, fid, vs-name, mode,
-gid);
+  gid);
 
 fidp = lookup_fid(s, fid);
 if (fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
 v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
 err = v9fs_do_mkdir(s, vs-fullname.data, mode, fidp-uid, gid);
-v9fs_mkdir_post_mkdir(s, vs, err);
-return;
-
+if (err == -1) {
+err = -errno;
+goto out;
+}
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+if (err == -1) {
+err = -errno;
+goto out;
+}
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
+err = vs-offset;
 out:
 complete_pdu(s, vs-pdu, err);
 v9fs_string_free(vs-fullname);
-- 
1.7.1




[Qemu-devel] [PATCH 16/25] hw/9pfs: Update v9fs_setattr to use coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  165 +--
 hw/9pfs/virtio-9p.h |8 ---
 2 files changed, 55 insertions(+), 118 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index fa2bb1f..8723039 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1339,140 +1339,85 @@ out:
 #define ATTR_ATIME_SET  (1  7)
 #define ATTR_MTIME_SET  (1  8)
 
-static void v9fs_setattr_post_truncate(V9fsState *s, V9fsSetattrState *vs,
-  int err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-err = vs-offset;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_chown(V9fsState *s, V9fsSetattrState *vs, int 
err)
+static void v9fs_setattr(void *opaque)
 {
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-if (vs-v9iattr.valid  (ATTR_SIZE)) {
-err = v9fs_do_truncate(s, vs-fidp-path, vs-v9iattr.size);
-}
-v9fs_setattr_post_truncate(s, vs, err);
-return;
+int err = 0;
+int32_t fid;
+V9fsFidState *fidp;
+size_t offset = 7;
+V9fsIattr v9iattr;
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
+pdu_unmarshal(pdu, offset, dI, fid, v9iattr);
 
-static void v9fs_setattr_post_utimensat(V9fsState *s, V9fsSetattrState *vs,
-   int err)
-{
-if (err == -1) {
-err = -errno;
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+err = -EINVAL;
 goto out;
 }
-
-/* If the only valid entry in iattr is ctime we can call
- * chown(-1,-1) to update the ctime of the file
- */
-if ((vs-v9iattr.valid  (ATTR_UID | ATTR_GID)) ||
-((vs-v9iattr.valid  ATTR_CTIME)
- !((vs-v9iattr.valid  ATTR_MASK)  ~ATTR_CTIME))) {
-if (!(vs-v9iattr.valid  ATTR_UID)) {
-vs-v9iattr.uid = -1;
-}
-if (!(vs-v9iattr.valid  ATTR_GID)) {
-vs-v9iattr.gid = -1;
+if (v9iattr.valid  ATTR_MODE) {
+err = v9fs_co_chmod(s, fidp-path, v9iattr.mode);
+if (err  0) {
+goto out;
 }
-err = v9fs_do_chown(s, vs-fidp-path, vs-v9iattr.uid,
-vs-v9iattr.gid);
 }
-v9fs_setattr_post_chown(s, vs, err);
-return;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr_post_chmod(V9fsState *s, V9fsSetattrState *vs, int 
err)
-{
-if (err == -1) {
-err = -errno;
-goto out;
-}
-
-if (vs-v9iattr.valid  (ATTR_ATIME | ATTR_MTIME)) {
+if (v9iattr.valid  (ATTR_ATIME | ATTR_MTIME)) {
 struct timespec times[2];
-if (vs-v9iattr.valid  ATTR_ATIME) {
-if (vs-v9iattr.valid  ATTR_ATIME_SET) {
-times[0].tv_sec = vs-v9iattr.atime_sec;
-times[0].tv_nsec = vs-v9iattr.atime_nsec;
+if (v9iattr.valid  ATTR_ATIME) {
+if (v9iattr.valid  ATTR_ATIME_SET) {
+times[0].tv_sec = v9iattr.atime_sec;
+times[0].tv_nsec = v9iattr.atime_nsec;
 } else {
 times[0].tv_nsec = UTIME_NOW;
 }
 } else {
 times[0].tv_nsec = UTIME_OMIT;
 }
-
-if (vs-v9iattr.valid  ATTR_MTIME) {
-if (vs-v9iattr.valid  ATTR_MTIME_SET) {
-times[1].tv_sec = vs-v9iattr.mtime_sec;
-times[1].tv_nsec = vs-v9iattr.mtime_nsec;
+if (v9iattr.valid  ATTR_MTIME) {
+if (v9iattr.valid  ATTR_MTIME_SET) {
+times[1].tv_sec = v9iattr.mtime_sec;
+times[1].tv_nsec = v9iattr.mtime_nsec;
 } else {
 times[1].tv_nsec = UTIME_NOW;
 }
 } else {
 times[1].tv_nsec = UTIME_OMIT;
 }
-err = v9fs_do_utimensat(s, vs-fidp-path, times);
+err = v9fs_co_utimensat(s, fidp-path, times);
+if (err  0) {
+goto out;
+}
 }
-v9fs_setattr_post_utimensat(s, vs, err);
-return;
-
-out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
-}
-
-static void v9fs_setattr(void *opaque)
-{
-V9fsCoPdu *copdu = opaque;
-V9fsState *s = copdu-s;
-V9fsPDU *pdu = copdu-pdu;
-int32_t fid;
-V9fsSetattrState *vs;
-int err = 0;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(pdu, vs-offset, dI, fid, vs-v9iattr);
-
-vs-fidp = lookup_fid(s, fid);
-if (vs-fidp == NULL) {
-err = -EINVAL;
-goto out

[Qemu-devel] [PATCH 12/25] hw/9pfs: Update v9fs_statfs to use coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   92 --
 hw/9pfs/virtio-9p.h |   22 
 2 files changed, 44 insertions(+), 70 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 148382d..86e9482 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3075,80 +3075,76 @@ out:
 qemu_free(copdu);
 }
 
-static void v9fs_statfs_post_statfs(V9fsState *s, V9fsStatfsState *vs, int err)
-{
+static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
+{
+uint32_t f_type;
+uint32_t f_bsize;
+uint64_t f_blocks;
+uint64_t f_bfree;
+uint64_t f_bavail;
+uint64_t f_files;
+uint64_t f_ffree;
+uint64_t fsid_val;
+uint32_t f_namelen;
+size_t offset = 7;
 int32_t bsize_factor;
 
-if (err) {
-err = -errno;
-goto out;
-}
-
 /*
  * compute bsize factor based on host file system block size
  * and client msize
  */
-bsize_factor = (s-msize - P9_IOHDRSZ)/vs-stbuf.f_bsize;
+bsize_factor = (s-msize - P9_IOHDRSZ)/stbuf-f_bsize;
 if (!bsize_factor) {
 bsize_factor = 1;
 }
-vs-v9statfs.f_type = vs-stbuf.f_type;
-vs-v9statfs.f_bsize = vs-stbuf.f_bsize;
-vs-v9statfs.f_bsize *= bsize_factor;
+f_type  = stbuf-f_type;
+f_bsize = stbuf-f_bsize;
+f_bsize *= bsize_factor;
 /*
  * f_bsize is adjusted(multiplied) by bsize factor, so we need to
  * adjust(divide) the number of blocks, free blocks and available
  * blocks by bsize factor
  */
-vs-v9statfs.f_blocks = vs-stbuf.f_blocks/bsize_factor;
-vs-v9statfs.f_bfree = vs-stbuf.f_bfree/bsize_factor;
-vs-v9statfs.f_bavail = vs-stbuf.f_bavail/bsize_factor;
-vs-v9statfs.f_files = vs-stbuf.f_files;
-vs-v9statfs.f_ffree = vs-stbuf.f_ffree;
-vs-v9statfs.fsid_val = (unsigned int) vs-stbuf.f_fsid.__val[0] |
-   (unsigned long long)vs-stbuf.f_fsid.__val[1]  32;
-vs-v9statfs.f_namelen = vs-stbuf.f_namelen;
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, ddqqd,
- vs-v9statfs.f_type, vs-v9statfs.f_bsize, vs-v9statfs.f_blocks,
- vs-v9statfs.f_bfree, vs-v9statfs.f_bavail, vs-v9statfs.f_files,
- vs-v9statfs.f_ffree, vs-v9statfs.fsid_val,
- vs-v9statfs.f_namelen);
+f_blocks = stbuf-f_blocks/bsize_factor;
+f_bfree  = stbuf-f_bfree/bsize_factor;
+f_bavail = stbuf-f_bavail/bsize_factor;
+f_files  = stbuf-f_files;
+f_ffree  = stbuf-f_ffree;
+fsid_val = (unsigned int) stbuf-f_fsid.__val[0] |
+   (unsigned long long)stbuf-f_fsid.__val[1]  32;
+f_namelen = stbuf-f_namelen;
 
-out:
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
+return pdu_marshal(pdu, offset, ddqqd,
+   f_type, f_bsize, f_blocks, f_bfree,
+   f_bavail, f_files, f_ffree,
+   fsid_val, f_namelen);
 }
 
 static void v9fs_statfs(void *opaque)
 {
+int32_t fid;
+ssize_t retval = 0;
+size_t offset = 7;
+V9fsFidState *fidp;
+struct statfs stbuf;
 V9fsCoPdu *copdu = opaque;
 V9fsState *s = copdu-s;
 V9fsPDU *pdu = copdu-pdu;
-V9fsStatfsState *vs;
-ssize_t err = 0;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-memset(vs-v9statfs, 0, sizeof(vs-v9statfs));
-
-pdu_unmarshal(vs-pdu, vs-offset, d, vs-fid);
-
-vs-fidp = lookup_fid(s, vs-fid);
-if (vs-fidp == NULL) {
-err = -ENOENT;
+pdu_unmarshal(pdu, offset, d, fid);
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+retval = -ENOENT;
 goto out;
 }
-
-err = v9fs_do_statfs(s, vs-fidp-path, vs-stbuf);
-v9fs_statfs_post_statfs(s, vs, err);
-return;
-
+retval = v9fs_co_statfs(s, fidp-path, stbuf);
+if (retval  0) {
+goto out;
+}
+retval = offset;
+retval += v9fs_fill_statfs(s, pdu, stbuf);
 out:
-complete_pdu(s, vs-pdu, err);
-qemu_free(vs);
+complete_pdu(s, pdu, retval);
 qemu_free(copdu);
 return;
 }
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index bf8f64b..ee8cb79 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -396,28 +396,6 @@ struct virtio_9p_config
 uint8_t tag[0];
 } __attribute__((packed));
 
-typedef struct V9fsStatfs
-{
-uint32_t f_type;
-uint32_t f_bsize;
-uint64_t f_blocks;
-uint64_t f_bfree;
-uint64_t f_bavail;
-uint64_t f_files;
-uint64_t f_ffree;
-uint64_t fsid_val;
-uint32_t f_namelen;
-} V9fsStatfs;
-
-typedef struct V9fsStatfsState {
-V9fsPDU *pdu;
-size_t offset;
-int32_t fid;
-V9fsStatfs v9statfs;
-V9fsFidState *fidp;
-struct statfs stbuf;
-} V9fsStatfsState;
-
 typedef struct V9fsMkState {
 V9fsPDU

[Qemu-devel] [PATCH 01/25] [virtio-9p] Add infrastructure to support glib threads and coroutines.

2011-05-12 Thread Venkateswararao Jujjuri (JV)
This patch is originally made by Arun Bharadwaj for glib support.
Later Harsh Prateek Bora added coroutines support.

Signed-off-by: Arun R Bharadwaj a...@linux.vnet.ibm.com
Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs  |2 +
 hw/9pfs/virtio-9p-coth.c   |   68 
 hw/9pfs/virtio-9p-coth.h   |   45 +
 hw/9pfs/virtio-9p-device.c |   26 +++-
 hw/9pfs/virtio-9p.h|1 -
 5 files changed, 139 insertions(+), 3 deletions(-)
 create mode 100644 hw/9pfs/virtio-9p-coth.c
 create mode 100644 hw/9pfs/virtio-9p-coth.h

diff --git a/Makefile.objs b/Makefile.objs
index 3873f10..96f6a24 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,8 +297,10 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
+$(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
 
 ##
diff --git a/hw/9pfs/virtio-9p-coth.c b/hw/9pfs/virtio-9p-coth.c
new file mode 100644
index 000..edd3cde
--- /dev/null
+++ b/hw/9pfs/virtio-9p-coth.c
@@ -0,0 +1,68 @@
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Harsh Prateek Bora ha...@linux.vnet.ibm.com
+ *  Venkateswararao Jujjuri(JV) jv...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+/* v9fs glib thread pool */
+V9fsThPool v9fs_pool;
+
+void v9fs_qemu_submit_request(V9fsRequest *req)
+{
+V9fsThPool *p = v9fs_pool;
+
+req-done = 0;
+p-requests = g_list_append(p-requests, req);
+g_thread_pool_push(v9fs_pool.pool, req, NULL);
+}
+
+void v9fs_qemu_process_req_done(void *arg)
+{
+struct V9fsThPool *p = v9fs_pool;
+char byte;
+ssize_t len;
+GList *cur_req, *next_req;
+
+do {
+len = read(p-rfd, byte, sizeof(byte));
+} while (len == -1  errno == EINTR);
+
+for (cur_req = p-requests; cur_req != NULL; cur_req = next_req) {
+V9fsRequest *req = cur_req-data;
+next_req = g_list_next(cur_req);
+
+if (!req-done) {
+continue;
+}
+
+Coroutine *entry = req-coroutine;
+qemu_coroutine_enter(entry, NULL);
+
+p-requests = g_list_delete_link(p-requests, cur_req);
+}
+}
+
+void v9fs_thread_routine(gpointer data, gpointer user_data)
+{
+V9fsRequest *req = data;
+char byte = 0;
+ssize_t len;
+req-func(req);
+req-done = 1;
+do {
+len = write(v9fs_pool.wfd, byte, sizeof(byte));
+} while (len == -1  errno == EINTR);
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
new file mode 100644
index 000..fdc44f6
--- /dev/null
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -0,0 +1,45 @@
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Harsh Prateek Bora ha...@linux.vnet.ibm.com
+ *  Venkateswararao Jujjuri(JV) jv...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef _QEMU_VIRTIO_9P_COTH_H
+#define _QEMU_VIRTIO_9P_COTH_H
+
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include glib.h
+
+typedef struct V9fsRequest {
+void (*func)(struct V9fsRequest *req);
+
+/* Flag to indicate that request is satisfied, ready for post-processing */
+int done;
+Coroutine *coroutine;
+} V9fsRequest;
+
+typedef struct V9fsThPool {
+GThreadPool *pool;
+GList *requests;
+int rfd;
+int wfd;
+} V9fsThPool;
+
+/* v9fs glib thread pool */
+extern V9fsThPool v9fs_pool;
+
+extern void v9fs_thread_routine(gpointer data, gpointer user_data);
+extern void v9fs_qemu_process_req_done(void *arg);
+extern void v9fs_qemu_submit_request(V9fsRequest *req);
+
+
+#endif
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index a2b6acc..21fb310 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -18,6 +18,9 @@
 #include virtio-9p.h
 #include fsdev/qemu-fsdev.h
 #include virtio-9p-xattr.h
+#include virtio-9p-coth.h
+
+static int notifier_fds[2];
 
 static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
 {
@@ -49,14 +52,13 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
 int i, len;
 struct stat stat;
 FsTypeEntry *fse;
-
+V9fsThPool *p = v9fs_pool;
 
 s = (V9fsState

[Qemu-devel] [PATCH 18/25] hw/9pfs: Update v9fs_xattrwalk to coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  198 ---
 1 files changed, 63 insertions(+), 135 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 8723039..b50ac3c 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -240,21 +240,6 @@ static int v9fs_do_statfs(V9fsState *s, V9fsString *path, 
struct statfs *stbuf)
 return s-ops-statfs(s-ctx, path-data, stbuf);
 }
 
-static ssize_t v9fs_do_lgetxattr(V9fsState *s, V9fsString *path,
- V9fsString *xattr_name,
- void *value, size_t size)
-{
-return s-ops-lgetxattr(s-ctx, path-data,
- xattr_name-data, value, size);
-}
-
-static ssize_t v9fs_do_llistxattr(V9fsState *s, V9fsString *path,
-  void *value, size_t size)
-{
-return s-ops-llistxattr(s-ctx, path-data,
-  value, size);
-}
-
 static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path,
  V9fsString *xattr_name,
  void *value, size_t size, int flags)
@@ -3289,150 +3274,93 @@ out:
 qemu_free(copdu);
 }
 
-static void v9fs_post_xattr_getvalue(V9fsState *s, V9fsXattrState *vs, int err)
-{
-
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, q, vs-size);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_post_xattr_check(V9fsState *s, V9fsXattrState *vs, ssize_t 
err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-/*
- * Read the xattr value
- */
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = -1;
-if (vs-size) {
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-err = v9fs_do_lgetxattr(s, vs-xattr_fidp-path,
-vs-name, vs-xattr_fidp-fs.xattr.value,
-vs-xattr_fidp-fs.xattr.len);
-}
-v9fs_post_xattr_getvalue(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
-static void v9fs_post_lxattr_getvalue(V9fsState *s,
-  V9fsXattrState *vs, int err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-vs-offset += pdu_marshal(vs-pdu, vs-offset, q, vs-size);
-err = vs-offset;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_post_lxattr_check(V9fsState *s,
-   V9fsXattrState *vs, ssize_t err)
-{
-if (err  0) {
-err = -errno;
-free_fid(s, vs-xattr_fidp-fid);
-goto out;
-}
-/*
- * Read the xattr value
- */
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = -1;
-if (vs-size) {
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-err = v9fs_do_llistxattr(s, vs-xattr_fidp-path,
- vs-xattr_fidp-fs.xattr.value,
- vs-xattr_fidp-fs.xattr.len);
-}
-v9fs_post_lxattr_getvalue(s, vs, err);
-return;
-out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
-}
-
 static void v9fs_xattrwalk(void *opaque)
 {
+int64_t size;
+V9fsString name;
+ssize_t err = 0;
+size_t offset = 7;
+int32_t fid, newfid;
+V9fsFidState *file_fidp;
+V9fsFidState *xattr_fidp;
 V9fsCoPdu *copdu = opaque;
 V9fsState *s = copdu-s;
 V9fsPDU *pdu = copdu-pdu;
-ssize_t err = 0;
-V9fsXattrState *vs;
-int32_t fid, newfid;
 
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
-
-pdu_unmarshal(vs-pdu, vs-offset, dds, fid, newfid, vs-name);
-vs-file_fidp = lookup_fid(s, fid);
-if (vs-file_fidp == NULL) {
+pdu_unmarshal(pdu, offset, dds, fid, newfid, name);
+file_fidp = lookup_fid(s, fid);
+if (file_fidp == NULL) {
 err = -ENOENT;
 goto out;
 }
-
-vs-xattr_fidp = alloc_fid(s, newfid);
-if (vs-xattr_fidp == NULL) {
+xattr_fidp = alloc_fid(s, newfid);
+if (xattr_fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-
-v9fs_string_copy(vs-xattr_fidp-path, vs-file_fidp-path);
-if (vs-name.data[0] == 0) {
+v9fs_string_copy(xattr_fidp-path, file_fidp-path);
+if (name.data[0] == 0

[Qemu-devel] [PATCH 10/25] hw/9pfs: Update v9fs_readdir to use coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |  170 +--
 1 files changed, 69 insertions(+), 101 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 883eced..148382d 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -112,11 +112,6 @@ static off_t v9fs_do_telldir(V9fsState *s, DIR *dir)
 return s-ops-telldir(s-ctx, dir);
 }
 
-static struct dirent *v9fs_do_readdir(V9fsState *s, DIR *dir)
-{
-return s-ops-readdir(s-ctx, dir);
-}
-
 static void v9fs_do_seekdir(V9fsState *s, DIR *dir, off_t off)
 {
 return s-ops-seekdir(s-ctx, dir, off);
@@ -1988,7 +1983,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, 
V9fsReadState *vs,
 v9fs_stat_free(vs-v9stat);
 v9fs_string_free(vs-name);
 vs-dir_pos = vs-dent-d_off;
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
+v9fs_co_readdir(s, vs-fidp, vs-dent);
 v9fs_read_post_readdir(s, vs, err);
 return;
 out:
@@ -2020,7 +2015,7 @@ static void v9fs_read_post_readdir(V9fsState *s, 
V9fsReadState *vs, ssize_t err)
 
 static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t 
err)
 {
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
+v9fs_co_readdir(s, vs-fidp, vs-dent);
 v9fs_read_post_readdir(s, vs, err);
 return;
 }
@@ -2151,127 +2146,100 @@ out:
 qemu_free(copdu);
 }
 
-typedef struct V9fsReadDirState {
-V9fsPDU *pdu;
-V9fsFidState *fidp;
-V9fsQID qid;
-off_t saved_dir_pos;
-struct dirent *dent;
-int32_t count;
-int32_t max_count;
-size_t offset;
-int64_t initial_offset;
-V9fsString name;
-} V9fsReadDirState;
-
-static void v9fs_readdir_post_seekdir(V9fsState *s, V9fsReadDirState *vs)
-{
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count;
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
-return;
-}
-
-/* Size of each dirent on the wire: size of qid (13) + size of offset (8)
+/*
+ * Size of each dirent on the wire: size of qid (13) + size of offset (8)
  * size of type (1) + size of name.size (2) + strlen(name.data)
  */
-#define V9_READDIR_DATA_SZ (24 + strlen(vs-name.data))
+#define V9_READDIR_DATA_SZ (24 + strlen(name.data))
 
-static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs)
+static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu,
+   V9fsFidState *fidp, int32_t max_count)
 {
-int len;
 size_t size;
+V9fsQID qid;
+V9fsString name;
+int len, err = 0;
+int32_t count = 0;
+off_t saved_dir_pos;
+struct dirent *dent;
 
-if (vs-dent) {
-v9fs_string_init(vs-name);
-v9fs_string_sprintf(vs-name, %s, vs-dent-d_name);
-
-if ((vs-count + V9_READDIR_DATA_SZ)  vs-max_count) {
+/* save the directory position */
+saved_dir_pos = v9fs_co_telldir(s, fidp);
+if (saved_dir_pos  0) {
+return saved_dir_pos;
+}
+while (1) {
+err = v9fs_co_readdir(s, fidp, dent);
+if (err || !dent) {
+break;
+}
+v9fs_string_init(name);
+v9fs_string_sprintf(name, %s, dent-d_name);
+if ((count + V9_READDIR_DATA_SZ)  max_count) {
 /* Ran out of buffer. Set dir back to old position and return */
-v9fs_do_seekdir(s, vs-fidp-fs.dir, vs-saved_dir_pos);
-v9fs_readdir_post_seekdir(s, vs);
-return;
+v9fs_co_seekdir(s, fidp, saved_dir_pos);
+v9fs_string_free(name);
+return count;
 }
-
-/* Fill up just the path field of qid because the client uses
+/*
+ * Fill up just the path field of qid because the client uses
  * only that. To fill the entire qid structure we will have
  * to stat each dirent found, which is expensive
  */
-size = MIN(sizeof(vs-dent-d_ino), sizeof(vs-qid.path));
-memcpy(vs-qid.path, vs-dent-d_ino, size);
+size = MIN(sizeof(dent-d_ino), sizeof(qid.path));
+memcpy(qid.path, dent-d_ino, size);
 /* Fill the other fields with dummy values */
-vs-qid.type = 0;
-vs-qid.version = 0;
-
-len = pdu_marshal(vs-pdu, vs-offset+4+vs-count, Qqbs,
-  vs-qid, vs-dent-d_off,
-  vs-dent-d_type, vs-name);
-vs-count += len;
-v9fs_string_free(vs-name);
-vs-saved_dir_pos = vs-dent-d_off;
-vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
-v9fs_readdir_post_readdir(s, vs);
-return;
-}
-
-vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count);
-vs-offset += vs-count;
-complete_pdu(s, vs-pdu, vs-offset);
-qemu_free(vs);
-return;
-}
-
-static void v9fs_readdir_post_telldir(V9fsState *s, V9fsReadDirState

[Qemu-devel] [PATCH 20/25] hw/9pfs: Add yield support to mknod coroutine

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   45 +
 hw/9pfs/virtio-9p-coth.h |2 ++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 02eb0ba..06127f7 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -224,3 +224,48 @@ int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t 
size)
 qemu_coroutine_yield();
 return vs.err;
 }
+
+typedef struct V9fsThMknodState {
+int err;
+uid_t uid;
+gid_t gid;
+mode_t mode;
+dev_t dev;
+V9fsState *s;
+V9fsString *path;
+struct stat *stbuf;
+V9fsRequest request;
+} V9fsThMknodState;
+
+static void v9fs_th_do_mknod(V9fsRequest *request)
+{
+FsCred cred;
+V9fsThMknodState *vsp = container_of(request, V9fsThMknodState,
+ request);
+cred_init(cred);
+cred.fc_uid  = vsp-uid;
+cred.fc_gid  = vsp-gid;
+cred.fc_mode = vsp-mode;
+cred.fc_rdev = vsp-dev;
+vsp-err = vsp-s-ops-mknod(vsp-s-ctx, vsp-path-data, cred);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t uid,
+  gid_t gid, dev_t dev, mode_t mode)
+{
+V9fsThMknodState vs;
+vs.s = s;
+vs.path = path;
+vs.uid  = uid;
+vs.gid  = gid;
+vs.dev  = dev;
+vs.mode = mode;
+vs.request.func = v9fs_th_do_mknod;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index c8d37dd..bd410cb 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -64,4 +64,6 @@ extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
 extern int v9fs_co_llistxattr(V9fsState *, V9fsString *, void *, size_t);
 extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
  V9fsString *, void *, size_t);
+extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
+ gid_t, dev_t, mode_t);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 22/25] [virtio-9p] coroutine and threading for mkdir

2011-05-12 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/codir.c  |   34 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   28 ++--
 3 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index adca50c..fcd204d 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -133,3 +133,37 @@ void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
 qemu_coroutine_yield();
 return;
 }
+
+typedef struct V9fsThMkDirState {
+V9fsState *s;
+FsCred cred;
+char *name;
+int err;
+V9fsRequest request;
+} V9fsThMkDirState;
+
+static void v9fs_th_do_mkdir(V9fsRequest *request)
+{
+V9fsThMkDirState *vsp = container_of(request, V9fsThMkDirState, request);
+
+vsp-err = vsp-s-ops-mkdir(vsp-s-ctx, vsp-name, vsp-cred);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_mkdir(V9fsState *s, char *name, mode_t mode, uid_t uid, gid_t gid)
+{
+V9fsThMkDirState vs;
+vs.s = s;
+vs.name = name;
+cred_init(vs.cred);
+vs.cred.fc_mode = mode;
+vs.cred.fc_uid = uid;
+vs.cred.fc_gid = gid;
+vs.request.func = v9fs_th_do_mkdir;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index bd410cb..3edab4e 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -66,4 +66,5 @@ extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
  V9fsString *, void *, size_t);
 extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
  gid_t, dev_t, mode_t);
+extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 4858f37..e5112fe 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -149,19 +149,6 @@ static int v9fs_do_mknod(V9fsState *s, char *name,
 return s-ops-mknod(s-ctx, name, cred);
 }
 
-static int v9fs_do_mkdir(V9fsState *s, char *name, mode_t mode,
-uid_t uid, gid_t gid)
-{
-FsCred cred;
-
-cred_init(cred);
-cred.fc_uid = uid;
-cred.fc_gid = gid;
-cred.fc_mode = mode;
-
-return s-ops-mkdir(s-ctx, name, cred);
-}
-
 static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf)
 {
 return s-ops-fstat(s-ctx, fd, stbuf);
@@ -2354,8 +2341,7 @@ out:
 
 static void v9fs_create_post_mkdir(V9fsState *s, V9fsCreateState *vs, int err)
 {
-if (err) {
-err = -errno;
+if (err  0) {
 goto out;
 }
 
@@ -2404,7 +2390,7 @@ static void v9fs_create_post_lstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 }
 
 if (vs-perm  P9_STAT_MODE_DIR) {
-err = v9fs_do_mkdir(s, vs-fullname.data, vs-perm  0777,
+err = v9fs_co_mkdir(s, vs-fullname.data, vs-perm  0777,
 vs-fidp-uid, -1);
 v9fs_create_post_mkdir(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_SYMLINK) {
@@ -3225,14 +3211,12 @@ static void v9fs_mkdir(void *opaque)
 goto out;
 }
 v9fs_string_sprintf(fullname, %s/%s, fidp-path.data, name.data);
-err = v9fs_do_mkdir(copdu-s, fullname.data, mode, fidp-uid, gid);
-if (err == -1) {
-err = -errno;
+err = v9fs_co_mkdir(copdu-s, fullname.data, mode, fidp-uid, gid);
+if (err  0) {
 goto out;
 }
-err = v9fs_do_lstat(copdu-s, fullname, stbuf);
-if (err == -1) {
-err = -errno;
+err = v9fs_co_lstat(copdu-s, fullname, stbuf);
+if (err  0) {
 goto out;
 }
 stat_to_qid(stbuf, qid);
-- 
1.7.1




[Qemu-devel] [PATCH 13/25] hw/9pfs: Add yield support to lstat coroutine

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/cofile.c |   50 ++
 hw/9pfs/virtio-9p-coth.h |1 +
 3 files changed, 52 insertions(+), 1 deletions(-)
 create mode 100644 hw/9pfs/cofile.c

diff --git a/Makefile.objs b/Makefile.objs
index 614bcaf..83d30bd 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
new file mode 100644
index 000..860b060
--- /dev/null
+++ b/hw/9pfs/cofile.c
@@ -0,0 +1,50 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+
+typedef struct V9fsThLstatState {
+int err;
+V9fsState *s;
+V9fsString *path;
+struct stat *stbuf;
+V9fsRequest request;
+} V9fsThLstatState;
+
+static void v9fs_th_do_lstat(V9fsRequest *request)
+{
+V9fsThLstatState *vsp = container_of(request, V9fsThLstatState,
+ request);
+vsp-err = vsp-s-ops-lstat(vsp-s-ctx, vsp-path-data, vsp-stbuf);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
+{
+V9fsThLstatState vs;
+vs.s = s;
+vs.path = path;
+vs.stbuf = stbuf;
+vs.request.func = v9fs_th_do_lstat;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 57f30ff..aedeba9 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -56,4 +56,5 @@ extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
 extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
+extern int v9fs_co_lstat(V9fsState *, V9fsString *, struct stat *);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 09/25] hw/9pfs: Add yield support for readdir related coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include readdir, telldir, seekdir, rewinddir.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 hw/9pfs/codir.c  |  135 ++
 hw/9pfs/virtio-9p-coth.h |5 ++
 3 files changed, 141 insertions(+), 1 deletions(-)
 create mode 100644 hw/9pfs/codir.c

diff --git a/Makefile.objs b/Makefile.objs
index 36005bb..614bcaf 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -297,7 +297,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
-9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o
+9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o
 
 hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
new file mode 100644
index 000..adca50c
--- /dev/null
+++ b/hw/9pfs/codir.c
@@ -0,0 +1,135 @@
+
+/*
+ * Virtio 9p backend
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include fsdev/qemu-fsdev.h
+#include qemu-thread.h
+#include qemu-coroutine.h
+#include virtio-9p-coth.h
+
+typedef struct V9fsThReaddirState {
+int err;
+V9fsState *s;
+V9fsFidState *fidp;
+struct dirent *dent;
+V9fsRequest request;
+} V9fsThReaddirState;
+
+static void v9fs_th_do_readdir(V9fsRequest *request)
+{
+V9fsThReaddirState *vsp = container_of(request, V9fsThReaddirState,
+   request);
+errno = 0;
+vsp-dent = vsp-s-ops-readdir(vsp-s-ctx, vsp-fidp-fs.dir);
+if (!vsp-dent  errno) {
+vsp-err = -errno;
+} else {
+vsp-err = 0;
+}
+}
+
+int v9fs_co_readdir(V9fsState *s, V9fsFidState *fidp, struct dirent **dent)
+{
+V9fsThReaddirState vs;
+vs.s = s;
+vs.fidp = fidp;
+vs.request.func = v9fs_th_do_readdir;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+*dent = vs.dent;
+return vs.err;
+}
+
+typedef struct V9fsThTelldirState {
+off_t err;
+V9fsState *s;
+V9fsFidState *fidp;
+V9fsRequest request;
+} V9fsThTelldirState;
+
+
+static void v9fs_th_do_telldir(V9fsRequest *request)
+{
+V9fsThTelldirState *vsp = container_of(request, V9fsThTelldirState,
+   request);
+errno = 0;
+vsp-err = vsp-s-ops-telldir(vsp-s-ctx, vsp-fidp-fs.dir);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+off_t v9fs_co_telldir(V9fsState *s, V9fsFidState *fidp)
+{
+V9fsThTelldirState vs;
+vs.s = s;
+vs.fidp = fidp;
+vs.request.func = v9fs_th_do_telldir;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
+
+typedef struct V9fsThSeekdirState {
+off_t offset;
+V9fsState *s;
+V9fsFidState *fidp;
+V9fsRequest request;
+} V9fsThSeekdirState;
+
+static void v9fs_th_do_seekdir(V9fsRequest *request)
+{
+V9fsThSeekdirState *vsp = container_of(request, V9fsThSeekdirState,
+   request);
+vsp-s-ops-seekdir(vsp-s-ctx, vsp-fidp-fs.dir, vsp-offset);
+}
+
+void v9fs_co_seekdir(V9fsState *s, V9fsFidState *fidp, off_t offset)
+{
+V9fsThSeekdirState vs;
+vs.s = s;
+vs.fidp = fidp;
+vs.offset = offset;
+vs.request.func = v9fs_th_do_seekdir;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return;
+}
+
+typedef struct V9fsThRewindirState {
+V9fsState *s;
+V9fsFidState *fidp;
+V9fsRequest request;
+} V9fsThRewinddirState;
+
+static void v9fs_th_do_rewinddir(V9fsRequest *request)
+{
+V9fsThRewinddirState *vsp = container_of(request, V9fsThRewinddirState,
+ request);
+vsp-s-ops-rewinddir(vsp-s-ctx, vsp-fidp-fs.dir);
+}
+
+void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
+{
+V9fsThSeekdirState vs;
+vs.s = s;
+vs.fidp = fidp;
+vs.request.func = v9fs_th_do_rewinddir;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index d0b856e..4d34098 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -50,4 +50,9 @@ extern void v9fs_qemu_submit_request

[Qemu-devel] [PATCH 15/25] hw/9pfs: Add yield support to setattr related coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

This include chmod, utimensat, chown and truncate.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |  135 ++
 hw/9pfs/virtio-9p-coth.h |4 ++
 2 files changed, 139 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 27e243e..02eb0ba 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -89,3 +89,138 @@ int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct 
statfs *stbuf)
 qemu_coroutine_yield();
 return vs.err;
 }
+
+typedef struct V9fsThChmodState {
+int err;
+mode_t mode;
+V9fsState *s;
+V9fsString *path;
+V9fsRequest request;
+} V9fsThChmodState;
+
+static void v9fs_th_do_chmod(V9fsRequest *request)
+{
+FsCred cred;
+V9fsThChmodState *vsp = container_of(request, V9fsThChmodState,
+ request);
+cred_init(cred);
+cred.fc_mode = vsp-mode;
+vsp-err = vsp-s-ops-chmod(vsp-s-ctx, vsp-path-data, cred);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_chmod(V9fsState *s, V9fsString *path, mode_t mode)
+{
+V9fsThChmodState vs;
+vs.s = s;
+vs.path = path;
+vs.mode = mode;
+vs.request.func = v9fs_th_do_chmod;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
+
+typedef struct V9fsThUtimeState {
+int err;
+V9fsState *s;
+V9fsString *path;
+struct timespec *times;
+V9fsRequest request;
+} V9fsThUtimeState;
+
+static void v9fs_th_do_utimensat(V9fsRequest *request)
+{
+V9fsThUtimeState *vsp = container_of(request, V9fsThUtimeState,
+ request);
+vsp-err = vsp-s-ops-utimensat(vsp-s-ctx,
+  vsp-path-data, vsp-times);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_utimensat(V9fsState *s, V9fsString *path,
+  struct timespec times[2])
+{
+V9fsThUtimeState vs;
+vs.s = s;
+vs.path = path;
+vs.times = times;
+vs.request.func = v9fs_th_do_utimensat;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
+
+typedef struct V9fsThChownState {
+int err;
+uid_t uid;
+gid_t gid;
+V9fsState *s;
+V9fsString *path;
+V9fsRequest request;
+} V9fsThChownState;
+
+static void v9fs_th_do_chown(V9fsRequest *request)
+{
+FsCred cred;
+V9fsThChownState *vsp = container_of(request, V9fsThChownState,
+ request);
+cred_init(cred);
+cred.fc_uid = vsp-uid;
+cred.fc_gid = vsp-gid;
+vsp-err = vsp-s-ops-chown(vsp-s-ctx, vsp-path-data, cred);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
+{
+V9fsThChownState vs;
+vs.s = s;
+vs.path = path;
+vs.uid  = uid;
+vs.gid  = gid;
+vs.request.func = v9fs_th_do_chown;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
+
+typedef struct V9fsThTruncateState {
+int err;
+off_t size;
+V9fsState *s;
+V9fsString *path;
+V9fsRequest request;
+} V9fsThTruncateState;
+
+static void v9fs_th_do_truncate(V9fsRequest *request)
+{
+V9fsThTruncateState *vsp = container_of(request, V9fsThTruncateState,
+request);
+vsp-err = vsp-s-ops-truncate(vsp-s-ctx, vsp-path-data, vsp-size);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_truncate(V9fsState *s, V9fsString *path, off_t size)
+{
+V9fsThTruncateState vs;
+vs.s = s;
+vs.path = path;
+vs.size = size;
+vs.request.func = v9fs_th_do_truncate;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index aedeba9..4e2bc23 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -57,4 +57,8 @@ extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, 
off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
 extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
 extern int v9fs_co_lstat(V9fsState *, V9fsString *, struct stat *);
+extern int v9fs_co_chmod(V9fsState *, V9fsString *, mode_t);
+extern int v9fs_co_utimensat(V9fsState *, V9fsString *, struct timespec [2]);
+extern int v9fs_co_chown(V9fsState *, V9fsString *, uid_t, gid_t);
+extern int v9fs_co_truncate(V9fsState *, V9fsString *, off_t);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 11/25] hw/9pfs: Add yield support to statfs coroutine

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   31 +++
 hw/9pfs/virtio-9p-coth.h |1 +
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index b972561..27e243e 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -58,3 +58,34 @@ int v9fs_co_readlink(V9fsState *s, V9fsString *path, 
V9fsString *buf,
 buf-data = vs.buf-data;
 return vs.err;
 }
+
+typedef struct V9fsThStatfsState {
+int err;
+V9fsState *s;
+V9fsString *path;
+struct statfs *stbuf;
+V9fsRequest request;
+} V9fsThStatfsState;
+
+static void v9fs_th_do_statfs(V9fsRequest *request)
+{
+V9fsThStatfsState *vsp = container_of(request, V9fsThStatfsState,
+  request);
+vsp-err = vsp-s-ops-statfs(vsp-s-ctx, vsp-path-data, vsp-stbuf);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf)
+{
+V9fsThStatfsState vs;
+vs.s = s;
+vs.path = path;
+vs.stbuf = stbuf;
+vs.request.func = v9fs_th_do_statfs;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 4d34098..57f30ff 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -55,4 +55,5 @@ extern int v9fs_co_readdir(V9fsState *, V9fsFidState *,
 extern off_t v9fs_co_telldir(V9fsState *, V9fsFidState *);
 extern void v9fs_co_seekdir(V9fsState *, V9fsFidState *, off_t);
 extern void v9fs_co_rewinddir(V9fsState *, V9fsFidState *);
+extern int v9fs_co_statfs(V9fsState *, V9fsString *, struct statfs *);
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 25/25] [virtio-9p] coroutine and threading for remove/unlink

2011-05-12 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/cofs.c   |   28 
 hw/9pfs/virtio-9p-coth.h |1 +
 hw/9pfs/virtio-9p.c  |   11 ++-
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c
index 06127f7..68cd3ab 100644
--- a/hw/9pfs/cofs.c
+++ b/hw/9pfs/cofs.c
@@ -269,3 +269,31 @@ int v9fs_co_mknod(V9fsState *s, V9fsString *path, uid_t 
uid,
 qemu_coroutine_yield();
 return vs.err;
 }
+
+typedef struct V9fsThRemoveState {
+V9fsState *s;
+V9fsString *path;
+int err;
+V9fsRequest request;
+} V9fsThRemoveState;
+
+static void v9fs_th_do_remove(V9fsRequest *request)
+{
+V9fsThRemoveState *vsp = container_of(request, V9fsThRemoveState, request);
+vsp-err = vsp-s-ops-remove(vsp-s-ctx, vsp-path-data);
+if (vsp-err  0) {
+vsp-err = -errno;
+}
+}
+
+int v9fs_co_remove(V9fsState *s, V9fsString *path)
+{
+V9fsThRemoveState vs;
+vs.s = s;
+vs.path = path;
+vs.request.func = v9fs_th_do_remove;
+vs.request.coroutine = qemu_coroutine_self();
+v9fs_qemu_submit_request(vs.request);
+qemu_coroutine_yield();
+return vs.err;
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 3edab4e..b6428ec 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -67,4 +67,5 @@ extern int v9fs_co_lgetxattr(V9fsState *, V9fsString *,
 extern int v9fs_co_mknod(V9fsState *, V9fsString *, uid_t,
  gid_t, dev_t, mode_t);
 extern int v9fs_co_mkdir(V9fsState *, char *, mode_t, uid_t, gid_t);
+extern int v9fs_co_remove(V9fsState *, V9fsString *);
 #endif
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 114162c..479ad78 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -212,11 +212,6 @@ static int v9fs_do_utimensat(V9fsState *s, V9fsString 
*path,
 return s-ops-utimensat(s-ctx, path-data, times);
 }
 
-static int v9fs_do_remove(V9fsState *s, V9fsString *path)
-{
-return s-ops-remove(s-ctx, path-data);
-}
-
 static int v9fs_do_fsync(V9fsState *s, int fd, int datasync)
 {
 return s-ops-fsync(s-ctx, fd, datasync);
@@ -2627,10 +2622,8 @@ static void v9fs_remove(void *opaque)
 err = -EINVAL;
 goto out;
 }
-err = v9fs_do_remove(copdu-s, fidp-path);
-if (err  0) {
-err = -errno;
-} else {
+err = v9fs_co_remove(copdu-s, fidp-path);
+if (!err) {
 err = offset;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 19/25] hw/9pfs: Update v9fs_xattrcreate to use coroutines

2011-05-12 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   55 +--
 hw/9pfs/virtio-9p.h |   11 --
 2 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index b50ac3c..764348d 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -3366,44 +3366,43 @@ out:
 
 static void v9fs_xattrcreate(void *opaque)
 {
-V9fsCoPdu *copdu = opaque;
-V9fsState *s = copdu-s;
-V9fsPDU *pdu = copdu-pdu;
 int flags;
 int32_t fid;
+int64_t size;
 ssize_t err = 0;
-V9fsXattrState *vs;
-
-vs = qemu_malloc(sizeof(*vs));
-vs-pdu = pdu;
-vs-offset = 7;
+V9fsString name;
+size_t offset = 7;
+V9fsFidState *file_fidp;
+V9fsFidState *xattr_fidp;
+V9fsCoPdu *copdu = opaque;
+V9fsState *s = copdu-s;
+V9fsPDU *pdu = copdu-pdu;
 
-pdu_unmarshal(vs-pdu, vs-offset, dsqd,
-  fid, vs-name, vs-size, flags);
+pdu_unmarshal(pdu, offset, dsqd,
+  fid, name, size, flags);
 
-vs-file_fidp = lookup_fid(s, fid);
-if (vs-file_fidp == NULL) {
+file_fidp = lookup_fid(s, fid);
+if (file_fidp == NULL) {
 err = -EINVAL;
 goto out;
 }
-
 /* Make the file fid point to xattr */
-vs-xattr_fidp = vs-file_fidp;
-vs-xattr_fidp-fid_type = P9_FID_XATTR;
-vs-xattr_fidp-fs.xattr.copied_len = 0;
-vs-xattr_fidp-fs.xattr.len = vs-size;
-vs-xattr_fidp-fs.xattr.flags = flags;
-v9fs_string_init(vs-xattr_fidp-fs.xattr.name);
-v9fs_string_copy(vs-xattr_fidp-fs.xattr.name, vs-name);
-if (vs-size)
-vs-xattr_fidp-fs.xattr.value = qemu_malloc(vs-size);
-else
-vs-xattr_fidp-fs.xattr.value = NULL;
-
+xattr_fidp = file_fidp;
+xattr_fidp-fid_type = P9_FID_XATTR;
+xattr_fidp-fs.xattr.copied_len = 0;
+xattr_fidp-fs.xattr.len = size;
+xattr_fidp-fs.xattr.flags = flags;
+v9fs_string_init(xattr_fidp-fs.xattr.name);
+v9fs_string_copy(xattr_fidp-fs.xattr.name, name);
+if (size) {
+xattr_fidp-fs.xattr.value = qemu_malloc(size);
+} else {
+xattr_fidp-fs.xattr.value = NULL;
+}
+err = offset;
 out:
-complete_pdu(s, vs-pdu, err);
-v9fs_string_free(vs-name);
-qemu_free(vs);
+complete_pdu(s, pdu, err);
+v9fs_string_free(name);
 qemu_free(copdu);
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index dd4bcc8..596d35b 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -397,17 +397,6 @@ typedef struct V9fsRenameState {
 V9fsString name;
 } V9fsRenameState;
 
-typedef struct V9fsXattrState
-{
-V9fsPDU *pdu;
-size_t offset;
-V9fsFidState *file_fidp;
-V9fsFidState *xattr_fidp;
-V9fsString name;
-int64_t size;
-int flags;
-void *value;
-} V9fsXattrState;
 
 #define P9_LOCK_SUCCESS 0
 #define P9_LOCK_BLOCKED 1
-- 
1.7.1




  1   2   3   4   >