Whamcloud - gitweb
LU-6142 lustre: use is_root_inode() 93/40293/7
authorMr NeilBrown <neilb@suse.de>
Fri, 16 Oct 2020 03:29:32 +0000 (14:29 +1100)
committerOleg Drokin <green@whamcloud.com>
Fri, 26 Feb 2021 22:10:34 +0000 (22:10 +0000)
Lustre has multiple tests to see if a given inode is the root of the
filesystem.  Linux has (since 3.19) a helper function is_root_inode().
Use that throughout.

Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ib5997e8976b6e935c268ad7ac9328fcd4d071b1f
Reviewed-on: https://review.whamcloud.com/40293
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/autoconf/lustre-core.m4
lustre/include/lustre_compat.h
lustre/llite/crypto.c
lustre/llite/dir.c
lustre/llite/file.c
lustre/llite/namei.c
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_scrub.c

index 286f717..7eeefa8 100644 (file)
@@ -996,6 +996,23 @@ aio_complete, [
 ]) # LC_HAVE_AIO_COMPLETE
 
 #
+# LC_HAVE_IS_ROOT_INODE
+#
+# 3.19 kernel adds is_root_inode()
+# Commit a7400222e3eb ("new helper: is_root_inode()")
+#
+AC_DEFUN([LC_HAVE_IS_ROOT_INODE], [
+LB_CHECK_COMPILE([if kernel has is_root_inode() ],
+is_root_inode, [
+       #include <linux/fs.h>
+],[
+       is_root_inode(NULL);
+],[
+       AC_DEFINE(HAVE_IS_ROOT_INODE, 1, [is_root_inode defined])
+])
+]) # LC_HAVE_IS_ROOT_INODE
+
+#
 # LC_BACKING_DEV_INFO_REMOVAL
 #
 # 3.20 kernel removed backing_dev_info from address_space
