From dd4d8a79468447e7e3b0ae773b75c6ff1d3d5883 Mon Sep 17 00:00:00 2001 From: Yang Sheng Date: Sat, 27 Jan 2018 01:26:26 +0800 Subject: [PATCH] LU-10565 osd: unify interface for vfs Some vfs changes were applied to other part but OSD. So unify them with OSD layer. Lustre-change: https://review.whamcloud.com/31646 Lustre-commit: 55ed739f7efb7029b02fe50999547f9aac40af72 Signed-off-by: Yang Sheng Change-Id: Ia3e907964d6321571f52e4c24a46a8ab64e4d056 Reviewed-by: Bob Glossman Reviewed-by: Wang Shilong Reviewed-on: https://review.whamcloud.com/33991 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Wang Shilong --- lustre/osd-ldiskfs/osd_compat.c | 40 ++++++++++++++++---------------- lustre/osd-ldiskfs/osd_handler.c | 22 +++++++++--------- lustre/osd-ldiskfs/osd_internal.h | 49 +++++++++++++++++++++++++++++++++++++-- lustre/osd-ldiskfs/osd_io.c | 3 +-- lustre/osd-ldiskfs/osd_quota.c | 6 ++--- lustre/osd-ldiskfs/osd_scrub.c | 2 +- 6 files changed, 82 insertions(+), 40 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_compat.c b/lustre/osd-ldiskfs/osd_compat.c index 5a3757e..2fbb782 100644 --- a/lustre/osd-ldiskfs/osd_compat.c +++ b/lustre/osd-ldiskfs/osd_compat.c @@ -244,14 +244,14 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd, sprintf(name, DFID_NOBRACE, PFID(lu_object_fid(&obj->oo_dt.do_lu))); dentry = osd_child_dentry_by_inode(env, parent->d_inode, name, strlen(name)); - mutex_lock(&parent->d_inode->i_mutex); + inode_lock(parent->d_inode); rc = osd_ldiskfs_add_entry(info, osd, oh->ot_handle, dentry, obj->oo_inode, NULL); CDEBUG(D_INODE, "%s: add %s:%lu to remote parent %lu.\n", osd_name(osd), name, obj->oo_inode->i_ino, parent->d_inode->i_ino); ldiskfs_inc_count(oh->ot_handle, parent->d_inode); mark_inode_dirty(parent->d_inode); - mutex_unlock(&parent->d_inode->i_mutex); + inode_unlock(parent->d_inode); RETURN(rc); } @@ -287,11 +287,11 @@ int osd_delete_from_remote_parent(const struct lu_env *env, sprintf(name, DFID_NOBRACE, PFID(lu_object_fid(&obj->oo_dt.do_lu))); dentry = osd_child_dentry_by_inode(env, parent->d_inode, name, strlen(name)); - mutex_lock(&parent->d_inode->i_mutex); + inode_lock(parent->d_inode); bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de, NULL, NULL); if (IS_ERR(bh)) { - mutex_unlock(&parent->d_inode->i_mutex); + inode_unlock(parent->d_inode); RETURN(PTR_ERR(bh)); } CDEBUG(D_INODE, "%s: el %s:%lu to remote parent %lu.\n", osd_name(osd), @@ -331,7 +331,7 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti, sprintf(name, DFID_NOBRACE, PFID(fid)); dentry = osd_child_dentry_by_inode(oti->oti_env, parent->d_inode, name, strlen(name)); - mutex_lock(&parent->d_inode->i_mutex); + inode_lock(parent->d_inode); bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de, NULL, NULL); if (IS_ERR(bh)) { @@ -351,7 +351,7 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti, rc = 0; } } - mutex_unlock(&parent->d_inode->i_mutex); + inode_unlock(parent->d_inode); if (rc == 0) osd_add_oi_cache(oti, osd, id, fid); RETURN(rc); @@ -563,7 +563,7 @@ static int osd_obj_update_entry(struct osd_thread_info *info, child->d_name.len = strlen(name); ll_vfs_dq_init(parent); - mutex_lock(&parent->i_mutex); + inode_lock(parent); bh = osd_ldiskfs_find_entry(parent, &child->d_name, &de, NULL, NULL); if (IS_ERR(bh)) GOTO(out, rc = PTR_ERR(bh)); @@ -670,7 +670,7 @@ update: out: if (!IS_ERR(bh)) brelse(bh); - mutex_unlock(&parent->i_mutex); + inode_unlock(parent); return rc; } @@ -698,7 +698,7 @@ static int osd_obj_del_entry(struct osd_thread_info *info, child->d_inode = NULL; ll_vfs_dq_init(dir); - mutex_lock(&dir->i_mutex); + inode_lock(dir); bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL); if (IS_ERR(bh)) { rc = PTR_ERR(bh); @@ -706,7 +706,7 @@ static int osd_obj_del_entry(struct osd_thread_info *info, rc = ldiskfs_delete_entry(th, dir, de, bh); brelse(bh); } - mutex_unlock(&dir->i_mutex); + inode_unlock(dir); RETURN(rc); } @@ -753,9 +753,9 @@ static int osd_obj_add_entry(struct osd_thread_info *info, inode->i_ino++; ll_vfs_dq_init(dir->d_inode); - mutex_lock(&dir->d_inode->i_mutex); + inode_lock(dir->d_inode); rc = osd_ldiskfs_add_entry(info, osd, th, child, inode, NULL); - mutex_unlock(&dir->d_inode->i_mutex); + inode_unlock(dir->d_inode); RETURN(rc); } @@ -967,9 +967,9 @@ int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev, child->d_name.len = strlen(name); dir = d_seq->d_inode; - mutex_lock(&dir->i_mutex); + inode_lock(dir); bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL); - mutex_unlock(&dir->i_mutex); + inode_unlock(dir); if (IS_ERR(bh)) RETURN(PTR_ERR(bh)); @@ -1151,8 +1151,8 @@ int osd_obj_map_recover(struct osd_thread_info *info, ll_vfs_dq_init(src_parent); ll_vfs_dq_init(dir); - mutex_lock(&src_parent->i_mutex); - mutex_lock(&dir->i_mutex); + inode_lock(src_parent); + inode_lock(dir); bh = osd_ldiskfs_find_entry(dir, &tgt_child->d_name, &de, NULL, NULL); if (!IS_ERR(bh)) { /* XXX: If some other object occupied the same slot. And If such @@ -1173,8 +1173,8 @@ int osd_obj_map_recover(struct osd_thread_info *info, * * So keep it there before we have suitable solution. */ brelse(bh); - mutex_unlock(&dir->i_mutex); - mutex_unlock(&src_parent->i_mutex); + inode_unlock(dir); + inode_unlock(src_parent); ldiskfs_journal_stop(jh); rc = -EEXIST; @@ -1203,8 +1203,8 @@ int osd_obj_map_recover(struct osd_thread_info *info, GOTO(unlock, rc); unlock: - mutex_unlock(&dir->i_mutex); - mutex_unlock(&src_parent->i_mutex); + inode_unlock(dir); + inode_unlock(src_parent); ldiskfs_journal_stop(jh); return rc; } diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index b2d994d..377f5a8 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2034,8 +2034,7 @@ int osd_statfs(const struct lu_env *env, struct dt_device *d, statfs_pack(sfs, ksfs); if (unlikely(sb->s_flags & MS_RDONLY)) sfs->os_state |= OS_STATE_READONLY; - if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, - LDISKFS_FEATURE_INCOMPAT_EXTENTS)) + if (ldiskfs_has_feature_extents(sb)) sfs->os_maxbytes = sb->s_maxbytes; else sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes; @@ -2091,7 +2090,7 @@ static void osd_conf_get(const struct lu_env *env, param->ddp_max_nlink = LDISKFS_LINK_MAX; param->ddp_symlink_max = sb->s_blocksize; param->ddp_mount_type = LDD_MT_LDISKFS; - if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EXTENTS)) + if (ldiskfs_has_feature_extents(sb)) param->ddp_maxbytes = sb->s_maxbytes; else param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes; @@ -2118,7 +2117,7 @@ static void osd_conf_get(const struct lu_env *env, LDISKFS_XATTR_LEN(XATTR_NAME_MAX_LEN); #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE) - if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE)) + if (ldiskfs_has_feature_ea_inode(sb)) param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE - ea_overhead; else @@ -3819,7 +3818,9 @@ static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt, LASSERT(!dt_object_remote(dt)); LASSERT(inode->i_op != NULL); +#ifdef HAVE_IOP_XATTR LASSERT(inode->i_op->getxattr != NULL); +#endif if (strcmp(name, XATTR_NAME_LOV) == 0 || strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) @@ -4161,8 +4162,10 @@ static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt, LASSERT(!dt_object_remote(dt)); LASSERT(inode->i_op != NULL); - LASSERT(inode->i_op->removexattr != NULL); LASSERT(handle != NULL); +#ifdef HAVE_IOP_XATTR + LASSERT(inode->i_op->removexattr != NULL); +#endif osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET); @@ -6169,8 +6172,7 @@ osd_dirent_reinsert(const struct lu_env *env, struct osd_device *dev, struct osd_thread_info *info = osd_oti_get(env); ENTRY; - if (!LDISKFS_HAS_INCOMPAT_FEATURE(inode->i_sb, - LDISKFS_FEATURE_INCOMPAT_DIRDATA)) + if (!ldiskfs_has_feature_dirdata(inode->i_sb)) RETURN(0); /* There is enough space to hold the FID-in-dirent. */ @@ -7043,15 +7045,13 @@ static int osd_mount(const struct lu_env *env, GOTO(out_mnt, rc = -EROFS); } - if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb, - LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) { + if (!ldiskfs_has_feature_journal(o->od_mnt->mnt_sb)) { CERROR("%s: device %s is mounted w/o journal\n", name, dev); GOTO(out_mnt, rc = -EINVAL); } #ifdef LDISKFS_MOUNT_DIRDATA - if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb, - LDISKFS_FEATURE_INCOMPAT_DIRDATA)) + if (ldiskfs_has_feature_dirdata(o->od_mnt->mnt_sb)) LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA; else if (strstr(name, "MDT")) /* don't complain for MGT or OSTs */ CWARN("%s: device %s was upgraded from Lustre-1.x without " diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 80f611b..204c791 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -630,6 +630,22 @@ struct osd_thread_info { extern int ldiskfs_pdo; +#ifndef HAVE_VFS_SETXATTR +#define osd_setxattr(dentry, inode, name, buf, len, flag) \ + ((inode)->i_op->setxattr(dentry, name, buf, len, flag)) +#define osd_getxattr(dentry, inode, name, buf, len) \ + ((inode)->i_op->getxattr(dentry, name, buf, len)) +#define osd_removexattr(dentry, inode, name) \ + ((inode)->i_op->removexattr(dentry, name)) +#else /* HAVE_VFS_SETXATTR */ +#define osd_setxattr(dentry, inode, name, buf, len, flag) \ + __vfs_setxattr(dentry, inode, name, buf, len, flag) +#define osd_getxattr(dentry, inode, name, buf, len) \ + __vfs_getxattr(dentry, inode, name, buf, len) +#define osd_removexattr(dentry, inode, name) \ + __vfs_removexattr(dentry, name) +#endif /* !HAVE_VFS_SETXATTR */ + static inline int __osd_xattr_get(struct inode *inode, struct dentry *dentry, const char *name, void *buf, int len) { @@ -638,7 +654,7 @@ static inline int __osd_xattr_get(struct inode *inode, struct dentry *dentry, dentry->d_inode = inode; dentry->d_sb = inode->i_sb; - return inode->i_op->getxattr(dentry, name, buf, len); + return osd_getxattr(dentry, inode, name, buf, len); } static inline int __osd_xattr_set(struct osd_thread_info *info, @@ -650,7 +666,7 @@ static inline int __osd_xattr_set(struct osd_thread_info *info, ll_vfs_dq_init(inode); dentry->d_inode = inode; dentry->d_sb = inode->i_sb; - return inode->i_op->setxattr(dentry, name, buf, buflen, fl); + return osd_setxattr(dentry, inode, name, buf, buflen, fl); } #ifdef CONFIG_PROC_FS @@ -1311,4 +1327,33 @@ void osd_fini_iobuf(struct osd_device *d, struct osd_iobuf *iobuf); */ #define LDISKFS_XATTR_MAX_LARGE_EA_SIZE (1024 * 1024) +#ifdef LDISKFS_HAS_INCOMPAT_FEATURE + +# ifdef LDISKFS_FEATURE_INCOMPAT_EXTENTS +# define ldiskfs_has_feature_extents(sb) \ + LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EXTENTS) +# endif +# ifdef LDISKFS_FEATURE_INCOMPAT_EA_INODE +# define ldiskfs_has_feature_ea_inode(sb) \ + LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE) +# endif +# ifdef LDISKFS_FEATURE_INCOMPAT_DIRDATA +# define ldiskfs_has_feature_dirdata(sb) \ + LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_DIRDATA) +# endif +# ifdef LDISKFS_FEATURE_COMPAT_HAS_JOURNAL +# define ldiskfs_has_feature_journal(sb) \ + LDISKFS_HAS_COMPAT_FEATURE(sb, LDISKFS_FEATURE_COMPAT_HAS_JOURNAL) +# endif +# ifdef LDISKFS_FEATURE_RO_COMPAT_QUOTA +# define ldiskfs_has_feature_quota(sb) \ + LDISKFS_HAS_RO_COMPAT_FEATURE(sb, LDISKFS_FEATURE_RO_COMPAT_QUOTA) +# endif +# ifdef LDISKFS_FEATURE_RO_COMPAT_PROJECT +# define ldiskfs_has_feature_project(sb) \ + LDISKFS_HAS_RO_COMPAT_FEATURE(sb, LDISKFS_FEATURE_RO_COMPAT_PROJECT) +# endif + +#endif + #endif /* _OSD_INTERNAL_H */ diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index f76bef8..0f3aa61 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -1533,8 +1533,7 @@ static inline int osd_extents_enabled(struct super_block *sb, if (inode != NULL) { if (LDISKFS_I(inode)->i_flags & LDISKFS_EXTENTS_FL) return 1; - } else if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, - LDISKFS_FEATURE_INCOMPAT_EXTENTS)) { + } else if (ldiskfs_has_feature_extents(sb)) { return 1; } return 0; diff --git a/lustre/osd-ldiskfs/osd_quota.c b/lustre/osd-ldiskfs/osd_quota.c index 3edea2d..e0647c8 100644 --- a/lustre/osd-ldiskfs/osd_quota.c +++ b/lustre/osd-ldiskfs/osd_quota.c @@ -72,8 +72,7 @@ int osd_acct_obj_lookup(struct osd_thread_info *info, struct osd_device *osd, ENTRY; LASSERT(fid_is_acct(fid)); - if (!LDISKFS_HAS_RO_COMPAT_FEATURE(sb, - LDISKFS_FEATURE_RO_COMPAT_QUOTA)) + if (!ldiskfs_has_feature_quota(sb)) RETURN(-ENOENT); id->oii_gen = OSD_OII_NOGEN; @@ -88,8 +87,7 @@ int osd_acct_obj_lookup(struct osd_thread_info *info, struct osd_device *osd, break; case PRJQUOTA: #ifdef HAVE_PROJECT_QUOTA - if (LDISKFS_HAS_RO_COMPAT_FEATURE(sb, - LDISKFS_FEATURE_RO_COMPAT_PROJECT)) + if (ldiskfs_has_feature_project(sb)) id->oii_ino = le32_to_cpu(LDISKFS_SB(sb)->s_es->s_prj_quota_inum); else diff --git a/lustre/osd-ldiskfs/osd_scrub.c b/lustre/osd-ldiskfs/osd_scrub.c index 6f85f6f..8f8d06a 100644 --- a/lustre/osd-ldiskfs/osd_scrub.c +++ b/lustre/osd-ldiskfs/osd_scrub.c @@ -416,7 +416,7 @@ osd_scrub_convert_ff(struct osd_thread_info *info, struct osd_device *dev, if (rc == sizeof(*ff)) { /* 2) delete the old XATTR_NAME_FID */ ll_vfs_dq_init(inode); - rc = inode->i_op->removexattr(dentry, XATTR_NAME_FID); + rc = osd_removexattr(dentry, inode, XATTR_NAME_FID); if (rc) GOTO(stop, rc); -- 1.8.3.1