Skip to content

Commit

Permalink
assertion in debug mode when destroying zvol (#65)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kryl <jan.kryl@cloudbyte.com>
  • Loading branch information
Jan Kryl committed Mar 15, 2018
1 parent 464120f commit 7444b88
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 44 deletions.
18 changes: 11 additions & 7 deletions cmd/uzfs_test/uzfs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion cmd/uzfs_test/uzfs_test_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion cmd/uzfs_test/uzfs_txg_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion cmd/uzfs_test/uzfs_zvol_zap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 12 additions & 10 deletions include/uzfs_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@
*/

#ifndef _UZFS_MGMT_H

#define _UZFS_MGMT_H

#include <sys/spa.h>
#include <sys/uzfs_zvol.h>

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);

Expand Down
6 changes: 4 additions & 2 deletions include/uzfs_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef _UZFS_TEST_H
#define _UZFS_TEST_H

#include <sys/spa.h>
#include <sys/uzfs_zvol.h>

extern int silent;
extern uint64_t io_block_size;
Expand All @@ -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;
Expand Down
29 changes: 15 additions & 14 deletions lib/libzpool/uzfs_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <sys/stat.h>
#include <uzfs.h>
#include <zrepl_mgmt.h>
#include <uzfs_mgmt.h>

static int uzfs_fd_rand = -1;

Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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));
}

Expand Down
11 changes: 3 additions & 8 deletions lib/libzpool/zrepl_mgmt.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <syslog.h>
#include <sys/zil.h>
#include <zrepl_mgmt.h>
#include <sys/zfs_rlock.h>
#include <sys/uzfs_zvol.h>
#include <sys/dnode.h>
#include <zrepl_mgmt.h>
#include <uzfs_mgmt.h>

#define true 1
#define false 0
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 7444b88

Please sign in to comment.