[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L

2010-06-04 Thread Sripathi Kodi
This patch implements the kernel part of readdir() implementation for 9p2000.L

Change from V3: Instead of inode, server now sends qids for each dirent

SYNOPSIS

size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]

DESCRIPTION

The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.

qid.type[1]
  the type of the file (directory, etc.), represented as a bit
  vector corresponding to the high 8 bits of the file's mode
  word.

qid.vers[4]
  version number for given path

qid.path[8]
  the file server's unique identification for the file

offset[8]
  offset into the next dirent.

type[1]
  type of this directory entry.

name[256]
  name of this directory entry.

This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L.
This function sends P9_TREADDIR command to the server. In response the 
server
sends a buffer filled with dirent structures. This is different from the
existing v9fs_dir_readdir() call which receives stat structures from the 
server.
This results in significant speedup of readdir() on large directories.
For example, doing 'ls /dev/null' on a directory with 1 files on my
laptop takes 1.088 seconds with the existing code, but only takes 0.339 
seconds
with the new readdir.

Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---

 fs/9p/vfs_dir.c |  134 +--
 include/net/9p/9p.h |   17 ++
 include/net/9p/client.h |   18 ++
 net/9p/client.c |   47 
 net/9p/protocol.c   |   27 +
 5 files changed, 227 insertions(+), 16 deletions(-)

diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index d61e3b2..aa1852d 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf)
 }
 
 /**
- * v9fs_dir_readdir - read a directory
+ * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
  * @filp: opened file structure
- * @dirent: directory structure ???
- * @filldir: function to populate directory structure ???
+ * @buflen: Length in bytes of buffer to allocate
  *
  */
 
-static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int v9fs_alloc_rdir_buf(struct file *filp, int buflen)
 {
-   int over;
-   struct p9_wstat st;
-   int err = 0;
-   struct p9_fid *fid;
-   int buflen;
-   int reclen = 0;
struct p9_rdir *rdir;
+   struct p9_fid *fid;
+   int err = 0;
 
-   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
fid = filp-private_data;
-
-   buflen = fid-clnt-msize - P9_IOHDRSZ;
-
-   /* allocate rdir on demand */
if (!fid-rdir) {
rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL);
 
@@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void 
*dirent, filldir_t filldir)
spin_unlock(filp-f_dentry-d_lock);
kfree(rdir);
}
+exit:
+   return err;
+}
+
+/**
+ * v9fs_dir_readdir - read a directory
+ * @filp: opened file structure
+ * @dirent: directory structure ???
+ * @filldir: function to populate directory structure ???
+ *
+ */
+
+static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+   int over;
+   struct p9_wstat st;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   int reclen = 0;
+   struct p9_rdir *rdir;
+
+   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
+   fid = filp-private_data;
+
+   buflen = fid-clnt-msize - P9_IOHDRSZ;
+
+   err = v9fs_alloc_rdir_buf(filp, buflen);
+   if (err)
+   goto exit;
rdir = (struct p9_rdir *) fid-rdir;
 
err = mutex_lock_interruptible(rdir-mutex);
@@ -176,6 +196,88 @@ exit:
return err;
 }
 
+/**
+ * v9fs_dir_readdir_dotl - read a directory
+ * @filp: opened file structure
+ * @dirent: buffer to fill dirent structures
+ * @filldir: function to populate dirent structures
+ *
+ */
+static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
+   filldir_t filldir)
+{
+   int over;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   struct p9_rdir *rdir;
+   struct p9_dirent curdirent;
+   u64 oldoffset = 0;
+
+   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
+   fid = filp-private_data;
+
+   buflen = 

[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L

2010-06-04 Thread Sripathi Kodi
This patch implements the kernel part of readdir() implementation for 9p2000.L

Change from V3: Instead of inode, server now sends qids for each dirent

SYNOPSIS

size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]

DESCRIPTION

The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.

qid.type[1]
  the type of the file (directory, etc.), represented as a bit
  vector corresponding to the high 8 bits of the file's mode
  word.

qid.vers[4]
  version number for given path

qid.path[8]
  the file server's unique identification for the file

offset[8]
  offset into the next dirent.

type[1]
  type of this directory entry.

name[256]
  name of this directory entry.

This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L.
This function sends P9_TREADDIR command to the server. In response the 
server
sends a buffer filled with dirent structures. This is different from the
existing v9fs_dir_readdir() call which receives stat structures from the 
server.
This results in significant speedup of readdir() on large directories.
For example, doing 'ls /dev/null' on a directory with 1 files on my
laptop takes 1.088 seconds with the existing code, but only takes 0.339 
seconds
with the new readdir.

Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---

 fs/9p/vfs_dir.c |  134 +--
 include/net/9p/9p.h |   17 ++
 include/net/9p/client.h |   18 ++
 net/9p/client.c |   47 
 net/9p/protocol.c   |   27 +
 5 files changed, 227 insertions(+), 16 deletions(-)

diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index d61e3b2..aa1852d 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf)
 }
 
 /**
- * v9fs_dir_readdir - read a directory
+ * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
  * @filp: opened file structure
- * @dirent: directory structure ???
- * @filldir: function to populate directory structure ???
+ * @buflen: Length in bytes of buffer to allocate
  *
  */
 
