[PATCH V2] ceph: use i_release_count to indicate dir's completeness

2013-03-13 Thread Yan, Zheng
From: "Yan, Zheng" 

Current ceph code tracks directory's completeness in two places.
ceph_readdir() checks i_release_count to decide if it can set the
I_COMPLETE flag in i_ceph_flags. All other places check the I_COMPLETE
flag. This indirection introduces locking complexity.

This patch adds a new variable i_complete_count to ceph_inode_info.
Set i_release_count's value to it when marking a directory complete.
By comparing the two variables, we know if a directory is complete

Signed-off-by: Yan, Zheng 
---
Changes since V1:
 define i_complete_count as atomic_t

 fs/ceph/caps.c   |  4 ++--
 fs/ceph/dir.c| 25 +
 fs/ceph/inode.c  | 13 +++--
 fs/ceph/mds_client.c | 10 +++---
 fs/ceph/super.h  | 42 --
 5 files changed, 45 insertions(+), 49 deletions(-)

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 76634f4..124e8a1 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -490,7 +490,7 @@ static void __check_cap_issue(struct ceph_inode_info *ci, 
struct ceph_cap *cap,
ci->i_rdcache_gen++;
 
/*
-* if we are newly issued FILE_SHARED, clear I_COMPLETE; we
+* if we are newly issued FILE_SHARED, mark dir not complete; we
 * don't know what happened to this directory while we didn't
 * have the cap.
 */
@@ -499,7 +499,7 @@ static void __check_cap_issue(struct ceph_inode_info *ci, 
struct ceph_cap *cap,
ci->i_shared_gen++;
if (S_ISDIR(ci->vfs_inode.i_mode)) {
dout(" marking %p NOT complete\n", &ci->vfs_inode);
-   ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
+   __ceph_dir_clear_complete(ci);
}
}
 }
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 76821be..11966c4 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -107,7 +107,7 @@ static unsigned fpos_off(loff_t p)
  * falling back to a "normal" sync readdir if any dentries in the dir
  * are dropped.
  *
- * I_COMPLETE tells indicates we have all dentries in the dir.  It is
+ * Complete dir indicates that we have all dentries in the dir.  It is
  * defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by
  * the MDS if/when the directory is modified).
  */
@@ -198,8 +198,8 @@ more:
filp->f_pos++;
 
