All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Venkateswararao Jujjuri (JV)" <jvrao@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>,
	"Venkateswararao Jujjuri \"" <jvrao@linux.vnet.ibm.com>,
	stefanha@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 29/29] use readdir_r instead of readdir for reentrancy
Date: Wed, 25 May 2011 16:53:17 -0700	[thread overview]
Message-ID: <1306367597-797-30-git-send-email-jvrao@linux.vnet.ibm.com> (raw)
In-Reply-To: <1306367597-797-1-git-send-email-jvrao@linux.vnet.ibm.com>

From: Harsh Prateek Bora <harsh@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 <harsh@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri "<jvrao@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 v9fs_do_readdir_with_stat(V9fsState *s, V9fsPDU *pdu,
         saved_dir_pos = dent->d_off;
     }
 out:
+    qemu_free(dent);
     v9fs_string_free(&name);
     if (err < 0) {
         return err;
@@ -1630,16 +1635,19 @@ static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu,
     int len, err = 0;
     int32_t count = 0;
     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) {
-        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_init(&name);
@@ -1648,6 +1656,7 @@ static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu,
             /* Ran out of buffer. Set dir back to old position and return */
             v9fs_co_seekdir(s, fidp, saved_dir_pos);
             v9fs_string_free(&name);
+            qemu_free(dent);
             return count;
         }
         /*
@@ -1669,6 +1678,7 @@ static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu,
         v9fs_string_free(&name);
         saved_dir_pos = dent->d_off;
     }
+    qemu_free(dent);
     if (err < 0) {
         return err;
     }
-- 
1.7.1

      parent reply	other threads:[~2011-05-25 23:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-25 23:52 [Qemu-devel] [0/29] Second batch of VirtFS routines converted to coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 01/29] hw/9pfs: Add yeild support to rename coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 02/29] hw/9pfs: Update vfs_rename to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 03/29] hw/9pfs: Add yeild support for fstat coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 04/29] hw/9pfs: Update v9fs_lock to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 05/29] hw/9pfs: Update v9fs_getlock " Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 06/29] hw/9pfs: Add yield support for open and opendir coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 07/29] hw/9pfs: Update v9fs_open to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 08/29] [virtio-9p] Remove post functions for v9fs_lcreate Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 09/29] [virtio-9p] clean up v9fs_lcreate Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 10/29] [PATCH] [virtio-9p] coroutine and threading for open2 Venkateswararao Jujjuri (JV)
2011-05-25 23:52 ` [Qemu-devel] [PATCH 11/29] hw/9pfs: Update v9fs_stat to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 12/29] hw/9pfs: Update v9fs_walk " Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 13/29] hw/9pfs: Add yeild support for clunk related coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 14/29] hw/9pfs: Update v9fs_clunk to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 15/29] hw/9pfs: Add yield support for fsync coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 16/29] hw/9pfs: Update v9fs_fsync to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 17/29] [virtio-9p] Remove post functions for v9fs_create Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 18/29] [virtio-9p] clean up v9fs_create Rearrange the code Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 19/29] [virtio-9p] Remove post functions for v9fs_symlink Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 20/29] [virtio-9p] clean up v9fs_symlink Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 21/29] [virtio-9p] coroutine and threading for v9fs_do_symlink Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 22/29] [virtio-9p] coroutine and threading for v9fs_do_link Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 23/29] hw/9pfs: Add yield support for pwritev coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 24/29] hw/9pfs: Update v9fs_write to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 25/29] hw/9pfs: Update v9fs_wstat " Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 26/29] hw/9pfs: Update v9fs_attach " Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 27/29] hw/9pfs: Add yield support for preadv coroutine Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` [Qemu-devel] [PATCH 28/29] hw/9pfs: Update v9fs_read to use coroutines Venkateswararao Jujjuri (JV)
2011-05-25 23:53 ` Venkateswararao Jujjuri (JV) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1306367597-797-30-git-send-email-jvrao@linux.vnet.ibm.com \
    --to=jvrao@linux.vnet.ibm.com \
    --cc=harsh@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.