diff mbox series

[12/49] lustre: fixup ldlm_pool and lu_object shrinker failure cases

Message ID 1618459361-17909-13-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series lustre: sync to OpenSFS as of March 30 2021 | expand

Commit Message

James Simmons April 15, 2021, 4:02 a.m. UTC
From: Mr NeilBrown <neilb@suse.de>

For ldlm_pools, ldlm_pools_fini() can be called when ldlm_pools_init()
fails, or even in case where it hasn't been called.  So add a static
flag to ensure we ldlm_pools_fini() does undo things that haven't been
done.

For lu_global_init() we need to add proper cleanup if anything fails.

Fixes: ab33cb5ad1e57 ("drivers: lustre: obdclass: check result of register_shrinker()")
WC-bug-id: https://jira.whamcloud.com/browse/LU-12477
Lustre-commit: 812b2ccf0284df42 ("LU-12477 lustre: check return status of register_shrinker()")
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Reviewed-on: https://review.whamcloud.com/40883
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 fs/lustre/ldlm/ldlm_pool.c     | 43 +++++++++++++++++++-----------------------
 fs/lustre/obdclass/lu_object.c | 39 +++++++++++++++++++-------------------
 2 files changed, 38 insertions(+), 44 deletions(-)
diff mbox series

Patch

diff --git a/fs/lustre/ldlm/ldlm_pool.c b/fs/lustre/ldlm/ldlm_pool.c
index 2e4d16b..b93ad4d 100644
--- a/fs/lustre/ldlm/ldlm_pool.c
+++ b/fs/lustre/ldlm/ldlm_pool.c
@@ -889,6 +889,12 @@  static unsigned long ldlm_pools_cli_scan(struct shrinker *s,
 			       sc->gfp_mask);
 }
 
+static struct shrinker ldlm_pools_cli_shrinker = {
+	.count_objects	= ldlm_pools_cli_count,
+	.scan_objects	= ldlm_pools_cli_scan,
+	.seeks		= DEFAULT_SEEKS,
+};
+
 static void ldlm_pools_recalc(struct work_struct *ws);
 static DECLARE_DELAYED_WORK(ldlm_recalc_pools, ldlm_pools_recalc);
 
@@ -976,40 +982,29 @@  static void ldlm_pools_recalc(struct work_struct *ws)
 	schedule_delayed_work(&ldlm_recalc_pools, delay * HZ);
 }
 
-static int ldlm_pools_thread_start(void)
-{
-	time64_t delay = LDLM_POOL_CLI_DEF_RECALC_PERIOD;
-
-	schedule_delayed_work(&ldlm_recalc_pools, delay);
-
-	return 0;
-}
-
-static void ldlm_pools_thread_stop(void)
-{
-	cancel_delayed_work_sync(&ldlm_recalc_pools);
-}
-
-static struct shrinker ldlm_pools_cli_shrinker = {
-	.count_objects	= ldlm_pools_cli_count,
-	.scan_objects	= ldlm_pools_cli_scan,
-	.seeks		= DEFAULT_SEEKS,
-};
+static bool ldlm_pools_init_done;
 
 int ldlm_pools_init(void)
 {
+	time64_t delay = LDLM_POOL_CLI_DEF_RECALC_PERIOD;
 	int rc;
 
-	rc = ldlm_pools_thread_start();
-	if (!rc)
-		rc = register_shrinker(&ldlm_pools_cli_shrinker);
+	rc = register_shrinker(&ldlm_pools_cli_shrinker);
+	if (rc)
+		goto out;
 
+	schedule_delayed_work(&ldlm_recalc_pools, delay);
+	ldlm_pools_init_done = true;
+out:
 	return rc;
 }
 
 void ldlm_pools_fini(void)
 {
-	unregister_shrinker(&ldlm_pools_cli_shrinker);
+	if (ldlm_pools_init_done) {
+		unregister_shrinker(&ldlm_pools_cli_shrinker);
 
-	ldlm_pools_thread_stop();
+		cancel_delayed_work_sync(&ldlm_recalc_pools);
+	}
 }
+
diff --git a/fs/lustre/obdclass/lu_object.c b/fs/lustre/obdclass/lu_object.c
index e8fc328..fcf0739 100644
--- a/fs/lustre/obdclass/lu_object.c
+++ b/fs/lustre/obdclass/lu_object.c
@@ -2138,10 +2138,8 @@  int lu_global_init(void)
 
 	LU_CONTEXT_KEY_INIT(&lu_global_key);
 	result = lu_context_key_register(&lu_global_key);
-	if (result != 0) {
-		lu_ref_global_fini();
-		return result;
-	}
+	if (result != 0)
+		goto out_lu_ref;
 
 	/*
 	 * At this level, we don't know what tags are needed, so allocate them
@@ -2153,8 +2151,7 @@  int lu_global_init(void)
 	up_write(&lu_sites_guard);
 	if (result != 0) {
 		lu_context_key_degister(&lu_global_key);
-		lu_ref_global_fini();
-		return result;
+		goto out_lu_ref;
 	}
 
 	/*
@@ -2163,23 +2160,25 @@  int lu_global_init(void)
 	 * lu_object/inode cache consuming all the memory.
 	 */
 	result = register_shrinker(&lu_site_shrinker);
-	if (result == 0) {
-		result = rhashtable_init(&lu_env_rhash, &lu_env_rhash_params);
-		if (result != 0)
-			unregister_shrinker(&lu_site_shrinker);
-	}
-	if (result != 0) {
-		/* Order explained in lu_global_fini(). */
-		lu_context_key_degister(&lu_global_key);
+	if (result)
+		goto out_env;
 
-		down_write(&lu_sites_guard);
-		lu_env_fini(&lu_shrink_env);
-		up_write(&lu_sites_guard);
+	result = rhashtable_init(&lu_env_rhash, &lu_env_rhash_params);
+	if (result)
+		goto out_shrinker;
 
-		lu_ref_global_fini();
-		return result;
-	}
+	return result;
 
+out_shrinker:
+	unregister_shrinker(&lu_site_shrinker);
+out_env:
+	/* Order explained in lu_global_fini(). */
+	lu_context_key_degister(&lu_global_key);
+	down_write(&lu_sites_guard);
+	lu_env_fini(&lu_shrink_env);
+	up_write(&lu_sites_guard);
+out_lu_ref:
+	lu_ref_global_fini();
 	return result;
 }