@@ -2369,6 +2386,7 @@ AC_DEFUN([LC_PROG_LINUX], [
        LC_KIOCB_HAS_NBYTES
        LC_HAVE_DQUOT_QC_DQBLK
        LC_HAVE_AIO_COMPLETE
+       LC_HAVE_IS_ROOT_INODE
 
        # 3.20
        LC_BACKING_DEV_INFO_REMOVAL
index 50b0399..8ab1fbd 100644 (file)
@@ -580,4 +580,11 @@ static inline int ll_vfs_removexattr(struct dentry *dentry, struct inode *inode,
 #define raw_cpu_ptr(p) __this_cpu_ptr(p)
 #endif
 
+#ifndef HAVE_IS_ROOT_INODE
+static inline bool is_root_inode(struct inode *inode)
+{
+       return inode == inode->i_sb->s_root->d_inode;
+}
+#endif
+
 #endif /* _LUSTRE_COMPAT_H */
index 764c9ed..6662759 100644 (file)
@@ -101,7 +101,7 @@ static int ll_set_context(struct inode *inode, const void *ctx, size_t len,
        }
 
        /* Encrypting the root directory is not allowed */
-       if (inode->i_ino == inode->i_sb->s_root->d_inode->i_ino)
+       if (is_root_inode(inode))
                return -EPERM;
 
        dentry = (struct dentry *)fs_data;
index 2082c85..a4729db 100644 (file)
@@ -1500,7 +1500,7 @@ lmv_out_free:
                if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
                        RETURN(-EFAULT);
 
-               if (inode->i_sb->s_root == file_dentry(file))
+               if (is_root_inode(inode))
                        set_default = 1;
 
                switch (lumv1.lmm_magic) {
index 114beb2..f307298 100644 (file)
@@ -393,7 +393,7 @@ int ll_file_release(struct inode *inode, struct file *file)
        if (S_ISDIR(inode->i_mode) && lli->lli_opendir_key == fd)
                ll_deauthorize_statahead(inode, fd);
 
-       if (inode->i_sb->s_root == file_dentry(file)) {
+       if (is_root_inode(inode)) {
                file->private_data = NULL;
                ll_file_data_put(fd);
                GOTO(out, rc = 0);
@@ -413,7 +413,7 @@ int ll_file_release(struct inode *inode, struct file *file)
                libcfs_debug_dumplog();
 
 out:
-       if (!rc && inode->i_sb->s_root != file_dentry(file))
+       if (!rc && !is_root_inode(inode))
                ll_stats_ops_tally(sbi, LPROC_LL_RELEASE,
                                   ktime_us_delta(ktime_get(), kstart));
        RETURN(rc);
@@ -785,7 +785,7 @@ int ll_file_open(struct inode *inode, struct file *file)
        if (S_ISDIR(inode->i_mode))
                ll_authorize_statahead(inode, fd);
 
-       if (inode->i_sb->s_root == file_dentry(file)) {
+       if (is_root_inode(inode)) {
                file->private_data = fd;
                RETURN(0);
        }
@@ -2462,26 +2462,26 @@ out:
  */
 int ll_release_openhandle(struct dentry *dentry, struct lookup_intent *it)
 {
-        struct inode *inode = dentry->d_inode;
-        struct obd_client_handle *och;
-        int rc;
-        ENTRY;
+       struct inode *inode = dentry->d_inode;
+       struct obd_client_handle *och;
+       int rc;
+       ENTRY;
 
-        LASSERT(inode);
+       LASSERT(inode);
 
-        /* Root ? Do nothing. */
-        if (dentry->d_inode->i_sb->s_root == dentry)
-                RETURN(0);
+       /* Root ? Do nothing. */
+       if (is_root_inode(inode))
+               RETURN(0);
 
-        /* No open handle to close? Move away */
-        if (!it_disposition(it, DISP_OPEN_OPEN))
-                RETURN(0);
+       /* No open handle to close? Move away */
+       if (!it_disposition(it, DISP_OPEN_OPEN))
+               RETURN(0);
 
-        LASSERT(it_open_error(DISP_OPEN_OPEN, it) == 0);
+       LASSERT(it_open_error(DISP_OPEN_OPEN, it) == 0);
 
-        OBD_ALLOC(och, sizeof(*och));
-        if (!och)
-                GOTO(out, rc = -ENOMEM);
+       OBD_ALLOC(och, sizeof(*och));
+       if (!och)
+               GOTO(out, rc = -ENOMEM);
 
        rc = ll_och_fill(ll_i2sbi(inode)->ll_md_exp, it, och);
        if (rc)
@@ -4560,7 +4560,7 @@ int ll_migrate(struct inode *parent, struct file *file, struct lmv_user_md *lum,
         * by checking the migrate FID against the FID of the
         * filesystem root.
         */
-       if (child_inode == parent->i_sb->s_root->d_inode)
+       if (is_root_inode(child_inode))
                GOTO(out_iput, rc = -EINVAL);
 
        op_data = ll_prep_md_op_data(NULL, parent, NULL, name, namelen,
@@ -5263,7 +5263,7 @@ int ll_inode_permission(struct inode *inode, int mask)
         * need to do it before permission check.
         */
 
-       if (inode == inode->i_sb->s_root->d_inode) {
+       if (is_root_inode(inode)) {
                rc = ll_inode_revalidate(inode->i_sb->s_root, IT_LOOKUP);
                if (rc)
                        RETURN(rc);
index ac23de7..b743aa8 100644 (file)
@@ -370,8 +370,7 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
        }
 
        if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
-           inode->i_sb->s_root != NULL &&
-           inode != inode->i_sb->s_root->d_inode)
+           !is_root_inode(inode))
                ll_prune_aliases(inode);
 
        if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))
index 9d22233..300d090 100644 (file)
@@ -559,7 +559,7 @@ int osd_ldiskfs_add_entry(struct osd_thread_info *info, struct osd_device *osd,
                if (!rc2) {
                        fid = &loa->loa_lma.lma_self_fid;
                } else if (rc2 == -ENODATA) {
-                       if (unlikely(parent == inode->i_sb->s_root->d_inode)) {
+                       if (unlikely(is_root_inode(parent))) {
                                fid = &info->oti_fid3;
                                lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
                        } else if (!osd->od_is_ost && osd->od_index == 0) {
@@ -604,7 +604,7 @@ osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
        if (!rc) {
                *fid = loa->loa_lma.lma_self_fid;
        } else if (rc == -ENODATA) {
-               if (unlikely(inode == osd_sb(dev)->s_root->d_inode))
+               if (unlikely(is_root_inode(inode)))
                        lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
                else
                        lu_igif_build(fid, inode->i_ino, inode->i_generation);
@@ -5584,8 +5584,7 @@ static int __osd_ea_add_rec(struct osd_thread_info *info,
        LASSERT(pobj->oo_inode);
 
        ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
-       if (unlikely(pobj->oo_inode ==
-                    osd_sb(osd_obj2dev(pobj))->s_root->d_inode))
+       if (unlikely(osd_object_is_root(pobj)))
                ldp->edp_magic = 0;
        else
                osd_get_ldiskfs_dirent_param(ldp, fid);
index fba02d0..b6e5a1e 100644 (file)
@@ -1068,7 +1068,7 @@ static inline void osd_object_put(const struct lu_env *env,
 
 static inline int osd_object_is_root(const struct osd_object *obj)
 {
-        return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
+       return obj->oo_inode && is_root_inode(obj->oo_inode);
 }
 
 static inline struct osd_object *osd_obj(const struct lu_object *o)
index 1c4adcc..9e64ae2 100644 (file)
@@ -1929,7 +1929,7 @@ osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
                    osd_index_need_recreate(info->oti_env, dev, inode)) {
                        struct lu_fid *pfid = &info->oti_fid3;
 
-                       if (parent == osd_sb(dev)->s_root->d_inode) {
+                       if (is_root_inode(parent)) {
                                lu_local_obj_fid(pfid, OSD_FS_ROOT_OID);
                        } else {
                                rc = osd_scrub_get_fid(info, dev, parent, pfid,