Skip to content

Commit

Permalink
ztest: Add raidz expansion testing as CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
fuporovvStack authored and ahrens committed Nov 16, 2021
1 parent 16a74ed commit 05a8136
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
63 changes: 33 additions & 30 deletions cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ typedef struct ztest_shared_opts {
size_t zo_vdev_size;
int zo_ashift;
int zo_mirrors;
int zo_raid_do_expand;
int zo_raid_children;
int zo_raid_parity;
char zo_raid_type[8];
Expand Down Expand Up @@ -372,8 +373,7 @@ typedef void ztest_func_t(ztest_ds_t *zd, uint64_t id);

/*
* XXX: remove zi_raidz_attach_compatible field, when
* raidz expansion will be completely integrated together with
* ztest_raidz_attach_test variable.
* raidz expansion will be completely integrated.
*/

typedef struct ztest_info {
Expand Down Expand Up @@ -564,7 +564,6 @@ static ztest_ds_t *ztest_ds;

static kmutex_t ztest_vdev_lock;
static boolean_t ztest_device_removal_active = B_FALSE;
static boolean_t ztest_raidz_attach_test = B_FALSE;
static boolean_t ztest_pool_scrubbed = B_FALSE;
static kmutex_t ztest_checkpoint_lock;

Expand Down Expand Up @@ -784,7 +783,7 @@ static ztest_option_t option_table[] = {
DEFAULT_RAID_CHILDREN, NULL},
{ 'R', "raid-parity", "INTEGER", "Raid parity",
DEFAULT_RAID_PARITY, NULL},
{ 'K', "raid-kind", "raidz|draid|random", "Raid kind",
{ 'K', "raid-kind", "raidz|eraidz|draid|random", "Raid kind",
NO_DEFAULT, "random"},
{ 'D', "draid-data", "INTEGER", "Number of draid data drives",
DEFAULT_DRAID_DATA, NULL},
Expand Down Expand Up @@ -1126,8 +1125,17 @@ process_options(int argc, char **argv)

/* When raid choice is 'random' add a draid pool 50% of the time */
if (strcmp(raid_kind, "random") == 0) {
(void) strlcpy(raid_kind, (ztest_random(2) == 0) ?
"draid" : "raidz", sizeof (raid_kind));
switch (ztest_random(3)) {
case 0:
(void) strlcpy(raid_kind, "raidz", sizeof (raid_kind));
break;
case 1:
(void) strlcpy(raid_kind, "eraidz", sizeof (raid_kind));
break;
case 2:
(void) strlcpy(raid_kind, "draid", sizeof (raid_kind));
break;
}

if (ztest_opts.zo_verbose >= 3)
(void) printf("choosing RAID type '%s'\n", raid_kind);
Expand Down Expand Up @@ -1166,6 +1174,16 @@ process_options(int argc, char **argv)
(void) strlcpy(zo->zo_raid_type, VDEV_TYPE_DRAID,
sizeof (zo->zo_raid_type));

} else if (strcmp(raid_kind, "eraidz") == 0) {
/* using eraidz (expandable raidz) */
zo->zo_raid_do_expand = B_TRUE;

/* No top-level mirrors with raidz expansion for now */
zo->zo_mirrors = 0;

zo->zo_raid_parity = MIN(zo->zo_raid_parity,
zo->zo_raid_children - 1);

} else /* using raidz */ {
ASSERT0(strcmp(raid_kind, "raidz"));

Expand Down Expand Up @@ -3911,21 +3929,6 @@ raidz_scratch_verify(void)
kernel_fini();
}

static boolean_t
ztest_vdev_raidz_attach_possible(spa_t *spa)
{
ztest_shared_t *zs = ztest_shared;
vdev_t *rvd = spa->spa_root_vdev;
vdev_t *vd = rvd->vdev_child[0];

if (rvd->vdev_children == 1 &&
strcmp(vd->vdev_ops->vdev_op_type, "raidz") == 0 &&
zs->zs_mirrors == 0)
return (B_TRUE);

return (B_FALSE);
}

static void
ztest_scratch_thread(void *arg)
{
Expand Down Expand Up @@ -3955,19 +3958,21 @@ ztest_vdev_raidz_attach(ztest_ds_t *zd, uint64_t id)
char *newpath = umem_alloc(MAXPATHLEN, UMEM_NOFAIL);
int error, expected_error = 0;

if (ztest_opts.zo_mmp_test)
return;

mutex_enter(&ztest_vdev_lock);

spa_config_enter(spa, SCL_ALL, FTAG, RW_READER);

if (ztest_device_removal_active) {
if (!ztest_opts.zo_raid_do_expand) {
spa_config_exit(spa, SCL_ALL, FTAG);
goto out;
}

if (!ztest_vdev_raidz_attach_possible(spa)) {
if (ztest_opts.zo_mmp_test) {
spa_config_exit(spa, SCL_ALL, FTAG);
goto out;
}

if (ztest_device_removal_active) {
spa_config_exit(spa, SCL_ALL, FTAG);
goto out;
}
Expand Down Expand Up @@ -7296,7 +7301,7 @@ ztest_execute(int test, ztest_info_t *zi, uint64_t id)
int i;

for (i = 0; i < zi->zi_iters; i++) {
if (!ztest_raidz_attach_test)
if (!ztest_opts.zo_raid_do_expand)
zi->zi_func(zd, id);
else if (zi->zi_raidz_attach_compatible)
zi->zi_func(zd, id);
Expand Down Expand Up @@ -7550,7 +7555,7 @@ ztest_freeze(void)
spa_t *spa;
int numloops = 0;

if (ztest_raidz_attach_test)
if (ztest_opts.zo_raid_do_expand)
return;

if (ztest_opts.zo_verbose >= 3)
Expand Down Expand Up @@ -8106,8 +8111,6 @@ ztest_run(ztest_shared_t *zs)
metaslab_preload_limit = ztest_random(20) + 1;
ztest_spa = spa;

ztest_raidz_attach_test = ztest_vdev_raidz_attach_possible(spa);

/*
* BUGBUG raidz expansion do not run this for now
* VERIFY0(vdev_raidz_impl_set("cycle"));
Expand Down
4 changes: 2 additions & 2 deletions man/man1/ztest.1
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ Number of mirror copies.
Number of raidz/draid disks.
.It Fl R , -raid-parity Ns = (default: Sy 1 )
Raid parity (raidz & draid).
.It Fl K , -raid-kind Ns = Ns Sy raidz Ns | Ns Sy draid Ns | Ns Sy random No (default: Sy random )
.It Fl K , -raid-kind Ns = Ns Sy raidz Ns | Ns Sy eraidz Ns | Ns Sy draid Ns | Ns Sy random No (default: Sy random )
The kind of RAID config to use.
With
.Sy random
the kind alternates between raidz and draid.
the kind alternates between raidz, eraidz (expandable raidz) and draid.
.It Fl D , -draid-data Ns = (default: Sy 4 )
Number of data disks in a dRAID redundancy group.
.It Fl S , -draid-spares Ns = (default: Sy 1 )
Expand Down

0 comments on commit 05a8136

Please sign in to comment.