Whamcloud - gitweb
LU-8066 obdclass : Add infrastructure for procfs to sysfs migration 20/26020/10
authorOleg Drokin <oleg.drokin@intel.com>
Tue, 2 May 2017 16:37:12 +0000 (12:37 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 19 Jul 2017 03:29:26 +0000 (03:29 +0000)
Prepare for procfs to sysfs migration

Add necessary plumbing to register obd types and instances
under /sys/fs/lustre

Linux-commit : 9b8013023cb62360b56c04313687e93a1c2bf3d6

Move common obd proc files to sysfs

This moves uuid display and also underlying fs statistics.

Linux-commit : 0bc36cb06e4bc5e936f2f442535daf557c7a4200

Change-Id: Ieb4e2f60c7003d658126beac071c05f94fa8eab8
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Signed-off-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-on: https://review.whamcloud.com/26020
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
24 files changed:
lustre/include/lprocfs_status.h
lustre/include/obd.h
lustre/lmv/lmv_obd.c
lustre/lmv/lproc_lmv.c
lustre/lod/lproc_lod.c
lustre/lov/lov_obd.c
lustre/lov/lproc_lov.c
lustre/mdc/lproc_mdc.c
lustre/mdc/mdc_request.c
lustre/mdt/mdt_lproc.c
lustre/mdt/mdt_mds.c
lustre/mgc/lproc_mgc.c
lustre/mgc/mgc_request.c
lustre/mgs/lproc_mgs.c
lustre/obdclass/genops.c
lustre/obdclass/lprocfs_status.c
lustre/obdecho/echo.c
lustre/ofd/lproc_ofd.c
lustre/ofd/ofd_dev.c
lustre/osc/lproc_osc.c
lustre/osc/osc_request.c
lustre/osp/lproc_osp.c
lustre/osp/lwp_dev.c
lustre/ost/ost_handler.c

index 212c32c..b141840 100644 (file)
@@ -534,7 +534,8 @@ static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
 { return 0; }
 #endif
-extern int lprocfs_obd_setup(struct obd_device *dev);
+
+extern int lprocfs_obd_setup(struct obd_device *dev, bool uuid_only);
 extern int lprocfs_obd_cleanup(struct obd_device *obd);
 #ifdef HAVE_SERVER_SUPPORT
 extern const struct file_operations lprocfs_evict_client_fops;
@@ -598,14 +599,6 @@ extern ssize_t
 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
                               size_t count, loff_t *off);
 
-/* Statfs helpers */
-extern int lprocfs_blksize_seq_show(struct seq_file *m, void *data);
-extern int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data);
-extern int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data);
-extern int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data);
-extern int lprocfs_filestotal_seq_show(struct seq_file *m, void *data);
-extern int lprocfs_filesfree_seq_show(struct seq_file *m, void *data);
-
 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
                                     long val, int mult);
@@ -882,7 +875,7 @@ static inline void lprocfs_remove(struct proc_dir_entry **root)
 static inline void lprocfs_remove_proc_entry(const char *name,
                                              struct proc_dir_entry *parent)
 { return; }
-static inline int lprocfs_obd_setup(struct obd_device *dev)
+static inline int lprocfs_obd_setup(struct obd_device *dev, bool uuid_only)
 { return 0; }
 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
 { return 0; }
index 007fc59..390e786 100644 (file)
@@ -105,6 +105,7 @@ struct obd_type {
        int                      typ_refcnt;
        struct lu_device_type   *typ_lu;
        spinlock_t               obd_type_lock;
+       struct kobject          *typ_kobj;
 };
 
 struct brw_page {
@@ -693,6 +694,7 @@ 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 lprocfs_vars     *obd_vars;
        atomic_t                obd_evict_inprogress;
        wait_queue_head_t       obd_evict_inprogress_waitq;
@@ -710,6 +712,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;
 };
 
 /* get/set_info keys */
index d148259..f226c5a 100644 (file)
@@ -1283,7 +1283,7 @@ static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 
 #ifdef CONFIG_PROC_FS
        obd->obd_vars = lprocfs_lmv_obd_vars;
