Whamcloud - gitweb
LU-8066 ptlrpc: migrate ptlrpc proc files to sysfs 73/25073/11
authorOleg Drokin <oleg.drokin@intel.com>
Sat, 8 Apr 2017 22:00:10 +0000 (18:00 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 19 Jul 2017 03:29:33 +0000 (03:29 +0000)
move procfs high_priority_ratio file to sysfs

Move ptlrpc service high_priority_ratio entry from procfs to sysfs.
Currently in use only by ldlm callback service only in
/sys/fs/lustre/ldlm/services/ldlm_cbd

Linux-commit: b40881e579588360242bd3f8f79f978d2a871e0e

move procfs threads* files to sysfs

Move ptlrpc service threads_min, threads_max and threads_running
entries from procfs to sysfs. Currently in use only by ldlm
callback service only in /sys/fs/lustre/ldlm/services/ldlm_cbd

Linux-commit: 673a6796f290fe8079af6a688f20c87e7416bba5

Add infrastructure for sysfs migration

Added necessary plumbing for ptlrpc sysfs integration for registered
services, sysfs directory registration.

Linux-commit: 328676f823b49741675f8ae47643669a31c79558

Add support for server side for this change.

Change-Id: Ia82a11dabd672a0c36083d06303aff2a81f3c48f
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/25073
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
12 files changed:
lustre/include/lprocfs_status.h
lustre/include/lustre_net.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/lprocfs_status_server.c
lustre/ost/ost_handler.c
lustre/ptlrpc/lproc_ptlrpc.c
lustre/ptlrpc/ptlrpc_internal.h
lustre/ptlrpc/service.c

index b141840..8f78a84 100644 (file)
@@ -470,6 +470,8 @@ struct nid_stat;
 extern int lprocfs_add_clear_entry(struct obd_device * obd,
                                   struct proc_dir_entry *entry);
 #ifdef HAVE_SERVER_SUPPORT
 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
 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
 extern int lprocfs_exp_cleanup(struct obd_export *exp);
 #else
index 8c918af..6c9f530 100644 (file)
@@ -50,7 +50,7 @@
  *
  * @{
  */
  *
  * @{
  */
-
+#include <linux/kobject.h>
 #include <linux/uio.h>
 #include <libcfs/libcfs.h>
 #include <lnet/nidstr.h>
 #include <linux/uio.h>
 #include <libcfs/libcfs.h>
 #include <lnet/nidstr.h>
@@ -1731,6 +1731,10 @@ struct ptlrpc_service {
        int                             srv_cpt_bits;
        /** CPT table this service is running over */
        struct cfs_cpt_table            *srv_cptable;
        int                             srv_cpt_bits;
        /** CPT table this service is running over */
        struct cfs_cpt_table            *srv_cptable;
+
+       /* sysfs object */
+       struct kobject                  srv_kobj;
+       struct completion               srv_kobj_unregister;
        /**
         * partition data for ptlrpc service
         */
        /**
         * partition data for ptlrpc service
         */
@@ -2263,6 +2267,7 @@ void ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs);
 int ptlrpc_hpreq_handler(struct ptlrpc_request *req);
 struct ptlrpc_service *ptlrpc_register_service(
                                struct ptlrpc_service_conf *conf,
 int ptlrpc_hpreq_handler(struct ptlrpc_request *req);
 struct ptlrpc_service *ptlrpc_register_service(
                                struct ptlrpc_service_conf *conf,
+                               struct kset *parent,
                                struct proc_dir_entry *proc_entry);
 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
 
                                struct proc_dir_entry *proc_entry);
 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
 
index 65c3c56..2e0a2fd 100644 (file)
@@ -3028,7 +3028,8 @@ static int ldlm_setup(void)
                },
        };
        ldlm_state->ldlm_cb_service = \
                },
        };
        ldlm_state->ldlm_cb_service = \
