From 266a0e3f717dcf74f750667e859c9382ddb8b817 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 2 Dec 2013 11:44:19 -0500 Subject: [PATCH] LU-3974 client: use standard dentry locking function Over time the struct dentry reference count have change its data structure. In the 3.11 kernel it was changed to a struct lockref. To handle these cases in the past Lustre implemented a d_refcount wrapper to handle all these changes. At the same time for 3.11 a d_count() wrapper was introduced. So this patch moved use to use this d_count wrapper and if not present we emulate it. Signed-off-by: James Simmons Change-Id: I4c175e789298841f9d599e5195dbd94ccea6216a Reviewed-on: http://review.whamcloud.com/7741 Reviewed-by: Peng Tao Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bob Glossman Reviewed-by: Oleg Drokin --- lustre/autoconf/lustre-core.m4 | 22 ++++++++++++++++++++++ lustre/include/linux/lustre_patchless_compat.h | 8 ++++---- lustre/include/linux/lvfs.h | 2 +- lustre/llite/dcache.c | 8 ++++---- lustre/llite/llite_internal.h | 4 ++-- lustre/llite/llite_lib.c | 2 +- lustre/llite/namei.c | 4 ++-- lustre/ptlrpc/sec_ctx.c | 4 ++-- 8 files changed, 38 insertions(+), 16 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 0732b9b..8124d2c 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -1288,6 +1288,25 @@ LB_LINUX_TRY_COMPILE([ ]) # +# 3.11 need to access d_count to get dentry reference count +# +AC_DEFUN([LC_HAVE_DCOUNT], +[AC_MSG_CHECKING([if d_count exist]) +LB_LINUX_TRY_COMPILE([ + #include +],[ + struct dentry de; + + d_count(&de); +],[ + AC_DEFINE(HAVE_D_COUNT, 1, [d_count exist]) + AC_MSG_RESULT([yes]) +],[ + AC_MSG_RESULT([no]) +]) +]) + +# # LC_PROG_LINUX # # Lustre linux kernel checks @@ -1386,6 +1405,9 @@ AC_DEFUN([LC_PROG_LINUX], LC_HAVE_ONLY_PROCFS_SEQ LC_BLKDEV_RELEASE_RETURN_INT + # 3.11 + LC_HAVE_DCOUNT + # if test x$enable_server != xno ; then LC_FUNC_DEV_SET_RDONLY diff --git a/lustre/include/linux/lustre_patchless_compat.h b/lustre/include/linux/lustre_patchless_compat.h index c948cda..747bd4d 100644 --- a/lustre/include/linux/lustre_patchless_compat.h +++ b/lustre/include/linux/lustre_patchless_compat.h @@ -91,10 +91,10 @@ truncate_complete_page(struct address_space *mapping, struct page *page) #endif /* !HAVE_TRUNCATE_COMPLETE_PAGE */ #ifdef HAVE_DCACHE_LOCK -# define dget_dlock(d) dget_locked(d) -# define d_refcount(d) atomic_read(&(d)->d_count) -#else -# define d_refcount(d) ((d)->d_count) +# define dget_dlock(d) dget_locked(d) +# define d_count(d) atomic_read(&(d)->d_count) +#elif !defined(HAVE_D_COUNT) +# define d_count(d) ((d)->d_count) #endif /* HAVE_DCACHE_LOCK */ #ifdef ATTR_OPEN diff --git a/lustre/include/linux/lvfs.h b/lustre/include/linux/lvfs.h index 64445b7..68b4317 100644 --- a/lustre/include/linux/lvfs.h +++ b/lustre/include/linux/lvfs.h @@ -99,7 +99,7 @@ static inline void l_dput(struct dentry *de) if (!de || IS_ERR(de)) return; //shrink_dcache_parent(de); - LASSERT(d_refcount(de) > 0); + LASSERT(d_count(de) > 0); dput(de); } diff --git a/lustre/llite/dcache.c b/lustre/llite/dcache.c index 7097833..6fca4cb 100644 --- a/lustre/llite/dcache.c +++ b/lustre/llite/dcache.c @@ -117,7 +117,7 @@ int ll_dcompare(struct dentry *parent, struct qstr *d_name, struct qstr *name) CDEBUG(D_DENTRY, "found name %.*s(%p) flags %#x refc %d\n", name->len, name->name, dentry, dentry->d_flags, - d_refcount(dentry)); + d_count(dentry)); /* mountpoint is always valid */ if (d_mountpoint((struct dentry *)dentry)) @@ -181,10 +181,10 @@ static int ll_ddelete(HAVE_D_DELETE_CONST struct dentry *de) list_empty(&de->d_subdirs) ? "" : "subdirs"); #ifdef HAVE_DCACHE_LOCK - LASSERT(d_refcount(de) == 0); + LASSERT(d_count(de) == 0); #else /* kernel >= 2.6.38 last refcount is decreased after this function. */ - LASSERT(d_refcount(de) == 1); + LASSERT(d_count(de) == 1); #endif /* Disable this piece of code temproarily because this is called @@ -210,7 +210,7 @@ int ll_d_init(struct dentry *de) CDEBUG(D_DENTRY, "ldd on dentry %.*s (%p) parent %p inode %p refc %d\n", de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode, - d_refcount(de)); + d_count(de)); if (de->d_fsdata == NULL) { struct ll_dentry_data *lld; diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 92c1de3..daeac51 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -1617,12 +1617,12 @@ static inline void d_lustre_invalidate(struct dentry *dentry, int nested) { CDEBUG(D_DENTRY, "invalidate dentry %.*s (%p) parent %p inode %p " "refc %d\n", dentry->d_name.len, dentry->d_name.name, dentry, - dentry->d_parent, dentry->d_inode, d_refcount(dentry)); + dentry->d_parent, dentry->d_inode, d_count(dentry)); spin_lock_nested(&dentry->d_lock, nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL); __d_lustre_invalidate(dentry); - if (d_refcount(dentry) == 0) + if (d_count(dentry) == 0) __d_drop(dentry); spin_unlock(&dentry->d_lock); } diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index a69d01d..9d9e432 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -676,7 +676,7 @@ void lustre_dump_dentry(struct dentry *dentry, int recur) " flags=0x%x, fsdata=%p, %d subdirs\n", dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_parent->d_name.len, dentry->d_parent->d_name.name, - dentry->d_parent, dentry->d_inode, d_refcount(dentry), + dentry->d_parent, dentry->d_inode, d_count(dentry), dentry->d_flags, dentry->d_fsdata, subdirs); if (dentry->d_inode != NULL) ll_dump_inode(dentry->d_inode); diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 8876711..5051c5e 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -420,7 +420,7 @@ struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de) iput(inode); CDEBUG(D_DENTRY, "Reuse dentry %p inode %p refc %d flags %#x\n", - new, new->d_inode, d_refcount(new), new->d_flags); + new, new->d_inode, d_count(new), new->d_flags); return new; } } @@ -429,7 +429,7 @@ struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de) return ERR_PTR(rc); d_add(de, inode); CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n", - de, de->d_inode, d_refcount(de), de->d_flags); + de, de->d_inode, d_count(de), de->d_flags); return de; } diff --git a/lustre/ptlrpc/sec_ctx.c b/lustre/ptlrpc/sec_ctx.c index 8f4deb3..3da4c25 100644 --- a/lustre/ptlrpc/sec_ctx.c +++ b/lustre/ptlrpc/sec_ctx.c @@ -101,8 +101,8 @@ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx, OBD_SET_CTXT_MAGIC(save); save->fs = get_fs(); - LASSERT(d_refcount(current->fs->pwd.dentry)); - LASSERT(d_refcount(new_ctx->pwd)); + LASSERT(d_count(current->fs->pwd.dentry)); + LASSERT(d_count(new_ctx->pwd)); save->pwd = dget(current->fs->pwd.dentry); save->pwdmnt = mntget(current->fs->pwd.mnt); save->luc.luc_umask = current_umask(); -- 1.8.3.1