From 080aa17e3d436c4b707e49b3598edbc5eeaebb1b Mon Sep 17 00:00:00 2001 From: LiuYing Date: Thu, 17 Dec 2009 10:30:32 +0800 Subject: [PATCH] b=20591 fix race on obd_device::md_stats move md_stats out of export_stats_init() and cleanup mdt/mgs procfs init/fini. i=wangdi i=liangzhen --- lustre/include/lprocfs_status.h | 3 +++ lustre/mdt/mdt_fs.c | 3 --- lustre/mdt/mdt_handler.c | 29 ---------------------- lustre/mdt/mdt_lproc.c | 52 ++++++++++++++++++++++++++++++++-------- lustre/mgs/lproc_mgs.c | 1 + lustre/mgs/mgs_fs.c | 5 +--- lustre/mgs/mgs_handler.c | 6 ++++- lustre/obdclass/lprocfs_status.c | 2 +- 8 files changed, 53 insertions(+), 48 deletions(-) diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index 7ea3031..cad6c92 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -424,6 +424,7 @@ extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index, unsigned conf, const char *name, const char *units); extern void lprocfs_free_obd_stats(struct obd_device *obddev); +extern void lprocfs_free_md_stats(struct obd_device *obddev); struct obd_export; struct nid_stat; extern int lprocfs_add_clear_entry(struct obd_device * obd, @@ -758,6 +759,8 @@ static inline int lprocfs_alloc_md_stats(struct obd_device *obddev, { return 0; } static inline void lprocfs_free_obd_stats(struct obd_device *obddev) { return; } +static inline void lprocfs_free_md_stats(struct obd_device *obddev) +{ return; } struct obd_export; static inline int lprocfs_add_clear_entry(struct obd_export *exp) diff --git a/lustre/mdt/mdt_fs.c b/lustre/mdt/mdt_fs.c index 7c6a489..713ab88 100644 --- a/lustre/mdt/mdt_fs.c +++ b/lustre/mdt/mdt_fs.c @@ -60,9 +60,6 @@ int mdt_export_stats_init(struct obd_device *obd, return rc; } - if ((obd->md_stats == NULL) && - (rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_NR))) - return rc; if (newnid) { /* Always add in ldlm_stats */ exp->exp_nid_stats->nid_ldlm_stats = diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 0f8d11b..295aa75 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -4368,14 +4368,8 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); mdt_procfs_fini(m); - if (obd->obd_proc_exports_entry) { - lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); - obd->obd_proc_exports_entry = NULL; - } lprocfs_free_per_client_stats(obd); lprocfs_free_obd_stats(obd); - ptlrpc_lprocfs_unregister_obd(obd); - lprocfs_obd_cleanup(obd); if (ls) { struct md_site *mite; @@ -4462,7 +4456,6 @@ int mdt_postrecov(const struct lu_env *, struct mdt_device *); static int mdt_init0(const struct lu_env *env, struct mdt_device *m, struct lu_device_type *ldt, struct lustre_cfg *cfg) { - struct lprocfs_static_vars lvars; struct mdt_thread_info *info; struct obd_device *obd; const char *dev = lustre_cfg_string(cfg, 0); @@ -4559,27 +4552,12 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, GOTO(err_free_site, rc); } - lprocfs_mdt_init_vars(&lvars); - rc = lprocfs_obd_setup(obd, lvars.obd_vars); - if (rc) { - CERROR("Can't init lprocfs, rc %d\n", rc); - GOTO(err_fini_site, rc); - } - ptlrpc_lprocfs_register_obd(obd); - rc = mdt_procfs_init(m, dev); if (rc) { CERROR("Can't init MDT lprocfs, rc %d\n", rc); GOTO(err_fini_proc, rc); } - obd->obd_proc_exports_entry = proc_mkdir("exports", - obd->obd_proc_entry); - if (obd->obd_proc_exports_entry) - lprocfs_add_simple(obd->obd_proc_exports_entry, - "clear", lprocfs_nid_stats_clear_read, - lprocfs_nid_stats_clear_write, obd, NULL); - /* set server index */ lu_site2md(s)->ms_node_id = node_id; @@ -4729,13 +4707,6 @@ err_fini_stack: mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); err_fini_proc: mdt_procfs_fini(m); - if (obd->obd_proc_exports_entry) { - lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); - obd->obd_proc_exports_entry = NULL; - } - ptlrpc_lprocfs_unregister_obd(obd); - lprocfs_obd_cleanup(obd); -err_fini_site: lu_site_fini(s); err_free_site: OBD_FREE_PTR(mite); diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index 133e424..d9347fc 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -74,31 +74,63 @@ static const char *mdt_proc_names[LPROC_MDT_NR] = { int mdt_procfs_init(struct mdt_device *mdt, const char *name) { struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev; - int result; + struct obd_device *obd = ld->ld_obd; + struct lprocfs_static_vars lvars; + int rc; ENTRY; LASSERT(name != NULL); - mdt->mdt_proc_entry = ld->ld_obd->obd_proc_entry; + + lprocfs_mdt_init_vars(&lvars); + rc = lprocfs_obd_setup(obd, lvars.obd_vars); + if (rc) { + CERROR("Can't init lprocfs, rc %d\n", rc); + return rc; + } + ptlrpc_lprocfs_register_obd(obd); + + mdt->mdt_proc_entry = obd->obd_proc_entry; LASSERT(mdt->mdt_proc_entry != NULL); - result = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry, - mdt_proc_names, ARRAY_SIZE(mdt_proc_names)); - if (result == 0) - result = lu_time_named_init(&ld->ld_site->ls_time_stats, - "site_time", mdt->mdt_proc_entry, - lu_time_names, - ARRAY_SIZE(lu_time_names)); - RETURN(result); + rc = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry, + mdt_proc_names, ARRAY_SIZE(mdt_proc_names)); + if (rc == 0) + rc = lu_time_named_init(&ld->ld_site->ls_time_stats, + "site_time", mdt->mdt_proc_entry, + lu_time_names, + ARRAY_SIZE(lu_time_names)); + if (rc) + return rc; + + obd->obd_proc_exports_entry = proc_mkdir("exports", + obd->obd_proc_entry); + if (obd->obd_proc_exports_entry) + lprocfs_add_simple(obd->obd_proc_exports_entry, + "clear", lprocfs_nid_stats_clear_read, + lprocfs_nid_stats_clear_write, obd, NULL); + rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_NR); + + RETURN(rc); } int mdt_procfs_fini(struct mdt_device *mdt) { struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev; + struct obd_device *obd = ld->ld_obd; + if (mdt->mdt_proc_entry) { lu_time_fini(&ld->ld_site->ls_time_stats); lu_time_fini(&mdt->mdt_stats); mdt->mdt_proc_entry = NULL; } + if (obd->obd_proc_exports_entry) { + lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); + obd->obd_proc_exports_entry = NULL; + } + ptlrpc_lprocfs_unregister_obd(obd); + lprocfs_free_md_stats(obd); + lprocfs_obd_cleanup(obd); + RETURN(0); } diff --git a/lustre/mgs/lproc_mgs.c b/lustre/mgs/lproc_mgs.c index b673280..97f4a70 100644 --- a/lustre/mgs/lproc_mgs.c +++ b/lustre/mgs/lproc_mgs.c @@ -182,6 +182,7 @@ int lproc_mgs_cleanup(struct obd_device *obd) } lprocfs_free_per_client_stats(obd); lprocfs_free_obd_stats(obd); + lprocfs_free_md_stats(obd); return lprocfs_obd_cleanup(obd); } diff --git a/lustre/mgs/mgs_fs.c b/lustre/mgs/mgs_fs.c index fce4ffb..0ff9ebf 100644 --- a/lustre/mgs/mgs_fs.c +++ b/lustre/mgs/mgs_fs.c @@ -73,13 +73,10 @@ static int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp, return rc; } - if ((obd->md_stats == NULL) && - (rc = lprocfs_alloc_md_stats(obd, LPROC_MGS_LAST))) - return rc; if (newnid) { /* Always add in ldlm_stats */ exp->exp_nid_stats->nid_ldlm_stats = - lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC, + lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC, LPROCFS_STATS_FLAG_NOPERCPU); if (exp->exp_nid_stats->nid_ldlm_stats == NULL) return -ENOMEM; diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 99dd197..f8394cf 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -226,8 +226,12 @@ static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg) /* Setup proc */ lprocfs_mgs_init_vars(&lvars); - if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0) + if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0) { lproc_mgs_setup(obd); + rc = lprocfs_alloc_md_stats(obd, LPROC_MGS_LAST); + if (rc) + GOTO(err_llog, rc); + } /* Start the service threads */ mgs->mgs_service = diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index c25a66c..d059730 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -1860,7 +1860,6 @@ int lprocfs_exp_cleanup(struct obd_export *exp) nidstat_putref(exp->exp_nid_stats); exp->exp_nid_stats = NULL; - lprocfs_free_md_stats(exp->exp_obd); return 0; } @@ -2276,6 +2275,7 @@ EXPORT_SYMBOL(lprocfs_init_ldlm_stats); EXPORT_SYMBOL(lprocfs_alloc_obd_stats); EXPORT_SYMBOL(lprocfs_alloc_md_stats); EXPORT_SYMBOL(lprocfs_free_obd_stats); +EXPORT_SYMBOL(lprocfs_free_md_stats); EXPORT_SYMBOL(lprocfs_exp_setup); EXPORT_SYMBOL(lprocfs_exp_cleanup); -- 1.8.3.1