From: Oleg Drokin Date: Thu, 21 May 2015 19:32:16 +0000 (-0400) Subject: staging/lustre/obdclass: Prepare for procfs to sysfs migration X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=9b8013023cb62360b56c04313687e93a1c2bf3d6;p=openwrt%2Fstaging%2Fblogic.git staging/lustre/obdclass: Prepare for procfs to sysfs migration Add necessary plumbing to register obd types and instances under /sys/fs/lustre Signed-off-by: Oleg Drokin Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/lustre/lustre/include/lprocfs_status.h b/drivers/staging/lustre/lustre/include/lprocfs_status.h index 1bbc93017ce7..3225e3c20992 100644 --- a/drivers/staging/lustre/lustre/include/lprocfs_status.h +++ b/drivers/staging/lustre/lustre/include/lprocfs_status.h @@ -62,6 +62,7 @@ struct lprocfs_vars { struct lprocfs_static_vars { struct lprocfs_vars *obd_vars; + struct attribute_group *sysfs_vars; }; /* if we find more consumers this could be generalized */ @@ -605,7 +606,8 @@ extern void lprocfs_remove(struct proc_dir_entry **root); extern void lprocfs_remove_proc_entry(const char *name, struct proc_dir_entry *parent); -extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list); +extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list, + struct attribute_group *attrs); extern int lprocfs_obd_cleanup(struct obd_device *obd); extern int ldebugfs_seq_create(struct dentry *parent, diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h index 2a88b806fca5..7bba91260e31 100644 --- a/drivers/staging/lustre/lustre/include/obd.h +++ b/drivers/staging/lustre/lustre/include/obd.h @@ -249,6 +249,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 { @@ -936,6 +937,9 @@ struct obd_device { struct lu_ref obd_reference; int obd_conn_inprogress; + + struct kobject obd_kobj; /* sysfs object */ + struct completion obd_kobj_unregister; }; #define OBD_LLOG_FL_SENDNOW 0x0001 diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c index 0b2d35f26fc5..14764ee96a93 100644 --- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c +++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c @@ -1309,7 +1309,7 @@ int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid, static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg) { struct lmv_obd *lmv = &obd->u.lmv; - struct lprocfs_static_vars lvars; + struct lprocfs_static_vars lvars = { NULL }; struct lmv_desc *desc; int rc; @@ -1343,7 +1343,7 @@ static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg) lprocfs_lmv_init_vars(&lvars); - lprocfs_obd_setup(obd, lvars.obd_vars); + lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars); #if defined (CONFIG_PROC_FS) { rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c index d4e8d9c30ed3..44739eae0108 100644 --- a/drivers/staging/lustre/lustre/lov/lov_obd.c +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c @@ -821,7 +821,7 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg) goto out; lprocfs_lov_init_vars(&lvars); - lprocfs_obd_setup(obd, lvars.obd_vars); + lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars); #if defined (CONFIG_PROC_FS) { int rc1; diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c index b24ec3f848f3..9f34d67b8f4e 100644 --- a/drivers/staging/lustre/lustre/mdc/mdc_request.c +++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c @@ -2447,7 +2447,7 @@ static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg) if (rc) goto err_close_lock; lprocfs_mdc_init_vars(&lvars); - lprocfs_obd_setup(obd, lvars.obd_vars); + lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars); sptlrpc_lprocfs_cliobd_attach(obd); ptlrpc_lprocfs_register_obd(obd); diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c index 5fff272f7b9f..517b8ce1a44a 100644 --- a/drivers/staging/lustre/lustre/mgc/mgc_request.c +++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c @@ -722,7 +722,7 @@ static int mgc_cleanup(struct obd_device *obd) static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg) { - struct lprocfs_static_vars lvars; + struct lprocfs_static_vars lvars = { NULL }; int rc; ptlrpcd_addref(); @@ -738,7 +738,7 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg) } lprocfs_mgc_init_vars(&lvars); - lprocfs_obd_setup(obd, lvars.obd_vars); + lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars); sptlrpc_lprocfs_cliobd_attach(obd); if (atomic_inc_return(&mgc_count) == 1) { diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index eab4130d6c49..8e3dfafcf62d 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -199,6 +199,12 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, goto failed; } + type->typ_kobj = kobject_create_and_add(type->typ_name, lustre_kobj); + if (!type->typ_kobj) { + rc = -ENOMEM; + goto failed; + } + if (ldt != NULL) { type->typ_lu = ldt; rc = lu_device_type_init(ldt); @@ -213,6 +219,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); kfree(type->typ_name); kfree(type->typ_md_ops); kfree(type->typ_dt_ops); @@ -239,6 +247,9 @@ int class_unregister_type(const char *name) return -EBUSY; } + if (type->typ_kobj) + kobject_put(type->typ_kobj); + if (type->typ_procroot) { lprocfs_remove(&type->typ_procroot); } diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c index 695b3e0dcfcf..e6f0d11205c9 100644 --- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c @@ -994,7 +994,26 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data) } EXPORT_SYMBOL(lprocfs_rd_connect_flags); -int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list) +static struct attribute *obd_def_attrs[] = { + 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 = { + .default_attrs = obd_def_attrs, + .sysfs_ops = &lustre_sysfs_ops, + .release = obd_sysfs_release, +}; + +int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list, + struct attribute_group *attrs) { int rc = 0; @@ -1002,15 +1021,32 @@ int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list) LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC); LASSERT(obd->obd_type->typ_procroot != NULL); + 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 (attrs) { + rc = sysfs_create_group(&obd->obd_kobj, attrs); + if (rc) { + kobject_put(&obd->obd_kobj); + return rc; + } + } + obd->obd_proc_entry = lprocfs_register(obd->obd_name, obd->obd_type->typ_procroot, list, 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); @@ -1028,6 +1064,8 @@ int lprocfs_obd_cleanup(struct obd_device *obd) 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); diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c index 5924f9f1b5b1..6b6851ad3990 100644 --- a/drivers/staging/lustre/lustre/osc/osc_request.c +++ b/drivers/staging/lustre/lustre/osc/osc_request.c @@ -3184,7 +3184,7 @@ int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg) cli->cl_grant_shrink_interval = GRANT_SHRINK_INTERVAL; lprocfs_osc_init_vars(&lvars); - if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0) { + if (lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars) == 0) { lproc_osc_attach_seqstat(obd); sptlrpc_lprocfs_cliobd_attach(obd); ptlrpc_lprocfs_register_obd(obd);