/* make sure a dentry wasn't dropped while we didn't have parent lock */
-   if (!ceph_i_test(dir, CEPH_I_COMPLETE)) {
-   dout(" lost I_COMPLETE on %p; falling back to mds\n", dir);
+   if (!ceph_dir_is_complete(dir)) {
+   dout(" lost dir complete on %p; falling back to mds\n", dir);
err = -EAGAIN;
goto out;
}
@@ -258,7 +258,7 @@ static int ceph_readdir(struct file *filp, void *dirent, 
filldir_t filldir)
if (filp->f_pos == 0) {
/* note dir version at start of readdir so we can tell
 * if any dentries get dropped */
-   fi->dir_release_count = ci->i_release_count;
+   fi->dir_release_count = atomic_read(&ci->i_release_count);
 
dout("readdir off 0 -> '.'\n");
if (filldir(dirent, ".", 1, ceph_make_fpos(0, 0),
@@ -284,7 +284,7 @@ static int ceph_readdir(struct file *filp, void *dirent, 
filldir_t filldir)
if ((filp->f_pos == 2 || fi->dentry) &&
!ceph_test_mount_opt(fsc, NOASYNCREADDIR) &&
ceph_snap(inode) != CEPH_SNAPDIR &&
-   (ci->i_ceph_flags & CEPH_I_COMPLETE) &&
+   __ceph_dir_is_complete(ci) &&
__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) {
spin_unlock(&ci->i_ceph_lock);
err = __dcache_readdir(filp, dirent, filldir);
@@ -350,7 +350,8 @@ more:
 
if (!req->r_did_prepopulate) {
dout("readdir !did_prepopulate");
-   fi->dir_release_count--;/* preclude I_COMPLETE */
+   /* preclude from marking dir complete */
+   fi->dir_release_count--;
}
 
/* note next offset and last dentry name */
@@ -428,9 +429,9 @@ more:
 * the complete dir contents in our cache.
 */
spin_lock(&ci->i_ceph_lock);
-   if (ci->i_release_count == fi->dir_release_count) {
+   if (atomic_read(&ci->i_release_count) == fi->dir_release_count) {
dout(" marking %p complete\n", inode);
-   ci->i_ceph_flags |= CEPH_I_COMPLETE;
+   __ceph_dir_set_complete(ci, fi->dir_release_count);
ci->i_max_offset = filp->f_pos;
}
spin_unlock(&ci->i_ceph_lock);
@@ -605,7 +606,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct 
dentry *dentry,
fsc->mount_options->snapdir_name,
dentry->d_name.len) &&
!is_root_ceph_dentry(dir, dentry) &&
-  

Re: [PATCH V2] ceph: use i_release_count to indicate dir's completeness

2013-03-13 Thread Greg Farnum
Looks good, thanks. :)

We'll also be testing the first patch in this series.
-Greg

On Wednesday, March 13, 2013 at 4:44 AM, Yan, Zheng wrote:

> From: "Yan, Zheng" mailto:zheng.z@intel.com)>
> 
> Current ceph code tracks directory's completeness in two places.
> ceph_readdir() checks i_release_count to decide if it can set the
> I_COMPLETE flag in i_ceph_flags. All other places check the I_COMPLETE
> flag. This indirection introduces locking complexity.
> 
> This patch adds a new variable i_complete_count to ceph_inode_info.
> Set i_release_count's value to it when marking a directory complete.
> By comparing the two variables, we know if a directory is complete
> 
> Signed-off-by: Yan, Zheng  (mailto:zheng.z@intel.com)>
> ---
> Changes since V1:
> define i_complete_count as atomic_t
> 
> fs/ceph/caps.c | 4 ++--
> fs/ceph/dir.c | 25 +
> fs/ceph/inode.c | 13 +++--
> fs/ceph/mds_client.c | 10 +++---
> fs/ceph/super.h | 42 --
> 5 files changed, 45 insertions(+), 49 deletions(-)
> 
> diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
> index 76634f4..124e8a1 100644
> --- a/fs/ceph/caps.c
> +++ b/fs/ceph/caps.c
> @@ -490,7 +490,7 @@ static void __check_cap_issue(struct ceph_inode_info *ci, 
> struct ceph_cap *cap,
> ci->i_rdcache_gen++;
> 
> /*
> - * if we are newly issued FILE_SHARED, clear I_COMPLETE; we
> + * if we are newly issued FILE_SHARED, mark dir not complete; we
> * don't know what happened to this directory while we didn't
> * have the cap.
> */
> @@ -499,7 +499,7 @@ static void __check_cap_issue(struct ceph_inode_info *ci, 
> struct ceph_cap *cap,
> ci->i_shared_gen++;
> if (S_ISDIR(ci->vfs_inode.i_mode)) {
> dout(" marking %p NOT complete\n", &ci->vfs_inode);
> - ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
> + __ceph_dir_clear_complete(ci);
> }
> }
> }
> diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
> index 76821be..11966c4 100644
> --- a/fs/ceph/dir.c
> +++ b/fs/ceph/dir.c
> @@ -107,7 +107,7 @@ static unsigned fpos_off(loff_t p)
> * falling back to a "normal" sync readdir if any dentries in the dir
> * are dropped.
> *
> - * I_COMPLETE tells indicates we have all dentries in the dir. It is
> + * Complete dir indicates that we have all dentries in the dir. It is
> * defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by
> * the MDS if/when the directory is modified).
> */
> @@ -198,8 +198,8 @@ more:
> filp->f_pos++;
> 
> /* make sure a dentry wasn't dropped while we didn't have parent lock */
> - if (!ceph_i_test(dir, CEPH_I_COMPLETE)) {
> - dout(" lost I_COMPLETE on %p; falling back to mds\n", dir);
> + if (!ceph_dir_is_complete(dir)) {
> + dout(" lost dir complete on %p; falling back to mds\n", dir);
> err = -EAGAIN;
> goto out;
> }
> @@ -258,7 +258,7 @@ static int ceph_readdir(struct file *filp, void *dirent, 
> filldir_t filldir)
> if (filp->f_pos == 0) {
> /* note dir version at start of readdir so we can tell
> * if any dentries get dropped */
> - fi->dir_release_count = ci->i_release_count;
> + fi->dir_release_count = atomic_read(&ci->i_release_count);
> 
> dout("readdir off 0 -> '.'\n");
> if (filldir(dirent, ".", 1, ceph_make_fpos(0, 0),
> @@ -284,7 +284,7 @@ static int ceph_readdir(struct file *filp, void *dirent, 
> filldir_t filldir)
> if ((filp->f_pos == 2 || fi->dentry) &&
> !ceph_test_mount_opt(fsc, NOASYNCREADDIR) &&
> ceph_snap(inode) != CEPH_SNAPDIR &&
> - (ci->i_ceph_flags & CEPH_I_COMPLETE) &&
> + __ceph_dir_is_complete(ci) &&
> __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) {
> spin_unlock(&ci->i_ceph_lock);
> err = __dcache_readdir(filp, dirent, filldir);
> @@ -350,7 +350,8 @@ more:
> 
> if (!req->r_did_prepopulate) {
> dout("readdir !did_prepopulate");
> - fi->dir_release_count--; /* preclude I_COMPLETE */
> + /* preclude from marking dir complete */
> + fi->dir_release_count--;
> }
> 
> /* note next offset and last dentry name */
> @@ -428,9 +429,9 @@ more:
> * the complete dir contents in our cache.
> */
> spin_lock(&ci->i_ceph_lock);
> - if (ci->i_release_count == fi->dir_release_count) {
> + if (atomic_read(&ci->i_release_count) == fi->dir_release_count) {
> dout(" marking %p complete\n", inode);
> - ci->i_ceph_flags |= CEPH_I_COMPLETE;
> + __ceph_dir_set_complete(ci, fi->dir_release_count);
> ci->i_max_offset = filp->f_pos;
> }
> spin_unlock(&ci->i_ceph_lock);
> @@ -605,7 +606,7 @@ static struct dentry *ceph_lookup(struct inode *dir, 
> struct dentry *dentry,
> fsc->mount_options->snapdir_name,
> dentry->d_name.len) &&
> !is_root_ceph_dentry(dir, dentry) &&
> - (ci->i_ceph_flags & CEPH_I_COMPLETE) &&
> + __ceph_dir_is_complete(ci) &&
> (__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) {
> spin_unlock(&ci->i_ceph_lock);
> dout(" dir %p complete, -ENOENT\n", dir);
> @@ -909,7 +910,7 @@ static int ceph_rename(struct inode *old_dir, struct 
> dentry *old_dentry,
> */
> 
> /* d_move screws up d_subdirs order */
> - ceph_i_clear(new_dir, CEPH_I_COMPLETE);
> + ceph_dir_clear_complet