Whamcloud - gitweb
LU-8066 obd: migrate to ksets 48/28948/11
authorJames Simmons <uja.ornl@yahoo.com>
Mon, 9 Oct 2017 14:39:23 +0000 (10:39 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 1 Nov 2017 04:57:11 +0000 (04:57 +0000)
Lustre's sysfs only uses kobjects but with the introduction of
ksets we can use functionality like kset_find_kobj() and uevents.
Currently lustre is layered as lustre_kobj -> class -> obd device.
This patch changes the obd devices and the top level lustre_kobj
into ksets. The class level is kept as kobjects but are bound to
the top level lustre kset so they searchable and uevents can be
created for them. Also much of the class functionality can be
replaced with what ksets can do. With obd devices now ksets we
can replace lprocfs_kset_register with lprocfs_obd_setup. Some
of the sysfs attributes were not cleaned up so added proper
removal. Reversed what the default sysfs attributes are. This
will be needed for the replacement functionality for
class_process_proc_param().

Change-Id: I3ced5f69ace6a0a9a6bc51957f20a0caecdbafc9
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/28948
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Sonia Sharma <sonia.sharma@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
16 files changed:
libcfs/autoconf/lustre-libcfs.m4
libcfs/libcfs/linux/linux-prim.c
lustre/include/lprocfs_status.h
lustre/include/obd.h
lustre/ldlm/ldlm_lockd.c
lustre/mdt/mdt_mds.c
lustre/mgs/lproc_mgs.c
lustre/mgs/mgs_handler.c
lustre/mgs/mgs_internal.h
lustre/obdclass/genops.c
lustre/obdclass/linux/linux-module.c
lustre/obdclass/linux/linux-sysctl.c
lustre/obdclass/lprocfs_status.c
lustre/obdclass/lprocfs_status_server.c
lustre/ost/ost_handler.c
lustre/ptlrpc/lproc_ptlrpc.c

index f9447df..3d8d7b0 100644 (file)
@@ -642,6 +642,16 @@ crypto_hash_helpers, [
 ]) # LIBCFS_CRYPTO_HASH_HELPERS
 
 #
+# Kernerl version 4.5-rc3 commit 2fe829aca9d7bed5fd6b49c6a1452e5e486b6cc3dd
+# made kset_find_obj() exportable to modules
+#
+AC_DEFUN([LIBCFS_EXPORT_KSET_FIND_OBJ], [
+LB_CHECK_EXPORT([kset_find_obj], [lib/kobject.c],
+       [AC_DEFINE(HAVE_KSET_FIND_OBJ, 1,
+               [kset_find_obj is exported by the kernel])])
+]) # LIBCFS_EXPORT_KSET_FIND_OBJ
+
+#
 # LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
 #
 # linux 4.6 kernel changed stacktrace_ops address to return an int
@@ -806,6 +816,7 @@ LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK
 LIBCFS_FPU_API
 # 4.5
 LIBCFS_CRYPTO_HASH_HELPERS
+LIBCFS_EXPORT_KSET_FIND_OBJ
 # 4.6
 LIBCFS_STACKTRACE_OPS_ADDRESS_RETURN_INT
 LIBCFS_GET_USER_PAGES_6ARG
index 1d07692..36fe0d2 100644 (file)
@@ -96,6 +96,28 @@ time64_t ktime_get_seconds(void)
 EXPORT_SYMBOL(ktime_get_seconds);
 #endif /* HAVE_KTIME_GET_SECONDS */
 
+#ifndef HAVE_KSET_FIND_OBJ
+struct kobject *kset_find_obj(struct kset *kset, const char *name)
+{
+       struct kobject *ret = NULL;
+       struct kobject *k;
+
+       spin_lock(&kset->list_lock);
+
+       list_for_each_entry(k, &kset->list, entry) {
+               if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
+                       if (kref_get_unless_zero(&k->kref))
+                               ret = k;
+                       break;
+               }
+       }
+
+       spin_unlock(&kset->list_lock);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(kset_find_obj);
+#endif
+
 sigset_t
 cfs_block_allsigs(void)
 {
index c119ce5..8656a08 100644 (file)
@@ -358,7 +358,7 @@ enum lprocfs_extra_opc {
 /* class_obd.c */
 extern struct proc_dir_entry *proc_lustre_root;
 extern struct dentry *debugfs_lustre_root;
-extern struct kobject *lustre_kobj;
+extern struct kset *lustre_kset;
 
 struct obd_device;
 struct obd_histogram;
@@ -470,8 +470,6 @@ struct nid_stat;
 extern int lprocfs_add_clear_entry(struct obd_device * obd,
                                   struct proc_dir_entry *entry);
 #ifdef HAVE_SERVER_SUPPORT
-void lprocfs_kset_unregister(struct obd_device *obj, struct kset *kset);
-int lprocfs_kset_register(struct obd_device *obd, struct kset **kset);
 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
 extern int lprocfs_exp_cleanup(struct obd_export *exp);
 #else
@@ -736,6 +734,7 @@ struct lustre_attr {
 #define LUSTRE_ATTR(name, mode, show, store) \
 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
 
+#define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
 
index 61aafdd..be2bec4 100644 (file)
@@ -33,7 +33,9 @@
 #ifndef __OBD_H
 #define __OBD_H
 
+#include <linux/kobject.h>
 #include <linux/spinlock.h>
+#include <linux/sysfs.h>
 
 #include <uapi/linux/lustre/lustre_idl.h>
 #include <lustre_lib.h>
@@ -105,7 +107,8 @@ struct obd_type {
        int                      typ_refcnt;
        struct lu_device_type   *typ_lu;
        spinlock_t               obd_type_lock;
-       struct kobject          *typ_kobj;
+       struct kobject           typ_kobj;
+       struct completion        typ_kobj_unregister;
 };
 
 struct brw_page {
@@ -694,7 +697,8 @@ struct obd_device {
        struct proc_dir_entry   *obd_proc_exports_entry;
        struct proc_dir_entry   *obd_svc_procroot;
        struct lprocfs_stats    *obd_svc_stats;
-       struct attribute_group  *obd_attrs;
+       struct attribute_group           obd_attrs_group;
+       struct attribute               **obd_attrs;
        struct lprocfs_vars     *obd_vars;
        atomic_t                obd_evict_inprogress;
        wait_queue_head_t       obd_evict_inprogress_waitq;
@@ -713,8 +717,9 @@ struct obd_device {
         * List of outstanding class_incref()'s fo this OBD. For debugging. */
        struct lu_ref                   obd_reference;
 
-       struct kobject          obd_kobj; /* sysfs object */
-       struct completion       obd_kobj_unregister;
+       struct kset                     obd_kset; /* sysfs object collection */
+       struct kobj_type                obd_ktype;
+       struct completion               obd_kobj_unregister;
 };
 
 /* get/set_info keys */
index ec17ae1..5d3b781 100644 (file)
@@ -2944,7 +2944,7 @@ static int ldlm_setup(void)
         if (ldlm_state == NULL)
                 RETURN(-ENOMEM);
 
-       ldlm_kobj = kobject_create_and_add("ldlm", lustre_kobj);
+       ldlm_kobj = kobject_create_and_add("ldlm", &lustre_kset->kobj);
        if (!ldlm_kobj)
                GOTO(out, -ENOMEM);
 
@@ -3152,8 +3152,10 @@ static int ldlm_cleanup(void)
                kset_unregister(ldlm_ns_kset);
        if (ldlm_svc_kset)
                kset_unregister(ldlm_svc_kset);
-       if (ldlm_kobj)
+       if (ldlm_kobj) {
+               sysfs_remove_group(ldlm_kobj, &ldlm_attr_group);
                kobject_put(ldlm_kobj);
+       }
 
        ldlm_proc_cleanup();
 
index a06e102..2b12f84 100644 (file)
@@ -65,7 +65,6 @@ struct mds_device {
        struct ptlrpc_service   *mds_mdss_service;
        struct ptlrpc_service   *mds_fld_service;
        struct mutex             mds_health_mutex;
-       struct kset             *mds_kset;
 };
 
 /*
@@ -184,7 +183,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = ptlrpc_hpreq_handler,
                },
        };
-       m->mds_regular_service = ptlrpc_register_service(&conf, m->mds_kset,
+       m->mds_regular_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                         procfs_entry);
        if (IS_ERR(m->mds_regular_service)) {
                rc = PTR_ERR(m->mds_regular_service);
@@ -228,7 +227,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_req_printer         = target_print_req,
                },
        };
-       m->mds_readpage_service = ptlrpc_register_service(&conf, m->mds_kset,
+       m->mds_readpage_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                          procfs_entry);
        if (IS_ERR(m->mds_readpage_service)) {
                rc = PTR_ERR(m->mds_readpage_service);
@@ -276,7 +275,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_setattr_service = ptlrpc_register_service(&conf, m->mds_kset,
+       m->mds_setattr_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                         procfs_entry);
        if (IS_ERR(m->mds_setattr_service)) {
                rc = PTR_ERR(m->mds_setattr_service);
@@ -322,7 +321,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_out_service = ptlrpc_register_service(&conf, m->mds_kset,
+       m->mds_out_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                     procfs_entry);
        if (IS_ERR(m->mds_out_service)) {
                rc = PTR_ERR(m->mds_out_service);
@@ -358,7 +357,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_mdsc_service = ptlrpc_register_service(&conf, m->mds_kset,
+       m->mds_mdsc_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                      procfs_entry);
        if (IS_ERR(m->mds_mdsc_service)) {
                rc = PTR_ERR(m->mds_mdsc_service);
@@ -395,7 +394,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_mdss_service = ptlrpc_register_service(&conf, m->mds_kset,
+       m->mds_mdss_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                      procfs_entry);
        if (IS_ERR(m->mds_mdss_service)) {
                rc = PTR_ERR(m->mds_mdss_service);
@@ -430,7 +429,7 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_fld_service = ptlrpc_register_service(&conf, m->mds_kset,
+       m->mds_fld_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                     procfs_entry);
        if (IS_ERR(m->mds_fld_service)) {
                rc = PTR_ERR(m->mds_fld_service);
@@ -461,7 +460,7 @@ static struct lu_device *mds_device_fini(const struct lu_env *env,
        ENTRY;
 
        mds_stop_ptlrpc_service(m);
-       lprocfs_kset_unregister(obd, m->mds_kset);
+       lprocfs_obd_cleanup(obd);
        RETURN(NULL);
 }
 
@@ -499,7 +498,7 @@ static struct lu_device *mds_device_alloc(const struct lu_env *env,
        /* set this lu_device to obd, because error handling need it */
        obd->obd_lu_dev = l;
 
-       rc = lprocfs_kset_register(obd, &m->mds_kset);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc != 0) {
                mds_device_free(env, l);
                l = ERR_PTR(rc);
@@ -510,7 +509,7 @@ static struct lu_device *mds_device_alloc(const struct lu_env *env,
 
        rc = mds_start_ptlrpc_service(m);
        if (rc != 0) {
-               lprocfs_kset_unregister(obd, m->mds_kset);
+               lprocfs_obd_cleanup(obd);
                mds_device_free(env, l);
                l = ERR_PTR(rc);
                return l;
index 7fafade..b1e18ec 100644 (file)
@@ -227,7 +227,7 @@ int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
        int                rc;
 
        obd->obd_vars = lprocfs_mgs_obd_vars;
-       rc = lprocfs_kset_register(obd, &mgs->mgs_kset);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc != 0)
                GOTO(out, rc);
 
@@ -309,7 +309,7 @@ void lproc_mgs_cleanup(struct mgs_device *mgs)
        }
 
         lprocfs_free_per_client_stats(obd);
-       lprocfs_kset_unregister(obd, mgs->mgs_kset);
+       lprocfs_obd_cleanup(obd);
         lprocfs_free_obd_stats(obd);
         lprocfs_free_md_stats(obd);
 }
index d50b594..392fee3 100644 (file)
@@ -1367,7 +1367,7 @@ static int mgs_init0(const struct lu_env *env, struct mgs_device *mgs,
        };
 
        /* Start the service threads */
-       mgs->mgs_service = ptlrpc_register_service(&conf, mgs->mgs_kset,
+       mgs->mgs_service = ptlrpc_register_service(&conf, &obd->obd_kset,
                                                   obd->obd_proc_entry);
        if (IS_ERR(mgs->mgs_service)) {
                rc = PTR_ERR(mgs->mgs_service);
index d9e95d6..eb5a955 100644 (file)
@@ -179,7 +179,6 @@ struct mgs_device {
        struct proc_dir_entry           *mgs_proc_mntdev;
        time64_t                         mgs_start_time;
        struct obd_device               *mgs_obd;
-       struct kset                     *mgs_kset;
        struct local_oid_storage        *mgs_los;
        struct mutex                     mgs_mutex;
        struct mutex                     mgs_health_mutex;
index 175e391..8f2c64b 100644 (file)
@@ -163,6 +163,19 @@ void class_put_type(struct obd_type *type)
        spin_unlock(&type->obd_type_lock);
 }
 
+static void class_sysfs_release(struct kobject *kobj)
+{
+       struct obd_type *type = container_of(kobj, struct obd_type,
+                                            typ_kobj);
+
+       complete(&type->typ_kobj_unregister);
+}
+
+static struct kobj_type class_ktype = {
+       .sysfs_ops      = &lustre_sysfs_ops,
+       .release        = class_sysfs_release,
+};
+
 #define CLASS_MAX_NAME 1024
 
 int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
@@ -214,28 +227,29 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
                }
        }
 #endif
-       type->typ_kobj = kobject_create_and_add(type->typ_name, lustre_kobj);
-       if (!type->typ_kobj) {
-               rc = -ENOMEM;
+       type->typ_kobj.kset = lustre_kset;
+       init_completion(&type->typ_kobj_unregister);
+       rc = kobject_init_and_add(&type->typ_kobj, &class_ktype,
+                                 &lustre_kset->kobj, "%s", type->typ_name);
+       if (rc)
                GOTO(failed, rc);
-       }
 
-        if (ldt != NULL) {
-                type->typ_lu = ldt;
-                rc = lu_device_type_init(ldt);
-                if (rc != 0)
-                        GOTO (failed, rc);
-        }
+       if (ldt) {
+               type->typ_lu = ldt;
+               rc = lu_device_type_init(ldt);
+               if (rc) {
+                       kobject_put(&type->typ_kobj);
+                       GOTO(failed, rc);
+               }
+       }
 
        spin_lock(&obd_types_lock);
        list_add(&type->typ_chain, &obd_types);
        spin_unlock(&obd_types_lock);
 
-        RETURN (0);
+       RETURN(0);
 
 failed:
-       if (type->typ_kobj)
-               kobject_put(type->typ_kobj);
        if (type->typ_name != NULL) {
 #ifdef CONFIG_PROC_FS
                if (type->typ_procroot != NULL)
@@ -271,8 +285,8 @@ int class_unregister_type(const char *name)
                 RETURN(-EBUSY);
         }
 
-       if (type->typ_kobj)
-               kobject_put(type->typ_kobj);
+       kobject_put(&type->typ_kobj);
+       wait_for_completion(&type->typ_kobj_unregister);
 
        /* we do not use type->typ_procroot as for compatibility purposes
         * other modules can share names (i.e. lod can use lov entry). so
index c59c9a7..6441c03 100644 (file)
@@ -512,8 +512,8 @@ static const struct file_operations obd_device_list_fops = {
         .release = seq_release,
 };
 
-struct kobject *lustre_kobj;
-EXPORT_SYMBOL_GPL(lustre_kobj);
+struct kset *lustre_kset;
+EXPORT_SYMBOL_GPL(lustre_kset);
 
 static struct attribute_group lustre_attr_group = {
        .attrs = lustre_attrs,
@@ -526,26 +526,26 @@ int class_procfs_init(void)
        int rc = -ENOMEM;
        ENTRY;
 
-       lustre_kobj = kobject_create_and_add("lustre", fs_kobj);
-       if (lustre_kobj == NULL)
+       lustre_kset = kset_create_and_add("lustre", NULL, fs_kobj);
+       if (!lustre_kset)
                goto out;
 
        /* Create the files associated with this kobject */
-       rc = sysfs_create_group(lustre_kobj, &lustre_attr_group);
+       rc = sysfs_create_group(&lustre_kset->kobj, &lustre_attr_group);
        if (rc) {
-               kobject_put(lustre_kobj);
+               kset_unregister(lustre_kset);
                goto out;
        }
 
        rc = obd_sysctl_init();
        if (rc) {
-               kobject_put(lustre_kobj);
+               kset_unregister(lustre_kset);
                goto out;
        }
 
        rc = jobid_cache_init();
        if (rc) {
-               kobject_put(lustre_kobj);
+               kset_unregister(lustre_kset);
                goto out;
        }
 
@@ -554,7 +554,7 @@ int class_procfs_init(void)
                rc = debugfs_lustre_root ? PTR_ERR(debugfs_lustre_root)
                                         : -ENOMEM;
                debugfs_lustre_root = NULL;
-               kobject_put(lustre_kobj);
+               kset_unregister(lustre_kset);
                goto out;
        }
 
@@ -562,7 +562,8 @@ int class_procfs_init(void)
                                   &obd_device_list_fops);
        if (IS_ERR_OR_NULL(file)) {
                rc = file ? PTR_ERR(file) : -ENOMEM;
-               kobject_put(lustre_kobj);
+               debugfs_remove(debugfs_lustre_root);
+               kset_unregister(lustre_kset);
                goto out;
        }
 
@@ -570,7 +571,8 @@ int class_procfs_init(void)
        if (IS_ERR(entry)) {
                rc = PTR_ERR(entry);
                CERROR("cannot create '/proc/fs/lustre': rc = %d\n", rc);
-               kobject_put(lustre_kobj);
+               debugfs_remove_recursive(debugfs_lustre_root);
+               kset_unregister(lustre_kset);
                goto out;
        }
 
@@ -591,7 +593,9 @@ int class_procfs_clean(void)
        if (proc_lustre_root)
                lprocfs_remove(&proc_lustre_root);
 
-       kobject_put(lustre_kobj);
+       sysfs_remove_group(&lustre_kset->kobj, &lustre_attr_group);
+
+       kset_unregister(lustre_kset);
 
        RETURN(0);
 }
index 19f95b8..da8a700 100644 (file)
@@ -181,10 +181,10 @@ static struct attribute_group lustre_attr_group = {
 
 int obd_sysctl_init(void)
 {
-       return sysfs_create_group(lustre_kobj, &lustre_attr_group);
+       return sysfs_create_group(&lustre_kset->kobj, &lustre_attr_group);
 }
 
 void obd_sysctl_clean(void)
 {
-       sysfs_remove_group(lustre_kobj, &lustre_attr_group);
+       sysfs_remove_group(&lustre_kset->kobj, &lustre_attr_group);
 }
index 7a3c683..37cb29d 100644 (file)
@@ -447,7 +447,7 @@ static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
                         char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
 
        return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
 }
@@ -467,7 +467,7 @@ static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
                              char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
        struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
@@ -483,7 +483,7 @@ static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
                                char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
        struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
@@ -506,7 +506,7 @@ static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
                               char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
        struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
@@ -529,7 +529,7 @@ static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
                                char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
        struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
@@ -552,7 +552,7 @@ static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
                               char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
        struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
@@ -568,7 +568,7 @@ static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
                              char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
        struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
@@ -1242,42 +1242,43 @@ static struct attribute *obd_def_attrs[] = {
 static void obd_sysfs_release(struct kobject *kobj)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
-                                             obd_kobj);
+                                             obd_kset.kobj);
 
        complete(&obd->obd_kobj_unregister);
 }
 
