Skip to content

Commit

Permalink
Allow for '-o feature@<feature>=disable' on the command line.
Browse files Browse the repository at this point in the history
Sometimes it is desired to specifically disable or enable a feature
directly on the 'zpool create' command line.

If a disable have been specified, the default for all not mentioned
features is 'enabled'.

If a enable have been specified, the default for all the not mentioned
features is 'disabled'.

Signed-off-by: Turbo Fredriksson turbo@bayour.com
Closes #3460
  • Loading branch information
FransUrbo committed Jun 2, 2015
1 parent 2a34db1 commit d4388b7
Showing 1 changed file with 96 additions and 2 deletions.
98 changes: 96 additions & 2 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,92 @@ add_prop_list_default(const char *propname, char *propval, nvlist_t **props,
return (add_prop_list(propname, propval, props, B_TRUE));
}

static boolean_t
setup_prop_list(const char *propname, char *propval, nvlist_t **props,
int call)
{
spa_feature_t i;
char *prop;

/* String WITHOUT the 'feature@' part */
char *res = strstr(propname, "@") + 1;

if ((strcmp(propval, "disable") == 0 ||
strcmp(propval, "disabled") == 0)) {
/*
* Because we've choosen to disable (a) feature(s) we first
* need to make sure we disable ALL features, then we enable
* all BUT the one(s) we choosed to disable.
* I.e. default=enabled
*/
if (call == 0) {
for (i = 0; i < SPA_FEATURES; i++) {
/* String WITH the 'feature@' part */
prop = safe_malloc(
strlen(spa_feature_table[i].fi_uname)
+ 9);

strcpy(prop, "feature@");
strcat(prop, spa_feature_table[i].fi_uname);
prop[strlen(prop)] = '\0';

if (!nvlist_exists(*props,
spa_feature_table[i].fi_uname) ||
!nvlist_exists(*props, prop)) {
if (add_prop_list(prop,
ZFS_FEATURE_ENABLED, props,
B_TRUE))
return (B_TRUE);
}
}
}

for (i = 0; i < SPA_FEATURES; i++) {
/* String WITH the 'feature@' part */
prop = safe_malloc(
strlen(spa_feature_table[i].fi_uname) + 9);

strcpy(prop, "feature@");
strcat(prop, spa_feature_table[i].fi_uname);
prop[strlen(prop)] = '\0';

if (strcmp(prop, propname) == 0)
(void) nvlist_remove_all(*props, prop);
}
} else if ((strcmp(propval, "enable") == 0 ||
strcmp(propval, "enabled") == 0)) {
/*
* Because we've choosen to enable a feature we first need
* to make sure we disable ALL features, then we enable only
* the one we've choosed to enable.
*
* I.e. default=disabled
*/
for (i = 0; i < SPA_FEATURES; i++) {
/* String WITH the 'feature@' part */
char *prop = safe_malloc(
strlen(spa_feature_table[i].fi_uname) + 9);

strcpy(prop, "feature@");
strcat(prop, spa_feature_table[i].fi_uname);
prop[strlen(prop)] = '\0';

if (!nvlist_exists(*props,
spa_feature_table[i].fi_uname) ||
!nvlist_exists(*props, prop))
(void) nvlist_remove_all(*props, prop);

if (strcmp(spa_feature_table[i].fi_uname, res) == 0) {
if (add_prop_list(prop, ZFS_FEATURE_ENABLED,
props, B_TRUE))
return (B_TRUE);
}
}
}

return (B_FALSE);
}

/*
* zpool add [-fn] [-o property=value] <pool> <vdev> ...
*
Expand Down Expand Up @@ -843,7 +929,7 @@ zpool_do_create(int argc, char **argv)
nvlist_t *nvroot = NULL;
char *poolname;
char *tname = NULL;
int ret = 1;
int ret = 1, call = 0;
char *altroot = NULL;
char *mountpoint = NULL;
nvlist_t *fsprops = NULL;
Expand Down Expand Up @@ -884,7 +970,15 @@ zpool_do_create(int argc, char **argv)
*propval = '\0';
propval++;

if (add_prop_list(optarg, propval, &props, B_TRUE))
if (zpool_prop_feature(optarg)) {
if (setup_prop_list(optarg, propval, &props,
call))
goto errout;
else
enable_all_pool_feat = B_FALSE;
call++;
} else if (add_prop_list(optarg, propval, &props,
B_TRUE))
goto errout;

/*
Expand Down

0 comments on commit d4388b7

Please sign in to comment.