Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ ztest_znode_init(uint64_t object)
ztest_znode_t *zp = umem_alloc(sizeof (*zp), UMEM_NOFAIL);

list_link_init(&zp->z_lnode);
refcount_create(&zp->z_refcnt);
zfs_refcount_create(&zp->z_refcnt);
zp->z_object = object;
zfs_rlock_init(&zp->z_range_lock);

Expand All @@ -1349,10 +1349,10 @@ ztest_znode_init(uint64_t object)
static void
ztest_znode_fini(ztest_znode_t *zp)
{
ASSERT(refcount_is_zero(&zp->z_refcnt));
ASSERT(zfs_refcount_is_zero(&zp->z_refcnt));
zfs_rlock_destroy(&zp->z_range_lock);
zp->z_object = 0;
refcount_destroy(&zp->z_refcnt);
zfs_refcount_destroy(&zp->z_refcnt);
list_link_init(&zp->z_lnode);
umem_free(zp, sizeof (*zp));
}
Expand Down Expand Up @@ -1402,8 +1402,8 @@ ztest_znode_put(ztest_ds_t *zd, ztest_znode_t *zp)
ASSERT3U(zp->z_object, !=, 0);
zll = &zd->zd_range_lock[zp->z_object & (ZTEST_OBJECT_LOCKS - 1)];
mutex_enter(&zll->z_lock);
refcount_remove(&zp->z_refcnt, RL_TAG);
if (refcount_is_zero(&zp->z_refcnt)) {
zfs_refcount_remove(&zp->z_refcnt, RL_TAG);
if (zfs_refcount_is_zero(&zp->z_refcnt)) {
list_remove(&zll->z_list, zp);
ztest_znode_fini(zp);
}
Expand Down
70 changes: 34 additions & 36 deletions include/sys/refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,57 +63,55 @@ typedef struct refcount {
* refcount_create[_untracked]()
*/

void refcount_create(zfs_refcount_t *rc);
void refcount_create_untracked(zfs_refcount_t *rc);
void refcount_create_tracked(zfs_refcount_t *rc);
void refcount_destroy(zfs_refcount_t *rc);
void refcount_destroy_many(zfs_refcount_t *rc, uint64_t number);
int refcount_is_zero(zfs_refcount_t *rc);
int64_t refcount_count(zfs_refcount_t *rc);
int64_t zfs_refcount_add(zfs_refcount_t *rc, void *holder_tag);
int64_t refcount_remove(zfs_refcount_t *rc, void *holder_tag);
int64_t refcount_add_many(zfs_refcount_t *rc, uint64_t number,
void *holder_tag);
int64_t refcount_remove_many(zfs_refcount_t *rc, uint64_t number,
void *holder_tag);
void refcount_transfer(zfs_refcount_t *dst, zfs_refcount_t *src);
void refcount_transfer_ownership(zfs_refcount_t *, void *, void *);
boolean_t refcount_held(zfs_refcount_t *, void *);
boolean_t refcount_not_held(zfs_refcount_t *, void *);

void refcount_init(void);
void refcount_fini(void);
void zfs_refcount_create(zfs_refcount_t *);
void zfs_refcount_create_untracked(zfs_refcount_t *);
void zfs_refcount_create_tracked(zfs_refcount_t *);
void zfs_refcount_destroy(zfs_refcount_t *);
void zfs_refcount_destroy_many(zfs_refcount_t *, uint64_t);
int zfs_refcount_is_zero(zfs_refcount_t *);
int64_t zfs_refcount_count(zfs_refcount_t *);
int64_t zfs_refcount_add(zfs_refcount_t *, void *);
int64_t zfs_refcount_remove(zfs_refcount_t *, void *);
int64_t zfs_refcount_add_many(zfs_refcount_t *, uint64_t, void *);
int64_t zfs_refcount_remove_many(zfs_refcount_t *, uint64_t, void *);
void zfs_refcount_transfer(zfs_refcount_t *, zfs_refcount_t *);
void zfs_refcount_transfer_ownership(zfs_refcount_t *, void *, void *);
boolean_t zfs_refcount_held(zfs_refcount_t *, void *);
boolean_t zfs_refcount_not_held(zfs_refcount_t *, void *);

void zfs_refcount_init(void);
void zfs_refcount_fini(void);

#else /* ZFS_DEBUG */

typedef struct refcount {
uint64_t rc_count;
} zfs_refcount_t;

#define refcount_create(rc) ((rc)->rc_count = 0)
#define refcount_create_untracked(rc) ((rc)->rc_count = 0)
#define refcount_create_tracked(rc) ((rc)->rc_count = 0)
#define refcount_destroy(rc) ((rc)->rc_count = 0)
#define refcount_destroy_many(rc, number) ((rc)->rc_count = 0)
#define refcount_is_zero(rc) ((rc)->rc_count == 0)
#define refcount_count(rc) ((rc)->rc_count)
#define zfs_refcount_create(rc) ((rc)->rc_count = 0)
#define zfs_refcount_create_untracked(rc) ((rc)->rc_count = 0)
#define zfs_refcount_create_tracked(rc) ((rc)->rc_count = 0)
#define zfs_refcount_destroy(rc) ((rc)->rc_count = 0)
#define zfs_refcount_destroy_many(rc, number) ((rc)->rc_count = 0)
#define zfs_refcount_is_zero(rc) ((rc)->rc_count == 0)
#define zfs_refcount_count(rc) ((rc)->rc_count)
#define zfs_refcount_add(rc, holder) atomic_inc_64_nv(&(rc)->rc_count)
#define refcount_remove(rc, holder) atomic_dec_64_nv(&(rc)->rc_count)
#define refcount_add_many(rc, number, holder) \
#define zfs_refcount_remove(rc, holder) atomic_dec_64_nv(&(rc)->rc_count)
#define zfs_refcount_add_many(rc, number, holder) \
atomic_add_64_nv(&(rc)->rc_count, number)
#define refcount_remove_many(rc, number, holder) \
#define zfs_refcount_remove_many(rc, number, holder) \
atomic_add_64_nv(&(rc)->rc_count, -number)
#define refcount_transfer(dst, src) { \
#define zfs_refcount_transfer(dst, src) { \
uint64_t __tmp = (src)->rc_count; \
atomic_add_64(&(src)->rc_count, -__tmp); \
atomic_add_64(&(dst)->rc_count, __tmp); \
}
#define refcount_transfer_ownership(rc, current_holder, new_holder) (void)0
#define refcount_held(rc, holder) ((rc)->rc_count > 0)
#define refcount_not_held(rc, holder) (B_TRUE)
#define zfs_refcount_transfer_ownership(rc, current_holder, new_holder) (void)0
#define zfs_refcount_held(rc, holder) ((rc)->rc_count > 0)
#define zfs_refcount_not_held(rc, holder) (B_TRUE)

#define refcount_init()
#define refcount_fini()
#define zfs_refcount_init()
#define zfs_refcount_fini()

#endif /* ZFS_DEBUG */

Expand Down
2 changes: 1 addition & 1 deletion include/sys/trace_dbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
__entry->db_offset = db->db.db_offset; \
__entry->db_size = db->db.db_size; \
__entry->db_state = db->db_state; \
__entry->db_holds = refcount_count(&db->db_holds); \
__entry->db_holds = zfs_refcount_count(&db->db_holds); \
snprintf(__get_str(msg), TRACE_DBUF_MSG_MAX, \
DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS); \
} else { \
Expand Down
22 changes: 11 additions & 11 deletions module/zfs/abd.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ abd_alloc(size_t size, boolean_t is_metadata)
}
abd->abd_size = size;
abd->abd_parent = NULL;
refcount_create(&abd->abd_children);
zfs_refcount_create(&abd->abd_children);

