@@ -1407,6 +1407,7 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)
1407
1407
{
1408
1408
struct dlm_ls * ls = lkb -> lkb_resource -> res_ls ;
1409
1409
int error = 0 ;
1410
+ int wc ;
1410
1411
1411
1412
mutex_lock (& ls -> ls_waiters_mutex );
1412
1413
@@ -1428,20 +1429,17 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)
1428
1429
error = - EBUSY ;
1429
1430
goto out ;
1430
1431
}
1431
- lkb -> lkb_wait_count ++ ;
1432
+ wc = atomic_inc_return ( & lkb -> lkb_wait_count ) ;
1432
1433
hold_lkb (lkb );
1433
1434
1434
1435
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 ));
1437
1438
goto out ;
1438
1439
}
1439
1440
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 ););
1445
1443
lkb -> lkb_wait_type = mstype ;
1446
1444
lkb -> lkb_wait_nodeid = to_nodeid ; /* for debugging */
1447
1445
hold_lkb (lkb );
@@ -1504,7 +1502,7 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
1504
1502
log_debug (ls , "remwait %x convert_reply zap overlap_cancel" ,
1505
1503
lkb -> lkb_id );
1506
1504
lkb -> lkb_wait_type = 0 ;
1507
- lkb -> lkb_wait_count -- ;
1505
+ atomic_dec ( & lkb -> lkb_wait_count ) ;
1508
1506
unhold_lkb (lkb );
1509
1507
goto out_del ;
1510
1508
}
@@ -1531,16 +1529,15 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
1531
1529
if (overlap_done && lkb -> lkb_wait_type ) {
1532
1530
log_error (ls , "remwait error %x reply %d wait_type %d overlap" ,
1533
1531
lkb -> lkb_id , mstype , lkb -> lkb_wait_type );
1534
- lkb -> lkb_wait_count -- ;
1532
+ atomic_dec ( & lkb -> lkb_wait_count ) ;
1535
1533
unhold_lkb (lkb );
1536
1534
lkb -> lkb_wait_type = 0 ;
1537
1535
}
1538
1536
1539
- DLM_ASSERT (lkb -> lkb_wait_count , dlm_print_lkb (lkb ););
1537
+ DLM_ASSERT (atomic_read ( & lkb -> lkb_wait_count ) , dlm_print_lkb (lkb ););
1540
1538
1541
1539
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 ))
1544
1541
list_del_init (& lkb -> lkb_wait_reply );
1545
1542
unhold_lkb (lkb );
1546
1543
return 0 ;
@@ -2669,7 +2666,7 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
2669
2666
goto out ;
2670
2667
2671
2668
/* 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 ) )
2673
2670
goto out ;
2674
2671
2675
2672
if (is_overlap (lkb ))
@@ -2731,7 +2728,7 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args)
2731
2728
2732
2729
/* normal unlock not allowed if there's any op in progress */
2733
2730
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 ) ))
2735
2732
goto out ;
2736
2733
2737
2734
/* 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
5063
/* drop all wait_count references we still
5067
5064
* hold a reference for this iteration.
5068
5065
*/
5069
- while (lkb -> lkb_wait_count ) {
5070
- lkb -> lkb_wait_count -- ;
5066
+ while (!atomic_dec_and_test (& lkb -> lkb_wait_count ))
5071
5067
unhold_lkb (lkb );
5072
- }
5068
+
5073
5069
mutex_lock (& ls -> ls_waiters_mutex );
5074
5070
list_del_init (& lkb -> lkb_wait_reply );
5075
5071
mutex_unlock (& ls -> ls_waiters_mutex );
0 commit comments