result = 0;
}
- rc = mdc_lock_discard_pages(env, obj, start, end, discard);
+ /* Avoid lock matching with CLM_WRITE, there can be no other locks */
+ rc = mdc_lock_discard_pages(env, obj, start, end,
+ mode == CLM_WRITE || discard);
if (result == 0 && rc < 0)
result = rc;
enum ldlm_mode mode;
bool glimpse = *flags & LDLM_FL_HAS_INTENT;
__u64 match_flags = *flags;
- int rc;
+ struct list_head cancels = LIST_HEAD_INIT(cancels);
+ int rc, count;
ENTRY;
if (req == NULL)
RETURN(-ENOMEM);
- rc = ldlm_prep_enqueue_req(exp, req, NULL, 0);
+ /* For WRITE lock cancel other locks on resource early if any */
+ if (einfo->ei_mode & LCK_PW)
+ count = mdc_resource_get_unused_res(exp, res_id, &cancels,
+ einfo->ei_mode,
+ MDS_INODELOCK_DOM);
+ else
+ count = 0;
+
+ rc = ldlm_prep_enqueue_req(exp, req, &cancels, count);
if (rc < 0) {
ptlrpc_request_free(req);
RETURN(rc);