From 55ed739f7efb7029b02fe50999547f9aac40af72 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. Signed-off-by: Yang Sheng Change-Id: Ia3e907964d6321571f52e4c24a46a8ab64e4d056 Reviewed-on: https://review.whamcloud.com/31646 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bob Glossman Reviewed-by: Wang Shilong Reviewed-by: Oleg Drokin --- lustre/obdclass/lprocfs_status_server.c | 3 +- lustre/osd-ldiskfs/osd_compat.c | 42 ++++++++++++++-------------- lustre/osd-ldiskfs/osd_handler.c | 26 ++++++++--------- 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 +- 7 files changed, 87 insertions(+), 44 deletions(-) diff --git a/lustre/obdclass/lprocfs_status_server.c b/lustre/obdclass/lprocfs_status_server.c index bbd81a9..b4d0dd6 100644 --- a/lustre/obdclass/lprocfs_status_server.c +++ b/lustre/obdclass/lprocfs_status_server.c @@ -57,7 +57,8 @@ struct dentry *ldebugfs_add_symlink(const char *name, const char *target, dname.name = target; dname.len = strlen(dname.name); - dname.hash = ll_full_name_hash(parent, dname.name, dname.len); + dname.hash = ll_full_name_hash(debugfs_lustre_root, + dname.name, dname.len); parent = d_lookup(debugfs_lustre_root, &dname); if (!parent) return NULL; diff --git a/lustre/osd-ldiskfs/osd_compat.c b/lustre/osd-ldiskfs/osd_compat.c index 7712187..b7e6872 100644 --- a/lustre/osd-ldiskfs/osd_compat.c +++ b/lustre/osd-ldiskfs/osd_compat.c @@ -278,7 +278,7 @@ 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); if (!rc && S_ISDIR(obj->oo_inode->i_mode)) @@ -290,7 +290,7 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd, CDEBUG(D_INODE, "%s: create agent entry for %s: rc = %d\n", osd_name(osd), name, rc); mark_inode_dirty(parent->d_inode); - mutex_unlock(&parent->d_inode->i_mutex); + inode_unlock(parent->d_inode); RETURN(rc); } @@ -313,11 +313,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); rc = PTR_ERR(bh); if (unlikely(rc == -ENOENT)) rc = 0; @@ -327,7 +327,7 @@ int osd_delete_from_remote_parent(const struct lu_env *env, if (!rc && S_ISDIR(obj->oo_inode->i_mode)) ldiskfs_dec_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); brelse(bh); CDEBUG(D_INODE, "%s: remove agent entry for %s: rc = %d\n", osd_name(osd), name, rc); @@ -376,7 +376,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)) { @@ -396,7 +396,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); @@ -629,7 +629,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)); @@ -736,7 +736,7 @@ update: out: if (!IS_ERR(bh)) brelse(bh); - mutex_unlock(&parent->i_mutex); + inode_unlock(parent); return rc; } @@ -764,7 +764,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); @@ -772,7 +772,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); } @@ -819,9 +819,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); } @@ -1015,9 +1015,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)); @@ -1199,8 +1199,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 @@ -1221,8 +1221,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; @@ -1251,8 +1251,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 00ec3e5..d6a68b7 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2103,8 +2103,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; @@ -2160,7 +2159,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; @@ -2187,7 +2186,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 @@ -3909,7 +3908,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) @@ -4112,7 +4113,7 @@ static int osd_xattr_set_pfid(const struct lu_env *env, struct osd_object *obj, /* Remove old PFID EA entry firstly. */ ll_vfs_dq_init(inode); - rc = inode->i_op->removexattr(dentry, XATTR_NAME_FID); + rc = osd_removexattr(dentry, inode, XATTR_NAME_FID); if (rc == -ENODATA) { if ((fl & LU_XATTR_REPLACE) && !(fl & LU_XATTR_CREATE)) RETURN(rc); @@ -4384,8 +4385,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); @@ -4408,7 +4411,7 @@ static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt, ll_vfs_dq_init(inode); dentry->d_inode = inode; dentry->d_sb = inode->i_sb; - rc = inode->i_op->removexattr(dentry, name); + rc = osd_removexattr(dentry, inode, name); } osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET); @@ -6387,8 +6390,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. */ @@ -7264,15 +7266,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 b326ac6..4f1bffd 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -639,6 +639,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) { @@ -647,7 +663,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, @@ -659,7 +675,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 @@ -1344,4 +1360,33 @@ osd_index_backup(const struct lu_env *env, struct osd_device *osd, bool backup) &osd->od_index_backup_stop, backup); } +#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 914c934..9fc9aef 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -1550,8 +1550,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 8cf39a3..7e15425 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 118f5b7..0e83f0c 100644 --- a/lustre/osd-ldiskfs/osd_scrub.c +++ b/lustre/osd-ldiskfs/osd_scrub.c @@ -208,7 +208,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