From 817a8e6ee03324ca230a2b1b5e02c9d9021e7f9f Mon Sep 17 00:00:00 2001 From: James Simmons Date: Thu, 24 May 2018 21:16:18 -0400 Subject: [PATCH] LU-8066 llite: Preparation to move /proc/fs/lustre/llite to sysfs Add necessary infrastructure, add support for mountpoint registration in /sys/fs/lustre/llite This is a heavly modified version of Linux-commit: fd0d04ba85f95169106701397417360541a983b3 due to the large amount of changes to the OpenSFS/Intel branch. Change-Id: Ic9ca2044249a59dc79ebc86553c8b7ce7afbf710 Signed-off-by: Oleg Drokin Signed-off-by: Greg Kroah-Hartman Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/24031 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/llite/llite_internal.h | 20 ++++--- lustre/llite/llite_lib.c | 52 +++++++++------- lustre/llite/lproc_llite.c | 135 +++++++++++++++++++++++++++++------------- lustre/llite/super25.c | 27 +++------ 4 files changed, 145 insertions(+), 89 deletions(-) diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index a83b131..5c46e34 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -541,6 +541,9 @@ struct ll_sb_info { /* st_blksize returned by stat(2), when non-zero */ unsigned int ll_stat_blksize; + + struct kset ll_kset; /* sysfs object */ + struct completion ll_kobj_unregister; }; /* @@ -657,6 +660,8 @@ struct ll_file_data { }; extern struct proc_dir_entry *proc_lustre_fs_root; +void llite_tunables_unregister(void); +int llite_tunables_register(void); static inline struct inode *ll_info2i(struct ll_inode_info *lli) { @@ -710,20 +715,17 @@ void cl_put_grouplock(struct ll_grouplock *lg); /* llite/lproc_llite.c */ #ifdef CONFIG_PROC_FS -int lprocfs_ll_register_mountpoint(struct proc_dir_entry *parent, - struct super_block *sb); int lprocfs_ll_register_obd(struct super_block *sb, const char *obdname); -void lprocfs_ll_unregister_mountpoint(struct ll_sb_info *sbi); void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count); extern struct lprocfs_vars lprocfs_llite_obd_vars[]; #else -static inline int lprocfs_ll_register_mountpoint(struct proc_dir_entry *parent, - struct super_block *sb) {return 0; } -static inline int lprocfs_ll_register_obd(struct super_block *sb, - const char *obdname) {return 0; } -static inline void lprocfs_ll_unregister_mountpoint(struct ll_sb_info *sbi) {} +static inline int ll_debugs_register_super(struct super_block *sb, + const char *name) +{ return 0; } static void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count) {} #endif +int ll_debugfs_register_super(struct super_block *sb, const char *name); +void ll_debugfs_unregister_super(struct super_block *sb); enum { LPROC_LL_DIRTY_HITS, @@ -920,7 +922,7 @@ void ll_clear_inode(struct inode *inode); int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import); int ll_setattr(struct dentry *de, struct iattr *attr); int ll_statfs(struct dentry *de, struct kstatfs *sfs); -int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs, +int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs, u32 flags); int ll_update_inode(struct inode *inode, struct lustre_md *md); int ll_read_inode2(struct inode *inode, void *opaque); diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 5d116f6..ac31f08 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -738,7 +738,7 @@ static void client_common_put_super(struct super_block *sb) obd_disconnect(sbi->ll_dt_exp); sbi->ll_dt_exp = NULL; - lprocfs_ll_unregister_mountpoint(sbi); + ll_debugfs_unregister_super(sb); obd_fid_fini(sbi->ll_md_exp->exp_obd); obd_disconnect(sbi->ll_md_exp); @@ -963,6 +963,8 @@ void ll_lli_init(struct ll_inode_info *lli) memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid)); } +#define MAX_STRING_SIZE 128 + #ifndef HAVE_SUPER_SETUP_BDI_NAME #define LSI_BDI_INITIALIZED 0x00400000 @@ -971,8 +973,6 @@ void ll_lli_init(struct ll_inode_info *lli) # define BDI_CAP_MAP_COPY 0 #endif -#define MAX_STRING_SIZE 128 - static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...) { struct lustre_sb_info *lsi = s2lsi(sb); @@ -1009,11 +1009,14 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) struct config_llog_instance *cfg; /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */ const int instlen = sizeof(cfg->cfg_instance) * 2 + 2; - int md_len = 0; - int dt_len = 0; - int err; - ENTRY; + char name[MAX_STRING_SIZE]; + int md_len = 0; + int dt_len = 0; + char *ptr; + int len; + int err; + ENTRY; CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb); try_module_get(THIS_MODULE); @@ -1039,16 +1042,24 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */ sb->s_d_op = &ll_d_ops; #endif + /* Get fsname */ + len = strlen(lsi->lsi_lmd->lmd_profile); + ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-'); + if (ptr && (strcmp(ptr, "-client") == 0)) + len -= 7; - /* Call lprocfs_ll_register_mountpoint() before lustre_process_log() - * so that "llite.*.*" params can be processed correctly. */ - if (proc_lustre_fs_root != NULL) { - err = lprocfs_ll_register_mountpoint(proc_lustre_fs_root, sb); - if (err < 0) { - CERROR("%s: could not register mountpoint in llite: " - "rc = %d\n", ll_get_fsname(sb, NULL, 0), err); - err = 0; - } + /* Mount info */ + snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len, + lsi->lsi_lmd->lmd_profile, sb); + + /* Call ll_debugfs_register_super() before lustre_process_log() + * so that "llite.*.*" params can be processed correctly. + */ + err = ll_debugfs_register_super(sb, name); + if (err < 0) { + CERROR("%s: could not register mountpoint in llite: rc = %d\n", + ll_get_fsname(sb, NULL, 0), err); + err = 0; } /* Generate a string unique to this super, in case some joker tries @@ -1095,7 +1106,7 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) out_proc: if (err < 0) - lprocfs_ll_unregister_mountpoint(sbi); + ll_debugfs_unregister_super(sb); out_free: if (md) OBD_FREE(md, md_len); @@ -1778,10 +1789,9 @@ int ll_setattr(struct dentry *de, struct iattr *attr) return ll_setattr_raw(de, attr, false); } -int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs, +int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs, u32 flags) { - struct ll_sb_info *sbi = ll_s2sbi(sb); struct obd_statfs obd_osfs; time64_t max_age; int rc; @@ -1795,7 +1805,7 @@ int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs, RETURN(rc); } - osfs->os_type = sb->s_magic; + osfs->os_type = LL_SUPER_MAGIC; CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n", osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files); @@ -1841,7 +1851,7 @@ int ll_statfs(struct dentry *de, struct kstatfs *sfs) ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1); /* Some amount of caching on the client is allowed */ - rc = ll_statfs_internal(sb, &osfs, 0); + rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, 0); if (rc) return rc; diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index c84394ba..91f003c 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -44,6 +44,38 @@ #include "vvp_internal.h" struct proc_dir_entry *proc_lustre_fs_root; +static struct kobject *llite_kobj; + +int llite_tunables_register(void) +{ + int rc = 0; + + proc_lustre_fs_root = lprocfs_register("llite", proc_lustre_root, + NULL, NULL); + if (IS_ERR(proc_lustre_fs_root)) { + rc = PTR_ERR(proc_lustre_fs_root); + CERROR("cannot register '/proc/fs/lustre/llite': rc = %d\n", + rc); + proc_lustre_fs_root = NULL; + return rc; + } + + llite_kobj = class_setup_tunables("llite"); + if (IS_ERR(llite_kobj)) { + rc = PTR_ERR(llite_kobj); + llite_kobj = NULL; + } + + return rc; +} + +void llite_tunables_unregister(void) +{ + if (llite_kobj) + kobject_put(llite_kobj); + + lprocfs_remove(&proc_lustre_fs_root); +} #ifdef CONFIG_PROC_FS /* /proc/lustre/llite mount point registration */ @@ -59,7 +91,7 @@ static int ll_blksize_seq_show(struct seq_file *m, void *v) int rc; LASSERT(sb != NULL); - rc = ll_statfs_internal(sb, &osfs, OBD_STATFS_NODELAY); + rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY); if (!rc) seq_printf(m, "%u\n", osfs.os_bsize); return rc; @@ -104,7 +136,7 @@ static int ll_kbytestotal_seq_show(struct seq_file *m, void *v) int rc; LASSERT(sb != NULL); - rc = ll_statfs_internal(sb, &osfs, OBD_STATFS_NODELAY); + rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY); if (!rc) { __u32 blk_size = osfs.os_bsize >> 10; __u64 result = osfs.os_blocks; @@ -125,7 +157,7 @@ static int ll_kbytesfree_seq_show(struct seq_file *m, void *v) int rc; LASSERT(sb != NULL); - rc = ll_statfs_internal(sb, &osfs, OBD_STATFS_NODELAY); + rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY); if (!rc) { __u32 blk_size = osfs.os_bsize >> 10; __u64 result = osfs.os_bfree; @@ -146,7 +178,7 @@ static int ll_kbytesavail_seq_show(struct seq_file *m, void *v) int rc; LASSERT(sb != NULL); - rc = ll_statfs_internal(sb, &osfs, OBD_STATFS_NODELAY); + rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY); if (!rc) { __u32 blk_size = osfs.os_bsize >> 10; __u64 result = osfs.os_bavail; @@ -167,7 +199,7 @@ static int ll_filestotal_seq_show(struct seq_file *m, void *v) int rc; LASSERT(sb != NULL); - rc = ll_statfs_internal(sb, &osfs, OBD_STATFS_NODELAY); + rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY); if (!rc) seq_printf(m, "%llu\n", osfs.os_files); return rc; @@ -181,7 +213,7 @@ static int ll_filesfree_seq_show(struct seq_file *m, void *v) int rc; LASSERT(sb != NULL); - rc = ll_statfs_internal(sb, &osfs, OBD_STATFS_NODELAY); + rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_NODELAY); if (!rc) seq_printf(m, "%llu\n", osfs.os_ffree); return rc; @@ -202,9 +234,10 @@ LPROC_SEQ_FOPS_RO(ll_client_type); static int ll_fstype_seq_show(struct seq_file *m, void *v) { struct super_block *sb = m->private; + struct ll_sb_info *sbi = ll_s2sbi(sb); LASSERT(sb != NULL); - seq_printf(m, "%s\n", sb->s_type->name); + seq_printf(m, "%s\n", sbi->ll_mnt.mnt->mnt_sb->s_type->name); return 0; } LPROC_SEQ_FOPS_RO(ll_fstype); @@ -1166,6 +1199,23 @@ struct lprocfs_vars lprocfs_llite_obd_vars[] = { #define MAX_STRING_SIZE 128 +static struct attribute *llite_attrs[] = { + NULL, +}; + +static void llite_kobj_release(struct kobject *kobj) +{ + struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, + ll_kset.kobj); + complete(&sbi->ll_kobj_unregister); +} + +static struct kobj_type llite_ktype = { + .default_attrs = llite_attrs, + .sysfs_ops = &lustre_sysfs_ops, + .release = llite_kobj_release, +}; + static const struct llite_file_opcode { __u32 opcode; __u32 type; @@ -1254,34 +1304,20 @@ static const char *ra_stat_string[] = { LPROC_SEQ_FOPS_RO_TYPE(llite, name); LPROC_SEQ_FOPS_RO_TYPE(llite, uuid); -int lprocfs_ll_register_mountpoint(struct proc_dir_entry *parent, - struct super_block *sb) +int ll_debugfs_register_super(struct super_block *sb, const char *name) { - struct lprocfs_vars lvars[2]; - struct lustre_sb_info *lsi = s2lsi(sb); struct ll_sb_info *sbi = ll_s2sbi(sb); - char name[MAX_STRING_SIZE + 1], *ptr; - int err, id, len, rc; - ENTRY; + struct lprocfs_vars lvars[2]; + int err, id, rc; + ENTRY; memset(lvars, 0, sizeof(lvars)); - - name[MAX_STRING_SIZE] = '\0'; lvars[0].name = name; LASSERT(sbi != NULL); - /* Get fsname */ - len = strlen(lsi->lsi_lmd->lmd_profile); - ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-'); - if (ptr && (strcmp(ptr, "-client") == 0)) - len -= 7; - - /* Mount info */ - snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len, - lsi->lsi_lmd->lmd_profile, sb); - - sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL); + sbi->ll_proc_root = lprocfs_register(name, proc_lustre_fs_root, + NULL, NULL); if (IS_ERR(sbi->ll_proc_root)) { err = PTR_ERR(sbi->ll_proc_root); sbi->ll_proc_root = NULL; @@ -1312,7 +1348,8 @@ int lprocfs_ll_register_mountpoint(struct proc_dir_entry *parent, sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES, LPROCFS_STATS_FLAG_NONE); if (sbi->ll_stats == NULL) - GOTO(out, err = -ENOMEM); + GOTO(out_proc, err = -ENOMEM); + /* do counter init */ for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) { __u32 type = llite_opcode_table[id].type; @@ -1328,14 +1365,15 @@ int lprocfs_ll_register_mountpoint(struct proc_dir_entry *parent, (type & LPROCFS_CNTR_AVGMINMAX), llite_opcode_table[id].opname, ptr); } + err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats); if (err) - GOTO(out, err); + GOTO(out_stats, err); sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string), LPROCFS_STATS_FLAG_NONE); if (sbi->ll_ra_stats == NULL) - GOTO(out, err = -ENOMEM); + GOTO(out_stats, err = -ENOMEM); for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++) lprocfs_counter_init(sbi->ll_ra_stats, id, 0, @@ -1343,19 +1381,31 @@ int lprocfs_ll_register_mountpoint(struct proc_dir_entry *parent, err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats", sbi->ll_ra_stats); if (err) - GOTO(out, err); - + GOTO(out_ra_stats, err); err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb); if (err) - GOTO(out, err); + GOTO(out_ra_stats, err); + + /* Yes we also register sysfs mount kset here as well */ + sbi->ll_kset.kobj.parent = llite_kobj; + sbi->ll_kset.kobj.ktype = &llite_ktype; + init_completion(&sbi->ll_kobj_unregister); + err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name); + if (err) + GOTO(out_ra_stats, err); + + err = kset_register(&sbi->ll_kset); + if (err) + GOTO(out_ra_stats, err); + RETURN(0); +out_ra_stats: + lprocfs_free_stats(&sbi->ll_ra_stats); +out_stats: + lprocfs_free_stats(&sbi->ll_stats); +out_proc: + lprocfs_remove(&sbi->ll_proc_root); -out: - if (err) { - lprocfs_remove(&sbi->ll_proc_root); - lprocfs_free_stats(&sbi->ll_ra_stats); - lprocfs_free_stats(&sbi->ll_stats); - } RETURN(err); } @@ -1408,8 +1458,13 @@ out: RETURN(err); } -void lprocfs_ll_unregister_mountpoint(struct ll_sb_info *sbi) +void ll_debugfs_unregister_super(struct super_block *sb) { + struct ll_sb_info *sbi = ll_s2sbi(sb); + + kset_unregister(&sbi->ll_kset); + wait_for_completion(&sbi->ll_kobj_unregister); + if (sbi->ll_proc_root) { lprocfs_remove(&sbi->ll_proc_root); lprocfs_free_stats(&sbi->ll_ra_stats); diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c index 0ce2675..32d1ec9 100644 --- a/lustre/llite/super25.c +++ b/lustre/llite/super25.c @@ -100,7 +100,6 @@ void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg)); static int __init lustre_init(void) { - struct proc_dir_entry *entry; struct lnet_process_id lnet_id; struct timespec64 ts; int i, rc, seed[2]; @@ -125,15 +124,9 @@ static int __init lustre_init(void) if (ll_file_data_slab == NULL) GOTO(out_cache, rc = -ENOMEM); - entry = lprocfs_register("llite", proc_lustre_root, NULL, NULL); - if (IS_ERR(entry)) { - rc = PTR_ERR(entry); - CERROR("cannot register '/proc/fs/lustre/llite': rc = %d\n", - rc); + rc = llite_tunables_register(); + if (rc) GOTO(out_cache, rc); - } - - proc_lustre_fs_root = entry; cfs_get_random_bytes(seed, sizeof(seed)); @@ -152,7 +145,7 @@ static int __init lustre_init(void) rc = vvp_global_init(); if (rc != 0) - GOTO(out_proc, rc); + GOTO(out_tunables, rc); cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck, LCT_REMEMBER | LCT_NOREF); @@ -175,15 +168,11 @@ out_inode_fini_env: cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck); out_vvp: vvp_global_fini(); -out_proc: - lprocfs_remove(&proc_lustre_fs_root); +out_tunables: + llite_tunables_unregister(); out_cache: - if (ll_inode_cachep != NULL) - kmem_cache_destroy(ll_inode_cachep); - - if (ll_file_data_slab != NULL) - kmem_cache_destroy(ll_file_data_slab); - + kmem_cache_destroy(ll_inode_cachep); + kmem_cache_destroy(ll_file_data_slab); return rc; } @@ -193,7 +182,7 @@ static void __exit lustre_exit(void) lustre_register_kill_super_cb(NULL); lustre_register_client_process_config(NULL); - lprocfs_remove(&proc_lustre_fs_root); + llite_tunables_unregister(); ll_xattr_fini(); cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck); -- 1.8.3.1