-                       ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
+                       ptlrpc_register_service(&conf, ldlm_svc_kset,
+                                               ldlm_svc_proc_dir);
        if (IS_ERR(ldlm_state->ldlm_cb_service)) {
                CERROR("failed to start service\n");
                rc = PTR_ERR(ldlm_state->ldlm_cb_service);
        if (IS_ERR(ldlm_state->ldlm_cb_service)) {
                CERROR("failed to start service\n");
                rc = PTR_ERR(ldlm_state->ldlm_cb_service);
@@ -3071,7 +3072,8 @@ static int ldlm_setup(void)
                },
        };
        ldlm_state->ldlm_cancel_service = \
                },
        };
        ldlm_state->ldlm_cancel_service = \
-                       ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
+                       ptlrpc_register_service(&conf, ldlm_svc_kset,
+                                               ldlm_svc_proc_dir);
        if (IS_ERR(ldlm_state->ldlm_cancel_service)) {
                CERROR("failed to start service\n");
                rc = PTR_ERR(ldlm_state->ldlm_cancel_service);
        if (IS_ERR(ldlm_state->ldlm_cancel_service)) {
                CERROR("failed to start service\n");
                rc = PTR_ERR(ldlm_state->ldlm_cancel_service);
index a781715..eee7e16 100644 (file)
@@ -65,6 +65,7 @@ struct mds_device {
        struct ptlrpc_service   *mds_mdss_service;
        struct ptlrpc_service   *mds_fld_service;
        struct mutex             mds_health_mutex;
        struct ptlrpc_service   *mds_mdss_service;
        struct ptlrpc_service   *mds_fld_service;
        struct mutex             mds_health_mutex;
+       struct kset             *mds_kset;
 };
 
 /*
 };
 
 /*
@@ -183,7 +184,8 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = ptlrpc_hpreq_handler,
                },
        };
                        .so_hpreq_handler       = ptlrpc_hpreq_handler,
                },
        };
-       m->mds_regular_service = ptlrpc_register_service(&conf, procfs_entry);
+       m->mds_regular_service = ptlrpc_register_service(&conf, m->mds_kset,
+                                                        procfs_entry);
        if (IS_ERR(m->mds_regular_service)) {
                rc = PTR_ERR(m->mds_regular_service);
                CERROR("failed to start regular mdt service: %d\n", rc);
        if (IS_ERR(m->mds_regular_service)) {
                rc = PTR_ERR(m->mds_regular_service);
                CERROR("failed to start regular mdt service: %d\n", rc);
@@ -226,7 +228,8 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_req_printer         = target_print_req,
                },
        };
                        .so_req_printer         = target_print_req,
                },
        };
-       m->mds_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
+       m->mds_readpage_service = ptlrpc_register_service(&conf, m->mds_kset,
+                                                         procfs_entry);
        if (IS_ERR(m->mds_readpage_service)) {
                rc = PTR_ERR(m->mds_readpage_service);
                CERROR("failed to start readpage service: %d\n", rc);
        if (IS_ERR(m->mds_readpage_service)) {
                rc = PTR_ERR(m->mds_readpage_service);
                CERROR("failed to start readpage service: %d\n", rc);
@@ -273,7 +276,8 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
+       m->mds_setattr_service = ptlrpc_register_service(&conf, m->mds_kset,
+                                                        procfs_entry);
        if (IS_ERR(m->mds_setattr_service)) {
                rc = PTR_ERR(m->mds_setattr_service);
                CERROR("failed to start setattr service: %d\n", rc);
        if (IS_ERR(m->mds_setattr_service)) {
                rc = PTR_ERR(m->mds_setattr_service);
                CERROR("failed to start setattr service: %d\n", rc);
@@ -318,7 +322,8 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_out_service = ptlrpc_register_service(&conf, procfs_entry);
+       m->mds_out_service = ptlrpc_register_service(&conf, m->mds_kset,
+                                                    procfs_entry);
        if (IS_ERR(m->mds_out_service)) {
                rc = PTR_ERR(m->mds_out_service);
                CERROR("failed to start out service: %d\n", rc);
        if (IS_ERR(m->mds_out_service)) {
                rc = PTR_ERR(m->mds_out_service);
                CERROR("failed to start out service: %d\n", rc);
@@ -353,7 +358,8 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
+       m->mds_mdsc_service = ptlrpc_register_service(&conf, m->mds_kset,
+                                                     procfs_entry);
        if (IS_ERR(m->mds_mdsc_service)) {
                rc = PTR_ERR(m->mds_mdsc_service);
                CERROR("failed to start seq controller service: %d\n", rc);
        if (IS_ERR(m->mds_mdsc_service)) {
                rc = PTR_ERR(m->mds_mdsc_service);
                CERROR("failed to start seq controller service: %d\n", rc);
@@ -389,7 +395,8 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
+       m->mds_mdss_service = ptlrpc_register_service(&conf, m->mds_kset,
+                                                     procfs_entry);
        if (IS_ERR(m->mds_mdss_service)) {
                rc = PTR_ERR(m->mds_mdss_service);
                CERROR("failed to start metadata seq server service: %d\n", rc);
        if (IS_ERR(m->mds_mdss_service)) {
                rc = PTR_ERR(m->mds_mdss_service);
                CERROR("failed to start metadata seq server service: %d\n", rc);
@@ -423,7 +430,8 @@ static int mds_start_ptlrpc_service(struct mds_device *m)
                        .so_hpreq_handler       = NULL,
                },
        };
                        .so_hpreq_handler       = NULL,
                },
        };
-       m->mds_fld_service = ptlrpc_register_service(&conf, procfs_entry);
+       m->mds_fld_service = ptlrpc_register_service(&conf, m->mds_kset,
+                                                    procfs_entry);
        if (IS_ERR(m->mds_fld_service)) {
                rc = PTR_ERR(m->mds_fld_service);
                CERROR("failed to start fld service: %d\n", rc);
        if (IS_ERR(m->mds_fld_service)) {
                rc = PTR_ERR(m->mds_fld_service);
                CERROR("failed to start fld service: %d\n", rc);
@@ -453,7 +461,7 @@ static struct lu_device *mds_device_fini(const struct lu_env *env,
        ENTRY;
 
        mds_stop_ptlrpc_service(m);
        ENTRY;
 
        mds_stop_ptlrpc_service(m);
-       lprocfs_obd_cleanup(obd);
+       lprocfs_kset_unregister(obd, m->mds_kset);
        RETURN(NULL);
 }
 
        RETURN(NULL);
 }
 
@@ -491,7 +499,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;
 
        /* set this lu_device to obd, because error handling need it */
        obd->obd_lu_dev = l;
 
-       rc = lprocfs_obd_setup(obd, true);
+       rc = lprocfs_kset_register(obd, &m->mds_kset);
        if (rc != 0) {
                mds_device_free(env, l);
                l = ERR_PTR(rc);
        if (rc != 0) {
                mds_device_free(env, l);
                l = ERR_PTR(rc);
@@ -501,8 +509,8 @@ static struct lu_device *mds_device_alloc(const struct lu_env *env,
        mutex_init(&m->mds_health_mutex);
 
        rc = mds_start_ptlrpc_service(m);
        mutex_init(&m->mds_health_mutex);
 
        rc = mds_start_ptlrpc_service(m);
-
        if (rc != 0) {
        if (rc != 0) {
+               lprocfs_kset_unregister(obd, m->mds_kset);
                mds_device_free(env, l);
                l = ERR_PTR(rc);
                return l;
                mds_device_free(env, l);
                l = ERR_PTR(rc);
                return l;
index e8dc509..fd6cc3b 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;
        int                rc;
 
        obd->obd_vars = lprocfs_mgs_obd_vars;
-       rc = lprocfs_obd_setup(obd, true);
+       rc = lprocfs_kset_register(obd, &mgs->mgs_kset);
        if (rc != 0)
                GOTO(out, rc);
 
        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_free_per_client_stats(obd);
-       lprocfs_obd_cleanup(obd);
+       lprocfs_kset_unregister(obd, mgs->mgs_kset);
         lprocfs_free_obd_stats(obd);
         lprocfs_free_md_stats(obd);
 }
         lprocfs_free_obd_stats(obd);
         lprocfs_free_md_stats(obd);
 }
index 6077b0d..8c92803 100644 (file)
@@ -1367,7 +1367,8 @@ static int mgs_init0(const struct lu_env *env, struct mgs_device *mgs,
        };
 
        /* Start the service threads */
        };
 
        /* Start the service threads */
-       mgs->mgs_service = ptlrpc_register_service(&conf, obd->obd_proc_entry);
+       mgs->mgs_service = ptlrpc_register_service(&conf, mgs->mgs_kset,
+                                                  obd->obd_proc_entry);
        if (IS_ERR(mgs->mgs_service)) {
                rc = PTR_ERR(mgs->mgs_service);
                CERROR("failed to start mgs service: %d\n", rc);
        if (IS_ERR(mgs->mgs_service)) {
                rc = PTR_ERR(mgs->mgs_service);
                CERROR("failed to start mgs service: %d\n", rc);
index 0f2463c..70d75ad 100644 (file)
@@ -179,6 +179,7 @@ struct mgs_device {
        struct proc_dir_entry           *mgs_proc_mntdev;
        cfs_time_t                       mgs_start_time;
        struct obd_device               *mgs_obd;
        struct proc_dir_entry           *mgs_proc_mntdev;
        cfs_time_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;
        struct local_oid_storage        *mgs_los;
        struct mutex                     mgs_mutex;
        struct mutex                     mgs_health_mutex;
index b73fdde..e32c8e8 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_CLASS
 
 
 #define DEBUG_SUBSYSTEM S_CLASS
 
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
 
 #include <obd_class.h>
 #include <lprocfs_status.h>
 #include <lustre/lustre_idl.h>
 #include <lustre_nodemap.h>
 
 
 #include <obd_class.h>
 #include <lprocfs_status.h>
 #include <lustre/lustre_idl.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)
 #ifdef CONFIG_PROC_FS
 
 int lprocfs_evict_client_open(struct inode *inode, struct file *f)
index 63fcc84..f0d351a 100644 (file)
@@ -67,6 +67,8 @@ MODULE_PARM_DESC(oss_io_cpts, "CPU partitions OSS IO threads should run on");
 
 static struct cfs_cpt_table    *ost_io_cptable;
 
 
 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)
 {
 /* Sigh - really, this is an OSS, the _server_, not the _target_ */
 static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
 {
@@ -76,7 +78,9 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
        int rc;
        ENTRY;
 
        int rc;
        ENTRY;
 
-       lprocfs_obd_setup(obd, true);
+       rc = lprocfs_kset_register(obd, &oss_kset);
+       if (rc)
+               return rc;
 
        mutex_init(&ost->ost_health_mutex);
 
 
        mutex_init(&ost->ost_health_mutex);
 
@@ -110,7 +114,7 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_hpreq_handler       = ptlrpc_hpreq_handler,
                },
        };
                        .so_hpreq_handler       = ptlrpc_hpreq_handler,
                },
        };
-       ost->ost_service = ptlrpc_register_service(&svc_conf,
+       ost->ost_service = ptlrpc_register_service(&svc_conf, oss_kset,
                                                   obd->obd_proc_entry);
        if (IS_ERR(ost->ost_service)) {
                rc = PTR_ERR(ost->ost_service);
                                                   obd->obd_proc_entry);
        if (IS_ERR(ost->ost_service)) {
                rc = PTR_ERR(ost->ost_service);
@@ -148,7 +152,7 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_req_printer         = target_print_req,
                },
        };
                        .so_req_printer         = target_print_req,
                },
        };
-       ost->ost_create_service = ptlrpc_register_service(&svc_conf,
+       ost->ost_create_service = ptlrpc_register_service(&svc_conf, oss_kset,
                                                          obd->obd_proc_entry);
        if (IS_ERR(ost->ost_create_service)) {
                rc = PTR_ERR(ost->ost_create_service);
                                                          obd->obd_proc_entry);
        if (IS_ERR(ost->ost_create_service)) {
                rc = PTR_ERR(ost->ost_create_service);
@@ -216,7 +220,7 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_req_printer         = target_print_req,
                },
        };
                        .so_req_printer         = target_print_req,
                },
        };