-       lprocfs_obd_setup(obd);
+       lprocfs_obd_setup(obd, true);
        lprocfs_alloc_md_stats(obd, 0);
        rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
                                0444, &lmv_proc_target_fops, obd);
index cefa71d..9b6f3a1 100644 (file)
@@ -148,15 +148,11 @@ static int lmv_target_seq_open(struct inode *inode, struct file *file)
        return 0;
 }
 
-LPROC_SEQ_FOPS_RO_TYPE(lmv, uuid);
-
 struct lprocfs_vars lprocfs_lmv_obd_vars[] = {
        { .name =       "numobd",
          .fops =       &lmv_numobd_fops        },
        { .name =       "activeobd",
          .fops =       &lmv_activeobd_fops     },
-       { .name =       "uuid",
-         .fops =       &lmv_uuid_fops          },
        { .name =       "desc_uuid",
          .fops =       &lmv_desc_uuid_fops     },
        { NULL }
index 3347a4d..4986f1f 100644 (file)
@@ -669,8 +669,6 @@ static int lod_osts_seq_open(struct inode *inode, struct file *file)
        return 0;
 }
 
-LPROC_SEQ_FOPS_RO_TYPE(lod, uuid);
-
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_blksize);
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytestotal);
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesfree);
@@ -738,8 +736,6 @@ lod_lmv_failout_seq_write(struct file *file, const char __user *buffer,
 LPROC_SEQ_FOPS(lod_lmv_failout);
 
 static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &lod_uuid_fops          },
        { .name =       "stripesize",
          .fops =       &lod_stripesize_fops    },
        { .name =       "stripeoffset",
@@ -799,7 +795,7 @@ int lod_procfs_init(struct lod_device *lod)
        int                      rc;
 
        obd->obd_vars = lprocfs_lod_obd_vars;
-       rc = lprocfs_obd_setup(obd);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc) {
                CERROR("%s: cannot setup procfs entry: %d\n",
                       obd->obd_name, rc);
index 563f121..10972cd 100644 (file)
@@ -814,7 +814,7 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                        obd->obd_proc_entry = NULL;
                }
        } else {
-               rc = lprocfs_obd_setup(obd);
+               rc = lprocfs_obd_setup(obd, false);
        }
 
        if (rc == 0) {
index 25b4e17..98c9db5 100644 (file)
@@ -282,17 +282,7 @@ static int lov_target_seq_open(struct inode *inode, struct file *file)
        return 0;
 }
 
-LPROC_SEQ_FOPS_RO_TYPE(lov, uuid);
-LPROC_SEQ_FOPS_RO_TYPE(lov, filestotal);
-LPROC_SEQ_FOPS_RO_TYPE(lov, filesfree);
-LPROC_SEQ_FOPS_RO_TYPE(lov, blksize);
-LPROC_SEQ_FOPS_RO_TYPE(lov, kbytestotal);
-LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesfree);
-LPROC_SEQ_FOPS_RO_TYPE(lov, kbytesavail);
-
 struct lprocfs_vars lprocfs_lov_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &lov_uuid_fops          },
        { .name =       "stripesize",
          .fops =       &lov_stripesize_fops    },
        { .name =       "stripeoffset",
@@ -305,18 +295,6 @@ struct lprocfs_vars lprocfs_lov_obd_vars[] = {
          .fops =       &lov_numobd_fops        },
        { .name =       "activeobd",
          .fops =       &lov_activeobd_fops     },
-       { .name =       "filestotal",
-         .fops =       &lov_filestotal_fops    },
-       { .name =       "filesfree",
-         .fops =       &lov_filesfree_fops     },
-       { .name =       "blocksize",
-         .fops =       &lov_blksize_fops       },
-       { .name =       "kbytestotal",
-         .fops =       &lov_kbytestotal_fops   },
-       { .name =       "kbytesfree",
-         .fops =       &lov_kbytesfree_fops    },
-       { .name =       "kbytesavail",
-         .fops =       &lov_kbytesavail_fops   },
        { .name =       "desc_uuid",
          .fops =       &lov_desc_uuid_fops     },
        { NULL }
index 2ede98f..9a6d707 100644 (file)
@@ -168,14 +168,7 @@ LPROC_SEQ_FOPS(mdc_rpc_stats);
 
 LPROC_SEQ_FOPS_WO_TYPE(mdc, ping);
 
-LPROC_SEQ_FOPS_RO_TYPE(mdc, uuid);
 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
-LPROC_SEQ_FOPS_RO_TYPE(mdc, blksize);
-LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytestotal);
-LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesfree);
-LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesavail);
-LPROC_SEQ_FOPS_RO_TYPE(mdc, filestotal);
-LPROC_SEQ_FOPS_RO_TYPE(mdc, filesfree);
 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
