])
#
+# 3.2 protects inode->i_nlink from direct modification
+# see kernel commit a78ef704a8dd430225955f0709b22d4a6ba21deb
+# at the same time adds set_nlink(), so checks set_nlink() for it.
+#
+AC_DEFUN([LC_HAVE_PROTECT_I_NLINK],
+[AC_MSG_CHECKING([if inode->i_nlink is protected from direct modification])
+LB_LINUX_TRY_COMPILE([
+ #include <linux/fs.h>
+],[
+ struct inode i;
+ set_nlink(&i, 1);
+],[
+ AC_DEFINE(HAVE_PROTECT_I_NLINK, 1,
+ [inode->i_nlink is protected from direct modification])
+ AC_MSG_RESULT([yes])
+],[
+ AC_MSG_RESULT([no])
+])
+])
+
+#
# 3.3 introduces migrate_mode.h and migratepage has 4 args
#
AC_DEFUN([LC_HAVE_MIGRATE_HEADER],
# 3.2
LC_HAVE_VOID_MAKE_REQUEST_FN
+ LC_HAVE_PROTECT_I_NLINK
# 3.3
LC_HAVE_MIGRATE_HEADER
# define LL_MRF_RETURN(rc) RETURN(rc)
#endif
+#include <linux/fs.h>
+#ifndef HAVE_PROTECT_I_NLINK
+static inline void set_nlink(struct inode *inode, unsigned int nlink)
+{
+ inode->i_nlink = nlink;
+}
+#endif
+
#endif /* _COMPAT25_H */
/* if not ldlm lock for this inode, set i_nlink to 0 so that
* this inode can be recycled later b=20433 */
if (de->d_inode && !find_cbdata(de->d_inode))
- de->d_inode->i_nlink = 0;
+ clear_nlink(de->d_inode);
#endif
if (d_lustre_invalid((struct dentry *)de))
void ll_d_iput(struct dentry *de, struct inode *inode)
{
- LASSERT(inode);
- if (!find_cbdata(inode))
- inode->i_nlink = 0;
- iput(inode);
+ LASSERT(inode);
+ if (!find_cbdata(inode))
+ clear_nlink(inode);
+ iput(inode);
}
struct dentry_operations ll_d_ops = {
}
static int ll_inode_revalidate_fini(struct inode *inode, int rc) {
- if (rc == -ENOENT) { /* Already unlinked. Just update nlink
- * and return success */
- inode->i_nlink = 0;
- /* This path cannot be hit for regular files unless in
- * case of obscure races, so no need to to validate
- * size. */
- if (!S_ISREG(inode->i_mode) &&
- !S_ISDIR(inode->i_mode))
- return 0;
- }
-
- if (rc) {
- CERROR("failure %d inode %lu\n", rc, inode->i_ino);
- return -abs(rc);
+ if (rc == -ENOENT) { /* Already unlinked. Just update nlink
+ * and return success */
+ clear_nlink(inode);
+ /* This path cannot be hit for regular files unless in
+ * case of obscure races, so no need to to validate
+ * size. */
+ if (!S_ISREG(inode->i_mode) &&
+ !S_ISDIR(inode->i_mode))
+ return 0;
+ }
- }
+ if (rc) {
+ CERROR("failure %d inode %lu\n", rc, inode->i_ino);
+ return -abs(rc);
+ }
- return 0;
+ return 0;
}
int __ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it,
rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL, 0,
&request, mod);
- if (rc) {
- ptlrpc_req_finished(request);
- if (rc == -ENOENT) {
- inode->i_nlink = 0;
- /* Unlinked special device node? Or just a race?
- * Pretend we done everything. */
- if (!S_ISREG(inode->i_mode) &&
- !S_ISDIR(inode->i_mode)) {
- ia_valid = op_data->op_attr.ia_valid;
- op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
- rc = simple_setattr(dentry, &op_data->op_attr);
- op_data->op_attr.ia_valid = ia_valid;
- }
- } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
- CERROR("md_setattr fails: rc = %d\n", rc);
- }
- RETURN(rc);
- }
+ if (rc) {
+ ptlrpc_req_finished(request);
+ if (rc == -ENOENT) {
+ clear_nlink(inode);
+ /* Unlinked special device node? Or just a race?
+ * Pretend we done everything. */
+ if (!S_ISREG(inode->i_mode) &&
+ !S_ISDIR(inode->i_mode)) {
+ ia_valid = op_data->op_attr.ia_valid;
+ op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
+ rc = simple_setattr(dentry, &op_data->op_attr);
+ op_data->op_attr.ia_valid = ia_valid;
+ }
+ } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
+ CERROR("md_setattr fails: rc = %d\n", rc);
+ }
+ RETURN(rc);
+ }
rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
sbi->ll_md_exp, &md);
} else {
inode->i_blkbits = inode->i_sb->s_blocksize_bits;
}
- if (body->valid & OBD_MD_FLUID)
- inode->i_uid = body->uid;
- if (body->valid & OBD_MD_FLGID)
- inode->i_gid = body->gid;
- if (body->valid & OBD_MD_FLFLAGS)
- inode->i_flags = ll_ext_to_inode_flags(body->flags);
- if (body->valid & OBD_MD_FLNLINK)
- inode->i_nlink = body->nlink;
- if (body->valid & OBD_MD_FLRDEV)
- inode->i_rdev = old_decode_dev(body->rdev);
+ if (body->valid & OBD_MD_FLUID)
+ inode->i_uid = body->uid;
+ if (body->valid & OBD_MD_FLGID)
+ inode->i_gid = body->gid;
+ if (body->valid & OBD_MD_FLFLAGS)
+ inode->i_flags = ll_ext_to_inode_flags(body->flags);
+ if (body->valid & OBD_MD_FLNLINK)
+ set_nlink(inode, body->nlink);
+ if (body->valid & OBD_MD_FLRDEV)
+ inode->i_rdev = old_decode_dev(body->rdev);
if (body->valid & OBD_MD_FLID) {
/* FID shouldn't be changed! */
if (bits & LA_GID)
inode->i_gid = attr->la_gid;
if (bits & LA_NLINK)
- inode->i_nlink = attr->la_nlink;
+ set_nlink(inode, attr->la_nlink);
if (bits & LA_RDEV)
inode->i_rdev = attr->la_rdev;
/* Parallel control for OI scrub. For most of cases, there is no
* lock contention. So it will not affect unlink performance. */
cfs_mutex_lock(&inode->i_mutex);
- if (S_ISDIR(inode->i_mode)) {
- LASSERT(osd_inode_unlinked(inode) ||
- inode->i_nlink == 1);
- cfs_spin_lock(&obj->oo_guard);
- inode->i_nlink = 0;
- cfs_spin_unlock(&obj->oo_guard);
- inode->i_sb->s_op->dirty_inode(inode);
- } else {
- LASSERT(osd_inode_unlinked(inode));
- }
+ if (S_ISDIR(inode->i_mode)) {
+ LASSERT(osd_inode_unlinked(inode) ||
+ inode->i_nlink == 1);
+ cfs_spin_lock(&obj->oo_guard);
+ clear_nlink(inode);
+ cfs_spin_unlock(&obj->oo_guard);
+ inode->i_sb->s_op->dirty_inode(inode);
+ } else {
+ LASSERT(osd_inode_unlinked(inode));
+ }
OSD_EXEC_OP(th, destroy);
OSD_EXEC_OP(th, ref_add);
- /*
- * DIR_NLINK feature is set for compatibility reasons if:
- * 1) nlinks > LDISKFS_LINK_MAX, or
- * 2) nlinks == 2, since this indicates i_nlink was previously 1.
- *
- * It is easier to always set this flag (rather than check and set),
- * since it has less overhead, and the superblock will be dirtied
- * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
- * do not actually care whether this flag is set or not.
- */
- cfs_spin_lock(&obj->oo_guard);
- inode->i_nlink++;
- if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
- if (inode->i_nlink >= LDISKFS_LINK_MAX ||
- inode->i_nlink == 2)
- inode->i_nlink = 1;
- }
- LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
- cfs_spin_unlock(&obj->oo_guard);
- inode->i_sb->s_op->dirty_inode(inode);
- LINVRNT(osd_invariant(obj));
+ /*
+ * DIR_NLINK feature is set for compatibility reasons if:
+ * 1) nlinks > LDISKFS_LINK_MAX, or
+ * 2) nlinks == 2, since this indicates i_nlink was previously 1.
+ *
+ * It is easier to always set this flag (rather than check and set),
+ * since it has less overhead, and the superblock will be dirtied
+ * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
+ * do not actually care whether this flag is set or not.
+ */
+ cfs_spin_lock(&obj->oo_guard);
+ /* inc_nlink from 0 may cause WARN_ON */
+ if(inode->i_nlink == 0)
+ set_nlink(inode, 1);
+ else
+ inc_nlink(inode);
+ if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
+ if (inode->i_nlink >= LDISKFS_LINK_MAX ||
+ inode->i_nlink == 2)
+ set_nlink(inode, 1);
+ }
+ LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
+ cfs_spin_unlock(&obj->oo_guard);
+ inode->i_sb->s_op->dirty_inode(inode);
+ LINVRNT(osd_invariant(obj));
- return 0;
+ return 0;
}
static int osd_declare_object_ref_del(const struct lu_env *env,
OSD_EXEC_OP(th, ref_del);
- cfs_spin_lock(&obj->oo_guard);
- LASSERT(inode->i_nlink > 0);
- inode->i_nlink--;
- /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
- * then the nlink count is 1. Don't let it be set to 0 or the directory
- * inode will be deleted incorrectly. */
- if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
- inode->i_nlink++;
- cfs_spin_unlock(&obj->oo_guard);
- inode->i_sb->s_op->dirty_inode(inode);
- LINVRNT(osd_invariant(obj));
+ cfs_spin_lock(&obj->oo_guard);
+ LASSERT(inode->i_nlink > 0);
+ drop_nlink(inode);
+ /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
+ * then the nlink count is 1. Don't let it be set to 0 or the directory
+ * inode will be deleted incorrectly. */
+ if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
+ set_nlink(inode, 1);
+ cfs_spin_unlock(&obj->oo_guard);
+ inode->i_sb->s_op->dirty_inode(inode);
+ LINVRNT(osd_invariant(obj));
- return 0;
+ return 0;
}
/*