abd->abd_u.abd_scatter.abd_offset = 0;

Expand All @@ -612,7 +612,7 @@ abd_free_scatter(abd_t *abd)
{
abd_free_pages(abd);

refcount_destroy(&abd->abd_children);
zfs_refcount_destroy(&abd->abd_children);
ABDSTAT_BUMPDOWN(abdstat_scatter_cnt);
ABDSTAT_INCR(abdstat_scatter_data_size, -(int)abd->abd_size);
ABDSTAT_INCR(abdstat_scatter_chunk_waste,
Expand All @@ -639,7 +639,7 @@ abd_alloc_linear(size_t size, boolean_t is_metadata)
}
abd->abd_size = size;
abd->abd_parent = NULL;
refcount_create(&abd->abd_children);
zfs_refcount_create(&abd->abd_children);

if (is_metadata) {
abd->abd_u.abd_linear.abd_buf = zio_buf_alloc(size);
Expand All @@ -662,7 +662,7 @@ abd_free_linear(abd_t *abd)
zio_data_buf_free(abd->abd_u.abd_linear.abd_buf, abd->abd_size);
}

refcount_destroy(&abd->abd_children);
zfs_refcount_destroy(&abd->abd_children);
ABDSTAT_BUMPDOWN(abdstat_linear_cnt);
ABDSTAT_INCR(abdstat_linear_data_size, -(int)abd->abd_size);

Expand Down Expand Up @@ -773,8 +773,8 @@ abd_get_offset_impl(abd_t *sabd, size_t off, size_t size)

abd->abd_size = size;
abd->abd_parent = sabd;
refcount_create(&abd->abd_children);
(void) refcount_add_many(&sabd->abd_children, abd->abd_size, abd);
zfs_refcount_create(&abd->abd_children);
(void) zfs_refcount_add_many(&sabd->abd_children, abd->abd_size, abd);

return (abd);
}
Expand Down Expand Up @@ -816,7 +816,7 @@ abd_get_from_buf(void *buf, size_t size)
abd->abd_flags = ABD_FLAG_LINEAR;
abd->abd_size = size;
abd->abd_parent = NULL;
refcount_create(&abd->abd_children);
zfs_refcount_create(&abd->abd_children);

abd->abd_u.abd_linear.abd_buf = buf;

Expand All @@ -834,11 +834,11 @@ abd_put(abd_t *abd)
ASSERT(!(abd->abd_flags & ABD_FLAG_OWNER));

if (abd->abd_parent != NULL) {
(void) refcount_remove_many(&abd->abd_parent->abd_children,
(void) zfs_refcount_remove_many(&abd->abd_parent->abd_children,
abd->abd_size, abd);
}

refcount_destroy(&abd->abd_children);
zfs_refcount_destroy(&abd->abd_children);
abd_free_struct(abd);
}

Expand Down Expand Up @@ -870,7 +870,7 @@ abd_borrow_buf(abd_t *abd, size_t n)
} else {
buf = zio_buf_alloc(n);
}
(void) refcount_add_many(&abd->abd_children, n, buf);
(void) zfs_refcount_add_many(&abd->abd_children, n, buf);

return (buf);
}
Expand Down Expand Up @@ -902,7 +902,7 @@ abd_return_buf(abd_t *abd, void *buf, size_t n)
ASSERT0(abd_cmp_buf(abd, buf, n));
zio_buf_free(buf, n);
}
(void) refcount_remove_many(&abd->abd_children, n, buf);
(void) zfs_refcount_remove_many(&abd->abd_children, n, buf);
}

void
Expand Down
Loading