From 328676f823b49741675f8ae47643669a31c79558 Mon Sep 17 00:00:00 2001 From: Oleg Drokin Date: Thu, 21 May 2015 15:32:08 -0400 Subject: [PATCH] staging/lustre/ptlrpc: Add infrastructure for sysfs migration Added necessary plumbing for ptlrpc sysfs integration for registered services, sysfs directory registration. Signed-off-by: Oleg Drokin Signed-off-by: Greg Kroah-Hartman --- .../lustre/lustre/include/lustre_net.h | 5 +++ .../staging/lustre/lustre/ldlm/ldlm_lockd.c | 3 +- .../lustre/lustre/ptlrpc/lproc_ptlrpc.c | 40 +++++++++++++++++++ .../lustre/lustre/ptlrpc/ptlrpc_internal.h | 4 ++ .../staging/lustre/lustre/ptlrpc/service.c | 8 ++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h index e2805bd1acf1..4fc987d4bdb4 100644 --- a/drivers/staging/lustre/lustre/include/lustre_net.h +++ b/drivers/staging/lustre/lustre/include/lustre_net.h @@ -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); diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c index 151d60d45baa..4287edbeff32 100644 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c @@ -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); diff --git a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c index aeceef5152ac..255798d2c7f4 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c +++ b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c @@ -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) { diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h index a66dc3c6da41..8ea8221caef8 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h +++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h @@ -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); diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c index 3fa52f117424..d6927e13c17a 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/service.c +++ b/drivers/staging/lustre/lustre/ptlrpc/service.c @@ -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); -- 2.34.1