From c2774e1984592ee2a7c8d308f44e3a6034a6b18d Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 13 Mar 2019 10:03:28 -0400 Subject: [PATCH] LU-8066 llite: don't use class_setup_tunables() llite is very different from the other types of lustre devices. Since this is the case llite should register independently. Doing this allows us to cleanup the debugfs registering in the release function of struct kobj_type. Also fix the improper handling to linking it to the lustre_kset. Use kset_get() and kset_put() to properly keep the reference count for the lustre_kset. This lastly provides flexibility for making changes to class_setup_tunables(). Change-Id: I676159caa7885485fdd57c908123214f68514227 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/34292 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Ben Evans Reviewed-by: Oleg Drokin --- lustre/llite/lproc_llite.c | 49 ++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index a57a625..ac3cfdb 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -46,18 +46,40 @@ static struct kobject *llite_kobj; static struct dentry *llite_root; +static void llite_kobj_release(struct kobject *kobj) +{ + if (!IS_ERR_OR_NULL(llite_root)) { + debugfs_remove(llite_root); + llite_root = NULL; + } + + kfree(kobj); +} + +static struct kobj_type llite_kobj_ktype = { + .release = llite_kobj_release, + .sysfs_ops = &lustre_sysfs_ops, +}; + int llite_tunables_register(void) { - int rc = 0; + int rc; - llite_kobj = class_setup_tunables("llite"); - if (IS_ERR(llite_kobj)) - return PTR_ERR(llite_kobj); + llite_kobj = kzalloc(sizeof(*llite_kobj), GFP_KERNEL); + if (!llite_kobj) + return -ENOMEM; + + llite_kobj->kset = lustre_kset; + rc = kobject_init_and_add(llite_kobj, &llite_kobj_ktype, + &lustre_kset->kobj, "%s", "llite"); + if (rc) + goto free_kobj; llite_root = debugfs_create_dir("llite", debugfs_lustre_root); if (IS_ERR_OR_NULL(llite_root)) { rc = llite_root ? PTR_ERR(llite_root) : -ENOMEM; llite_root = NULL; +free_kobj: kobject_put(llite_kobj); llite_kobj = NULL; } @@ -67,15 +89,8 @@ int llite_tunables_register(void) void llite_tunables_unregister(void) { - if (llite_kobj) { - kobject_put(llite_kobj); - llite_kobj = NULL; - } - - if (!IS_ERR_OR_NULL(llite_root)) { - debugfs_remove(llite_root); - llite_root = NULL; - } + kobject_put(llite_kobj); + llite_kobj = NULL; } /* /lustre/llite mount point registration */ @@ -1258,17 +1273,17 @@ static struct attribute *llite_attrs[] = { NULL, }; -static void llite_kobj_release(struct kobject *kobj) +static void sbi_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 = { +static struct kobj_type sbi_ktype = { .default_attrs = llite_attrs, .sysfs_ops = &lustre_sysfs_ops, - .release = llite_kobj_release, + .release = sbi_kobj_release, }; static const struct llite_file_opcode { @@ -1443,7 +1458,7 @@ int ll_debugfs_register_super(struct super_block *sb, const char *name) out_ll_kset: /* Yes we also register sysfs mount kset here as well */ sbi->ll_kset.kobj.parent = llite_kobj; - sbi->ll_kset.kobj.ktype = &llite_ktype; + sbi->ll_kset.kobj.ktype = &sbi_ktype; init_completion(&sbi->ll_kobj_unregister); err = kobject_set_name(&sbi->ll_kset.kobj, "%s", name); if (err) -- 1.8.3.1