From 7337db63e1212ef4422a5fe88e1e42e03161daeb Mon Sep 17 00:00:00 2001
From: "John L. Hammond" <john.hammond@intel.com>
Date: Thu, 24 Jan 2013 15:41:56 -0600
Subject: [PATCH] LU-2673 procfs: call lprocfs_free_xxx_stats() later

Defer calls to lprocfs_free_{obd,md}_stats() and
lprocfs_job_stats_fini() until after the corresponding proc entries
have been removed. Change the return of some proc fini()s to void.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: Ic410a4cf12eeb084270f5e679222c54b12d80266
Reviewed-on: http://review.whamcloud.com/5160
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Keith Mannthey <keith.mannthey@intel.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
---
 lustre/mdt/mdt_internal.h |  2 +-
 lustre/mdt/mdt_lproc.c    |  7 ++-----
 lustre/mgs/lproc_mgs.c    |  9 ++++-----
 lustre/mgs/mgs_internal.h |  2 +-
 lustre/ofd/ofd_dev.c      | 17 ++++++++---------
 5 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h
index f2ccb95986..3473c94618 100644
--- a/lustre/mdt/mdt_internal.h
+++ b/lustre/mdt/mdt_internal.h
@@ -1012,7 +1012,7 @@ void mdt_stats_counter_init(struct lprocfs_stats *stats);
 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars);
 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars);
 int mdt_procfs_init(struct mdt_device *mdt, const char *name);
-int mdt_procfs_fini(struct mdt_device *mdt);
+void mdt_procfs_fini(struct mdt_device *mdt);
 void mdt_rename_counter_tally(struct mdt_thread_info *info,
 			      struct mdt_device *mdt,
 			      struct ptlrpc_request *req,
diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c
index e6275802e4..d922f6edf2 100644
--- a/lustre/mdt/mdt_lproc.c
+++ b/lustre/mdt/mdt_lproc.c
@@ -258,13 +258,11 @@ int mdt_procfs_init(struct mdt_device *mdt, const char *name)
         RETURN(rc);
 }
 
-int mdt_procfs_fini(struct mdt_device *mdt)
+void 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;
 
-	lprocfs_job_stats_fini(obd);
-
         if (obd->obd_proc_exports_entry) {
                 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
                 obd->obd_proc_exports_entry = NULL;
@@ -274,8 +272,7 @@ int mdt_procfs_fini(struct mdt_device *mdt)
         ptlrpc_lprocfs_unregister_obd(obd);
         lprocfs_free_md_stats(obd);
         lprocfs_free_obd_stats(obd);
-
-        RETURN(0);
+	lprocfs_job_stats_fini(obd);
 }
 
 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
diff --git a/lustre/mgs/lproc_mgs.c b/lustre/mgs/lproc_mgs.c
index 7020470c31..54f299b74f 100644
--- a/lustre/mgs/lproc_mgs.c
+++ b/lustre/mgs/lproc_mgs.c
@@ -198,12 +198,12 @@ int lproc_mgs_setup(struct mgs_device *mgs, char *osd_name)
 	return rc;
 }
 
-int lproc_mgs_cleanup(struct mgs_device *mgs)
+void lproc_mgs_cleanup(struct mgs_device *mgs)
 {
 	struct obd_device *obd = mgs->mgs_obd;
 
-        if (!obd)
-                return -EINVAL;
+	if (obd == NULL)
+		return;
 
 	if (mgs->mgs_proc_osd != NULL)
 		lprocfs_remove(&mgs->mgs_proc_osd);
@@ -220,10 +220,9 @@ int lproc_mgs_cleanup(struct mgs_device *mgs)
                 mgs->mgs_proc_live = NULL;
         }
         lprocfs_free_per_client_stats(obd);
+	lprocfs_obd_cleanup(obd);
         lprocfs_free_obd_stats(obd);
         lprocfs_free_md_stats(obd);
-
-        return lprocfs_obd_cleanup(obd);
 }
 
 static int mgs_live_seq_show(struct seq_file *seq, void *v)
diff --git a/lustre/mgs/mgs_internal.h b/lustre/mgs/mgs_internal.h
index f62413fe8c..00aae388e6 100644
--- a/lustre/mgs/mgs_internal.h
+++ b/lustre/mgs/mgs_internal.h
@@ -242,7 +242,7 @@ int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *m);
 #define strsuf(buf, suffix) (strcmp((buf)+strlen(buf)-strlen(suffix), (suffix)))
 #ifdef LPROCFS
 int lproc_mgs_setup(struct mgs_device *mgs, char *osd_name);
-int lproc_mgs_cleanup(struct mgs_device *mgs);
+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);
diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c
index 13245d0cdc..f90d8204cf 100644
--- a/lustre/ofd/ofd_dev.c
+++ b/lustre/ofd/ofd_dev.c
@@ -430,7 +430,7 @@ static int ofd_procfs_init(struct ofd_device *ofd)
 	rc = lproc_ofd_attach_seqstat(obd);
 	if (rc) {
 		CERROR("%s: create seqstat failed: %d.\n", obd->obd_name, rc);
-		GOTO(free_obd_stats, rc);
+		GOTO(obd_cleanup, rc);
 	}
 
 	entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
@@ -438,7 +438,7 @@ static int ofd_procfs_init(struct ofd_device *ofd)
 		rc = PTR_ERR(entry);
 		CERROR("%s: error %d setting up lprocfs for %s\n",
 		       obd->obd_name, rc, "exports");
-		GOTO(free_obd_stats, rc);
+		GOTO(obd_cleanup, rc);
 	}
 	obd->obd_proc_exports_entry = entry;
 
@@ -449,7 +449,7 @@ static int ofd_procfs_init(struct ofd_device *ofd)
 		rc = PTR_ERR(entry);
 		CERROR("%s: add proc entry 'clear' failed: %d.\n",
 		       obd->obd_name, rc);
-		GOTO(free_obd_stats, rc);
+		GOTO(obd_cleanup, rc);
 	}
 
 	rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
@@ -459,23 +459,22 @@ static int ofd_procfs_init(struct ofd_device *ofd)
 	RETURN(0);
 remove_entry_clear:
 	lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
-free_obd_stats:
-	lprocfs_free_obd_stats(obd);
 obd_cleanup:
 	lprocfs_obd_cleanup(obd);
+	lprocfs_free_obd_stats(obd);
+
 	return rc;
 }
 
-static int ofd_procfs_fini(struct ofd_device *ofd)
+static void ofd_procfs_fini(struct ofd_device *ofd)
 {
 	struct obd_device *obd = ofd_obd(ofd);
 
-	lprocfs_job_stats_fini(obd);
 	lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
 	lprocfs_free_per_client_stats(obd);
-	lprocfs_free_obd_stats(obd);
 	lprocfs_obd_cleanup(obd);
-	return 0;
+	lprocfs_free_obd_stats(obd);
+	lprocfs_job_stats_fini(obd);
 }
 
 extern int ost_handle(struct ptlrpc_request *req);
-- 
GitLab