From bc388f536e52bbb9aca2dcf5765bfbd2681ba2d5 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Thu, 2 May 2024 11:50:34 +0200 Subject: [PATCH] LU-17431 nodemap: determine if nodemap is currently loading To control operations on dynamic nodemaps, we need to know if the current nodemap configuration is in the process of being loaded. Only once it is fully loaded the nodemap_mgs() function returns true. So change semantic of global variable nodemap_config_loaded, to be: * 0: not loaded yet * 1: successfully loaded * -1: loading in progress Signed-off-by: Sebastien Buisson Change-Id: If5e52e924415f644d0134f4093c2405df0887f87 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55001 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/include/lustre_nodemap.h | 1 + lustre/mgc/mgc_request_server.c | 5 +++++ lustre/ptlrpc/nodemap_internal.h | 1 + lustre/ptlrpc/nodemap_storage.c | 37 +++++++++++++++++++++++++++---------- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lustre/include/lustre_nodemap.h b/lustre/include/lustre_nodemap.h index e421c3b..0df134b 100644 --- a/lustre/include/lustre_nodemap.h +++ b/lustre/include/lustre_nodemap.h @@ -224,6 +224,7 @@ struct nodemap_config { struct nodemap_config *nodemap_config_alloc(void); void nodemap_config_dealloc(struct nodemap_config *config); +void nodemap_config_set_loading_mgc(bool loading); void nodemap_config_set_active_mgc(struct nodemap_config *config); int nodemap_process_idx_pages(struct nodemap_config *config, union lu_page *lip, diff --git a/lustre/mgc/mgc_request_server.c b/lustre/mgc/mgc_request_server.c index 20d7c36..3dd2e8b 100644 --- a/lustre/mgc/mgc_request_server.c +++ b/lustre/mgc/mgc_request_server.c @@ -404,6 +404,8 @@ again: * recent_nodemap should be set to NULL when the nodemap_config * is either destroyed or set active. */ + if (new_config) + nodemap_config_set_loading_mgc(true); for (i = 0; i < nrpages && ealen > 0; i++) { union lu_page *ptr; int rc2; @@ -424,6 +426,9 @@ again: } out: + if (new_config) + nodemap_config_set_loading_mgc(false); + if (req) { ptlrpc_req_put(req); req = NULL; diff --git a/lustre/ptlrpc/nodemap_internal.h b/lustre/ptlrpc/nodemap_internal.h index ea76dc5..7abd2088 100644 --- a/lustre/ptlrpc/nodemap_internal.h +++ b/lustre/ptlrpc/nodemap_internal.h @@ -152,6 +152,7 @@ int nm_hash_list_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd, void *nodemap_list_head); bool nodemap_mgs(void); +bool nodemap_loading(void); int nodemap_idx_nodemap_add(const struct lu_nodemap *nodemap); int nodemap_idx_nodemap_update(const struct lu_nodemap *nodemap); int nodemap_idx_nodemap_del(const struct lu_nodemap *nodemap); diff --git a/lustre/ptlrpc/nodemap_storage.c b/lustre/ptlrpc/nodemap_storage.c index 2d41c89..6cc3fa2 100644 --- a/lustre/ptlrpc/nodemap_storage.c +++ b/lustre/ptlrpc/nodemap_storage.c @@ -1327,9 +1327,26 @@ static void nodemap_save_all_caches(void) } /* tracks if config still needs to be loaded, either from disk or network */ -static bool nodemap_config_loaded; +/* 0: not loaded yet + * 1: successfully loaded + * -1: loading in progress + */ +static int nodemap_config_loaded; static DEFINE_MUTEX(nodemap_config_loaded_lock); +bool nodemap_loading(void) +{ + return (nodemap_config_loaded == -1); +} + +void nodemap_config_set_loading_mgc(bool loading) +{ + mutex_lock(&nodemap_config_loaded_lock); + nodemap_config_loaded = loading ? -1 : 0; + mutex_unlock(&nodemap_config_loaded_lock); +} +EXPORT_SYMBOL(nodemap_config_set_loading_mgc); + /** * Ensures that configs loaded over the wire are prioritized over those loaded * from disk. @@ -1340,7 +1357,7 @@ void nodemap_config_set_active_mgc(struct nodemap_config *config) { mutex_lock(&nodemap_config_loaded_lock); nodemap_config_set_active(config); - nodemap_config_loaded = true; + nodemap_config_loaded = 1; nodemap_save_all_caches(); mutex_unlock(&nodemap_config_loaded_lock); } @@ -1379,9 +1396,9 @@ struct nm_config_file *nm_config_file_register_mgs(const struct lu_env *env, * loading is done, so disk config is overwritten by MGS config. */ mutex_lock(&nodemap_config_loaded_lock); + nodemap_config_loaded = -1; rc = nodemap_load_entries(env, obj); - if (!rc) - nodemap_config_loaded = true; + nodemap_config_loaded = !rc; mutex_unlock(&nodemap_config_loaded_lock); if (rc) { @@ -1415,15 +1432,15 @@ struct nm_config_file *nm_config_file_register_tgt(const struct lu_env *env, /* don't load from cache if config already loaded */ mutex_lock(&nodemap_config_loaded_lock); - if (!nodemap_config_loaded) { + if (nodemap_config_loaded < 1) { config_obj = nodemap_cache_find_create(env, dev, los, 0); - if (IS_ERR(config_obj)) + if (IS_ERR(config_obj)) { rc = PTR_ERR(config_obj); - else + } else { + nodemap_config_loaded = -1; rc = nodemap_load_entries(env, config_obj); - - if (!rc) - nodemap_config_loaded = true; + } + nodemap_config_loaded = !rc; } mutex_unlock(&nodemap_config_loaded_lock); if (rc) -- 1.8.3.1