-static struct kobj_type obd_ktype = {
-       .sysfs_ops      = &lustre_sysfs_ops,
-       .release        = obd_sysfs_release,
-};
-
-int
-lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
+int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
 {
-       int rc = 0;
+       int rc;
 
-       LASSERT(obd != NULL);
-       LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
+       if (!obd || obd->obd_magic != OBD_DEVICE_MAGIC)
+               return -ENODEV;
 
-       if (uuid_only)
-               obd_ktype.default_attrs = obd_def_uuid_attrs;
-       else
-               obd_ktype.default_attrs = obd_def_attrs;
+       rc = kobject_set_name(&obd->obd_kset.kobj, "%s", obd->obd_name);
+       if (rc)
+               return rc;
 
+       obd->obd_ktype.sysfs_ops = &lustre_sysfs_ops;
+       obd->obd_ktype.release = obd_sysfs_release;
+       if (obd->obd_attrs)
+               obd->obd_ktype.default_attrs = obd->obd_attrs;
+
+       obd->obd_kset.kobj.parent = &obd->obd_type->typ_kobj;
+       obd->obd_kset.kobj.ktype = &obd->obd_ktype;
        init_completion(&obd->obd_kobj_unregister);
-       rc = kobject_init_and_add(&obd->obd_kobj, &obd_ktype,
-                                 obd->obd_type->typ_kobj,
-                                 "%s", obd->obd_name);
+       rc = kset_register(&obd->obd_kset);
        if (rc)
                return rc;
 
-       if (obd->obd_attrs) {
-               rc = sysfs_create_group(&obd->obd_kobj, obd->obd_attrs);
-               if (rc) {
-                       kobject_put(&obd->obd_kobj);
-                       return rc;
-               }
+       if (uuid_only)
+               obd->obd_attrs_group.attrs = obd_def_uuid_attrs;
+       else
+               obd->obd_attrs_group.attrs = obd_def_attrs;
+
+       rc = sysfs_create_group(&obd->obd_kset.kobj, &obd->obd_attrs_group);
+       if (rc) {
+               kset_unregister(&obd->obd_kset);
+               return rc;
        }
 
        if (obd->obd_proc_entry)
@@ -1289,10 +1290,10 @@ lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
                                               obd->obd_type->typ_procroot,
                                               obd->obd_vars, obd);
        if (IS_ERR(obd->obd_proc_entry)) {
-               kobject_put(&obd->obd_kobj);
                rc = PTR_ERR(obd->obd_proc_entry);
                CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
                obd->obd_proc_entry = NULL;
+               lprocfs_obd_cleanup(obd);
        }
 already_registered:
        return rc;
@@ -1315,8 +1316,10 @@ int lprocfs_obd_cleanup(struct obd_device *obd)
                obd->obd_proc_entry = NULL;
        }
 