-       ost->ost_io_service = ptlrpc_register_service(&svc_conf,
+       ost->ost_io_service = ptlrpc_register_service(&svc_conf, oss_kset,
                                                      obd->obd_proc_entry);
        if (IS_ERR(ost->ost_io_service)) {
                rc = PTR_ERR(ost->ost_io_service);
                                                      obd->obd_proc_entry);
        if (IS_ERR(ost->ost_io_service)) {
                rc = PTR_ERR(ost->ost_io_service);
@@ -257,7 +261,7 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_hpreq_handler       = NULL,
                },
        };
                        .so_hpreq_handler       = NULL,
                },
        };
-       ost->ost_seq_service = ptlrpc_register_service(&svc_conf,
+       ost->ost_seq_service = ptlrpc_register_service(&svc_conf, oss_kset,
                                                      obd->obd_proc_entry);
        if (IS_ERR(ost->ost_seq_service)) {
                rc = PTR_ERR(ost->ost_seq_service);
                                                      obd->obd_proc_entry);
        if (IS_ERR(ost->ost_seq_service)) {
                rc = PTR_ERR(ost->ost_seq_service);
@@ -303,7 +307,7 @@ static int ost_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                        .so_hpreq_handler       = NULL,
                },
        };
                        .so_hpreq_handler       = NULL,
                },
        };
