From: Oleg Drokin Date: Tue, 24 Aug 2021 03:44:45 +0000 (-0400) Subject: LU-14959 ldlm: Check return value of ldlm_resource_get() X-Git-Tag: 2.14.55~48 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F38%2F44738%2F4;p=fs%2Flustre-release.git LU-14959 ldlm: Check return value of ldlm_resource_get() 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 Reviewed-on: https://review.whamcloud.com/44738 Tested-by: jenkins Reviewed-by: Andreas Dilger Reviewed-by: Yang Sheng Tested-by: Maloo Reviewed-by: Neil Brown --- diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 01a2e42..3360fa5 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -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 - * 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, diff --git a/lustre/mdc/mdc_dev.c b/lustre/mdc/mdc_dev.c index 5ef4480..9767b74 100644 --- a/lustre/mdc/mdc_dev.c +++ b/lustre/mdc/mdc_dev.c @@ -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); - 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 { diff --git a/lustre/osc/osc_object.c b/lustre/osc/osc_object.c index f720946..64f6b94 100644 --- a/lustre/osc/osc_object.c +++ b/lustre/osc/osc_object.c @@ -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); - 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();