Whamcloud - gitweb
LU-14959 ldlm: Check return value of ldlm_resource_get() 38/44738/4
authorOleg Drokin <green@whamcloud.com>
Tue, 24 Aug 2021 03:44:45 +0000 (23:44 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 17 Sep 2021 14:06:55 +0000 (14:06 +0000)
Fix the comment to properly indicate it returns ERR_PTR on
error and fix osc_req_attr_set() and mdc_get_lock_handle()
to actually check the return value before passing it on and
causing an unintended crash.

Change-Id: Ib85a62140a39744e85989c9a9c8aa2ed771d70d1
Signed-off-by: Oleg Drokin <green@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/44738
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
lustre/ldlm/ldlm_resource.c
lustre/mdc/mdc_dev.c
lustre/osc/osc_object.c

index 01a2e42..3360fa5 100644 (file)
@@ -1478,7 +1478,7 @@ static void ldlm_resource_free(struct ldlm_resource *res)
  * Return a reference to resource with given name, creating it if necessary.
  * Args: namespace with ns_lock unlocked
  * Locks: takes and releases NS hash-lock and res->lr_lock
  * Return a reference to resource with given name, creating it if necessary.
  * Args: namespace with ns_lock unlocked
  * Locks: takes and releases NS hash-lock and res->lr_lock
- * Returns: referenced, unlocked ldlm_resource or NULL
+ * Returns: referenced, unlocked ldlm_resource or ERR_PTR
  */
 struct ldlm_resource *
 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
  */
 struct ldlm_resource *
 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
index 5ef4480..9767b74 100644 (file)
@@ -1026,7 +1026,11 @@ static int mdc_get_lock_handle(const struct lu_env *env, struct osc_object *osc,
                fid_build_reg_res_name(lu_object_fid(osc2lu(osc)), resname);
                res = ldlm_resource_get(osc_export(osc)->exp_obd->obd_namespace,
                                        NULL, resname, LDLM_IBITS, 0);
                fid_build_reg_res_name(lu_object_fid(osc2lu(osc)), resname);
                res = ldlm_resource_get(osc_export(osc)->exp_obd->obd_namespace,
                                        NULL, resname, LDLM_IBITS, 0);
-               ldlm_resource_dump(D_ERROR, res);
+               if (IS_ERR(res))
+                       CERROR("No lock resource for "DFID"\n",
+                               PFID(lu_object_fid(osc2lu(osc))));
+               else
+                       ldlm_resource_dump(D_ERROR, res);
                libcfs_debug_dumpstack(NULL);
                return -ENOENT;
        } else {
                libcfs_debug_dumpstack(NULL);
                return -ENOENT;
        } else {
index f720946..64f6b94 100644 (file)
@@ -401,7 +401,10 @@ static void osc_req_attr_set(const struct lu_env *env, struct cl_object *obj,
                        res = ldlm_resource_get(
                                osc_export(cl2osc(obj))->exp_obd->obd_namespace,
                                NULL, resname, LDLM_EXTENT, 0);
                        res = ldlm_resource_get(
                                osc_export(cl2osc(obj))->exp_obd->obd_namespace,
                                NULL, resname, LDLM_EXTENT, 0);
-                       ldlm_resource_dump(D_ERROR, res);
+                       if (IS_ERR(res))
+                               CERROR("No lock resource\n");
+                       else
+                               ldlm_resource_dump(D_ERROR, res);
 
                        libcfs_debug_dumpstack(NULL);
                        LBUG();
 
                        libcfs_debug_dumpstack(NULL);
                        LBUG();