-       ost->ost_out_service = ptlrpc_register_service(&svc_conf,
+       ost->ost_out_service = ptlrpc_register_service(&svc_conf, oss_kset,
                                                       obd->obd_proc_entry);
        if (IS_ERR(ost->ost_out_service)) {
                rc = PTR_ERR(ost->ost_out_service);
                                                       obd->obd_proc_entry);
        if (IS_ERR(ost->ost_out_service)) {
                rc = PTR_ERR(ost->ost_out_service);
@@ -329,7 +333,7 @@ out_service:
         ptlrpc_unregister_service(ost->ost_service);
         ost->ost_service = NULL;
 out_lprocfs:
         ptlrpc_unregister_service(ost->ost_service);
         ost->ost_service = NULL;
 out_lprocfs:
-        lprocfs_obd_cleanup(obd);
+       lprocfs_kset_unregister(obd, oss_kset);
         RETURN(rc);
 }
 
         RETURN(rc);
 }
 
@@ -359,7 +363,7 @@ static int ost_cleanup(struct obd_device *obd)
 
        mutex_unlock(&ost->ost_health_mutex);
 
 
        mutex_unlock(&ost->ost_health_mutex);
 
-       lprocfs_obd_cleanup(obd);
+       lprocfs_kset_unregister(obd, oss_kset);
 
        if (ost_io_cptable != NULL) {
                cfs_cpt_table_free(ost_io_cptable);
 
        if (ost_io_cptable != NULL) {
                cfs_cpt_table_free(ost_io_cptable);
index 9aa7ed5..532cbaa 100644 (file)
@@ -338,26 +338,24 @@ ptlrpc_lprocfs_req_history_max_seq_write(struct file *file,
 }
 LPROC_SEQ_FOPS(ptlrpc_lprocfs_req_history_max);
 
 }
 LPROC_SEQ_FOPS(ptlrpc_lprocfs_req_history_max);
 
-static int
-ptlrpc_lprocfs_threads_min_seq_show(struct seq_file *m, void *n)
+static ssize_t threads_min_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
 {
 {
-       struct ptlrpc_service *svc = m->private;
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
 
 
-       seq_printf(m, "%d\n",
-                  svc->srv_nthrs_cpt_init * svc->srv_ncpts);
-       return 0;
+       return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_init * svc->srv_ncpts);
 }
 
 }
 