@@ -185,25 +178,11 @@ LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
 
 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &mdc_uuid_fops          },
        { .name =       "ping",
          .fops =       &mdc_ping_fops,
          .proc_mode =  0222                    },
        { .name =       "connect_flags",
          .fops =       &mdc_connect_flags_fops },
-       { .name =       "blocksize",
-         .fops =       &mdc_blksize_fops       },
-       { .name =       "kbytestotal",
-         .fops =       &mdc_kbytestotal_fops   },
-       { .name =       "kbytesfree",
-         .fops =       &mdc_kbytesfree_fops    },
-       { .name =       "kbytesavail",
-         .fops =       &mdc_kbytesavail_fops   },
-       { .name =       "filestotal",
-         .fops =       &mdc_filestotal_fops    },
-       { .name =       "filesfree",
-         .fops =       &mdc_filesfree_fops     },
        { .name =       "mds_server_uuid",
          .fops =       &mdc_server_uuid_fops   },
        { .name =       "mds_conn_uuid",
index b02866e..128eaea 100644 (file)
@@ -2491,7 +2491,7 @@ static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
                GOTO(err_ptlrpcd_decref, rc);
 #ifdef CONFIG_PROC_FS
        obd->obd_vars = lprocfs_mdc_obd_vars;
-       lprocfs_obd_setup(obd);
+       lprocfs_obd_setup(obd, false);
        lprocfs_alloc_md_stats(obd, 0);
 #endif
        sptlrpc_lprocfs_cliobd_attach(obd);
index 7c34b80..f10e910 100644 (file)
@@ -762,8 +762,6 @@ mdt_sync_count_seq_write(struct file *file, const char __user *buffer,
 }
 LPROC_SEQ_FOPS(mdt_sync_count);
 
-
-LPROC_SEQ_FOPS_RO_TYPE(mdt, uuid);
 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
 LPROC_SEQ_FOPS_RO_TYPE(mdt, num_exports);
 LPROC_SEQ_FOPS_RO_TYPE(mdt, target_instance);
@@ -778,8 +776,6 @@ LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_hard);
 LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_soft);
 
 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &mdt_uuid_fops                          },
        { .name =       "recovery_status",
          .fops =       &mdt_recovery_status_fops               },
        { .name =       "num_exports",
@@ -927,7 +923,7 @@ int mdt_procfs_init(struct mdt_device *mdt, const char *name)
        LASSERT(name != NULL);
 
        obd->obd_vars = lprocfs_mdt_obd_vars;
-       rc = lprocfs_obd_setup(obd);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc) {
                CERROR("%s: cannot create proc entries: rc = %d\n",
                       mdt_obd_name(mdt), rc);
index 7c5560d..a781715 100644 (file)
@@ -468,18 +468,6 @@ static struct lu_device *mds_device_free(const struct lu_env *env,
        RETURN(NULL);
 }
 
-LPROC_SEQ_FOPS_RO_TYPE(mds, uuid);
-
-static struct lprocfs_vars lprocfs_mds_obd_vars[] = {
-       {
-               .name   = "uuid",
-               .fops   = &mds_uuid_fops
-       },
-       {
-               .name   = NULL
-       }
-};
-
 static struct lu_device *mds_device_alloc(const struct lu_env *env,
                                          struct lu_device_type *t,
                                          struct lustre_cfg *cfg)
@@ -503,8 +491,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;
 
-       obd->obd_vars = lprocfs_mds_obd_vars;
-       rc = lprocfs_obd_setup(obd);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc != 0) {
                mds_device_free(env, l);
                l = ERR_PTR(rc);
index ab1985d..7486d1c 100644 (file)
@@ -39,7 +39,6 @@
 
 #ifdef CONFIG_PROC_FS
 
-LPROC_SEQ_FOPS_RO_TYPE(mgc, uuid);
 LPROC_SEQ_FOPS_RO_TYPE(mgc, connect_flags);
 LPROC_SEQ_FOPS_RO_TYPE(mgc, server_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(mgc, conn_uuid);
@@ -55,8 +54,6 @@ static int mgc_ir_state_seq_show(struct seq_file *m, void *v)
 LPROC_SEQ_FOPS_RO(mgc_ir_state);
 
 struct lprocfs_vars lprocfs_mgc_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &mgc_uuid_fops          },
        { .name =       "ping",
          .fops =       &mgc_ping_fops,
          .proc_mode =  0222                    },
index 4bc226c..a23a683 100644 (file)
@@ -969,7 +969,7 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 
 #ifdef CONFIG_PROC_FS
        obd->obd_vars = lprocfs_mgc_obd_vars;
-       lprocfs_obd_setup(obd);
+       lprocfs_obd_setup(obd, true);
 #endif
        sptlrpc_lprocfs_cliobd_attach(obd);
 
index 3caf79c..e8dc509 100644 (file)
@@ -202,15 +202,12 @@ int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
        return 0;
 }
 
