@@ -158,7 +158,7 @@ static struct afs_cell *afs_alloc_cell(struct afs_net *net,
158158 cell -> name [i ] = tolower (name [i ]);
159159 cell -> name [i ] = 0 ;
160160
161- atomic_set (& cell -> ref , 1 );
161+ refcount_set (& cell -> ref , 1 );
162162 atomic_set (& cell -> active , 0 );
163163 INIT_WORK (& cell -> manager , afs_manage_cell_work );
164164 cell -> volumes = RB_ROOT ;
@@ -287,15 +287,15 @@ struct afs_cell *afs_lookup_cell(struct afs_net *net,
287287 cell = candidate ;
288288 candidate = NULL ;
289289 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 );
291291 rb_link_node_rcu (& cell -> net_node , parent , pp );
292292 rb_insert_color (& cell -> net_node , & net -> cells );
293293 up_write (& net -> cells_lock );
294294
295295 afs_queue_cell (cell , afs_cell_trace_get_queue_new );
296296
297297wait_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 ),
299299 afs_cell_trace_wait );
300300 _debug ("wait_for_cell" );
301301 wait_var_event (& cell -> state ,
@@ -490,13 +490,13 @@ static void afs_cell_destroy(struct rcu_head *rcu)
490490{
491491 struct afs_cell * cell = container_of (rcu , struct afs_cell , rcu );
492492 struct afs_net * net = cell -> net ;
493- int u ;
493+ int r ;
494494
495495 _enter ("%p{%s}" , cell , cell -> name );
496496
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 );
500500
501501 afs_put_vlserverlist (net , rcu_access_pointer (cell -> vl_servers ));
502502 afs_unuse_cell (net , cell -> alias_of , afs_cell_trace_unuse_alias );
@@ -539,13 +539,10 @@ void afs_cells_timer(struct timer_list *timer)
539539 */
540540struct afs_cell * afs_get_cell (struct afs_cell * cell , enum afs_cell_trace reason )
541541{
542- int u ;
542+ int r ;
543543
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 );
549546 return cell ;
550547}
551548
@@ -556,12 +553,14 @@ void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason)
556553{
557554 if (cell ) {
558555 unsigned int debug_id = cell -> debug_id ;
559- unsigned int u , a ;
556+ unsigned int a ;
557+ bool zero ;
558+ int r ;
560559
561560 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 ) {
565564 a = atomic_read (& cell -> active );
566565 WARN (a != 0 , "Cell active count %u > 0\n" , a );
567566 call_rcu (& cell -> rcu , afs_cell_destroy );
@@ -574,14 +573,12 @@ void afs_put_cell(struct afs_cell *cell, enum afs_cell_trace reason)
574573 */
575574struct afs_cell * afs_use_cell (struct afs_cell * cell , enum afs_cell_trace reason )
576575{
577- int u , a ;
578-
579- if (atomic_read (& cell -> ref ) <= 0 )
580- BUG ();
576+ int r , a ;
581577
582- u = atomic_read (& cell -> ref );
578+ r = refcount_read (& cell -> ref );
579+ WARN_ON (r == 0 );
583580 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 );
585582 return cell ;
586583}
587584
@@ -593,7 +590,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
593590{
594591 unsigned int debug_id ;
595592 time64_t now , expire_delay ;
596- int u , a ;
593+ int r , a ;
597594
598595 if (!cell )
599596 return ;
@@ -607,9 +604,9 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr
607604 expire_delay = afs_cell_gc_delay ;
608605
609606 debug_id = cell -> debug_id ;
610- u = atomic_read (& cell -> ref );
607+ r = refcount_read (& cell -> ref );
611608 a = atomic_dec_return (& cell -> active );
612- trace_afs_cell (debug_id , u , a , reason );
609+ trace_afs_cell (debug_id , r , a , reason );
613610 WARN_ON (a == 0 );
614611 if (a == 1 )
615612 /* '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
621618 */
622619void afs_see_cell (struct afs_cell * cell , enum afs_cell_trace reason )
623620{
624- int u , a ;
621+ int r , a ;
625622
626- u = atomic_read (& cell -> ref );
623+ r = refcount_read (& cell -> ref );
627624 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 );
629626}
630627
631628/*
@@ -739,7 +736,7 @@ static void afs_manage_cell(struct afs_cell *cell)
739736 active = 1 ;
740737 if (atomic_try_cmpxchg_relaxed (& cell -> active , & active , 0 )) {
741738 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 ,
743740 afs_cell_trace_unuse_delete );
744741 smp_store_release (& cell -> state , AFS_CELL_REMOVED );
745742 }
@@ -866,15 +863,15 @@ void afs_manage_cells(struct work_struct *work)
866863 bool sched_cell = false;
867864
868865 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 ),
870867 active , afs_cell_trace_manage );
871868
872869 ASSERTCMP (active , >=, 1 );
873870
874871 if (purging ) {
875872 if (test_and_clear_bit (AFS_CELL_FL_NO_GC , & cell -> flags )) {
876873 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 ),
878875 active , afs_cell_trace_unuse_pin );
879876 }
880877 }
0 commit comments