@@ -112,13 +112,13 @@ zfs_refcount_destroy(zfs_refcount_t *rc)
112
112
int
113
113
zfs_refcount_is_zero (zfs_refcount_t * rc )
114
114
{
115
- return (rc -> rc_count == 0 );
115
+ return (zfs_refcount_count ( rc ) == 0 );
116
116
}
117
117
118
118
int64_t
119
119
zfs_refcount_count (zfs_refcount_t * rc )
120
120
{
121
- return (rc -> rc_count );
121
+ return (atomic_load_64 ( & rc -> rc_count ) );
122
122
}
123
123
124
124
int64_t
@@ -127,15 +127,18 @@ zfs_refcount_add_many(zfs_refcount_t *rc, uint64_t number, const void *holder)
127
127
reference_t * ref = NULL ;
128
128
int64_t count ;
129
129
130
- if (rc -> rc_tracked ) {
131
- ref = kmem_cache_alloc ( reference_cache , KM_SLEEP );
132
- ref -> ref_holder = holder ;
133
- ref -> ref_number = number ;
130
+ if (! rc -> rc_tracked ) {
131
+ count = atomic_add_64_nv ( & ( rc ) -> rc_count , number );
132
+ ASSERT3U ( count , >=, number ) ;
133
+ return ( count ) ;
134
134
}
135
+
136
+ ref = kmem_cache_alloc (reference_cache , KM_SLEEP );
137
+ ref -> ref_holder = holder ;
138
+ ref -> ref_number = number ;
135
139
mutex_enter (& rc -> rc_mtx );
136
140
ASSERT3U (rc -> rc_count , >=, 0 );
137
- if (rc -> rc_tracked )
138
- list_insert_head (& rc -> rc_list , ref );
141
+ list_insert_head (& rc -> rc_list , ref );
139
142
rc -> rc_count += number ;
140
143
count = rc -> rc_count ;
141
144
mutex_exit (& rc -> rc_mtx );
@@ -156,16 +159,14 @@ zfs_refcount_remove_many(zfs_refcount_t *rc, uint64_t number,
156
159
reference_t * ref ;
157
160
int64_t count ;
158
161
159
- mutex_enter (& rc -> rc_mtx );
160
- ASSERT3U (rc -> rc_count , >=, number );
161
-
162
162
if (!rc -> rc_tracked ) {
163
- rc -> rc_count -= number ;
164
- count = rc -> rc_count ;
165
- mutex_exit (& rc -> rc_mtx );
163
+ count = atomic_add_64_nv (& (rc )-> rc_count , - number );
164
+ ASSERT3S (count , >=, 0 );
166
165
return (count );
167
166
}
168
167
168
+ mutex_enter (& rc -> rc_mtx );
169
+ ASSERT3U (rc -> rc_count , >=, number );
169
170
for (ref = list_head (& rc -> rc_list ); ref ;
170
171
ref = list_next (& rc -> rc_list , ref )) {
171
172
if (ref -> ref_holder == holder && ref -> ref_number == number ) {
@@ -242,12 +243,10 @@ zfs_refcount_transfer_ownership_many(zfs_refcount_t *rc, uint64_t number,
242
243
reference_t * ref ;
243
244
boolean_t found = B_FALSE ;
244
245
245
- mutex_enter (& rc -> rc_mtx );
246
- if (!rc -> rc_tracked ) {
247
- mutex_exit (& rc -> rc_mtx );
246
+ if (!rc -> rc_tracked )
248
247
return ;
249
- }
250
248
249
+ mutex_enter (& rc -> rc_mtx );
251
250
for (ref = list_head (& rc -> rc_list ); ref ;
252
251
ref = list_next (& rc -> rc_list , ref )) {
253
252
if (ref -> ref_holder == current_holder &&
@@ -279,13 +278,10 @@ zfs_refcount_held(zfs_refcount_t *rc, const void *holder)
279
278
{
280
279
reference_t * ref ;
281
280
282
- mutex_enter (& rc -> rc_mtx );
283
-
284
- if (!rc -> rc_tracked ) {
285
- mutex_exit (& rc -> rc_mtx );
286
- return (rc -> rc_count > 0 );
287
- }
281
+ if (!rc -> rc_tracked )
282
+ return (zfs_refcount_count (rc ) > 0 );
288
283
284
+ mutex_enter (& rc -> rc_mtx );
289
285
for (ref = list_head (& rc -> rc_list ); ref ;
290
286
ref = list_next (& rc -> rc_list , ref )) {
291
287
if (ref -> ref_holder == holder ) {
@@ -307,13 +303,10 @@ zfs_refcount_not_held(zfs_refcount_t *rc, const void *holder)
307
303
{
308
304
reference_t * ref ;
309
305
310
- mutex_enter (& rc -> rc_mtx );
311
-
312
- if (!rc -> rc_tracked ) {
313
- mutex_exit (& rc -> rc_mtx );
306
+ if (!rc -> rc_tracked )
314
307
return (B_TRUE );
315
- }
316
308
309
+ mutex_enter (& rc -> rc_mtx );
317
310
for (ref = list_head (& rc -> rc_list ); ref ;
318
311
ref = list_next (& rc -> rc_list , ref )) {
319
312
if (ref -> ref_holder == holder ) {
0 commit comments