-LPROC_SEQ_FOPS_RO_TYPE(mgs, uuid);
 LPROC_SEQ_FOPS_RO_TYPE(mgs, num_exports);
 LPROC_SEQ_FOPS_RO_TYPE(mgs, hash);
 LPROC_SEQ_FOPS_WO_TYPE(mgs, evict_client);
 LPROC_SEQ_FOPS_RW_TYPE(mgs, ir_timeout);
 
 static struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &mgs_uuid_fops          },
        { .name =       "num_exports",
          .fops =       &mgs_num_exports_fops   },
        { .name =       "hash_stats",
@@ -230,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_obd_setup(obd);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc != 0)
                GOTO(out, rc);
 
index 6587603..fb3bd9a 100644 (file)
@@ -213,6 +213,12 @@ 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;
+               GOTO(failed, rc);
+       }
+
         if (ldt != NULL) {
                 type->typ_lu = ldt;
                 rc = lu_device_type_init(ldt);
@@ -227,6 +233,8 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
         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)
@@ -262,6 +270,9 @@ int class_unregister_type(const char *name)
                 RETURN(-EBUSY);
         }
 
+       if (type->typ_kobj)
+               kobject_put(type->typ_kobj);
+
        /* we do not use type->typ_procroot as for compatibility purposes
         * other modules can share names (i.e. lod can use lov entry). so
         * we can't reference pointer as it can get invalided when another
index eb46f76..0f7b5b9 100644 (file)
@@ -444,6 +444,16 @@ int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
 }
 EXPORT_SYMBOL(lprocfs_uuid_seq_show);
 
+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);
+
+       return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
+}
+LUSTRE_RO_ATTR(uuid);
+
 int lprocfs_name_seq_show(struct seq_file *m, void *data)
 {
        struct obd_device *dev = data;
@@ -454,104 +464,122 @@ int lprocfs_name_seq_show(struct seq_file *m, void *data)
 }
 EXPORT_SYMBOL(lprocfs_name_seq_show);
 
-int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
+static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf)
 {
-       struct obd_device *obd = data;
-       struct obd_statfs  osfs;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kobj);
+       struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                            OBD_STATFS_NODELAY);
        if (!rc)
-               seq_printf(m, "%u\n", osfs.os_bsize);
+               return sprintf(buf, "%u\n", osfs.os_bsize);
+
        return rc;
 }
-EXPORT_SYMBOL(lprocfs_blksize_seq_show);
+LUSTRE_RO_ATTR(blocksize);
 
-int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
+static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
 {
-       struct obd_device *obd = data;
-       struct obd_statfs  osfs;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kobj);
+       struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                            OBD_STATFS_NODELAY);
        if (!rc) {
-               __u32 blk_size = osfs.os_bsize >> 10;
-               __u64 result = osfs.os_blocks;
+               u32 blk_size = osfs.os_bsize >> 10;
+               u64 result = osfs.os_blocks;
 
                while (blk_size >>= 1)
                        result <<= 1;
 
-               seq_printf(m, "%llu\n", result);
+               return sprintf(buf, "%llu\n", result);
        }
+
        return rc;
 }
-EXPORT_SYMBOL(lprocfs_kbytestotal_seq_show);
+LUSTRE_RO_ATTR(kbytestotal);
 
-int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
+static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
+                              char *buf)
 {
-       struct obd_device *obd = data;
-       struct obd_statfs  osfs;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kobj);
+       struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                            OBD_STATFS_NODELAY);
        if (!rc) {
-               __u32 blk_size = osfs.os_bsize >> 10;
-               __u64 result = osfs.os_bfree;
+               u32 blk_size = osfs.os_bsize >> 10;
+               u64 result = osfs.os_bfree;
 
                while (blk_size >>= 1)
                        result <<= 1;
 
-               seq_printf(m, "%llu\n", result);
+               return sprintf(buf, "%llu\n", result);
        }
+
        return rc;
 }
-EXPORT_SYMBOL(lprocfs_kbytesfree_seq_show);
+LUSTRE_RO_ATTR(kbytesfree);
 
-int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
+static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
 {
-       struct obd_device *obd = data;
-       struct obd_statfs  osfs;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kobj);
+       struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                            OBD_STATFS_NODELAY);
        if (!rc) {
-               __u32 blk_size = osfs.os_bsize >> 10;
-               __u64 result = osfs.os_bavail;
+               u32 blk_size = osfs.os_bsize >> 10;
+               u64 result = osfs.os_bavail;
 
                while (blk_size >>= 1)
                        result <<= 1;
 
-               seq_printf(m, "%llu\n", result);
+               return sprintf(buf, "%llu\n", result);
        }
+
        return rc;
 }
-EXPORT_SYMBOL(lprocfs_kbytesavail_seq_show);
+LUSTRE_RO_ATTR(kbytesavail);
 
-int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
+static ssize_t filestotal_show(struct kobject *kobj, struct attribute *attr,
+                              char *buf)
 {
-       struct obd_device *obd = data;
-       struct obd_statfs  osfs;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kobj);
+       struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                            OBD_STATFS_NODELAY);
        if (!rc)
-               seq_printf(m, "%llu\n", osfs.os_files);
+               return sprintf(buf, "%llu\n", osfs.os_files);
+
        return rc;
 }
-EXPORT_SYMBOL(lprocfs_filestotal_seq_show);
+LUSTRE_RO_ATTR(filestotal);
 
-int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
+static ssize_t filesfree_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf)
 {
-       struct obd_device *obd = data;
-       struct obd_statfs  osfs;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kobj);
+       struct obd_statfs osfs;
        int rc = obd_statfs(NULL, obd->obd_self_export, &osfs,
                            cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                            OBD_STATFS_NODELAY);
        if (!rc)
-               seq_printf(m, "%llu\n", osfs.os_ffree);
+               return sprintf(buf, "%llu\n", osfs.os_ffree);
+
        return rc;
 }
-EXPORT_SYMBOL(lprocfs_filesfree_seq_show);
+LUSTRE_RO_ATTR(filesfree);
 
 int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data)
 {
@@ -1195,8 +1223,37 @@ int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
 }
 EXPORT_SYMBOL(lprocfs_connect_flags_seq_show);
 
+static struct attribute *obd_def_uuid_attrs[] = {
+       &lustre_attr_uuid.attr,
+       NULL,
+};
+
+static struct attribute *obd_def_attrs[] = {
+       &lustre_attr_blocksize.attr,
+       &lustre_attr_kbytestotal.attr,
+       &lustre_attr_kbytesfree.attr,
+       &lustre_attr_kbytesavail.attr,
+       &lustre_attr_filestotal.attr,
+       &lustre_attr_filesfree.attr,
+       &lustre_attr_uuid.attr,
+       NULL,
+};
+
+static void obd_sysfs_release(struct kobject *kobj)
+{
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_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)
+lprocfs_obd_setup(struct obd_device *obd, bool uuid_only)
 {
        int rc = 0;
 
@@ -1204,32 +1261,59 @@ lprocfs_obd_setup(struct obd_device *obd)
        LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
        LASSERT(obd->obd_type->typ_procroot != NULL);
 
+       if (uuid_only)
+               obd_ktype.default_attrs = obd_def_uuid_attrs;
+       else
+               obd_ktype.default_attrs = obd_def_attrs;
+
+       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);
+       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;
+               }
+       }
+
        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)) {
+               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;
        }
+
        return rc;
 }
 EXPORT_SYMBOL(lprocfs_obd_setup);
 
 int lprocfs_obd_cleanup(struct obd_device *obd)
 {
-        if (!obd)
-                return -EINVAL;
-        if (obd->obd_proc_exports_entry) {
-                /* Should be no exports left */
-                lprocfs_remove(&obd->obd_proc_exports_entry);
-                obd->obd_proc_exports_entry = NULL;
-        }
-        if (obd->obd_proc_entry) {
-                lprocfs_remove(&obd->obd_proc_entry);
-                obd->obd_proc_entry = NULL;
-        }
-        return 0;
+       if (!obd)
+               return -EINVAL;
+
+       if (obd->obd_proc_exports_entry) {
+               /* Should be no exports left */
+               lprocfs_remove(&obd->obd_proc_exports_entry);
+               obd->obd_proc_exports_entry = NULL;
+       }
+
+       if (obd->obd_proc_entry) {
+               lprocfs_remove(&obd->obd_proc_entry);
+               obd->obd_proc_entry = NULL;
+       }
+
+       kobject_put(&obd->obd_kobj);
+       wait_for_completion(&obd->obd_kobj_unregister);
+       return 0;
 }
 EXPORT_SYMBOL(lprocfs_obd_cleanup);
 
