Commit 9b801302 authored by Oleg Drokin's avatar Oleg Drokin Committed by Greg Kroah-Hartman

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: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b8c7ceda
......@@ -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,
......
......@@ -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
......
......@@ -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",
......
......@@ -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;
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment