ztest: Use fnvlist_* instead of VERIFYing nvlist_*

Simplify ztest by using fnvlist functions to verify success.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #11441
This commit is contained in:
Ryan Moeller 2021-01-11 12:30:33 -05:00 committed by GitHub
parent 2ac90457f5
commit bea3fc71ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 65 additions and 72 deletions

View File

@ -1122,11 +1122,11 @@ make_vdev_file(char *path, char *aux, char *pool, size_t size, uint64_t ashift)
(void) close(fd); (void) close(fd);
} }
VERIFY0(nvlist_alloc(&file, NV_UNIQUE_NAME, 0)); file = fnvlist_alloc();
VERIFY0(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, fnvlist_add_string(file, ZPOOL_CONFIG_TYPE,
draid_spare ? VDEV_TYPE_DRAID_SPARE : VDEV_TYPE_FILE)); draid_spare ? VDEV_TYPE_DRAID_SPARE : VDEV_TYPE_FILE);
VERIFY0(nvlist_add_string(file, ZPOOL_CONFIG_PATH, path)); fnvlist_add_string(file, ZPOOL_CONFIG_PATH, path);
VERIFY0(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift)); fnvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift);
umem_free(pathbuf, MAXPATHLEN); umem_free(pathbuf, MAXPATHLEN);
return (file); return (file);
@ -1146,13 +1146,12 @@ make_vdev_raid(char *path, char *aux, char *pool, size_t size,
for (c = 0; c < r; c++) for (c = 0; c < r; c++)
child[c] = make_vdev_file(path, aux, pool, size, ashift); child[c] = make_vdev_file(path, aux, pool, size, ashift);
VERIFY0(nvlist_alloc(&raid, NV_UNIQUE_NAME, 0)); raid = fnvlist_alloc();
VERIFY0(nvlist_add_string(raid, ZPOOL_CONFIG_TYPE, fnvlist_add_string(raid, ZPOOL_CONFIG_TYPE,
ztest_opts.zo_raid_type)); ztest_opts.zo_raid_type);
VERIFY0(nvlist_add_uint64(raid, ZPOOL_CONFIG_NPARITY, fnvlist_add_uint64(raid, ZPOOL_CONFIG_NPARITY,
ztest_opts.zo_raid_parity)); ztest_opts.zo_raid_parity);
VERIFY0(nvlist_add_nvlist_array(raid, ZPOOL_CONFIG_CHILDREN, fnvlist_add_nvlist_array(raid, ZPOOL_CONFIG_CHILDREN, child, r);
child, r));
if (strcmp(ztest_opts.zo_raid_type, VDEV_TYPE_DRAID) == 0) { if (strcmp(ztest_opts.zo_raid_type, VDEV_TYPE_DRAID) == 0) {
uint64_t ndata = ztest_opts.zo_draid_data; uint64_t ndata = ztest_opts.zo_draid_data;
@ -1176,7 +1175,7 @@ make_vdev_raid(char *path, char *aux, char *pool, size_t size,
} }
for (c = 0; c < r; c++) for (c = 0; c < r; c++)
nvlist_free(child[c]); fnvlist_free(child[c]);
umem_free(child, r * sizeof (nvlist_t *)); umem_free(child, r * sizeof (nvlist_t *));
@ -1198,14 +1197,12 @@ make_vdev_mirror(char *path, char *aux, char *pool, size_t size,
for (c = 0; c < m; c++) for (c = 0; c < m; c++)
child[c] = make_vdev_raid(path, aux, pool, size, ashift, r); child[c] = make_vdev_raid(path, aux, pool, size, ashift, r);
VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0); mirror = fnvlist_alloc();
VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE, fnvlist_add_string(mirror, ZPOOL_CONFIG_TYPE, VDEV_TYPE_MIRROR);
VDEV_TYPE_MIRROR) == 0); fnvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN, child, m);
VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
child, m) == 0);
for (c = 0; c < m; c++) for (c = 0; c < m; c++)
nvlist_free(child[c]); fnvlist_free(child[c]);
umem_free(child, m * sizeof (nvlist_t *)); umem_free(child, m * sizeof (nvlist_t *));
@ -1229,23 +1226,22 @@ make_vdev_root(char *path, char *aux, char *pool, size_t size, uint64_t ashift,
for (c = 0; c < t; c++) { for (c = 0; c < t; c++) {
child[c] = make_vdev_mirror(path, aux, pool, size, ashift, child[c] = make_vdev_mirror(path, aux, pool, size, ashift,
r, m); r, m);
VERIFY(nvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG, fnvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG, log);
log) == 0);
if (class != NULL && class[0] != '\0') { if (class != NULL && class[0] != '\0') {
ASSERT(m > 1 || log); /* expecting a mirror */ ASSERT(m > 1 || log); /* expecting a mirror */
VERIFY(nvlist_add_string(child[c], fnvlist_add_string(child[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, class) == 0); ZPOOL_CONFIG_ALLOCATION_BIAS, class);
} }
} }
VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0); root = fnvlist_alloc();
VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0); fnvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT);
VERIFY(nvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN, fnvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN,
child, t) == 0); child, t);
for (c = 0; c < t; c++) for (c = 0; c < t; c++)
nvlist_free(child[c]); fnvlist_free(child[c]);
umem_free(child, t * sizeof (nvlist_t *)); umem_free(child, t * sizeof (nvlist_t *));
@ -1402,12 +1398,12 @@ ztest_spa_prop_set_uint64(zpool_prop_t prop, uint64_t value)
nvlist_t *props = NULL; nvlist_t *props = NULL;
int error; int error;
VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0); props = fnvlist_alloc();
VERIFY(nvlist_add_uint64(props, zpool_prop_to_name(prop), value) == 0); fnvlist_add_uint64(props, zpool_prop_to_name(prop), value);
error = spa_prop_set(spa, props); error = spa_prop_set(spa, props);
nvlist_free(props); fnvlist_free(props);
if (error == ENOSPC) { if (error == ENOSPC) {
ztest_record_enospc(FTAG); ztest_record_enospc(FTAG);
@ -2817,7 +2813,7 @@ ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, NULL, 0, 0, 1); nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, NULL, 0, 0, 1);
VERIFY3U(ENOENT, ==, VERIFY3U(ENOENT, ==,
spa_create("ztest_bad_file", nvroot, NULL, NULL, NULL)); spa_create("ztest_bad_file", nvroot, NULL, NULL, NULL));
nvlist_free(nvroot); fnvlist_free(nvroot);
/* /*
* Attempt to create using a bad mirror. * Attempt to create using a bad mirror.
@ -2825,7 +2821,7 @@ ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, NULL, 0, 2, 1); nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, NULL, 0, 2, 1);
VERIFY3U(ENOENT, ==, VERIFY3U(ENOENT, ==,
spa_create("ztest_bad_mirror", nvroot, NULL, NULL, NULL)); spa_create("ztest_bad_mirror", nvroot, NULL, NULL, NULL));
nvlist_free(nvroot); fnvlist_free(nvroot);
/* /*
* Attempt to create an existing pool. It shouldn't matter * Attempt to create an existing pool. It shouldn't matter
@ -2835,7 +2831,7 @@ ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, NULL, 0, 0, 1); nvroot = make_vdev_root("/dev/bogus", NULL, NULL, 0, 0, NULL, 0, 0, 1);
VERIFY3U(EEXIST, ==, VERIFY3U(EEXIST, ==,
spa_create(zo->zo_pool, nvroot, NULL, NULL, NULL)); spa_create(zo->zo_pool, nvroot, NULL, NULL, NULL));
nvlist_free(nvroot); fnvlist_free(nvroot);
/* /*
* We open a reference to the spa and then we try to export it * We open a reference to the spa and then we try to export it
@ -3146,7 +3142,7 @@ ztest_vdev_add_remove(ztest_ds_t *zd, uint64_t id)
1); 1);
error = spa_vdev_add(spa, nvroot); error = spa_vdev_add(spa, nvroot);
nvlist_free(nvroot); fnvlist_free(nvroot);
switch (error) { switch (error) {
case 0: case 0:
@ -3208,7 +3204,7 @@ ztest_vdev_class_add(ztest_ds_t *zd, uint64_t id)
class, ztest_opts.zo_raid_children, zs->zs_mirrors, 1); class, ztest_opts.zo_raid_children, zs->zs_mirrors, 1);
error = spa_vdev_add(spa, nvroot); error = spa_vdev_add(spa, nvroot);
nvlist_free(nvroot); fnvlist_free(nvroot);
if (error == ENOSPC) if (error == ENOSPC)
ztest_record_enospc("spa_vdev_add"); ztest_record_enospc("spa_vdev_add");
@ -3321,7 +3317,7 @@ ztest_vdev_aux_add_remove(ztest_ds_t *zd, uint64_t id)
default: default:
fatal(0, "spa_vdev_add(%p) = %d", nvroot, error); fatal(0, "spa_vdev_add(%p) = %d", nvroot, error);
} }
nvlist_free(nvroot); fnvlist_free(nvroot);
} else { } else {
/* /*
* Remove an existing device. Sometimes, dirty its * Remove an existing device. Sometimes, dirty its
@ -3383,12 +3379,11 @@ ztest_split_pool(ztest_ds_t *zd, uint64_t id)
/* generate a config from the existing config */ /* generate a config from the existing config */
mutex_enter(&spa->spa_props_lock); mutex_enter(&spa->spa_props_lock);
VERIFY(nvlist_lookup_nvlist(spa->spa_config, ZPOOL_CONFIG_VDEV_TREE, tree = fnvlist_lookup_nvlist(spa->spa_config, ZPOOL_CONFIG_VDEV_TREE);
&tree) == 0);
mutex_exit(&spa->spa_props_lock); mutex_exit(&spa->spa_props_lock);
VERIFY(nvlist_lookup_nvlist_array(tree, ZPOOL_CONFIG_CHILDREN, &child, VERIFY0(nvlist_lookup_nvlist_array(tree, ZPOOL_CONFIG_CHILDREN,
&children) == 0); &child, &children));
schild = malloc(rvd->vdev_children * sizeof (nvlist_t *)); schild = malloc(rvd->vdev_children * sizeof (nvlist_t *));
for (c = 0; c < children; c++) { for (c = 0; c < children; c++) {
@ -3397,37 +3392,35 @@ ztest_split_pool(ztest_ds_t *zd, uint64_t id)
uint_t mchildren; uint_t mchildren;
if (tvd->vdev_islog || tvd->vdev_ops == &vdev_hole_ops) { if (tvd->vdev_islog || tvd->vdev_ops == &vdev_hole_ops) {
VERIFY(nvlist_alloc(&schild[schildren], NV_UNIQUE_NAME, schild[schildren] = fnvlist_alloc();
0) == 0); fnvlist_add_string(schild[schildren],
VERIFY(nvlist_add_string(schild[schildren], ZPOOL_CONFIG_TYPE, VDEV_TYPE_HOLE);
ZPOOL_CONFIG_TYPE, VDEV_TYPE_HOLE) == 0); fnvlist_add_uint64(schild[schildren],
VERIFY(nvlist_add_uint64(schild[schildren], ZPOOL_CONFIG_IS_HOLE, 1);
ZPOOL_CONFIG_IS_HOLE, 1) == 0);
if (lastlogid == 0) if (lastlogid == 0)
lastlogid = schildren; lastlogid = schildren;
++schildren; ++schildren;
continue; continue;
} }
lastlogid = 0; lastlogid = 0;
VERIFY(nvlist_lookup_nvlist_array(child[c], VERIFY0(nvlist_lookup_nvlist_array(child[c],
ZPOOL_CONFIG_CHILDREN, &mchild, &mchildren) == 0); ZPOOL_CONFIG_CHILDREN, &mchild, &mchildren));
VERIFY(nvlist_dup(mchild[0], &schild[schildren++], 0) == 0); schild[schildren++] = fnvlist_dup(mchild[0]);
} }
/* OK, create a config that can be used to split */ /* OK, create a config that can be used to split */
VERIFY(nvlist_alloc(&split, NV_UNIQUE_NAME, 0) == 0); split = fnvlist_alloc();
VERIFY(nvlist_add_string(split, ZPOOL_CONFIG_TYPE, fnvlist_add_string(split, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT);
VDEV_TYPE_ROOT) == 0); fnvlist_add_nvlist_array(split, ZPOOL_CONFIG_CHILDREN, schild,
VERIFY(nvlist_add_nvlist_array(split, ZPOOL_CONFIG_CHILDREN, schild, lastlogid != 0 ? lastlogid : schildren);
lastlogid != 0 ? lastlogid : schildren) == 0);
VERIFY(nvlist_alloc(&config, NV_UNIQUE_NAME, 0) == 0); config = fnvlist_alloc();
VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, split) == 0); fnvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, split);
for (c = 0; c < schildren; c++) for (c = 0; c < schildren; c++)
nvlist_free(schild[c]); fnvlist_free(schild[c]);
free(schild); free(schild);
nvlist_free(split); fnvlist_free(split);
spa_config_exit(spa, SCL_VDEV, FTAG); spa_config_exit(spa, SCL_VDEV, FTAG);
@ -3435,7 +3428,7 @@ ztest_split_pool(ztest_ds_t *zd, uint64_t id)
error = spa_vdev_split_mirror(spa, "splitp", config, NULL, B_FALSE); error = spa_vdev_split_mirror(spa, "splitp", config, NULL, B_FALSE);
(void) pthread_rwlock_unlock(&ztest_name_lock); (void) pthread_rwlock_unlock(&ztest_name_lock);
nvlist_free(config); fnvlist_free(config);
if (error == 0) { if (error == 0) {
(void) printf("successful split - results:\n"); (void) printf("successful split - results:\n");
@ -3658,7 +3651,7 @@ ztest_vdev_attach_detach(ztest_ds_t *zd, uint64_t id)
error = spa_vdev_attach(spa, oldguid, root, replacing, rebuilding); error = spa_vdev_attach(spa, oldguid, root, replacing, rebuilding);
nvlist_free(root); fnvlist_free(root);
/* /*
* If our parent was the replacing vdev, but the replace completed, * If our parent was the replacing vdev, but the replace completed,
@ -5713,7 +5706,7 @@ ztest_spa_prop_get_set(ztest_ds_t *zd, uint64_t id)
if (ztest_opts.zo_verbose >= 6) if (ztest_opts.zo_verbose >= 6)
dump_nvlist(props, 4); dump_nvlist(props, 4);
nvlist_free(props); fnvlist_free(props);
(void) pthread_rwlock_unlock(&ztest_name_lock); (void) pthread_rwlock_unlock(&ztest_name_lock);
} }
@ -6702,7 +6695,7 @@ ztest_spa_import_export(char *oldname, char *newname)
*/ */
newconfig = spa_tryimport(config); newconfig = spa_tryimport(config);
ASSERT(newconfig != NULL); ASSERT(newconfig != NULL);
nvlist_free(newconfig); fnvlist_free(newconfig);
/* /*
* Import it under the new name. * Import it under the new name.
@ -6738,7 +6731,7 @@ ztest_spa_import_export(char *oldname, char *newname)
ASSERT(pool_guid == spa_guid(spa)); ASSERT(pool_guid == spa_guid(spa));
spa_close(spa, FTAG); spa_close(spa, FTAG);
nvlist_free(config); fnvlist_free(config);
} }
static void static void
@ -7452,13 +7445,13 @@ make_random_props(void)
{ {
nvlist_t *props; nvlist_t *props;
VERIFY0(nvlist_alloc(&props, NV_UNIQUE_NAME, 0)); props = fnvlist_alloc();
if (ztest_random(2) == 0) if (ztest_random(2) == 0)
return (props); return (props);
VERIFY0(nvlist_add_uint64(props, fnvlist_add_uint64(props,
zpool_prop_to_name(ZPOOL_PROP_AUTOREPLACE), 1)); zpool_prop_to_name(ZPOOL_PROP_AUTOREPLACE), 1);
return (props); return (props);
} }
@ -7496,9 +7489,9 @@ ztest_init(ztest_shared_t *zs)
* in which case ztest_fault_inject() temporarily takes away * in which case ztest_fault_inject() temporarily takes away
* the only valid replica. * the only valid replica.
*/ */
VERIFY0(nvlist_add_uint64(props, fnvlist_add_uint64(props,
zpool_prop_to_name(ZPOOL_PROP_FAILUREMODE), zpool_prop_to_name(ZPOOL_PROP_FAILUREMODE),
MAXFAULTS(zs) ? ZIO_FAILURE_MODE_PANIC : ZIO_FAILURE_MODE_WAIT)); MAXFAULTS(zs) ? ZIO_FAILURE_MODE_PANIC : ZIO_FAILURE_MODE_WAIT);
for (i = 0; i < SPA_FEATURES; i++) { for (i = 0; i < SPA_FEATURES; i++) {
char *buf; char *buf;
@ -7513,13 +7506,13 @@ ztest_init(ztest_shared_t *zs)
VERIFY3S(-1, !=, asprintf(&buf, "feature@%s", VERIFY3S(-1, !=, asprintf(&buf, "feature@%s",
spa_feature_table[i].fi_uname)); spa_feature_table[i].fi_uname));
VERIFY3U(0, ==, nvlist_add_uint64(props, buf, 0)); fnvlist_add_uint64(props, buf, 0);
free(buf); free(buf);
} }
VERIFY0(spa_create(ztest_opts.zo_pool, nvroot, props, NULL, NULL)); VERIFY0(spa_create(ztest_opts.zo_pool, nvroot, props, NULL, NULL));
nvlist_free(nvroot); fnvlist_free(nvroot);
nvlist_free(props); fnvlist_free(props);
VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG)); VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
zs->zs_metaslab_sz = zs->zs_metaslab_sz =