-static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int v9fs_alloc_rdir_buf(struct file *filp, int buflen)
 {
-   int over;
-   struct p9_wstat st;
-   int err = 0;
-   struct p9_fid *fid;
-   int buflen;
-   int reclen = 0;
struct p9_rdir *rdir;
+   struct p9_fid *fid;
+   int err = 0;
 
-   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
fid = filp-private_data;
-
-   buflen = fid-clnt-msize - P9_IOHDRSZ;
-
-   /* allocate rdir on demand */
if (!fid-rdir) {
rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL);
 
@@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void 
*dirent, filldir_t filldir)
spin_unlock(filp-f_dentry-d_lock);
kfree(rdir);
}
+exit:
+   return err;
+}
+
+/**
+ * v9fs_dir_readdir - read a directory
+ * @filp: opened file structure
+ * @dirent: directory structure ???
+ * @filldir: function to populate directory structure ???
+ *
+ */
+
+static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+   int over;
+   struct p9_wstat st;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   int reclen = 0;
+   struct p9_rdir *rdir;
+
+   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
+   fid = filp-private_data;
+
+   buflen = fid-clnt-msize - P9_IOHDRSZ;
+
+   err = v9fs_alloc_rdir_buf(filp, buflen);
+   if (err)
+   goto exit;
rdir = (struct p9_rdir *) fid-rdir;
 
err = mutex_lock_interruptible(rdir-mutex);
@@ -176,6 +196,88 @@ exit:
return err;
 }
 
+/**
+ * v9fs_dir_readdir_dotl - read a directory
+ * @filp: opened file structure
+ * @dirent: buffer to fill dirent structures
+ * @filldir: function to populate dirent structures
+ *
+ */
+static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
+   filldir_t filldir)
+{
+   int over;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   struct p9_rdir *rdir;
+   struct p9_dirent curdirent;
+   u64 oldoffset = 0;
+
+   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
+   fid = filp-private_data;
+
+   buflen = 

[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L

2010-06-04 Thread Sripathi Kodi
This patch implements the kernel part of readdir() implementation for 9p2000.L

Change from V3: Instead of inode, server now sends qids for each dirent

SYNOPSIS

size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]

DESCRIPTION

The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.

qid.type[1]
  the type of the file (directory, etc.), represented as a bit
  vector corresponding to the high 8 bits of the file's mode
  word.

qid.vers[4]
  version number for given path

qid.path[8]
  the file server's unique identification for the file

offset[8]
  offset into the next dirent.

type[1]
  type of this directory entry.

name[256]
  name of this directory entry.

This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L.
This function sends P9_TREADDIR command to the server. In response the 
server
sends a buffer filled with dirent structures. This is different from the
existing v9fs_dir_readdir() call which receives stat structures from the 
server.
This results in significant speedup of readdir() on large directories.
For example, doing 'ls /dev/null' on a directory with 1 files on my
laptop takes 1.088 seconds with the existing code, but only takes 0.339 
seconds
with the new readdir.

Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---

 fs/9p/vfs_dir.c |  134 +--
 include/net/9p/9p.h |   17 ++
 include/net/9p/client.h |   18 ++
 net/9p/client.c |   47 
 net/9p/protocol.c   |   27 +
 5 files changed, 227 insertions(+), 16 deletions(-)

diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index d61e3b2..aa1852d 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf)
 }
 
 /**
- * v9fs_dir_readdir - read a directory
+ * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
  * @filp: opened file structure
- * @dirent: directory structure ???
- * @filldir: function to populate directory structure ???
+ * @buflen: Length in bytes of buffer to allocate
  *
  */
 
-static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int v9fs_alloc_rdir_buf(struct file *filp, int buflen)
 {
-   int over;
-   struct p9_wstat st;
-   int err = 0;
-   struct p9_fid *fid;
-   int buflen;
-   int reclen = 0;
struct p9_rdir *rdir;
+   struct p9_fid *fid;
+   int err = 0;
 
-   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
fid = filp-private_data;
-
-   buflen = fid-clnt-msize - P9_IOHDRSZ;
-
-   /* allocate rdir on demand */
if (!fid-rdir) {
rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL);
 
@@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void 
*dirent, filldir_t filldir)
spin_unlock(filp-f_dentry-d_lock);
kfree(rdir);
}
+exit:
+   return err;
+}
+
+/**
+ * v9fs_dir_readdir - read a directory
+ * @filp: opened file structure
+ * @dirent: directory structure ???
+ * @filldir: function to populate directory structure ???
+ *
+ */
+
+static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+   int over;
+   struct p9_wstat st;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   int reclen = 0;
+   struct p9_rdir *rdir;
+
+   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
+   fid = filp-private_data;
+
+   buflen = fid-clnt-msize - P9_IOHDRSZ;
+
+   err = v9fs_alloc_rdir_buf(filp, buflen);
+   if (err)
+   goto exit;
rdir = (struct p9_rdir *) fid-rdir;
 
err = mutex_lock_interruptible(rdir-mutex);
@@ -176,6 +196,88 @@ exit:
return err;
 }
 
+/**
+ * v9fs_dir_readdir_dotl - read a directory
+ * @filp: opened file structure
+ * @dirent: buffer to fill dirent structures
+ * @filldir: function to populate dirent structures
+ *
+ */
+static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
+   filldir_t filldir)
+{
+   int over;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   struct p9_rdir *rdir;
+   struct p9_dirent curdirent;
+   u64 oldoffset = 0;
+
+   P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name);
+   fid = filp-private_data;
+
+   buflen =