-       kobject_put(&obd->obd_kobj);
+       sysfs_remove_group(&obd->obd_kset.kobj, &obd->obd_attrs_group);
+       kset_unregister(&obd->obd_kset);
        wait_for_completion(&obd->obd_kobj_unregister);
+
        return 0;
 }
 EXPORT_SYMBOL(lprocfs_obd_cleanup);
index 686ec70..bade9df 100644 (file)
 #include <lprocfs_status.h>
 #include <lustre_nodemap.h>
 
-static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
-                        char *buf)
-{
-       struct obd_device *obd = class_name2obd(kobj->name);
-
-       return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
-}
-LUSTRE_RO_ATTR(uuid);
-
-static struct attribute *server_uuid_attrs[] = {
-       &lustre_attr_uuid.attr,
-       NULL,
-};
-
-static struct attribute_group server_def_attr_group = {
-       .attrs = server_uuid_attrs,
-};
-
-void lprocfs_kset_unregister(struct obd_device *obd, struct kset *kset)
-{
-       if (obd->obd_proc_entry) {
-               lprocfs_remove(&obd->obd_proc_entry);
-               obd->obd_proc_entry = NULL;
-       }
-
-       if (kset)
-               kset_unregister(kset);
-}
-EXPORT_SYMBOL(lprocfs_kset_unregister);
-
-int lprocfs_kset_register(struct obd_device *obd, struct kset **kset)
-{
-       struct kset *obd_kset;
-       int rc = 0;
-
-       obd_kset = kset_create_and_add(obd->obd_name, NULL,
-                                      obd->obd_type->typ_kobj);
-       if (!obd_kset) {
-               CERROR("%s: cannot add new kset: rc = %d\n", obd->obd_name, rc);
-               rc = -ENOMEM;
-       }
-
-       if (!obd->obd_attrs)
-               obd->obd_attrs = &server_def_attr_group;
-
-       rc = sysfs_create_group(&obd_kset->kobj, obd->obd_attrs);
-       if (rc) {
-               CERROR("%s: cannot create attr group: rc = %d\n", obd->obd_name,
-                      rc);
-               kset_unregister(obd_kset);
-               obd_kset = NULL;
-               return rc;
-       }
-
-       obd->obd_proc_entry = lprocfs_register(obd->obd_name,
-                                              obd->obd_type->typ_procroot,
-                                              obd->obd_vars, obd);
-       if (IS_ERR(obd->obd_proc_entry)) {
-               rc = PTR_ERR(obd->obd_proc_entry);
-               CERROR("%s: error %d setting up lprocfs\n", obd->obd_name, rc);
-               obd->obd_proc_entry = NULL;
-
-               kset_unregister(obd_kset);
-               obd_kset = NULL;
-       }
-       *kset = obd_kset;
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_kset_register);
-
 #ifdef CONFIG_PROC_FS
 
 int lprocfs_evict_client_open(struct inode *inode, struct file *f)