index de7fd77..6b75c23 100644 (file)
@@ -546,13 +546,6 @@ commitrw_cleanup:
        return rc;
 }
 
-LPROC_SEQ_FOPS_RO_TYPE(echo, uuid);
-static struct lprocfs_vars lprocfs_echo_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &echo_uuid_fops         },
-       { NULL }
-};
-
 static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
        int                     rc;
@@ -581,8 +574,7 @@ static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                                    LVB_T_NONE, NULL, &obd->u.echo.eo_nl_lock);
         LASSERT (rc == ELDLM_OK);
 
-       obd->obd_vars = lprocfs_echo_obd_vars;
-       if (lprocfs_obd_setup(obd) == 0 &&
+       if (!lprocfs_obd_setup(obd, true) &&
             lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST) == 0) {
                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES,
                                      LPROCFS_CNTR_AVGMINMAX,
index b39135f..08d8a69 100644 (file)
@@ -888,14 +888,6 @@ static int ofd_site_stats_seq_show(struct seq_file *m, void *data)
 }
 LPROC_SEQ_FOPS_RO(ofd_site_stats);
 
-LPROC_SEQ_FOPS_RO_TYPE(ofd, uuid);
-LPROC_SEQ_FOPS_RO_TYPE(ofd, blksize);
-LPROC_SEQ_FOPS_RO_TYPE(ofd, kbytestotal);
-LPROC_SEQ_FOPS_RO_TYPE(ofd, kbytesfree);
-LPROC_SEQ_FOPS_RO_TYPE(ofd, kbytesavail);
-LPROC_SEQ_FOPS_RO_TYPE(ofd, filestotal);
-LPROC_SEQ_FOPS_RO_TYPE(ofd, filesfree);
-
 LPROC_SEQ_FOPS_RO_TYPE(ofd, recovery_status);
 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_soft);
 LPROC_SEQ_FOPS_RW_TYPE(ofd, recovery_time_hard);
