From: Ben Evans Date: Mon, 20 May 2019 12:46:10 +0000 (-0400) Subject: LU-12316 llog: convert llog_client defines to functions X-Git-Tag: 2.15.59~76 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=85944639da7238ff61fca480c21cfd4778391c4f;p=fs%2Flustre-release.git LU-12316 llog: convert llog_client defines to functions Convert preprocessor functions into actual functions. The original commit that added these macros (81c713adeb) did not provide an explaination for why these were chosen to be macros rather than functions. Hence, bias towards using functions rather than complex macros since they appear in stack traces, are easier to debug, and simpler to develop with. Signed-off-by: Ben Evans Signed-off-by: Timothy Day Change-Id: I7a73e9af57dcf5edb9d013272ff5cf85e4234146 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/34904 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: Shaun Tancheff Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/lustre/ptlrpc/llog_client.c b/lustre/ptlrpc/llog_client.c index d0c3e61..fa715aa 100644 --- a/lustre/ptlrpc/llog_client.c +++ b/lustre/ptlrpc/llog_client.c @@ -46,30 +46,32 @@ #include "ptlrpc_internal.h" -#define LLOG_CLIENT_ENTRY(ctxt, imp) do { \ - mutex_lock(&ctxt->loc_mutex); \ - if (ctxt->loc_imp) { \ - imp = class_import_get(ctxt->loc_imp); \ - } else { \ - CERROR("ctxt->loc_imp == NULL for context idx %d." \ - "Unable to complete MDS/OSS recovery," \ - "but I'll try again next time. Not fatal.\n", \ - ctxt->loc_idx); \ - imp = NULL; \ - mutex_unlock(&ctxt->loc_mutex); \ - return -EINVAL; \ - } \ - mutex_unlock(&ctxt->loc_mutex); \ -} while (0) - -#define LLOG_CLIENT_EXIT(ctxt, imp) do { \ - mutex_lock(&ctxt->loc_mutex); \ - if (ctxt->loc_imp != imp) \ - CWARN("loc_imp has changed from %p to %p\n", \ - ctxt->loc_imp, imp); \ - class_import_put(imp); \ - mutex_unlock(&ctxt->loc_mutex); \ -} while (0) +struct obd_import *llog_client_entry(struct llog_ctxt *ctxt) +{ + struct obd_import *imp = ERR_PTR(-EINVAL); + + mutex_lock(&ctxt->loc_mutex); + if (ctxt->loc_imp) + imp = class_import_get(ctxt->loc_imp); + else + CWARN("%s: cannot finish recovery, ctxt #%d import not set, will retry rc = %ld\n", + ctxt->loc_obd ? ctxt->loc_obd->obd_name : "llog", + ctxt->loc_idx, PTR_ERR(imp)); + + mutex_unlock(&ctxt->loc_mutex); + return imp; +} + +void llog_client_exit(struct llog_ctxt *ctxt, struct obd_import *imp) +{ + mutex_lock(&ctxt->loc_mutex); + if (ctxt->loc_imp != imp) + CWARN("%s: import has changed from %p to %p\n", + ctxt->loc_obd ? ctxt->loc_obd->obd_name : "llog", + ctxt->loc_imp, imp); + class_import_put(imp); + mutex_unlock(&ctxt->loc_mutex); +} /* * This is a callback from the llog_* functions. @@ -87,7 +89,9 @@ static int llog_client_open(const struct lu_env *env, ENTRY; - LLOG_CLIENT_ENTRY(ctxt, imp); + imp = llog_client_entry(ctxt); + if (IS_ERR(imp)) + return PTR_ERR(imp); /* client cannot create llog */ LASSERTF(open_param != LLOG_OPEN_NEW, "%#x\n", open_param); @@ -138,7 +142,7 @@ static int llog_client_open(const struct lu_env *env, lgh->lgh_ctxt = ctxt; EXIT; out: - LLOG_CLIENT_EXIT(ctxt, imp); + llog_client_exit(ctxt, imp); ptlrpc_req_finished(req); return rc; } @@ -156,7 +160,10 @@ static int llog_client_next_block(const struct lu_env *env, ENTRY; - LLOG_CLIENT_ENTRY(loghandle->lgh_ctxt, imp); + imp = llog_client_entry(loghandle->lgh_ctxt); + if (IS_ERR(imp)) + return PTR_ERR(imp); + req = ptlrpc_request_alloc_pack(imp, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK, LUSTRE_LOG_VERSION, LLOG_ORIGIN_HANDLE_NEXT_BLOCK); @@ -212,7 +219,7 @@ static int llog_client_next_block(const struct lu_env *env, out: ptlrpc_req_finished(req); err_exit: - LLOG_CLIENT_EXIT(loghandle->lgh_ctxt, imp); + llog_client_exit(loghandle->lgh_ctxt, imp); return rc; } @@ -228,7 +235,10 @@ static int llog_client_prev_block(const struct lu_env *env, ENTRY; - LLOG_CLIENT_ENTRY(loghandle->lgh_ctxt, imp); + imp = llog_client_entry(loghandle->lgh_ctxt); + if (IS_ERR(imp)) + return PTR_ERR(imp); + req = ptlrpc_request_alloc_pack(imp, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK, LUSTRE_LOG_VERSION, LLOG_ORIGIN_HANDLE_PREV_BLOCK); @@ -262,7 +272,7 @@ static int llog_client_prev_block(const struct lu_env *env, out: ptlrpc_req_finished(req); err_exit: - LLOG_CLIENT_EXIT(loghandle->lgh_ctxt, imp); + llog_client_exit(loghandle->lgh_ctxt, imp); return rc; } @@ -278,7 +288,10 @@ static int llog_client_read_header(const struct lu_env *env, ENTRY; - LLOG_CLIENT_ENTRY(handle->lgh_ctxt, imp); + imp = llog_client_entry(handle->lgh_ctxt); + if (IS_ERR(imp)) + return PTR_ERR(imp); + req = ptlrpc_request_alloc_pack(imp, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER, LUSTRE_LOG_VERSION, @@ -327,7 +340,7 @@ static int llog_client_read_header(const struct lu_env *env, out: ptlrpc_req_finished(req); err_exit: - LLOG_CLIENT_EXIT(handle->lgh_ctxt, imp); + llog_client_exit(handle->lgh_ctxt, imp); return rc; }