diff options
Diffstat (limited to 'module/zfs/dmu_zfetch.c')
-rw-r--r-- | module/zfs/dmu_zfetch.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/module/zfs/dmu_zfetch.c b/module/zfs/dmu_zfetch.c index 6b5d58528..fc3d23b87 100644 --- a/module/zfs/dmu_zfetch.c +++ b/module/zfs/dmu_zfetch.c @@ -203,14 +203,37 @@ dmu_zfetch_dofetch(zfetch_t *zf, zstream_t *zs) void dmu_zfetch_init(zfetch_t *zf, dnode_t *dno) { - if (zf == NULL) { - return; - } - zf->zf_dnode = dno; zf->zf_stream_cnt = 0; zf->zf_alloc_fail = 0; +} +/* + * Clean-up state associated with a zfetch structure. This frees allocated + * structure members, empties the zf_stream tree, and generally makes things + * nice. This doesn't free the zfetch_t itself, that's left to the caller. + */ +void +dmu_zfetch_rele(zfetch_t *zf) +{ + zstream_t *zs; + zstream_t *zs_next; + + for (zs = list_head(&zf->zf_stream); zs; zs = zs_next) { + zs_next = list_next(&zf->zf_stream, zs); + + list_remove(&zf->zf_stream, zs); + mutex_destroy(&zs->zst_lock); + kmem_free(zs, sizeof (zstream_t)); + } +} + +/* + * Construct a zfetch structure. + */ +void +dmu_zfetch_cons(zfetch_t *zf) +{ list_create(&zf->zf_stream, sizeof (zstream_t), offsetof(zstream_t, zst_node)); @@ -218,6 +241,16 @@ dmu_zfetch_init(zfetch_t *zf, dnode_t *dno) } /* + * Destruct a zfetch structure. + */ +void +dmu_zfetch_dest(zfetch_t *zf) +{ + list_destroy(&zf->zf_stream); + rw_destroy(&zf->zf_rwlock); +} + +/* * This function computes the actual size, in blocks, that can be prefetched, * and fetches it. */ @@ -442,32 +475,6 @@ out: } /* - * Clean-up state associated with a zfetch structure. This frees allocated - * structure members, empties the zf_stream tree, and generally makes things - * nice. This doesn't free the zfetch_t itself, that's left to the caller. - */ -void -dmu_zfetch_rele(zfetch_t *zf) -{ - zstream_t *zs; - zstream_t *zs_next; - - ASSERT(!RW_LOCK_HELD(&zf->zf_rwlock)); - - for (zs = list_head(&zf->zf_stream); zs; zs = zs_next) { - zs_next = list_next(&zf->zf_stream, zs); - - list_remove(&zf->zf_stream, zs); - mutex_destroy(&zs->zst_lock); - kmem_free(zs, sizeof (zstream_t)); - } - list_destroy(&zf->zf_stream); - rw_destroy(&zf->zf_rwlock); - - zf->zf_dnode = NULL; -} - -/* * Given a zfetch and zstream structure, insert the zstream structure into the * AVL tree contained within the zfetch structure. Peform the appropriate * book-keeping. It is possible that another thread has inserted a stream which |