- new functions au_dir_size() and au_rdhash_est().
- new macros AUFS_RDBLK_DEF and AUFS_RDHASH_DEF.

Signed-off-by: J. R. Okajima <[email protected]>
---
 fs/aufs/dir.c             |   50 +++++++++++++++++++++++++++++++++++++++++++++
 fs/aufs/dir.h             |    2 +
 fs/aufs/vdir.c            |   15 +++++++++++++
 include/linux/aufs_type.h |    2 +
 priv_def.mk               |    2 +
 5 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/fs/aufs/dir.c b/fs/aufs/dir.c
index 6dbe3ff..599d7f2 100644
--- a/fs/aufs/dir.c
+++ b/fs/aufs/dir.c
@@ -24,6 +24,56 @@
 
 #include "aufs.h"
 
+loff_t au_dir_size(struct file *file, struct dentry *dentry)
+{
+       loff_t sz;
+       aufs_bindex_t bindex, bend;
+       struct file *h_file;
+       struct dentry *h_dentry;
+
+       sz = 0;
+       if (file) {
+               AuDebugOn(!file->f_dentry);
+               AuDebugOn(!file->f_dentry->d_inode);
+               AuDebugOn(!S_ISDIR(file->f_dentry->d_inode->i_mode));
+
+               bend = au_fbend(file);
+               for (bindex = au_fbstart(file);
+                    bindex <= bend && sz < KMALLOC_MAX_SIZE;
+                    bindex++) {
+                       h_file = au_h_fptr(file, bindex);
+                       if (h_file
+                           && h_file->f_dentry
+                           && h_file->f_dentry->d_inode)
+                               sz += i_size_read(h_file->f_dentry->d_inode);
+               }
+       } else {
+               AuDebugOn(!dentry);
+               AuDebugOn(!dentry->d_inode);
+               AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
+
+               bend = au_dbtaildir(dentry);
+               for (bindex = au_dbstart(dentry);
+                    bindex <= bend && sz < KMALLOC_MAX_SIZE;
+                    bindex++) {
+                       h_dentry = au_h_dptr(dentry, bindex);
+                       if (h_dentry && h_dentry->d_inode)
+                               sz += i_size_read(h_dentry->d_inode);
+               }
+       }
+       if (sz < KMALLOC_MAX_SIZE)
+               sz = roundup_pow_of_two(sz);
+       if (sz > KMALLOC_MAX_SIZE)
+               sz = KMALLOC_MAX_SIZE;
+       else if (sz < NAME_MAX) {
+               BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
+               sz = AUFS_RDBLK_DEF;
+       }
+       return sz;
+}
+
+/* ---------------------------------------------------------------------- */
+
 static int reopen_dir(struct file *file)
 {
        int err;
diff --git a/fs/aufs/dir.h b/fs/aufs/dir.h
index 1870601..5cf5159 100644
--- a/fs/aufs/dir.h
+++ b/fs/aufs/dir.h
@@ -104,10 +104,12 @@ struct au_vdir {
 
 /* dir.c */
 extern struct file_operations aufs_dir_fop;
+loff_t au_dir_size(struct file *file, struct dentry *dentry);
 int au_test_empty_lower(struct dentry *dentry);
 int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
 
 /* vdir.c */
+unsigned int au_rdhash_est(loff_t sz);
 struct au_nhash *au_nhash_new(gfp_t gfp);
 void au_nhash_del(struct au_nhash *nhash);
 void au_nhash_init(struct au_nhash *nhash);
diff --git a/fs/aufs/vdir.c b/fs/aufs/vdir.c
index d3a470e..ea9ef37 100644
--- a/fs/aufs/vdir.c
+++ b/fs/aufs/vdir.c
@@ -66,6 +66,21 @@ static au_vdir_deblk_t *last_deblk(struct au_vdir *vdir)
        return vdir->vd_deblk[vdir->vd_nblk - 1];
 }
 
+/* estimate the apropriate size for name hash table */
+unsigned int au_rdhash_est(loff_t sz)
+{
+       unsigned int n;
+
+       n = UINT_MAX;
+       sz >>= 10;
+       if (sz < n)
+               n = sz;
+       if (sz < AUFS_RDHASH_DEF)
+               n = AUFS_RDHASH_DEF;
+       /* AuInfo("n %u\n", n); */
+       return n;
+}
+
 void au_nhash_init(struct au_nhash *nhash)
 {
        int i;
diff --git a/include/linux/aufs_type.h b/include/linux/aufs_type.h
index cee8d68..b2108be 100644
--- a/include/linux/aufs_type.h
+++ b/include/linux/aufs_type.h
@@ -61,6 +61,8 @@ typedef short aufs_bindex_t;
 #define AUFS_XINO_TRUNC_STEP   4  /* blocks */
 #define AUFS_DIRWH_DEF         3
 #define AUFS_RDCACHE_DEF       10 /* seconds */
+#define AUFS_RDBLK_DEF         512 /* bytes */
+#define AUFS_RDHASH_DEF                32
 #define AUFS_WKQ_NAME          AUFS_NAME "d"
 #define AUFS_NWKQ_DEF          4
 #define AUFS_MFS_SECOND_DEF    30 /* seconds */
diff --git a/priv_def.mk b/priv_def.mk
index 1f78679..0d709df 100644
--- a/priv_def.mk
+++ b/priv_def.mk
@@ -1 +1,3 @@
+ifeq (${HOSTNAME},jrofr)
 export CONFIG_AUFS_SPLICE_PATCH = y
+endif
-- 
1.6.1.284.g5dc13


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

Reply via email to