@@ -158,7 +158,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
158
158
cell -> name [i ] = tolower (name [i ]);
159
159
cell -> name [i ] = 0 ;
160
160
161
- atomic_set (& cell -> ref , 1 );
161
+ refcount_set (& cell -> ref , 1 );
162
162
atomic_set (& cell -> active , 0 );
163
163
INIT_WORK (& cell -> manager , afs_manage_cell_work );
164
164
cell -> volumes = RB_ROOT ;
@@ -287,15 +287,15 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net,
287
287
cell = candidate ;
288
288
candidate = NULL ;
289
289
atomic_set (& cell -> active , 2 );
290
- trace_afs_cell (cell -> debug_id , atomic_read (& cell -> ref ), 2 , afs_cell_trace_insert );
290
+ trace_afs_cell (cell -> debug_id , refcount_read (& cell -> ref ), 2 , afs_cell_trace_insert );
291
291
rb_link_node_rcu (& cell -> net_node , parent , pp );
292
292
rb_insert_color (& cell -> net_node , & net -> cells );
293
293
up_write (& net -> cells_lock );
294
294
295
295
afs_queue_cell (cell , afs_cell_trace_get_queue_new );
296
296
297
297
wait_for_cell :
298
- trace_afs_cell (cell -> debug_id , atomic_read (& cell -> ref ), atomic_read (& cell -> active ),
298
+ trace_afs_cell (cell -> debug_id , refcount_read (& cell -> ref ), atomic_read (& cell -> active ),
299
299
afs_cell_trace_wait );
300
300
_debug ("wait_for_cell" );
301
301
wait_var_event (& cell -> state ,
@@ -490,13 +490,13 @@ static void afs_cell_destroy(struct rcu_head *rcu)
490
490
{
491
491
struct afs_cell * cell = container_of (rcu , struct afs_cell , rcu );
492
492
struct afs_net * net = cell -> net ;
493
- int u ;
493
+ int r ;
494
494
495
495
_enter ("%p{%s}" , cell , cell -> name );
496
496
497
- u = atomic_read (& cell -> ref );
498
- ASSERTCMP (u , = = , 0 );
499
- trace_afs_cell (cell -> debug_id , u , atomic_read (& cell -> active ), afs_cell_trace_free );
497
+ r = refcount_read (& cell -> ref );
498
+ ASSERTCMP (r , = = , 0 );
499
+ trace_afs_cell (cell -> debug_id , r , atomic_read (& cell -> active ), afs_cell_trace_free );
500
500
501
501
afs_put_vlserverlist (net , rcu_access_pointer (cell -> vl_servers ));
502
502
afs_unuse_cell (net , cell -> alias_of , afs_cell_trace_unuse_alias );
@@ -539,13 +539,10 @@ void afs_cells_timer(struct timer_list *timer)
539
539
*/
540
540
struct afs_cell * afs_get_cell (struct afs_cell * cell , enum afs_cell_trace reason )
541
541
{
542
- int u ;
542
+ int r ;
543
543
544
- if (atomic_read (& cell -> ref ) <= 0 )
545
- BUG ();
546
-
547
- u = atomic_inc_return (& cell -> ref );
548
- trace_afs_cell (cell -> debug_id , u , atomic_read (& cell -> active ), reason );
544
+ __refcount_inc (& cell -> ref , & r );
545
+ trace_afs_cell (cell -> debug_id , r + 1 , atomic_read (& cell -> active ), reason );
549
546
return cell ;
550
547
}
551
548
@@ -556,12 +553,14 @@ void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason)
556
553
{
557
554
if (cell ) {
558
555
unsigned int debug_id = cell -> debug_id ;
559
- unsigned int u , a ;
556
+ unsigned int a ;
557
+ bool zero ;
558
+ int r ;
560
559
561
560
a = atomic_read (& cell -> active );
562
- u = atomic_dec_return (& cell -> ref );
563
- trace_afs_cell (debug_id , u , a , reason );
564
- if (u == 0 ) {
561
+ zero = __refcount_dec_and_test (& cell -> ref , & r );
562
+ trace_afs_cell (debug_id , r - 1 , a , reason );
563
+ if (zero ) {
565
564
a = atomic_read (& cell -> active );
566
565
WARN (a != 0 , "Cell active count %u > 0\n" , a );
567
566
call_rcu (& cell -> rcu , afs_cell_destroy );
@@ -574,14 +573,12 @@ void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason)
574
573
*/
575
574
struct afs_cell * afs_use_cell (struct afs_cell * cell , enum afs_cell_trace reason )
576
575
{
577
- int u , a ;
578
-
579
- if (atomic_read (& cell -> ref ) <= 0 )
580
- BUG ();
576
+ int r , a ;
581
577
582
- u = atomic_read (& cell -> ref );
578
+ r = refcount_read (& cell -> ref );
579
+ WARN_ON (r == 0 );
583
580
a = atomic_inc_return (& cell -> active );
584
- trace_afs_cell (cell -> debug_id , u , a , reason );
581
+ trace_afs_cell (cell -> debug_id , r , a , reason );
585
582
return cell ;
586
583
}
587
584
@@ -593,7 +590,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
593
590
{
594
591
unsigned int debug_id ;
595
592
time64_t now , expire_delay ;
596
- int u , a ;
593
+ int r , a ;
597
594
598
595
if (!cell )
599
596
return ;
@@ -607,9 +604,9 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
607
604
expire_delay = afs_cell_gc_delay ;
608
605
609
606
debug_id = cell -> debug_id ;
610
- u = atomic_read (& cell -> ref );
607
+ r = refcount_read (& cell -> ref );
611
608
a = atomic_dec_return (& cell -> active );
612
- trace_afs_cell (debug_id , u , a , reason );
609
+ trace_afs_cell (debug_id , r , a , reason );
613
610
WARN_ON (a == 0 );
614
611
if (a == 1 )
615
612
/* 'cell' may now be garbage collected. */
@@ -621,11 +618,11 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
621
618
*/
622
619
void afs_see_cell (struct afs_cell * cell , enum afs_cell_trace reason )
623
620
{
624
- int u , a ;
621
+ int r , a ;
625
622
626
- u = atomic_read (& cell -> ref );
623
+ r = refcount_read (& cell -> ref );
627
624
a = atomic_read (& cell -> active );
628
- trace_afs_cell (cell -> debug_id , u , a , reason );
625
+ trace_afs_cell (cell -> debug_id , r , a , reason );
629
626
}
630
627
631
628
/*
@@ -739,7 +736,7 @@ static void afs_manage_cell(struct afs_cell *cell)
739
736
active = 1 ;
740
737
if (atomic_try_cmpxchg_relaxed (& cell -> active , & active , 0 )) {
741
738
rb_erase (& cell -> net_node , & net -> cells );
742
- trace_afs_cell (cell -> debug_id , atomic_read (& cell -> ref ), 0 ,
739
+ trace_afs_cell (cell -> debug_id , refcount_read (& cell -> ref ), 0 ,
743
740
afs_cell_trace_unuse_delete );
744
741
smp_store_release (& cell -> state , AFS_CELL_REMOVED );
745
742
}
@@ -866,15 +863,15 @@ void afs_manage_cells(struct work_struct *work)
866
863
bool sched_cell = false;
867
864
868
865
active = atomic_read (& cell -> active );
869
- trace_afs_cell (cell -> debug_id , atomic_read (& cell -> ref ),
866
+ trace_afs_cell (cell -> debug_id , refcount_read (& cell -> ref ),
870
867
active , afs_cell_trace_manage );
871
868
872
869
ASSERTCMP (active , >=, 1 );
873
870
874
871
if (purging ) {
875
872
if (test_and_clear_bit (AFS_CELL_FL_NO_GC , & cell -> flags )) {
876
873
active = atomic_dec_return (& cell -> active );
877
- trace_afs_cell (cell -> debug_id , atomic_read (& cell -> ref ),
874
+ trace_afs_cell (cell -> debug_id , refcount_read (& cell -> ref ),
878
875
active , afs_cell_trace_unuse_pin );
879
876
}
880
877
}
0 commit comments