From d5cbb8f65267962a1c12aa89e3effebed7b73e3e Mon Sep 17 00:00:00 2001 From: James Simmons Date: Tue, 4 Mar 2014 10:45:30 -0500 Subject: [PATCH 1/1] LU-3319 procfs: move mgs proc handling to seq_files With 3.10 linux kernel and above proc handling now only uses struct seq_files. This patch migrates the mgs layer proc entries over to using seq_files. Signed-off-by: James Simmons Change-Id: I1a12dd9b1fc8f139116a8f3a684956a5ba88f055 Reviewed-on: http://review.whamcloud.com/7935 Reviewed-by: Bob Glossman Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- lustre/mgs/lproc_mgs.c | 202 +++++++++++++++++++++++----------------------- lustre/mgs/mgs_handler.c | 5 +- lustre/mgs/mgs_internal.h | 13 +-- lustre/mgs/mgs_nids.c | 11 ++- 4 files changed, 110 insertions(+), 121 deletions(-) diff --git a/lustre/mgs/lproc_mgs.c b/lustre/mgs/lproc_mgs.c index ffa2d0d..f0ea956 100644 --- a/lustre/mgs/lproc_mgs.c +++ b/lustre/mgs/lproc_mgs.c @@ -126,19 +126,110 @@ static int mgsself_srpc_seq_show(struct seq_file *seq, void *v) return 0; } - LPROC_SEQ_FOPS_RO(mgsself_srpc); +static int mgs_live_seq_show(struct seq_file *seq, void *v) +{ + struct fs_db *fsdb = seq->private; + struct mgs_tgt_srpc_conf *srpc_tgt; + int i; + + mutex_lock(&fsdb->fsdb_mutex); + + seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name); + seq_printf(seq, "flags: %#lx gen: %d\n", + fsdb->fsdb_flags, fsdb->fsdb_gen); + for (i = 0; i < INDEX_MAP_SIZE * 8; i++) + if (test_bit(i, fsdb->fsdb_mdt_index_map)) + seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i); + for (i = 0; i < INDEX_MAP_SIZE * 8; i++) + if (test_bit(i, fsdb->fsdb_ost_index_map)) + seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i); + + seq_printf(seq, "\nSecure RPC Config Rules:\n"); +#if 0 + seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name, + PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no"); +#endif + for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt; + srpc_tgt = srpc_tgt->mtsc_next) { + seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt, + &srpc_tgt->mtsc_rset); + } + seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen); + + lprocfs_rd_ir_state(seq, fsdb); + + mutex_unlock(&fsdb->fsdb_mutex); + return 0; +} + +static ssize_t mgs_live_seq_write(struct file *file, const char *buf, + size_t len, loff_t *off) +{ + struct seq_file *seq = file->private_data; + struct fs_db *fsdb = seq->private; + ssize_t rc; + + rc = lprocfs_wr_ir_state(file, buf, len, fsdb); + if (rc >= 0) + rc = len; + return rc; +} +LPROC_SEQ_FOPS(mgs_live); + +int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb) +{ + int rc; + + if (!mgs->mgs_proc_live) + return 0; + rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644, + &mgs_live_fops, fsdb); + + return 0; +} + +int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb) +{ + if (!mgs->mgs_proc_live) + return 0; + + /* didn't create the proc file for MGSSELF_NAME */ + if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags)) + lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live); + return 0; +} + +LPROC_SEQ_FOPS_RO_TYPE(mgs, uuid); +LPROC_SEQ_FOPS_RO_TYPE(mgs, num_exports); +LPROC_SEQ_FOPS_RO_TYPE(mgs, hash); +LPROC_SEQ_FOPS_WO_TYPE(mgs, evict_client); +LPROC_SEQ_FOPS_RW_TYPE(mgs, ir_timeout); + +struct lprocfs_seq_vars lprocfs_mgs_obd_vars[] = { + { .name = "uuid", + .fops = &mgs_uuid_fops }, + { .name = "num_exports", + .fops = &mgs_num_exports_fops }, + { .name = "hash_stats", + .fops = &mgs_hash_fops }, + { .name = "evict_client", + .fops = &mgs_evict_client_fops }, + { .name = "ir_timeout", + .fops = &mgs_ir_timeout_fops }, + { 0 } +}; + int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name) { struct obd_device *obd = mgs->mgs_obd; struct obd_device *osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd; int osd_len = strlen(osd_name) - strlen("-osd"); int rc; - struct lprocfs_static_vars lvars; - lprocfs_mgs_init_vars(&lvars); - rc = lprocfs_obd_setup(obd, lvars.obd_vars); + obd->obd_vars = lprocfs_mgs_obd_vars; + rc = lprocfs_seq_obd_setup(obd); if (rc != 0) GOTO(out, rc); @@ -152,17 +243,17 @@ int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name) if (rc != 0) GOTO(out, rc); - mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry, - NULL, NULL); + mgs->mgs_proc_live = lprocfs_seq_register("live", obd->obd_proc_entry, + NULL, NULL); if (IS_ERR(mgs->mgs_proc_live)) { rc = PTR_ERR(mgs->mgs_proc_live); mgs->mgs_proc_live = NULL; GOTO(out, rc); } - obd->obd_proc_exports_entry = lprocfs_register("exports", - obd->obd_proc_entry, - NULL, NULL); + obd->obd_proc_exports_entry = lprocfs_seq_register("exports", + obd->obd_proc_entry, + NULL, NULL); if (IS_ERR(obd->obd_proc_exports_entry)) { rc = PTR_ERR(obd->obd_proc_exports_entry); obd->obd_proc_exports_entry = NULL; @@ -215,7 +306,6 @@ void lproc_mgs_cleanup(struct mgs_device *mgs) if (mgs->mgs_proc_live != NULL) { /* Should be no live entries */ - LASSERT(mgs->mgs_proc_live->subdir == NULL); lprocfs_remove(&mgs->mgs_proc_live); mgs->mgs_proc_live = NULL; } @@ -226,92 +316,6 @@ void lproc_mgs_cleanup(struct mgs_device *mgs) lprocfs_free_md_stats(obd); } -static int mgs_live_seq_show(struct seq_file *seq, void *v) -{ - struct fs_db *fsdb = seq->private; - struct mgs_tgt_srpc_conf *srpc_tgt; - int i; - - mutex_lock(&fsdb->fsdb_mutex); - - seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name); - seq_printf(seq, "flags: %#lx gen: %d\n", - fsdb->fsdb_flags, fsdb->fsdb_gen); - for (i = 0; i < INDEX_MAP_SIZE * 8; i++) - if (test_bit(i, fsdb->fsdb_mdt_index_map)) - seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i); - for (i = 0; i < INDEX_MAP_SIZE * 8; i++) - if (test_bit(i, fsdb->fsdb_ost_index_map)) - seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i); - - seq_printf(seq, "\nSecure RPC Config Rules:\n"); -#if 0 - seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name, - PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no"); -#endif - for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt; - srpc_tgt = srpc_tgt->mtsc_next) { - seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt, - &srpc_tgt->mtsc_rset); - } - seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen); - - lprocfs_rd_ir_state(seq, fsdb); - - mutex_unlock(&fsdb->fsdb_mutex); - return 0; -} - -static ssize_t mgs_live_seq_write(struct file *file, const char *buf, - size_t len, loff_t *off) -{ - struct seq_file *seq = file->private_data; - struct fs_db *fsdb = seq->private; - ssize_t rc; - - rc = lprocfs_wr_ir_state(file, buf, len, fsdb); - if (rc >= 0) - rc = len; - return rc; -} -LPROC_SEQ_FOPS(mgs_live); - -int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb) -{ - int rc; - - if (!mgs->mgs_proc_live) - return 0; - rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644, - &mgs_live_fops, fsdb); - - return 0; -} - -int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb) -{ - if (!mgs->mgs_proc_live) - return 0; - - /* didn't create the proc file for MGSSELF_NAME */ - if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags)) - lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live); - return 0; -} - -struct lprocfs_vars lprocfs_mgs_obd_vars[] = { - { "uuid", lprocfs_rd_uuid, 0, 0 }, - { "num_exports", lprocfs_rd_num_exports, 0, 0 }, - { "hash_stats", lprocfs_obd_rd_hash, 0, 0 }, - { "evict_client", 0, lprocfs_wr_evict_client, 0 }, - { "ir_timeout", lprocfs_rd_ir_timeout, lprocfs_wr_ir_timeout, 0 }, - { 0 } -}; - -struct lprocfs_vars lprocfs_mgs_module_vars[] = { - { 0 } -}; - void mgs_counter_incr(struct obd_export *exp, int opcode) { lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode); @@ -329,10 +333,4 @@ void mgs_stats_counter_init(struct lprocfs_stats *stats) lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs"); lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs"); } - -void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars) -{ - lvars->module_vars = lprocfs_mgs_module_vars; - lvars->obd_vars = lprocfs_mgs_obd_vars; -} #endif diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 85b219c..a9b0857 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -1513,12 +1513,9 @@ static struct obd_ops mgs_obd_device_ops = { static int __init mgs_init(void) { - struct lprocfs_static_vars lvars; - - lprocfs_mgs_init_vars(&lvars); return class_register_type(&mgs_obd_device_ops, NULL, true, NULL, #ifndef HAVE_ONLY_PROCFS_SEQ - lvars.module_vars, + NULL, #endif LUSTRE_MGS_NAME, &mgs_device_type); } diff --git a/lustre/mgs/mgs_internal.h b/lustre/mgs/mgs_internal.h index ca2846e..d3baacd 100644 --- a/lustre/mgs/mgs_internal.h +++ b/lustre/mgs/mgs_internal.h @@ -229,10 +229,10 @@ int mgs_get_ir_logs(struct ptlrpc_request *req); int lprocfs_wr_ir_state(struct file *file, const char *buffer, unsigned long count, void *data); int lprocfs_rd_ir_state(struct seq_file *seq, void *data); -int lprocfs_wr_ir_timeout(struct file *file, const char *buffer, - unsigned long count, void *data); -int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count, - int *eof, void *data); +ssize_t +lprocfs_ir_timeout_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off); +int lprocfs_ir_timeout_seq_show(struct seq_file *seq, void *data); void mgs_fsc_cleanup(struct obd_export *exp); void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb); int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp, @@ -250,7 +250,6 @@ int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name); void lproc_mgs_cleanup(struct mgs_device *mgs); int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb); int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb); -void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars); #else static inline int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name) {return 0;} @@ -260,10 +259,6 @@ static inline int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb) {return 0;} static inline int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb) {return 0;} -static void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars) -{ - memset(lvars, 0, sizeof(*lvars)); -} #endif /* mgs/lproc_mgs.c */ diff --git a/lustre/mgs/mgs_nids.c b/lustre/mgs/mgs_nids.c index 24c9d22..a4d8800 100644 --- a/lustre/mgs/mgs_nids.c +++ b/lustre/mgs/mgs_nids.c @@ -838,15 +838,14 @@ int lprocfs_rd_ir_state(struct seq_file *seq, void *data) return 0; } -int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count, - int *eof, void *data) +int lprocfs_ir_timeout_seq_show(struct seq_file *m, void *data) { - *eof = 1; - return snprintf(page, count, "%d\n", ir_timeout); + return lprocfs_uint_seq_show(m, &ir_timeout); } -int lprocfs_wr_ir_timeout(struct file *file, const char *buffer, - unsigned long count, void *data) +ssize_t +lprocfs_ir_timeout_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { return lprocfs_wr_uint(file, buffer, count, &ir_timeout); } -- 1.8.3.1