-static ssize_t
-ptlrpc_lprocfs_threads_min_seq_write(struct file *file,
-                                    const char __user *buffer,
-                                    size_t count, loff_t *off)
+static ssize_t threads_min_store(struct kobject *kobj, struct attribute *attr,
+                                const char *buffer, size_t count)
 {
 {
-       struct seq_file *m = file->private_data;
-       struct ptlrpc_service *svc = m->private;
-       __s64 val;
-       int rc = lprocfs_str_to_s64(buffer, count, &val);
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
+       unsigned long val;
+       int rc;
 
 
+       rc = kstrtoul(buffer, 10, &val);
        if (rc < 0)
                return rc;
 
        if (rc < 0)
                return rc;
 
@@ -376,44 +374,43 @@ ptlrpc_lprocfs_threads_min_seq_write(struct file *file,
 
        return count;
 }
 
        return count;
 }
-LPROC_SEQ_FOPS(ptlrpc_lprocfs_threads_min);
+LUSTRE_RW_ATTR(threads_min);
 
 
-static int
-ptlrpc_lprocfs_threads_started_seq_show(struct seq_file *m, void *n)
+static ssize_t threads_started_show(struct kobject *kobj,
+                                   struct attribute *attr,
+                                   char *buf)
 {
 {
-       struct ptlrpc_service           *svc = m->private;
-       struct ptlrpc_service_part      *svcpt;
-       int     total = 0;
-       int     i;
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
+       struct ptlrpc_service_part *svcpt;
+       int total = 0;
+       int i;
 
        ptlrpc_service_for_each_part(svcpt, i, svc)
                total += svcpt->scp_nthrs_running;
 
 
        ptlrpc_service_for_each_part(svcpt, i, svc)
                total += svcpt->scp_nthrs_running;
 
-       seq_printf(m, "%d\n", total);
-       return 0;
+       return sprintf(buf, "%d\n", total);
 }
 }
-LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_threads_started);
+LUSTRE_RO_ATTR(threads_started);
 
 
-static int
-ptlrpc_lprocfs_threads_max_seq_show(struct seq_file *m, void *n)
+static ssize_t threads_max_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
 {
 {
-       struct ptlrpc_service *svc = m->private;
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
 
 
-       seq_printf(m, "%d\n",
-                  svc->srv_nthrs_cpt_limit * svc->srv_ncpts);
-       return 0;
+       return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_limit * svc->srv_ncpts);
 }
 
 }
 
-static ssize_t
-ptlrpc_lprocfs_threads_max_seq_write(struct file *file,
-                                    const char __user *buffer,
-                                    size_t count, loff_t *off)
+static ssize_t threads_max_store(struct kobject *kobj, struct attribute *attr,
+                                const char *buffer, size_t count)
 {
 {
-       struct seq_file *m = file->private_data;
-       struct ptlrpc_service *svc = m->private;
-       __s64 val;
-       int rc = lprocfs_str_to_s64(buffer, count, &val);
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
+       unsigned long val;
+       int rc;
 
 
+       rc = kstrtoul(buffer, 10, &val);
        if (rc < 0)
                return rc;
 
        if (rc < 0)
                return rc;
 
@@ -432,7 +429,7 @@ ptlrpc_lprocfs_threads_max_seq_write(struct file *file,
 
        return count;
 }
 
        return count;
 }
-LPROC_SEQ_FOPS(ptlrpc_lprocfs_threads_max);
+LUSTRE_RW_ATTR(threads_max);
 
 /**
  * Translates \e ptlrpc_nrs_pol_state values to human-readable strings.
 
 /**
  * Translates \e ptlrpc_nrs_pol_state values to human-readable strings.
@@ -1068,59 +1065,92 @@ static int ptlrpc_lprocfs_timeouts_seq_show(struct seq_file *m, void *n)
 }
 LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_timeouts);
 
 }
 LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_timeouts);
 
-static int ptlrpc_lprocfs_hp_ratio_seq_show(struct seq_file *m, void *v)
+static ssize_t high_priority_ratio_show(struct kobject *kobj,
+                                       struct attribute *attr,
+                                       char *buf)
 {
 {
-       struct ptlrpc_service *svc = m->private;
-       seq_printf(m, "%d\n", svc->srv_hpreq_ratio);
-       return 0;
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
+
+       return sprintf(buf, "%d\n", svc->srv_hpreq_ratio);
 }
 
 }
 
-static ssize_t
-ptlrpc_lprocfs_hp_ratio_seq_write(struct file *file, const char __user *buffer,
-                                 size_t count, loff_t *off)
+static ssize_t high_priority_ratio_store(struct kobject *kobj,
+                                        struct attribute *attr,
+                                        const char *buffer,
+                                        size_t count)
 {
 {
-       struct seq_file *m = file->private_data;
-       struct ptlrpc_service *svc = m->private;
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
        int rc;
        int rc;
-       __s64 val;
+       unsigned long val;
 
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtoul(buffer, 10, &val);
        if (rc < 0)
                return rc;
 
        if (rc < 0)
                return rc;
 
-       if (val < 0 || val > INT_MAX)
-               return -ERANGE;
-
        spin_lock(&svc->srv_lock);
        svc->srv_hpreq_ratio = val;
        spin_unlock(&svc->srv_lock);
 
        return count;
 }
        spin_lock(&svc->srv_lock);
        svc->srv_hpreq_ratio = val;
        spin_unlock(&svc->srv_lock);
 
        return count;
 }
-LPROC_SEQ_FOPS(ptlrpc_lprocfs_hp_ratio);
+LUSTRE_RW_ATTR(high_priority_ratio);
+
+static struct attribute *ptlrpc_svc_attrs[] = {
+       &lustre_attr_threads_min.attr,
+       &lustre_attr_threads_started.attr,
+       &lustre_attr_threads_max.attr,
+       &lustre_attr_high_priority_ratio.attr,
+       NULL,
+};
+
+static void ptlrpc_sysfs_svc_release(struct kobject *kobj)
+{
+       struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service,
+                                                 srv_kobj);
+
+       complete(&svc->srv_kobj_unregister);
+}
+
+static struct kobj_type ptlrpc_svc_ktype = {
+       .default_attrs  = ptlrpc_svc_attrs,
+       .sysfs_ops      = &lustre_sysfs_ops,
+       .release        = ptlrpc_sysfs_svc_release,
+};
+
+void ptlrpc_sysfs_unregister_service(struct ptlrpc_service *svc)
+{
+       /* Let's see if we had a chance at initialization first */
+       if (svc->srv_kobj.kset) {
+               kobject_put(&svc->srv_kobj);
+               wait_for_completion(&svc->srv_kobj_unregister);
+       }
+}
+
+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;
+}
 
 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
                                      struct ptlrpc_service *svc)
 {
        struct lprocfs_vars lproc_vars[] = {
 
 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *entry,
                                      struct ptlrpc_service *svc)
 {
        struct lprocfs_vars lproc_vars[] = {
-               { .name = "high_priority_ratio",
-                 .fops = &ptlrpc_lprocfs_hp_ratio_fops,
-                 .data = svc },
                { .name = "req_buffer_history_len",
                  .fops = &ptlrpc_lprocfs_req_history_len_fops,
                  .data = svc },
                { .name = "req_buffer_history_max",
                  .fops = &ptlrpc_lprocfs_req_history_max_fops,
                  .data = svc },
                { .name = "req_buffer_history_len",
                  .fops = &ptlrpc_lprocfs_req_history_len_fops,
                  .data = svc },
                { .name = "req_buffer_history_max",
                  .fops = &ptlrpc_lprocfs_req_history_max_fops,
                  .data = svc },
-               { .name = "threads_min",
-                 .fops = &ptlrpc_lprocfs_threads_min_fops,
-                 .data = svc },
-               { .name = "threads_max",
-                 .fops = &ptlrpc_lprocfs_threads_max_fops,
-                 .data = svc },
-               { .name = "threads_started",
-                 .fops = &ptlrpc_lprocfs_threads_started_fops,
-                 .data = svc },
                { .name = "timeouts",
                  .fops = &ptlrpc_lprocfs_timeouts_fops,
                  .data = svc },
                { .name = "timeouts",
                  .fops = &ptlrpc_lprocfs_timeouts_fops,
                  .data = svc },
index cfd1de5..9c011cf 100644 (file)
@@ -105,6 +105,10 @@ void ptlrpc_initiate_recovery(struct obd_import *imp);
 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset);
 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset);
 
 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset);
 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset);
 