index f0d351a..7326142 100644 (file)
@@ -67,8 +67,6 @@ MODULE_PARM_DESC(oss_io_cpts, "CPU partitions OSS IO threads should run on");
 
 static struct cfs_cpt_table    *ost_io_cptable;
 
-static struct kset *oss_kset;
-
 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
 {
@@ -78,7 +76,7 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
        int rc;
        ENTRY;
 
-       rc = lprocfs_kset_register(obd, &oss_kset);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc)
                return rc;
 
@@ -114,7 +112,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_hpreq_handler       = ptlrpc_hpreq_handler,
                },
        };
-       ost->ost_service = ptlrpc_register_service(&svc_conf, oss_kset,
+       ost->ost_service = ptlrpc_register_service(&svc_conf,
+                                                  &obd->obd_kset,
                                                   obd->obd_proc_entry);
        if (IS_ERR(ost->ost_service)) {
                rc = PTR_ERR(ost->ost_service);
@@ -152,7 +151,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_req_printer         = target_print_req,
                },
        };
-       ost->ost_create_service = ptlrpc_register_service(&svc_conf, oss_kset,
+       ost->ost_create_service = ptlrpc_register_service(&svc_conf,
+                                                         &obd->obd_kset,
                                                          obd->obd_proc_entry);
        if (IS_ERR(ost->ost_create_service)) {
                rc = PTR_ERR(ost->ost_create_service);
@@ -220,7 +220,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_req_printer         = target_print_req,
                },
        };
