From c6e1c8ea60be6c6814b6bc325d16959056436124 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Mon, 26 Nov 2012 15:46:07 -0600 Subject: [PATCH] LU-2363 lod: Fix statfs entries in lod procfs Factor toplevel lod procfs out of lod_pools_{init,fini}. Support lod statfs entries using osd methods. Change-Id: I27f8c1441079ad455a03f16abb05491fd655d2e3 Signed-off-by: John L. Hammond Reviewed-on: http://review.whamcloud.com/4637 Tested-by: Hudson Reviewed-by: Alex Zhuravlev Tested-by: Maloo Reviewed-by: Keith Mannthey Reviewed-by: Andreas Dilger --- lustre/include/lprocfs_status.h | 14 +++--- lustre/lod/lod_dev.c | 28 +++--------- lustre/lod/lod_internal.h | 3 +- lustre/lod/lod_lov.c | 37 --------------- lustre/lod/lproc_lod.c | 97 +++++++++++++++++++++++++++++++++++----- lustre/obdclass/lprocfs_status.c | 16 ++++--- 6 files changed, 114 insertions(+), 81 deletions(-) diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 354f9eb..d0ae402 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -556,12 +556,14 @@ extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list); extern int lprocfs_obd_cleanup(struct obd_device *obd); extern struct file_operations lprocfs_evict_client_fops; -extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name, - mode_t mode, struct file_operations *seq_fops, - void *data); -extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name, - mode_t mode, struct file_operations *seq_fops, - void *data); +extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, const char *name, + mode_t mode, + const struct file_operations *seq_fops, + void *data); +extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name, + mode_t mode, + const struct file_operations *seq_fops, + void *data); /* Generic callbacks */ diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index 7340df9..3733700 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -406,7 +406,6 @@ static int lod_init0(const struct lu_env *env, struct lod_device *lod, struct lu_device_type *ldt, struct lustre_cfg *cfg) { struct dt_device_param ddp; - struct proc_dir_entry *lov_proc_dir; struct obd_device *obd; int rc; ENTRY; @@ -435,23 +434,9 @@ static int lod_init0(const struct lu_env *env, struct lod_device *lod, if (rc) GOTO(out_disconnect, rc); - /* for compatibility we link old procfs's OSC entries to osp ones */ - lov_proc_dir = lprocfs_srch(proc_lustre_root, "lov"); - if (lov_proc_dir) { - cfs_proc_dir_entry_t *symlink = NULL; - char *name; - OBD_ALLOC(name, strlen(obd->obd_name) + 1); - if (name) { - strcpy(name, obd->obd_name); - if (strstr(name, "lov")) - symlink = lprocfs_add_symlink(name, - lov_proc_dir, - "../lod/%s", - obd->obd_name); - OBD_FREE(name, strlen(obd->obd_name) + 1); - lod->lod_symlink = symlink; - } - } + rc = lod_procfs_init(lod); + if (rc) + GOTO(out_pools, rc); mutex_init(&lod->lod_mutex); init_rwsem(&lod->lod_rw_sem); @@ -459,6 +444,8 @@ static int lod_init0(const struct lu_env *env, struct lod_device *lod, RETURN(0); +out_pools: + lod_pools_fini(lod); out_disconnect: obd_disconnect(lod->lod_child_exp); RETURN(rc); @@ -508,11 +495,10 @@ static struct lu_device *lod_device_fini(const struct lu_env *env, struct lod_device *lod = lu2lod_dev(d); ENTRY; - if (lod->lod_symlink) - lprocfs_remove(&lod->lod_symlink); - lod_pools_fini(lod); + lod_procfs_fini(lod); + RETURN(NULL); } diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 1a76ef5..609254b 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -294,8 +294,9 @@ int qos_add_tgt(struct lod_device*, struct lod_ost_desc *); int qos_del_tgt(struct lod_device *, struct lod_ost_desc *); /* lproc_lod.c */ -extern struct file_operations lod_proc_target_fops; void lprocfs_lod_init_vars(struct lprocfs_static_vars *lvars); +int lod_procfs_init(struct lod_device *lod); +void lod_procfs_fini(struct lod_device *lod); /* lod_object.c */ int lod_object_set_pool(struct lod_object *o, char *pool); diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index 8a1ca48..f46e98e 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -846,7 +846,6 @@ void lod_fix_desc(struct lov_desc *desc) int lod_pools_init(struct lod_device *lod, struct lustre_cfg *lcfg) { - struct lprocfs_static_vars lvars = { 0 }; struct obd_device *obd; struct lov_desc *desc; int rc; @@ -932,35 +931,8 @@ int lod_pools_init(struct lod_device *lod, struct lustre_cfg *lcfg) lod->lod_death_row = 0; lod->lod_refcount = 0; - lprocfs_lod_init_vars(&lvars); - lprocfs_obd_setup(obd, lvars.obd_vars); - -#ifdef LPROCFS - rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", - 0444, &lod_proc_target_fops, obd); - if (rc) { - CWARN("%s: Error adding the target_obd file %d\n", - obd->obd_name, rc); - GOTO(out_lproc, rc); - } - lod->lod_pool_proc_entry = lprocfs_register("pools", - obd->obd_proc_entry, - NULL, NULL); - if (IS_ERR(lod->lod_pool_proc_entry)) { - int ret = PTR_ERR(lod->lod_pool_proc_entry); - lod->lod_pool_proc_entry = NULL; - CWARN("%s: Failed to create pool proc file %d\n", - obd->obd_name, ret); - rc = lod_pools_fini(lod); - RETURN(ret); - } -#endif - RETURN(0); -out_lproc: - lprocfs_obd_cleanup(obd); - lod_ost_pool_free(&lod->lod_qos.lq_rr.lqr_pool); out_pool_info: lod_ost_pool_free(&lod->lod_pool_info); out_hash: @@ -1003,15 +975,6 @@ int lod_pools_fini(struct lod_device *lod) cfs_hash_putref(lod->lod_pools_hash_body); lod_ost_pool_free(&(lod->lod_qos.lq_rr.lqr_pool)); lod_ost_pool_free(&lod->lod_pool_info); - - /* clear pools parent proc entry only after all pools are killed */ - if (lod->lod_pool_proc_entry) { - lprocfs_remove(&lod->lod_pool_proc_entry); - lod->lod_pool_proc_entry = NULL; - } - - lprocfs_obd_cleanup(obd); - OBD_FREE_PTR(lod->lod_qos.lq_statfs_data); RETURN(0); } diff --git a/lustre/lod/lproc_lod.c b/lustre/lod/lproc_lod.c index 881e914..37b214f 100644 --- a/lustre/lod/lproc_lod.c +++ b/lustre/lod/lproc_lod.c @@ -405,7 +405,7 @@ static int lod_osts_seq_show(struct seq_file *p, void *v) active ? "" : "IN"); } -struct seq_operations lod_osts_sops = { +static const struct seq_operations lod_osts_sops = { .start = lod_osts_seq_start, .stop = lod_osts_seq_stop, .next = lod_osts_seq_next, @@ -430,7 +430,7 @@ static int lod_osts_seq_open(struct inode *inode, struct file *file) return 0; } -struct lprocfs_vars lprocfs_lod_obd_vars[] = { +static struct lprocfs_vars lprocfs_lod_obd_vars[] = { { "uuid", lprocfs_rd_uuid, 0, 0 }, { "stripesize", lod_rd_stripesize, lod_wr_stripesize, 0 }, { "stripeoffset", lod_rd_stripeoffset, lod_wr_stripeoffset, 0 }, @@ -438,13 +438,6 @@ struct lprocfs_vars lprocfs_lod_obd_vars[] = { { "stripetype", lod_rd_stripetype, lod_wr_stripetype, 0 }, { "numobd", lod_rd_numobd, 0, 0 }, { "activeobd", lod_rd_activeobd, 0, 0 }, - { "filestotal", lprocfs_rd_filestotal, 0, 0 }, - { "filesfree", lprocfs_rd_filesfree, 0, 0 }, - /*{ "filegroups", lprocfs_rd_filegroups, 0, 0 },*/ - { "blocksize", lprocfs_rd_blksize, 0, 0 }, - { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 }, - { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 }, - { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 }, { "desc_uuid", lod_rd_desc_uuid, 0, 0 }, { "qos_prio_free",lod_rd_qos_priofree, lod_wr_qos_priofree, 0 }, { "qos_threshold_rr", lod_rd_qos_thresholdrr, lod_wr_qos_thresholdrr, 0 }, @@ -452,6 +445,16 @@ struct lprocfs_vars lprocfs_lod_obd_vars[] = { { 0 } }; +static struct lprocfs_vars lprocfs_lod_osd_vars[] = { + { "blocksize", lprocfs_osd_rd_blksize, 0, 0 }, + { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 }, + { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 }, + { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 }, + { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 }, + { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 }, + { 0 } +}; + static struct lprocfs_vars lprocfs_lod_module_vars[] = { { "num_refs", lprocfs_rd_numrefs, 0, 0 }, { 0 } @@ -463,12 +466,86 @@ void lprocfs_lod_init_vars(struct lprocfs_static_vars *lvars) lvars->obd_vars = lprocfs_lod_obd_vars; } -struct file_operations lod_proc_target_fops = { +static const struct file_operations lod_proc_target_fops = { .owner = THIS_MODULE, .open = lod_osts_seq_open, .read = seq_read, .llseek = seq_lseek, .release = lprocfs_seq_release, }; + +int lod_procfs_init(struct lod_device *lod) +{ + struct obd_device *obd = lod2obd(lod); + struct lprocfs_static_vars lvars; + cfs_proc_dir_entry_t *lov_proc_dir; + int rc; + + lprocfs_lod_init_vars(&lvars); + rc = lprocfs_obd_setup(obd, lvars.obd_vars); + if (rc) { + CERROR("%s: cannot setup procfs entry: %d\n", + obd->obd_name, rc); + RETURN(rc); + } + + rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_lod_osd_vars, + &lod->lod_dt_dev); + if (rc) { + CERROR("%s: cannot setup procfs entry: %d\n", + obd->obd_name, rc); + GOTO(out, rc); + } + + rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", + 0444, &lod_proc_target_fops, obd); + if (rc) { + CWARN("%s: Error adding the target_obd file %d\n", + obd->obd_name, rc); + GOTO(out, rc); + } + + lod->lod_pool_proc_entry = lprocfs_register("pools", + obd->obd_proc_entry, + NULL, NULL); + if (IS_ERR(lod->lod_pool_proc_entry)) { + rc = PTR_ERR(lod->lod_pool_proc_entry); + lod->lod_pool_proc_entry = NULL; + CWARN("%s: Failed to create pool proc file: %d\n", + obd->obd_name, rc); + GOTO(out, rc); + } + + /* for compatibility we link old procfs's OSC entries to osp ones */ + lov_proc_dir = lprocfs_srch(proc_lustre_root, "lov"); + if (lov_proc_dir != NULL && strstr(obd->obd_name, "lov") != NULL) + lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, + lov_proc_dir, + "../lod/%s", + obd->obd_name); + + RETURN(0); + +out: + lprocfs_obd_cleanup(obd); + + return rc; +} + +void lod_procfs_fini(struct lod_device *lod) +{ + struct obd_device *obd = lod2obd(lod); + + if (lod->lod_symlink != NULL) + lprocfs_remove(&lod->lod_symlink); + + if (lod->lod_pool_proc_entry != NULL) { + lprocfs_remove(&lod->lod_pool_proc_entry); + lod->lod_pool_proc_entry = NULL; + } + + lprocfs_obd_cleanup(obd); +} + #endif /* LPROCFS */ diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index 9a78fe4..d8146ae 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -2346,8 +2346,11 @@ char *lprocfs_find_named_value(const char *buffer, const char *name, } EXPORT_SYMBOL(lprocfs_find_named_value); -int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name, mode_t mode, - struct file_operations *seq_fops, void *data) +int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, + const char *name, + mode_t mode, + const struct file_operations *seq_fops, + void *data) { struct proc_dir_entry *entry; ENTRY; @@ -2367,10 +2370,11 @@ int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name, mode_t mode, } EXPORT_SYMBOL(lprocfs_seq_create); -__inline__ int lprocfs_obd_seq_create(struct obd_device *dev, char *name, - mode_t mode, - struct file_operations *seq_fops, - void *data) +int lprocfs_obd_seq_create(struct obd_device *dev, + const char *name, + mode_t mode, + const struct file_operations *seq_fops, + void *data) { return (lprocfs_seq_create(dev->obd_proc_entry, name, mode, seq_fops, data)); -- 1.8.3.1