From 7d4106cd9fd9ef48822d19c35a711570be25d5ee Mon Sep 17 00:00:00 2001 From: Oleg Drokin Date: Thu, 16 Jun 2016 16:22:28 -0400 Subject: [PATCH] LU-8246 ldlm: Do not grant a lock twice in a race This leads to wrong ldlm pool accounting of granted locks. Also handle the case of a destroyed lock. Change-Id: Ied262d6688766e37f71304e6ee6659b48124e7ad Signed-off-by: Oleg Drokin Reviewed-on: http://review.whamcloud.com/20839 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Niu Yawei --- lustre/ldlm/ldlm_inodebits.c | 19 +++++++++++++++++-- lustre/ldlm/ldlm_plain.c | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lustre/ldlm/ldlm_inodebits.c b/lustre/ldlm/ldlm_inodebits.c index 22d1382..9917607 100644 --- a/lustre/ldlm/ldlm_inodebits.c +++ b/lustre/ldlm/ldlm_inodebits.c @@ -234,14 +234,29 @@ int ldlm_process_inodebits_lock(struct ldlm_lock *lock, __u64 *flags, rc = ldlm_run_ast_work(ldlm_res_to_ns(res), &rpc_list, LDLM_WORK_BL_AST); lock_res(res); - if (rc == -ERESTART) + if (rc == -ERESTART) { + /* We were granted while waiting, nothing left to do */ + if (lock->l_granted_mode == lock->l_req_mode) + GOTO(out, rc = 0); + /* Lock was destroyed while we were waiting, abort */ + if (ldlm_is_destroyed(lock)) + GOTO(out, rc = -EAGAIN); + + /* Otherwise try again */ GOTO(restart, rc); + } *flags |= LDLM_FL_BLOCK_GRANTED; } else { ldlm_resource_unlink_lock(lock); ldlm_grant_lock(lock, NULL); } - RETURN(0); + + rc = 0; +out: + *err = rc; + LASSERT(list_empty(&rpc_list)); + + RETURN(rc); } #endif /* HAVE_SERVER_SUPPORT */ diff --git a/lustre/ldlm/ldlm_plain.c b/lustre/ldlm/ldlm_plain.c index c1ad996..32cf816 100644 --- a/lustre/ldlm/ldlm_plain.c +++ b/lustre/ldlm/ldlm_plain.c @@ -176,14 +176,29 @@ int ldlm_process_plain_lock(struct ldlm_lock *lock, __u64 *flags, rc = ldlm_run_ast_work(ldlm_res_to_ns(res), &rpc_list, LDLM_WORK_BL_AST); lock_res(res); - if (rc == -ERESTART) + if (rc == -ERESTART) { + /* We were granted while waiting, nothing left to do */ + if (lock->l_granted_mode == lock->l_req_mode) + GOTO(out, rc = 0); + /* Lock was destroyed while we were waiting, abort */ + if (ldlm_is_destroyed(lock)) + GOTO(out, rc = -EAGAIN); + + /* Otherwise try again */ GOTO(restart, rc); + } *flags |= LDLM_FL_BLOCK_GRANTED; } else { ldlm_resource_unlink_lock(lock); ldlm_grant_lock(lock, NULL); } - RETURN(0); + + rc = 0; +out: + *err = rc; + LASSERT(list_empty(&rpc_list)); + + RETURN(rc); } #endif /* HAVE_SERVER_SUPPORT */ -- 1.8.3.1