Whamcloud - gitweb
LU-8066 obd: cleanup server sysfs symlinks handling 15/34715/14
authorJames Simmons <uja.ornl@yahoo.com>
Wed, 5 Jun 2019 16:32:38 +0000 (12:32 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 20 Jun 2019 03:53:00 +0000 (03:53 +0000)
Rename class_setup_tunables() to class_add_symlinks(). Move all the
special sysfs and debugfs symlink handling into the function
class_add_symlinks(). Now that the obd_type is created using sysfs
handling we can complete the initializion if the real obd device is
registered later. For example if lod is registered first and it
creates the the "lov" obd_type. Then if the lov module is loaded
later then class_register_type() will use the "lov" obd_type created
by the lod module.

Change-Id: I754ec15a88458b170422b988d783efbe20141b87
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/34715
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/obd.h
lustre/include/obd_class.h
lustre/lod/lod_dev.c
lustre/lod/lproc_lod.c
lustre/lov/lov_obd.c
lustre/lov/lproc_lov.c
lustre/obdclass/genops.c
lustre/osc/lproc_osc.c
lustre/osc/osc_request.c
lustre/osp/osp_dev.c

index 5627685..233f4f0 100644 (file)
@@ -103,7 +103,6 @@ struct obd_type {
        struct obd_ops          *typ_dt_ops;
        struct md_ops           *typ_md_ops;
        struct proc_dir_entry   *typ_procroot;
-       struct proc_dir_entry   *typ_procsym;
        struct dentry           *typ_debugfs_entry;
 #ifdef HAVE_SERVER_SUPPORT
        bool                     typ_sym_filter;
index 7f58d31..328832b 100644 (file)
@@ -64,7 +64,7 @@ struct lu_device_type;
 /* genops.c */
 struct obd_export *class_conn2export(struct lustre_handle *);
 #ifdef HAVE_SERVER_SUPPORT
-struct obd_type *class_setup_tunables(const char *name);
+struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
 #endif
 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
                        struct lprocfs_vars *module_vars,
index 98c1369..dc26c29 100644 (file)
@@ -2227,9 +2227,6 @@ static struct obd_type *sym;
 
 static int __init lod_init(void)
 {
-       struct dentry *symlink;
-       struct obd_type *type;
-       struct qstr dname;
        int rc;
 
        rc = lu_kmem_init(lod_caches);
@@ -2243,46 +2240,15 @@ static int __init lod_init(void)
                return rc;
        }
 
-       sym = class_setup_tunables(LUSTRE_LOV_NAME);
+       /* create "lov" entry for compatibility purposes */
+       sym = class_add_symlinks(LUSTRE_LOV_NAME, true);
        if (IS_ERR(sym)) {
                rc = PTR_ERR(sym);
                /* does real "lov" already exist ? */
                if (rc == -EEXIST)
-                       GOTO(try_proc, rc = 0);
-               GOTO(no_lov, rc);
-       }
-
-       /* create "lov" entry for compatibility purposes */
-       dname.name = "lov";
-       dname.len = strlen(dname.name);
-       dname.hash = ll_full_name_hash(debugfs_lustre_root, dname.name,
-                                      dname.len);
-       symlink = d_lookup(debugfs_lustre_root, &dname);
-       if (!symlink) {
-               symlink = debugfs_create_dir(dname.name, debugfs_lustre_root);
-               if (IS_ERR_OR_NULL(symlink)) {
-                       rc = symlink ? PTR_ERR(symlink) : -ENOMEM;
-                       GOTO(no_lov, rc);
-               }
-               sym->typ_debugfs_entry = symlink;
-       } else {
-               dput(symlink);
+                       rc = 0;
        }
 
-try_proc:
-       type = class_search_type(LUSTRE_LOV_NAME);
-       if (type && type->typ_procroot)
-               GOTO(no_lov, rc);
-
-       type = class_search_type(LUSTRE_LOD_NAME);
-       type->typ_procsym = lprocfs_register("lov", proc_lustre_root,
-                                            NULL, NULL);
-       if (IS_ERR(type->typ_procsym)) {
-               CERROR("lod: can't create compat entry \"lov\": %d\n",
-                      (int)PTR_ERR(type->typ_procsym));
-               type->typ_procsym = NULL;
-       }
-no_lov:
        return rc;
 }
 
index 80c6d44..cb2c780 100644 (file)
@@ -808,15 +808,15 @@ static struct attribute *lod_attrs[] = {
  */
 int lod_procfs_init(struct lod_device *lod)
 {
+       struct lprocfs_vars ldebugfs_obd_vars[] = { { NULL } };
        struct obd_device *obd = lod2obd(lod);
-       struct proc_dir_entry *lov_proc_dir;
        struct obd_type *type;
        struct kobject *lov;
        int rc;
 
        lod->lod_dt_dev.dd_ktype.default_attrs = lod_attrs;
        rc = dt_tunables_init(&lod->lod_dt_dev, obd->obd_type, obd->obd_name,
-                             NULL);
+                             ldebugfs_obd_vars);
        if (rc) {
                CERROR("%s: failed to setup DT tunables: %d\n",
                       obd->obd_name, rc);
@@ -854,32 +854,31 @@ int lod_procfs_init(struct lod_device *lod)
        }
 
        lov = kset_find_obj(lustre_kset, "lov");
-       if (lov) {
-               rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj,
-                                      obd->obd_name);
-               kobject_put(lov);
+       if (!lov) {
+               CERROR("%s: lov subsystem not found\n", obd->obd_name);
+               GOTO(out, rc = -ENODEV);
        }
 
+       rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj,
+                              obd->obd_name);
+       if (rc)
+               CERROR("%s: failed to create LOV sysfs symlink\n",
+                      obd->obd_name);
+       kobject_put(lov);
+
        lod->lod_debugfs = ldebugfs_add_symlink(obd->obd_name, "lov",
                                                "../lod/%s", obd->obd_name);
        if (!lod->lod_debugfs)
                CERROR("%s: failed to create LOV debugfs symlink\n",
                       obd->obd_name);
 
-       /* If the real LOV is present which is the case for setups
-        * with both server and clients on the same node then use
-        * the LOV's proc root */
-       type = class_search_type(LUSTRE_LOV_NAME);
-       if (type != NULL && type->typ_procroot != NULL)
-               lov_proc_dir = type->typ_procroot;
-       else
-               lov_proc_dir = obd->obd_type->typ_procsym;
-
-       if (lov_proc_dir == NULL)
+       type = container_of(lov, struct obd_type, typ_kobj);
+       if (!type->typ_procroot)
                RETURN(0);
 
        /* for compatibility we link old procfs's LOV entries to lod ones */
-       lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, lov_proc_dir,
+       lod->lod_symlink = lprocfs_add_symlink(obd->obd_name,
+                                              type->typ_procroot,
                                               "../lod/%s", obd->obd_name);
        if (lod->lod_symlink == NULL)
                CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
index 6ca463e..467cfd0 100644 (file)
@@ -1347,8 +1347,6 @@ struct kmem_cache *lov_oinfo_slab;
 
 static int __init lov_init(void)
 {
-       bool enable_proc = true;
-       struct obd_type *type;
        int rc;
        ENTRY;
 
@@ -1369,13 +1367,8 @@ static int __init lov_init(void)
                 return -ENOMEM;
         }
 
-       type = class_search_type(LUSTRE_LOD_NAME);
-       if (type != NULL && type->typ_procsym != NULL)
-               enable_proc = false;
-
-       rc = class_register_type(&lov_obd_ops, NULL, enable_proc, NULL,
+       rc = class_register_type(&lov_obd_ops, NULL, true, NULL,
                                 LUSTRE_LOV_NAME, &lov_device_type);
-
         if (rc) {
                kmem_cache_destroy(lov_oinfo_slab);
                 lu_kmem_fini(lov_caches);
index fca6a8c..bce82d2 100644 (file)
@@ -291,32 +291,9 @@ static struct attribute *lov_attrs[] = {
 int lov_tunables_init(struct obd_device *obd)
 {
        struct lov_obd *lov = &obd->u.lov;
-#if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
-       struct obd_type *type;
-#endif
        int rc;
 
        obd->obd_vars = lprocfs_lov_obd_vars;
-#if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
-       /* If this is true then both client (lov) and server
-        * (lod) are on the same node. The lod layer if loaded
-        * first will register the lov proc directory. In that
-        * case obd->obd_type->typ_procroot will be not set.
-        * Instead we use type->typ_procsym as the parent.
-        */
-       type = class_search_type(LUSTRE_LOD_NAME);
-       if (type && type->typ_procsym) {
-               obd->obd_proc_entry = lprocfs_register(obd->obd_name,
-                                                      type->typ_procsym,
-                                                      obd->obd_vars, obd);
-               if (IS_ERR(obd->obd_proc_entry)) {
-                       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;
-               }
-       }
-#endif
        obd->obd_ktype.default_attrs = lov_attrs;
        rc = lprocfs_obd_setup(obd, false);
        if (rc)
index 9508495..42d90a8 100644 (file)
@@ -171,8 +171,9 @@ static struct kobj_type class_ktype = {
 };
 
 #ifdef HAVE_SERVER_SUPPORT
-struct obd_type *class_setup_tunables(const char *name)
+struct obd_type *class_add_symlinks(const char *name, bool enable_proc)
 {
+       struct dentry *symlink;
        struct obd_type *type;
        struct kobject *kobj;
        int rc;
@@ -188,15 +189,33 @@ struct obd_type *class_setup_tunables(const char *name)
                return ERR_PTR(-ENOMEM);
 
        type->typ_kobj.kset = lustre_kset;
-       kobject_init(&type->typ_kobj, &class_ktype);
-       rc = kobject_add(&type->typ_kobj, &lustre_kset->kobj, "%s", name);
-       if (rc) {
+       rc = kobject_init_and_add(&type->typ_kobj, &class_ktype,
+                                 &lustre_kset->kobj, "%s", name);
+       if (rc)
+               return ERR_PTR(rc);
+
+       symlink = debugfs_create_dir(name, debugfs_lustre_root);
+       if (IS_ERR_OR_NULL(symlink)) {
+               rc = symlink ? PTR_ERR(symlink) : -ENOMEM;
                kobject_put(&type->typ_kobj);
                return ERR_PTR(rc);
        }
+       type->typ_debugfs_entry = symlink;
+       type->typ_sym_filter = true;
+
+       if (enable_proc) {
+               type->typ_procroot = lprocfs_register(name, proc_lustre_root,
+                                                     NULL, NULL);
+               if (IS_ERR(type->typ_procroot)) {
+                       CERROR("%s: can't create compat proc entry: %d\n",
+                              name, (int)PTR_ERR(type->typ_procroot));
+                       type->typ_procroot = NULL;
+               }
+       }
+
        return type;
 }
-EXPORT_SYMBOL(class_setup_tunables);
+EXPORT_SYMBOL(class_add_symlinks);
 #endif /* HAVE_SERVER_SUPPORT */
 
 #define CLASS_MAX_NAME 1024
@@ -234,19 +253,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
                RETURN(-ENOMEM);
 
        type->typ_kobj.kset = lustre_kset;
-       rc = kobject_init_and_add(&type->typ_kobj, &class_ktype,
-                                 &lustre_kset->kobj, "%s", name);
-       if (rc)
-               GOTO(failed, rc);
-
-       type->typ_debugfs_entry = ldebugfs_register(name, debugfs_lustre_root,
-                                                   vars, type);
-       if (IS_ERR_OR_NULL(type->typ_debugfs_entry)) {
-               rc = type->typ_debugfs_entry ? PTR_ERR(type->typ_debugfs_entry)
-                                            : -ENOMEM;
-               type->typ_debugfs_entry = NULL;
-               GOTO(failed, rc);
-       }
+       kobject_init(&type->typ_kobj, &class_ktype);
 #ifdef HAVE_SERVER_SUPPORT
 dir_exist:
 #endif /* HAVE_SERVER_SUPPORT */
@@ -257,7 +264,7 @@ dir_exist:
         if (type->typ_dt_ops == NULL ||
             type->typ_md_ops == NULL ||
             type->typ_name == NULL)
-                GOTO (failed, rc);
+               GOTO (failed, rc = -ENOMEM);
 
         *(type->typ_dt_ops) = *dt_ops;
         /* md_ops is optional */
@@ -266,6 +273,10 @@ dir_exist:
         strcpy(type->typ_name, name);
        spin_lock_init(&type->obd_type_lock);
 
+#ifdef HAVE_SERVER_SUPPORT
+       if (type->typ_sym_filter)
+               goto setup_ldt;
+#endif
 #ifdef CONFIG_PROC_FS
        if (enable_proc && !type->typ_procroot) {
                type->typ_procroot = lprocfs_register(type->typ_name,
@@ -278,6 +289,21 @@ dir_exist:
                }
        }
 #endif
+       type->typ_debugfs_entry = ldebugfs_register(name, debugfs_lustre_root,
+                                                   vars, type);
+       if (IS_ERR_OR_NULL(type->typ_debugfs_entry)) {
+               rc = type->typ_debugfs_entry ? PTR_ERR(type->typ_debugfs_entry)
+                                            : -ENOMEM;
+               type->typ_debugfs_entry = NULL;
+               GOTO(failed, rc);
+       }
+
+       rc = kobject_add(&type->typ_kobj, &lustre_kset->kobj, "%s", name);
+       if (rc)
+               GOTO(failed, rc);
+#ifdef HAVE_SERVER_SUPPORT
+setup_ldt:
+#endif
        if (ldt) {
                type->typ_lu = ldt;
                rc = lu_device_type_init(ldt);
@@ -341,8 +367,6 @@ int class_unregister_type(const char *name)
 #ifdef CONFIG_PROC_FS
        if (type->typ_procroot != NULL)
                remove_proc_subtree(type->typ_name, proc_lustre_root);
-       if (type->typ_procsym != NULL)
-               lprocfs_remove(&type->typ_procsym);
 #endif
 #ifdef HAVE_SERVER_SUPPORT
        if (type->typ_sym_filter)
index 0db33e2..46eae66 100644 (file)
@@ -968,31 +968,9 @@ static struct attribute *osc_attrs[] = {
 
 int osc_tunables_init(struct obd_device *obd)
 {
-#if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
-       struct obd_type *type;
-#endif
        int rc;
 
        obd->obd_vars = lprocfs_osc_obd_vars;
-#if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
-       /* If this is true then both client (osc) and server (osp) are on the
-        * same node. The osp layer if loaded first will register the osc proc
-        * directory. In that case this obd_device will be attached its proc
-        * tree to type->typ_procsym instead of obd->obd_type->typ_procroot.
-        */
-       type = class_search_type(LUSTRE_OSP_NAME);
-       if (type && type->typ_procsym) {
-               obd->obd_proc_entry = lprocfs_register(obd->obd_name,
-                                                      type->typ_procsym,
-                                                      obd->obd_vars, obd);
-               if (IS_ERR(obd->obd_proc_entry)) {
-                       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;
-               }
-       }
-#endif
        obd->obd_ktype.default_attrs = osc_attrs;
        rc = lprocfs_obd_setup(obd, false);
        if (rc)
index 3c144a9..5624214 100644 (file)
@@ -3395,8 +3395,6 @@ static int osc_cache_shrink(SHRINKER_ARGS(sc, nr_to_scan, gfp_mask))
 
 static int __init osc_init(void)
 {
-       bool enable_proc = true;
-       struct obd_type *type;
        unsigned int reqpool_size;
        unsigned int reqsize;
        int rc;
@@ -3413,11 +3411,7 @@ static int __init osc_init(void)
        if (rc)
                RETURN(rc);
 
-       type = class_search_type(LUSTRE_OSP_NAME);
-       if (type != NULL && type->typ_procsym != NULL)
-               enable_proc = false;
-
-       rc = class_register_type(&osc_obd_ops, NULL, enable_proc, NULL,
+       rc = class_register_type(&osc_obd_ops, NULL, true, NULL,
                                 LUSTRE_OSC_NAME, &osc_device_type);
        if (rc)
                GOTO(out_kmem, rc);
index 40e631e..aeb1113 100644 (file)
@@ -1892,16 +1892,13 @@ static struct obd_type *sym;
  */
 static int __init osp_init(void)
 {
-       struct dentry *symlink;
-       struct obd_type *type;
-       struct qstr dname;
        int rc;
 
        rc = lu_kmem_init(osp_caches);
        if (rc)
                return rc;
 
-       rc = class_register_type(&osp_obd_device_ops, NULL, true, NULL,
+       rc = class_register_type(&osp_obd_device_ops, NULL, false, NULL,
                                 LUSTRE_OSP_NAME, &osp_device_type);
        if (rc != 0) {
                lu_kmem_fini(osp_caches);
@@ -1916,46 +1913,15 @@ static int __init osp_init(void)
                return rc;
        }
 
-       sym = class_setup_tunables(LUSTRE_OSC_NAME);
+       /* create "osc" entry for compatibility purposes */
+       sym = class_add_symlinks(LUSTRE_OSC_NAME, false);
        if (IS_ERR(sym)) {
                rc = PTR_ERR(sym);
                /* does real "osc" already exist ? */
                if (rc == -EEXIST)
-                       GOTO(try_proc, rc = 0);
-               GOTO(no_osc, rc);
-       }
-
-       /* create "osc" entry for compatibility purposes */
-       dname.name = "osc";
-       dname.len = strlen(dname.name);
-       dname.hash = ll_full_name_hash(debugfs_lustre_root, dname.name,
-                                      dname.len);
-       symlink = d_lookup(debugfs_lustre_root, &dname);
-       if (!symlink) {
-               symlink = debugfs_create_dir(dname.name, debugfs_lustre_root);
-               if (IS_ERR_OR_NULL(symlink)) {
-                       rc = symlink ? PTR_ERR(symlink) : -ENOMEM;
-                       GOTO(no_osc, rc);
-               }
-               sym->typ_debugfs_entry = symlink;
-       } else {
-               dput(symlink);
+                       rc = 0;
        }
 
-try_proc:
-       type = class_search_type(LUSTRE_OSC_NAME);
-       if (type != NULL && type->typ_procroot != NULL)
-               GOTO(no_osc, rc);
-
-       type = class_search_type(LUSTRE_OSP_NAME);
-       type->typ_procsym = lprocfs_register("osc", proc_lustre_root,
-                                            NULL, NULL);
-       if (IS_ERR(type->typ_procsym)) {
-               CERROR("osp: can't create compat entry \"osc\": %d\n",
-                      (int) PTR_ERR(type->typ_procsym));
-               type->typ_procsym = NULL;
-       }
-no_osc:
        return rc;
 }