From fca56be02b8fe074e7fce4bf8e9224a644cc7572 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Fri, 16 Oct 2020 14:29:32 +1100 Subject: [PATCH] LU-6142 lustre: use is_root_inode() 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 Change-Id: Ib5997e8976b6e935c268ad7ac9328fcd4d071b1f Reviewed-on: https://review.whamcloud.com/40293 Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Tested-by: jenkins Tested-by: Maloo --- lustre/autoconf/lustre-core.m4 | 18 ++++++++++++++++++ lustre/include/lustre_compat.h | 7 +++++++ lustre/llite/crypto.c | 2 +- lustre/llite/dir.c | 2 +- lustre/llite/file.c | 40 +++++++++++++++++++-------------------- lustre/llite/namei.c | 3 +-- lustre/osd-ldiskfs/osd_handler.c | 7 +++---- lustre/osd-ldiskfs/osd_internal.h | 2 +- lustre/osd-ldiskfs/osd_scrub.c | 2 +- 9 files changed, 53 insertions(+), 30 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 286f717..7eeefa8 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -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 +],[ + 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 diff --git a/lustre/include/lustre_compat.h b/lustre/include/lustre_compat.h index 50b0399..8ab1fbd 100644 --- a/lustre/include/lustre_compat.h +++ b/lustre/include/lustre_compat.h @@ -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 */ diff --git a/lustre/llite/crypto.c b/lustre/llite/crypto.c index 764c9ed..6662759 100644 --- a/lustre/llite/crypto.c +++ b/lustre/llite/crypto.c @@ -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; diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 2082c85..a4729db 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -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) { diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 114beb2..f307298 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -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); diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index ac23de7..b743aa8 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -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)) diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 9d22233..300d090 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -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); diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index fba02d0..b6e5a1e 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -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) diff --git a/lustre/osd-ldiskfs/osd_scrub.c b/lustre/osd-ldiskfs/osd_scrub.c index 1c4adcc..9e64ae2 100644 --- a/lustre/osd-ldiskfs/osd_scrub.c +++ b/lustre/osd-ldiskfs/osd_scrub.c @@ -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, -- 1.8.3.1