@@ -907,20 +899,6 @@ LPROC_SEQ_FOPS_RW_TYPE(ofd, checksum_dump);
 LPROC_SEQ_FOPS_RW_TYPE(ofd, job_interval);
 
 struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &ofd_uuid_fops                  },
-       { .name =       "blocksize",
-         .fops =       &ofd_blksize_fops               },
-       { .name =       "kbytestotal",
-         .fops =       &ofd_kbytestotal_fops           },
-       { .name =       "kbytesfree",
-         .fops =       &ofd_kbytesfree_fops            },
-       { .name =       "kbytesavail",
-         .fops =       &ofd_kbytesavail_fops           },
-       { .name =       "filestotal",
-         .fops =       &ofd_filestotal_fops            },
-       { .name =       "filesfree",
-         .fops =       &ofd_filesfree_fops             },
        { .name =       "seqs_allocated",
          .fops =       &ofd_seqs_fops                  },
        { .name =       "fstype",
index 2476f9e..3f0e426 100644 (file)
@@ -692,7 +692,7 @@ static int ofd_procfs_init(struct ofd_device *ofd)
        /* lprocfs must be setup before the ofd so state can be safely added
         * to /proc incrementally as the ofd is setup */
        obd->obd_vars = lprocfs_ofd_obd_vars;
-       rc = lprocfs_obd_setup(obd);
+       rc = lprocfs_obd_setup(obd, false);
        if (rc) {
                CERROR("%s: lprocfs_obd_setup failed: %d.\n",
                       obd->obd_name, rc);
index 3d90088..fa78071 100644 (file)
@@ -591,14 +591,7 @@ static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
 }
 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
 
-LPROC_SEQ_FOPS_RO_TYPE(osc, uuid);
 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
-LPROC_SEQ_FOPS_RO_TYPE(osc, blksize);
-LPROC_SEQ_FOPS_RO_TYPE(osc, kbytestotal);
-LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesfree);
-LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesavail);
-LPROC_SEQ_FOPS_RO_TYPE(osc, filestotal);
-LPROC_SEQ_FOPS_RO_TYPE(osc, filesfree);
 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
