diff --git a/cmd/uzfs_test/uzfs_test.c b/cmd/uzfs_test/uzfs_test.c index bc30d84f43ed..49923116caca 100644 --- a/cmd/uzfs_test/uzfs_test.c +++ b/cmd/uzfs_test/uzfs_test.c @@ -261,10 +261,13 @@ setup_unit_test(void) void unit_test_create_pool_ds(void) { - void *spa1, *spa2, *spa3, *spa4, *spa; - void *zv1 = NULL; void *zv3 = NULL; - void *zv2 = NULL; void *zv4 = NULL; - void *zv5 = NULL; void *zv = NULL; + spa_t *spa1, *spa2, *spa3, *spa4, *spa; + zvol_state_t *zv1 = NULL; + zvol_state_t *zv3 = NULL; + zvol_state_t *zv2 = NULL; + zvol_state_t *zv4 = NULL; + zvol_state_t *zv5 = NULL; + zvol_state_t *zv = NULL; int err, err1, err2, err3, err4, err5; err1 = uzfs_create_pool(pool, "/tmp/uztest.xyz", &spa1); @@ -503,7 +506,7 @@ static void process_options(int argc, char **argv) } void -open_pool(void **spa) +open_pool(spa_t **spa) { int err; err = uzfs_open_pool(pool, spa); @@ -514,7 +517,7 @@ open_pool(void **spa) } void -open_ds(void *spa, void **zv) +open_ds(spa_t *spa, zvol_state_t **zv) { int err; err = uzfs_open_dataset(spa, ds, zv); @@ -527,7 +530,8 @@ open_ds(void *spa, void **zv) void unit_test_fn(void *arg) { - void *spa, *zv; + spa_t *spa; + zvol_state_t *zv; kthread_t *reader1; kthread_t *writer[3]; char name[MAXNAMELEN]; diff --git a/cmd/uzfs_test/uzfs_test_sync.c b/cmd/uzfs_test/uzfs_test_sync.c index 9c81b6465519..f1240ad6c919 100644 --- a/cmd/uzfs_test/uzfs_test_sync.c +++ b/cmd/uzfs_test/uzfs_test_sync.c @@ -140,7 +140,8 @@ test_replay(void *zv, uint64_t block_size) void replay_fn(void *arg) { - void *spa, *zv; + spa_t *spa; + zvol_state_t *zv; char name[MAXNAMELEN]; zvol_info_t *zinfo = NULL; diff --git a/cmd/uzfs_test/uzfs_txg_diff.c b/cmd/uzfs_test/uzfs_txg_diff.c index a0da425335a2..2dee9e8b1674 100644 --- a/cmd/uzfs_test/uzfs_txg_diff.c +++ b/cmd/uzfs_test/uzfs_txg_diff.c @@ -167,7 +167,9 @@ uzfs_txg_diff_verifcation_test(void *arg) hrtime_t end, now; uint64_t blk_offset, offset, vol_blocks; uint64_t io_num = 0; - void *spa, *zvol, *cookie = NULL; + spa_t *spa; + zvol_state_t *zvol; + void *cookie = NULL; char *buf; int max_io, count, i = 0; avl_tree_t *write_io_tree; diff --git a/cmd/uzfs_test/uzfs_zvol_zap.c b/cmd/uzfs_test/uzfs_zvol_zap.c index 6cd4411ee408..cbfee1422fd2 100644 --- a/cmd/uzfs_test/uzfs_zvol_zap.c +++ b/cmd/uzfs_test/uzfs_zvol_zap.c @@ -114,7 +114,8 @@ uzfs_zvol_zap_operation(void *arg) uzfs_test_info_t *test_info = (uzfs_test_info_t *)arg; int i = 0; hrtime_t end, now; - void *spa, *zvol; + spa_t *spa; + zvol_state_t *zvol; uzfs_zap_kv_t **kv_array; int zap_count; uint64_t txg1, txg2, txg3, txg4; diff --git a/include/uzfs_mgmt.h b/include/uzfs_mgmt.h index 13ba501dc0d7..b74bc76782c3 100644 --- a/include/uzfs_mgmt.h +++ b/include/uzfs_mgmt.h @@ -20,21 +20,23 @@ */ #ifndef _UZFS_MGMT_H - #define _UZFS_MGMT_H +#include +#include + extern int uzfs_init(void); -extern int uzfs_create_pool(char *name, char *path, void **spa); -extern int uzfs_open_pool(char *name, void **spa); -extern int uzfs_vdev_add(void *spa, char *path, int ashift, int log); -extern int uzfs_create_dataset(void *spa, char *ds, uint64_t vol_size, - uint64_t block_size, void **zv); -extern int uzfs_open_dataset(void *spa, char *ds, void **zv); +extern int uzfs_create_pool(char *name, char *path, spa_t **spa); +extern int uzfs_open_pool(char *name, spa_t **spa); +extern int uzfs_vdev_add(spa_t *spa, char *path, int ashift, int log); +extern int uzfs_create_dataset(spa_t *spa, char *ds, uint64_t vol_size, + uint64_t block_size, zvol_state_t **zv); +extern int uzfs_open_dataset(spa_t *spa, const char *ds, zvol_state_t **zv); extern int uzfs_zvol_create_cb(const char *ds_name, void *n); extern int uzfs_zvol_destroy_cb(const char *ds_name, void *n); -extern uint64_t uzfs_synced_txg(void *zv); -extern void uzfs_close_dataset(void *zv); -extern void uzfs_close_pool(void *spa); +extern uint64_t uzfs_synced_txg(zvol_state_t *zv); +extern void uzfs_close_dataset(zvol_state_t *zv); +extern void uzfs_close_pool(spa_t *spa); extern void uzfs_fini(void); extern uint64_t uzfs_random(uint64_t); diff --git a/include/uzfs_test.h b/include/uzfs_test.h index d53c9ed79361..6c13cd695a95 100644 --- a/include/uzfs_test.h +++ b/include/uzfs_test.h @@ -22,6 +22,8 @@ #ifndef _UZFS_TEST_H #define _UZFS_TEST_H +#include +#include extern int silent; extern uint64_t io_block_size; @@ -46,8 +48,8 @@ extern unsigned long zfs_arc_min; extern void replay_fn(void *arg); extern void setup_unit_test(void); extern void unit_test_create_pool_ds(void); -extern void open_pool(void **); -extern void open_ds(void *, void **); +extern void open_pool(spa_t **); +extern void open_ds(spa_t *, zvol_state_t **); typedef struct worker_args { void *zv; diff --git a/lib/libzpool/uzfs_mgmt.c b/lib/libzpool/uzfs_mgmt.c index b8b75ffe730a..8795d5e567c1 100644 --- a/lib/libzpool/uzfs_mgmt.c +++ b/lib/libzpool/uzfs_mgmt.c @@ -25,6 +25,7 @@ #include #include #include +#include static int uzfs_fd_rand = -1; @@ -263,7 +264,7 @@ uzfs_objset_create_cb(objset_t *new_os, void *arg, cred_t *cr, dmu_tx_t *tx) /* owns objset with name 'ds_name' in pool 'spa'. Sets 'sync' property */ int -uzfs_open_dataset_init(spa_t *spa, const char *ds_name, zvol_state_t **z) +uzfs_open_dataset_init(const char *ds_name, zvol_state_t **z) { zvol_state_t *zv = NULL; int error = -1; @@ -272,15 +273,19 @@ uzfs_open_dataset_init(spa_t *spa, const char *ds_name, zvol_state_t **z) uint64_t block_size, vol_size; uint64_t meta_vol_block_size; uint64_t meta_data_size; - - if (spa == NULL) - goto ret; + spa_t *spa = NULL; zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP); if (zv == NULL) goto ret; - zv->zv_spa = spa; + error = spa_open(ds_name, &spa, zv); + if (error != 0) { + kmem_free(zv, sizeof (zvol_state_t)); + goto ret; + } + + zv->zv_spa = spa; zfs_rlock_init(&zv->zv_range_lock); zfs_rlock_init(&zv->zv_mrange_lock); @@ -323,6 +328,7 @@ uzfs_open_dataset_init(spa_t *spa, const char *ds_name, zvol_state_t **z) disown_free: dmu_objset_disown(zv->zv_objset, zv); free_ret: + spa_close(spa, zv); zfs_rlock_destroy(&zv->zv_range_lock); zfs_rlock_destroy(&zv->zv_mrange_lock); kmem_free(zv, sizeof (zvol_state_t)); @@ -357,7 +363,7 @@ uzfs_open_dataset(spa_t *spa, const char *ds_name, zvol_state_t **z) return (error); (void) snprintf(name, sizeof (name), "%s/%s", spa_name(spa), ds_name); - error = uzfs_open_dataset_init(spa, name, z); + error = uzfs_open_dataset_init(name, z); return (error); } @@ -405,19 +411,12 @@ uzfs_zvol_create_cb(const char *ds_name, void *arg) { zvol_state_t *zv = NULL; - spa_t *spa; int error = -1; printf("ds_name %s\n", ds_name); - error = spa_open(ds_name, &spa, "UZINFO"); - if (error != 0) { - (void) spa_destroy((char *)ds_name); - return (error); - } - error = uzfs_open_dataset_init(spa, ds_name, &zv); + error = uzfs_open_dataset_init(ds_name, &zv); if (error) { - spa_close(spa, "UZINFO"); printf("Failed to open dataset: %s\n", ds_name); return (error); } @@ -426,6 +425,7 @@ uzfs_zvol_create_cb(const char *ds_name, void *arg) printf("Failed in uzfs_zinfo_init\n"); return (error); } + return (0); } @@ -449,6 +449,7 @@ uzfs_close_dataset(zvol_state_t *zv) dmu_objset_disown(zv->zv_objset, zv); zfs_rlock_destroy(&zv->zv_range_lock); zfs_rlock_destroy(&zv->zv_mrange_lock); + spa_close(zv->zv_spa, zv); kmem_free(zv, sizeof (zvol_state_t)); } diff --git a/lib/libzpool/zrepl_mgmt.c b/lib/libzpool/zrepl_mgmt.c index 23b766c4452f..994933ed8219 100644 --- a/lib/libzpool/zrepl_mgmt.c +++ b/lib/libzpool/zrepl_mgmt.c @@ -1,9 +1,10 @@ #include #include -#include #include #include #include +#include +#include #define true 1 #define false 0 @@ -154,13 +155,7 @@ uzfs_zinfo_destroy(const char *name) zinfo->name[namelen] == '@'))) { zv = zinfo->zv; uzfs_remove_zinfo_list(zinfo); - zil_close(zv->zv_zilog); - zfs_rlock_destroy(&zv->zv_range_lock); - zfs_rlock_destroy(&zv->zv_mrange_lock); - dnode_rele(zv->zv_dn, zv); - dmu_objset_disown(zv->zv_objset, zv); - spa_close(zv->zv_spa, "UZINFO"); - kmem_free(zv, sizeof (zvol_state_t)); + uzfs_close_dataset(zv); break; } }