+int ptlrpc_sysfs_register_service(struct kset *parent,
+                                 struct ptlrpc_service *svc);
+void ptlrpc_sysfs_unregister_service(struct ptlrpc_service *svc);
+
 #ifdef CONFIG_PROC_FS
 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *proc_entry,
                                      struct ptlrpc_service *svc);
 #ifdef CONFIG_PROC_FS
 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *proc_entry,
                                      struct ptlrpc_service *svc);
index 5daa2ec..9e18d97 100644 (file)
@@ -683,6 +683,7 @@ ptlrpc_service_part_init(struct ptlrpc_service *svc,
  */
 struct ptlrpc_service *
 ptlrpc_register_service(struct ptlrpc_service_conf *conf,
  */
 struct ptlrpc_service *
 ptlrpc_register_service(struct ptlrpc_service_conf *conf,
+                       struct kset *parent,
                        struct proc_dir_entry *proc_entry)
 {
        struct ptlrpc_service_cpt_conf  *cconf = &conf->psc_cpt;
                        struct proc_dir_entry *proc_entry)
 {
        struct ptlrpc_service_cpt_conf  *cconf = &conf->psc_cpt;
@@ -800,6 +801,12 @@ ptlrpc_register_service(struct ptlrpc_service_conf *conf,
        list_add(&service->srv_list, &ptlrpc_all_services);
        mutex_unlock(&ptlrpc_all_services_mutex);
 
        list_add(&service->srv_list, &ptlrpc_all_services);
        mutex_unlock(&ptlrpc_all_services_mutex);
 
+       if (parent) {
+               rc = ptlrpc_sysfs_register_service(parent, service);
+               if (rc)
+                       GOTO(failed, rc);
+       }
+
        if (proc_entry != NULL)
                ptlrpc_lprocfs_register_service(proc_entry, service);
 
        if (proc_entry != NULL)
                ptlrpc_lprocfs_register_service(proc_entry, service);
 
@@ -3239,6 +3246,7 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service)
        ptlrpc_service_nrs_cleanup(service);
 
        ptlrpc_lprocfs_unregister_service(service);
        ptlrpc_service_nrs_cleanup(service);
 
        ptlrpc_lprocfs_unregister_service(service);
+       ptlrpc_sysfs_unregister_service(service);
 
        ptlrpc_service_free(service);
 
 
        ptlrpc_service_free(service);