Skip to content

Commit 75a7d60

Browse files
Alexander Aringteigland
authored andcommitted
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: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent 07ee386 commit 75a7d60

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

fs/dlm/dlm_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct dlm_lkb {
246246
int8_t lkb_highbast; /* highest mode bast sent for */
247247

248248
int8_t lkb_wait_type; /* type of reply waiting for */
249-
int8_t lkb_wait_count;
249+
atomic_t lkb_wait_count;
250250
int lkb_wait_nodeid; /* for debugging */
251251

252252
struct list_head lkb_statequeue; /* rsb g/c/w list */

fs/dlm/lock.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)
14071407
{
14081408
struct dlm_ls *ls = lkb->lkb_resource->res_ls;
14091409
int error = 0;
1410+
int wc;
14101411

14111412
mutex_lock(&ls->ls_waiters_mutex);
14121413

@@ -1428,20 +1429,17 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)
14281429
error = -EBUSY;
14291430
goto out;
14301431
}
1431-
lkb->lkb_wait_count++;
1432+
wc = atomic_inc_return(&lkb->lkb_wait_count);
14321433
hold_lkb(lkb);
14331434

14341435
log_debug(ls, "addwait %x cur %d overlap %d count %d f %x",
1435-
lkb->lkb_id, lkb->lkb_wait_type, mstype,
1436-
lkb->lkb_wait_count, dlm_iflags_val(lkb));
1436+
lkb->lkb_id, lkb->lkb_wait_type, mstype, wc,
1437+
dlm_iflags_val(lkb));
14371438
goto out;
14381439
}
14391440

1440-
DLM_ASSERT(!lkb->lkb_wait_count,
1441-
dlm_print_lkb(lkb);
1442-
printk("wait_count %d\n", lkb->lkb_wait_count););
1443-
1444-
lkb->lkb_wait_count++;
1441+
wc = atomic_fetch_inc(&lkb->lkb_wait_count);
1442+
DLM_ASSERT(!wc, dlm_print_lkb(lkb); printk("wait_count %d\n", wc););
14451443
lkb->lkb_wait_type = mstype;
14461444
lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */
14471445
hold_lkb(lkb);
@@ -1504,7 +1502,7 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
15041502
log_debug(ls, "remwait %x convert_reply zap overlap_cancel",
15051503
lkb->lkb_id);
15061504
lkb->lkb_wait_type = 0;
1507-
lkb->lkb_wait_count--;
1505+
atomic_dec(&lkb->lkb_wait_count);
15081506
unhold_lkb(lkb);
15091507
goto out_del;
15101508
}
@@ -1531,16 +1529,15 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
15311529
if (overlap_done && lkb->lkb_wait_type) {
15321530
log_error(ls, "remwait error %x reply %d wait_type %d overlap",
15331531
lkb->lkb_id, mstype, lkb->lkb_wait_type);
1534-
lkb->lkb_wait_count--;
1532+
atomic_dec(&lkb->lkb_wait_count);
15351533
unhold_lkb(lkb);
15361534
lkb->lkb_wait_type = 0;
15371535
}
15381536

1539-
DLM_ASSERT(lkb->lkb_wait_count, dlm_print_lkb(lkb););
1537+
DLM_ASSERT(atomic_read(&lkb->lkb_wait_count), dlm_print_lkb(lkb););
15401538

15411539
clear_bit(DLM_IFL_RESEND_BIT, &lkb->lkb_iflags);
1542-
lkb->lkb_wait_count--;
1543-
if (!lkb->lkb_wait_count)
1540+
if (atomic_dec_and_test(&lkb->lkb_wait_count))
15441541
list_del_init(&lkb->lkb_wait_reply);
15451542
unhold_lkb(lkb);
15461543
return 0;
@@ -2669,7 +2666,7 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
26692666
goto out;
26702667

26712668
/* lock not allowed if there's any op in progress */
2672-
if (lkb->lkb_wait_type || lkb->lkb_wait_count)
2669+
if (lkb->lkb_wait_type || atomic_read(&lkb->lkb_wait_count))
26732670
goto out;
26742671

26752672
if (is_overlap(lkb))
@@ -2731,7 +2728,7 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args)
27312728

27322729
/* normal unlock not allowed if there's any op in progress */
27332730
if (!(args->flags & (DLM_LKF_CANCEL | DLM_LKF_FORCEUNLOCK)) &&
2734-
(lkb->lkb_wait_type || lkb->lkb_wait_count))
2731+
(lkb->lkb_wait_type || atomic_read(&lkb->lkb_wait_count)))
27352732
goto out;
27362733

27372734
/* 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)
50665063
/* drop all wait_count references we still
50675064
* hold a reference for this iteration.
50685065
*/
5069-
while (lkb->lkb_wait_count) {
5070-
lkb->lkb_wait_count--;
5066+
while (!atomic_dec_and_test(&lkb->lkb_wait_count))
50715067
unhold_lkb(lkb);
5072-
}
5068+
50735069
mutex_lock(&ls->ls_waiters_mutex);
50745070
list_del_init(&lkb->lkb_wait_reply);
50755071
mutex_unlock(&ls->ls_waiters_mutex);

0 commit comments

Comments
 (0)