@@ -610,25 +603,11 @@ LPROC_SEQ_FOPS_RW_TYPE(osc, import);
 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
 
 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &osc_uuid_fops                  },
        { .name =       "ping",
          .fops =       &osc_ping_fops,
          .proc_mode =  0222                            },
        { .name =       "connect_flags",
          .fops =       &osc_connect_flags_fops         },
-       { .name =       "blocksize",
-         .fops =       &osc_blksize_fops               },
-       { .name =       "kbytestotal",
-         .fops =       &osc_kbytestotal_fops           },
-       { .name =       "kbytesfree",
-         .fops =       &osc_kbytesfree_fops            },
-       { .name =       "kbytesavail",
-         .fops =       &osc_kbytesavail_fops           },
-       { .name =       "filestotal",
-         .fops =       &osc_filestotal_fops            },
-       { .name =       "filesfree",
-         .fops =       &osc_filesfree_fops             },
        { .name =       "ost_server_uuid",
          .fops =       &osc_server_uuid_fops           },
        { .name =       "ost_conn_uuid",
index 3e03092..5e590c5 100644 (file)
@@ -2874,7 +2874,7 @@ int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                        obd->obd_proc_entry = NULL;
                }
        } else {
-               rc = lprocfs_obd_setup(obd);
+               rc = lprocfs_obd_setup(obd, false);
        }
 
        /* If the basic OSC proc tree construction succeeded then
index 5fc7a02..862b2bf 100644 (file)
@@ -745,7 +745,6 @@ osp_lfsck_max_rpcs_in_flight_seq_write(struct file *file,
 LPROC_SEQ_FOPS(osp_lfsck_max_rpcs_in_flight);
 
 LPROC_SEQ_FOPS_WO_TYPE(osp, ping);
-LPROC_SEQ_FOPS_RO_TYPE(osp, uuid);
 LPROC_SEQ_FOPS_RO_TYPE(osp, connect_flags);
 LPROC_SEQ_FOPS_RO_TYPE(osp, server_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(osp, conn_uuid);
@@ -876,8 +875,6 @@ osp_reserved_mb_low_seq_write(struct file *file, const char __user *buffer,
 LPROC_SEQ_FOPS(osp_reserved_mb_low);
 
 static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &osp_uuid_fops                  },
        { .name =       "ping",
          .fops =       &osp_ping_fops,
          .proc_mode =  0222                            },
@@ -939,8 +936,6 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
 };
 
 static struct lprocfs_vars lprocfs_osp_md_vars[] = {
-       { .name =       "uuid",
-         .fops =       &osp_uuid_fops                  },
        { .name =       "ping",
          .fops =       &osp_ping_fops,
          .proc_mode =  0222                            },
@@ -1014,7 +1009,7 @@ void osp_lprocfs_init(struct osp_device *osp)
                obd->obd_vars = lprocfs_osp_md_vars;
        else
                obd->obd_vars = lprocfs_osp_obd_vars;
-       if (lprocfs_obd_setup(obd) != 0)
+       if (lprocfs_obd_setup(obd, true) != 0)
                return;
 
        rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_osp_osd_vars,
index d966358..c83b84b 100644 (file)
@@ -275,11 +275,24 @@ static int lwp_init0(const struct lu_env *env, struct lwp_device *lwp,
                RETURN(rc);
        }
 
-       if (lprocfs_obd_setup(lwp->lpd_obd) == 0) {
-               sptlrpc_lprocfs_cliobd_attach(lwp->lpd_obd);
-               ptlrpc_lprocfs_register_obd(lwp->lpd_obd);
+       rc = lprocfs_obd_setup(lwp->lpd_obd, true);
+       if (rc) {
+               CERROR("%s: lprocfs_obd_setup failed. %d\n",
+                      lwp->lpd_obd->obd_name, rc);
+               ptlrpcd_decref();
+               RETURN(rc);
        }
 
+       rc = sptlrpc_lprocfs_cliobd_attach(lwp->lpd_obd);
+       if (rc) {
+               CERROR("%s: sptlrpc_lprocfs_cliobd_attached failed. %d\n",
+                      lwp->lpd_obd->obd_name, rc);
+               ptlrpcd_decref();
+               RETURN(rc);
+       }
+
+       ptlrpc_lprocfs_register_obd(lwp->lpd_obd);
+
        RETURN(0);
 }
 
index 4592fe4..63fcc84 100644 (file)
@@ -67,16 +67,6 @@ MODULE_PARM_DESC(oss_io_cpts, "CPU partitions OSS IO threads should run on");
 
 static struct cfs_cpt_table    *ost_io_cptable;
 
-#ifdef CONFIG_PROC_FS
-LPROC_SEQ_FOPS_RO_TYPE(ost, uuid);
-
-static struct lprocfs_vars lprocfs_ost_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &ost_uuid_fops  },
-       { NULL }
-};
-#endif /* CONFIG_PROC_FS */
-
 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
 {
@@ -86,10 +76,8 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
        int rc;
        ENTRY;
 
-#ifdef CONFIG_PROC_FS
-       obd->obd_vars = lprocfs_ost_obd_vars;
-       lprocfs_obd_setup(obd);
-#endif
+       lprocfs_obd_setup(obd, true);
+
        mutex_init(&ost->ost_health_mutex);
 
        svc_conf = (typeof(svc_conf)) {