-       ost->ost_io_service = ptlrpc_register_service(&svc_conf, oss_kset,
+       ost->ost_io_service = ptlrpc_register_service(&svc_conf,
+                                                     &obd->obd_kset,
                                                      obd->obd_proc_entry);
        if (IS_ERR(ost->ost_io_service)) {
                rc = PTR_ERR(ost->ost_io_service);
@@ -261,8 +262,9 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_hpreq_handler       = NULL,
                },
        };
-       ost->ost_seq_service = ptlrpc_register_service(&svc_conf, oss_kset,
-                                                     obd->obd_proc_entry);
+       ost->ost_seq_service = ptlrpc_register_service(&svc_conf,
+                                                      &obd->obd_kset,
+                                                      obd->obd_proc_entry);
        if (IS_ERR(ost->ost_seq_service)) {
                rc = PTR_ERR(ost->ost_seq_service);
                CERROR("failed to start OST seq service: %d\n", rc);
@@ -307,7 +309,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_hpreq_handler       = NULL,
                },
        };
-       ost->ost_out_service = ptlrpc_register_service(&svc_conf, oss_kset,
+       ost->ost_out_service = ptlrpc_register_service(&svc_conf,
+                                                      &obd->obd_kset,
                                                       obd->obd_proc_entry);
        if (IS_ERR(ost->ost_out_service)) {
                rc = PTR_ERR(ost->ost_out_service);
@@ -333,7 +336,7 @@ out_service:
         ptlrpc_unregister_service(ost->ost_service);
         ost->ost_service = NULL;
 out_lprocfs:
-       lprocfs_kset_unregister(obd, oss_kset);
+       lprocfs_obd_cleanup(obd);
         RETURN(rc);
 }
 
@@ -363,7 +366,7 @@ static int ost_cleanup(struct obd_device *obd)
 
        mutex_unlock(&ost->ost_health_mutex);
 
-       lprocfs_kset_unregister(obd, oss_kset);
+       lprocfs_obd_cleanup(obd);
 
        if (ost_io_cptable != NULL) {
                cfs_cpt_table_free(ost_io_cptable);
index 7e4187a..95b167d 100644 (file)
@@ -1130,14 +1130,10 @@ void ptlrpc_sysfs_unregister_service(struct ptlrpc_service *svc)
 int ptlrpc_sysfs_register_service(struct kset *parent,
                                  struct ptlrpc_service *svc)
 {
-       int rc;
-
        svc->srv_kobj.kset = parent;
        init_completion(&svc->srv_kobj_unregister);
-       rc = kobject_init_and_add(&svc->srv_kobj, &ptlrpc_svc_ktype, NULL,
-                                 "%s", svc->srv_name);
-
-       return rc;
+       return kobject_init_and_add(&svc->srv_kobj, &ptlrpc_svc_ktype,
+                                   &parent->kobj, "%s", svc->srv_name);
 }
 
 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,