Commit 75a7d601 authored by Alexander Aring's avatar Alexander Aring Committed by David Teigland

fs: dlm: handle lkb wait count as atomic_t

Currently the lkb_wait_count is locked by the rsb lock and it should be
fine to handle lkb_wait_count as non atomic_t value. However for the
overall process of reducing locking this patch converts it to an
atomic_t value.
Signed-off-by: default avatarAlexander Aring <aahringo@redhat.com>
Signed-off-by: default avatarDavid Teigland <teigland@redhat.com>
parent 07ee3867
...@@ -246,7 +246,7 @@ struct dlm_lkb { ...@@ -246,7 +246,7 @@ struct dlm_lkb {
int8_t lkb_highbast; /* highest mode bast sent for */ int8_t lkb_highbast; /* highest mode bast sent for */
int8_t lkb_wait_type; /* type of reply waiting for */ int8_t lkb_wait_type; /* type of reply waiting for */
int8_t lkb_wait_count; atomic_t lkb_wait_count;
int lkb_wait_nodeid; /* for debugging */ int lkb_wait_nodeid; /* for debugging */
struct list_head lkb_statequeue; /* rsb g/c/w list */ struct list_head lkb_statequeue; /* rsb g/c/w list */
......
...@@ -1407,6 +1407,7 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid) ...@@ -1407,6 +1407,7 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)
{ {
struct dlm_ls *ls = lkb->lkb_resource->res_ls; struct dlm_ls *ls = lkb->lkb_resource->res_ls;
int error = 0; int error = 0;
int wc;
mutex_lock(&ls->ls_waiters_mutex); mutex_lock(&ls->ls_waiters_mutex);
...@@ -1428,20 +1429,17 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid) ...@@ -1428,20 +1429,17 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)
error = -EBUSY; error = -EBUSY;
goto out; goto out;
} }
lkb->lkb_wait_count++; wc = atomic_inc_return(&lkb->lkb_wait_count);
hold_lkb(lkb); hold_lkb(lkb);
log_debug(ls, "addwait %x cur %d overlap %d count %d f %x", log_debug(ls, "addwait %x cur %d overlap %d count %d f %x",
lkb->lkb_id, lkb->lkb_wait_type, mstype, lkb->lkb_id, lkb->lkb_wait_type, mstype, wc,
lkb->lkb_wait_count, dlm_iflags_val(lkb)); dlm_iflags_val(lkb));
goto out; goto out;
} }
DLM_ASSERT(!lkb->lkb_wait_count, wc = atomic_fetch_inc(&lkb->lkb_wait_count);
dlm_print_lkb(lkb); DLM_ASSERT(!wc, dlm_print_lkb(lkb); printk("wait_count %d\n", wc););
printk("wait_count %d\n", lkb->lkb_wait_count););
lkb->lkb_wait_count++;
lkb->lkb_wait_type = mstype; lkb->lkb_wait_type = mstype;
lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */ lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */
hold_lkb(lkb); hold_lkb(lkb);
...@@ -1504,7 +1502,7 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype, ...@@ -1504,7 +1502,7 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
log_debug(ls, "remwait %x convert_reply zap overlap_cancel", log_debug(ls, "remwait %x convert_reply zap overlap_cancel",
lkb->lkb_id); lkb->lkb_id);
lkb->lkb_wait_type = 0; lkb->lkb_wait_type = 0;
lkb->lkb_wait_count--; atomic_dec(&lkb->lkb_wait_count);
unhold_lkb(lkb); unhold_lkb(lkb);
goto out_del; goto out_del;
} }
...@@ -1531,16 +1529,15 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype, ...@@ -1531,16 +1529,15 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
if (overlap_done && lkb->lkb_wait_type) { if (overlap_done && lkb->lkb_wait_type) {
log_error(ls, "remwait error %x reply %d wait_type %d overlap", log_error(ls, "remwait error %x reply %d wait_type %d overlap",
lkb->lkb_id, mstype, lkb->lkb_wait_type); lkb->lkb_id, mstype, lkb->lkb_wait_type);
lkb->lkb_wait_count--; atomic_dec(&lkb->lkb_wait_count);
unhold_lkb(lkb); unhold_lkb(lkb);
lkb->lkb_wait_type = 0; lkb->lkb_wait_type = 0;
} }
DLM_ASSERT(lkb->lkb_wait_count, dlm_print_lkb(lkb);); DLM_ASSERT(atomic_read(&lkb->lkb_wait_count), dlm_print_lkb(lkb););
clear_bit(DLM_IFL_RESEND_BIT, &lkb->lkb_iflags); clear_bit(DLM_IFL_RESEND_BIT, &lkb->lkb_iflags);
lkb->lkb_wait_count--; if (atomic_dec_and_test(&lkb->lkb_wait_count))
if (!lkb->lkb_wait_count)
list_del_init(&lkb->lkb_wait_reply); list_del_init(&lkb->lkb_wait_reply);
unhold_lkb(lkb); unhold_lkb(lkb);
return 0; return 0;
...@@ -2669,7 +2666,7 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb, ...@@ -2669,7 +2666,7 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
goto out; goto out;
/* lock not allowed if there's any op in progress */ /* lock not allowed if there's any op in progress */
if (lkb->lkb_wait_type || lkb->lkb_wait_count) if (lkb->lkb_wait_type || atomic_read(&lkb->lkb_wait_count))
goto out; goto out;
if (is_overlap(lkb)) if (is_overlap(lkb))
...@@ -2731,7 +2728,7 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) ...@@ -2731,7 +2728,7 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args)
/* normal unlock not allowed if there's any op in progress */ /* normal unlock not allowed if there's any op in progress */
if (!(args->flags & (DLM_LKF_CANCEL | DLM_LKF_FORCEUNLOCK)) && if (!(args->flags & (DLM_LKF_CANCEL | DLM_LKF_FORCEUNLOCK)) &&
(lkb->lkb_wait_type || lkb->lkb_wait_count)) (lkb->lkb_wait_type || atomic_read(&lkb->lkb_wait_count)))
goto out; goto out;
/* an lkb may be waiting for an rsb lookup to complete where the /* an lkb may be waiting for an rsb lookup to complete where the
...@@ -5066,10 +5063,9 @@ int dlm_recover_waiters_post(struct dlm_ls *ls) ...@@ -5066,10 +5063,9 @@ int dlm_recover_waiters_post(struct dlm_ls *ls)
/* drop all wait_count references we still /* drop all wait_count references we still
* hold a reference for this iteration. * hold a reference for this iteration.
*/ */
while (lkb->lkb_wait_count) { while (!atomic_dec_and_test(&lkb->lkb_wait_count))
lkb->lkb_wait_count--;
unhold_lkb(lkb); unhold_lkb(lkb);
}
mutex_lock(&ls->ls_waiters_mutex); mutex_lock(&ls->ls_waiters_mutex);
list_del_init(&lkb->lkb_wait_reply); list_del_init(&lkb->lkb_wait_reply);
mutex_unlock(&ls->ls_waiters_mutex); mutex_unlock(&ls->ls_waiters_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment