staging/lustre/ptlrpc: Add infrastructure for sysfs migration
authorOleg Drokin <green@linuxhacker.ru>
Thu, 21 May 2015 19:32:08 +0000 (15:32 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 31 May 2015 02:13:20 +0000 (11:13 +0900)
Added necessary plumbing for ptlrpc sysfs integration for registered
services, sysfs directory registration.

Signed-off-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/include/lustre_net.h
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
drivers/staging/lustre/lustre/ptlrpc/service.c

index e2805bd1acf1070b176b22f974515dd567f9e2a9..4fc987d4bdb4269cbab6db308907e38925f2f51d 100644 (file)
@@ -2016,6 +2016,10 @@ struct ptlrpc_service {
        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
         */
@@ -2525,6 +2529,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,
+                               struct kset *parent,
                                struct proc_dir_entry *proc_entry);
 void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
 
index 151d60d45baa9df881d43cde7a99000c8f49456d..4287edbeff3215acc9579ff2028a843c8dddb947 100644 (file)
@@ -1112,7 +1112,8 @@ static int ldlm_setup(void)
                },
        };
        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);
index aeceef5152ac9b09ac26af25a7d84688a2b8d2b6..255798d2c7f467c0b77a5b7bab980e0c3fc4e747 100644 (file)
@@ -1049,6 +1049,46 @@ static ssize_t ptlrpc_lprocfs_hp_ratio_seq_write(struct file *file,
 }
 LPROC_SEQ_FOPS(ptlrpc_lprocfs_hp_ratio);
 
+static struct attribute *ptlrpc_svc_attrs[] = {
+       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)
 {
index a66dc3c6da419d6fa80b06a19100a4bb83647557..8ea8221caef833a04dda6006fdf667dfa34449a5 100644 (file)
@@ -76,6 +76,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 ptlrpc_sysfs_register_service(struct kset *parent,
+                                 struct ptlrpc_service *svc);
+void ptlrpc_sysfs_unregister_service(struct ptlrpc_service *svc);
+
 #if defined(CONFIG_PROC_FS)
 void ptlrpc_lprocfs_register_service(struct proc_dir_entry *proc_entry,
                                     struct ptlrpc_service *svc);
index 3fa52f117424800d3fcc55772247ed3cb8f1c6f3..d6927e13c17a35d2cd5199fa7be946fd5240d77d 100644 (file)
@@ -680,6 +680,7 @@ free_reqs_array:
  */
 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;
@@ -798,6 +799,12 @@ ptlrpc_register_service(struct ptlrpc_service_conf *conf,
        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;
+       }
+
        if (proc_entry != NULL)
                ptlrpc_lprocfs_register_service(proc_entry, service);
 
@@ -3033,6 +3040,7 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service)
        ptlrpc_service_nrs_cleanup(service);
 
        ptlrpc_lprocfs_unregister_service(service);
+       ptlrpc_sysfs_unregister_service(service);
 
        ptlrpc_service_free(service);