From fa7cb6496dcfec5144e7893720c20fb3261e2f2d Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 21 Aug 2024 21:16:28 -0400 Subject: [PATCH] LU-18155 ptlrpc: use LASSERT/F instead of if () LBUG() We should use a proper LASSERT statement rather than more verbose if/LBUG blocks. The patch has been generated with the coccinelle script below. I manually inverted the logic in the asserts. @@ expression L; expression list F; @@ - if (L) { ( - CDEBUG(F); | - CWARN(F); | - CERROR(F); | - CEMERG(F); | - CNETERR(F); | - LCONSOLE(F); | - LCONSOLE_INFO(F); | - LCONSOLE_WARN(F); | - LCONSOLE_ERROR(F); | - LCONSOLE_EMERG(F); ) - LBUG(); - } + LASSERTF(L, F); @@ expression L; @@ -if (L) LBUG(); +LASSERT(L); Test-Parameters: trivial Signed-off-by: Timothy Day Change-Id: If3b2d519239ec2c86bc940135346b37ebe1d050e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56114 Reviewed-by: Andreas Dilger Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/ldlm/ldlm_inodebits.c | 7 +++---- lustre/ldlm/ldlm_lock.c | 9 +++------ lustre/ldlm/ldlm_request.c | 16 ++++------------ lustre/ptlrpc/gss/gss_cli_upcall.c | 6 ++---- lustre/ptlrpc/layout.c | 19 ++++++++----------- lustre/ptlrpc/pack_generic.c | 4 +--- 6 files changed, 21 insertions(+), 40 deletions(-) diff --git a/lustre/ldlm/ldlm_inodebits.c b/lustre/ldlm/ldlm_inodebits.c index 81a7dcd..6ae1dd9 100644 --- a/lustre/ldlm/ldlm_inodebits.c +++ b/lustre/ldlm/ldlm_inodebits.c @@ -286,10 +286,9 @@ ldlm_inodebits_compat_queue(struct list_head *queue, struct ldlm_lock *req, * allowed, the trybits to be used * instead. */ - if (!req->l_export && - (req_bits & MDS_INODELOCK_DOM) && - (req_bits & ~MDS_INODELOCK_DOM)) - LBUG(); + LASSERT(!(!req->l_export && + (req_bits & MDS_INODELOCK_DOM) && + (req_bits & ~MDS_INODELOCK_DOM))); goto skip_work_list; } diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c index f7040b3..ee6c07d 100644 --- a/lustre/ldlm/ldlm_lock.c +++ b/lustre/ldlm/ldlm_lock.c @@ -430,8 +430,7 @@ static struct ldlm_lock *ldlm_lock_new(struct ldlm_resource *resource) ENTRY; - if (resource == NULL) - LBUG(); + LASSERT(resource); OBD_SLAB_ALLOC_PTR_GFP(lock, ldlm_lock_slab, GFP_NOFS); if (lock == NULL) @@ -2396,10 +2395,8 @@ restart: #else ENTRY; - if (!ns_is_client(ldlm_res_to_ns(res))) { - CERROR("This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n"); - LBUG(); - } + LASSERTF(ns_is_client(ldlm_res_to_ns(res)), + "This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n"); #endif EXIT; } diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c index d6bcd6b..a62f4b5 100644 --- a/lustre/ldlm/ldlm_request.c +++ b/lustre/ldlm/ldlm_request.c @@ -462,10 +462,8 @@ int ldlm_cli_enqueue_local(const struct lu_env *env, ENTRY; LASSERT(!(*flags & LDLM_FL_REPLAY)); - if (unlikely(ns_is_client(ns))) { - CERROR("Trying to enqueue local lock in a shadow namespace\n"); - LBUG(); - } + LASSERTF(unlikely(!ns_is_client(ns)), + "Trying to enqueue local lock in a shadow namespace\n"); lock = ldlm_lock_create(ns, res_id, type, mode, &cbs, data, lvb_len, lvb_type); @@ -498,10 +496,7 @@ int ldlm_cli_enqueue_local(const struct lu_env *env, if (client_cookie != NULL) lock->l_client_cookie = *client_cookie; if (type == LDLM_EXTENT) { - /* extent lock without policy is a bug */ - if (policy == NULL) - LBUG(); - + LASSERT(policy); lock->l_req_extent = policy->l_extent; } @@ -1017,10 +1012,7 @@ int ldlm_cli_enqueue(struct obd_export *exp, struct ptlrpc_request **reqp, lock->l_policy_data = *policy; if (einfo->ei_type == LDLM_EXTENT) { - /* extent lock without policy is a bug */ - if (policy == NULL) - LBUG(); - + LASSERT(policy); lock->l_req_extent = policy->l_extent; } else if (einfo->ei_type == LDLM_FLOCK) { ldlm_lock_add_to_enqueueing(lock); diff --git a/lustre/ptlrpc/gss/gss_cli_upcall.c b/lustre/ptlrpc/gss/gss_cli_upcall.c index 7ada030..62a6527 100644 --- a/lustre/ptlrpc/gss/gss_cli_upcall.c +++ b/lustre/ptlrpc/gss/gss_cli_upcall.c @@ -116,16 +116,14 @@ int ctx_init_pack_request(struct obd_import *imp, /* 2. target uuid */ obj.len = strlen(imp->imp_obd->u.cli.cl_target_uuid.uuid) + 1; obj.data = imp->imp_obd->u.cli.cl_target_uuid.uuid; - if (rawobj_serialize(&obj, &p, &size)) - LBUG(); + LASSERT(!rawobj_serialize(&obj, &p, &size)); /* 3. reverse context handle. actually only needed by root user, * but we send it anyway. */ gsec = sec2gsec(req->rq_cli_ctx->cc_sec); obj.len = sizeof(gsec->gs_rvs_hdl); obj.data = (__u8 *) &gsec->gs_rvs_hdl; - if (rawobj_serialize(&obj, &p, &size)) - LBUG(); + LASSERT(!rawobj_serialize(&obj, &p, &size)); /* 4. now the token */ total_size = sizeof(__u32) + token_size; diff --git a/lustre/ptlrpc/layout.c b/lustre/ptlrpc/layout.c index 7bfbae3..8b4d1f6 100644 --- a/lustre/ptlrpc/layout.c +++ b/lustre/ptlrpc/layout.c @@ -2523,17 +2523,14 @@ void req_capsule_set_size(struct req_capsule *pill, (size > 0)) { __u32 rmf_size = (__u32)field->rmf_size; - if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) && - (size % rmf_size != 0)) { - CERROR("%s: array field size mismatch %u %% %u != 0 (%d)\n", - field->rmf_name, size, rmf_size, loc); - LBUG(); - } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) && - size < rmf_size) { - CERROR("%s: field size mismatch %u != %u (%d)\n", - field->rmf_name, size, rmf_size, loc); - LBUG(); - } + LASSERTF(!((field->rmf_flags & RMF_F_STRUCT_ARRAY) && + (size % rmf_size != 0)), + "%s: array field size mismatch %u %% %u != 0 (%d)\n", + field->rmf_name, size, rmf_size, loc); + LASSERTF(!(!(field->rmf_flags & RMF_F_STRUCT_ARRAY) && + size < rmf_size), + "%s: field size mismatch %u != %u (%d)\n", + field->rmf_name, size, rmf_size, loc); } pill->rc_area[loc][__req_capsule_offset(pill, field, loc)] = size; diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index fd47f5d..4433afe 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -750,9 +750,7 @@ EXPORT_SYMBOL(lustre_msg_buflen); static inline void lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, __u32 n, __u32 len) { - if (n >= m->lm_bufcount) - LBUG(); - + LASSERT(n < m->lm_bufcount); m->lm_buflens[n] = len; } -- 1.8.3.1