Whamcloud - gitweb
LU-18155 ptlrpc: use LASSERT/F instead of if () LBUG() 14/56114/5
authorTimothy Day <timday@amazon.com>
Thu, 22 Aug 2024 01:16:28 +0000 (21:16 -0400)
committerOleg Drokin <green@whamcloud.com>
Mon, 2 Dec 2024 05:47:24 +0000 (05:47 +0000)
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 <timday@amazon.com>
Change-Id: If3b2d519239ec2c86bc940135346b37ebe1d050e
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56114
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/ldlm/ldlm_inodebits.c
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_request.c
lustre/ptlrpc/gss/gss_cli_upcall.c
lustre/ptlrpc/layout.c
lustre/ptlrpc/pack_generic.c

index 81a7dcd..6ae1dd9 100644 (file)
@@ -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;
                                }
index f7040b3..ee6c07d 100644 (file)
@@ -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;
 }
index d6bcd6b..a62f4b5 100644 (file)
@@ -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);
index 7ada030..62a6527 100644 (file)
@@ -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;
index 7bfbae3..8b4d1f6 100644 (file)
@@ -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;
index fd47f5d..4433afe 100644 (file)
@@ -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;
 }