Skip to content

Commit

Permalink
Rewrite of a25d0a3.
Browse files Browse the repository at this point in the history
Instead of using '-D' for relevant commands, use the '-o whole_disk={on,off}'
for the same purpose.
  • Loading branch information
FransUrbo committed May 29, 2015
1 parent a25d0a3 commit 1ec7b2f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 121 deletions.
56 changes: 19 additions & 37 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ static const char *
get_usage(zpool_help_t idx) {
switch (idx) {
case HELP_ADD:
return (gettext("\tadd [-fnD] [-o property=value] "
return (gettext("\tadd [-fn] [-o property=value] "
"<pool> <vdev> ...\n"));
case HELP_ATTACH:
return (gettext("\tattach [-fD] [-o property=value] "
return (gettext("\tattach [-f] [-o property=value] "
"<pool> <device> <new-device>\n"));
case HELP_CLEAR:
return (gettext("\tclear [-nF] <pool> [device]\n"));
case HELP_CREATE:
return (gettext("\tcreate [-fndD] [-o property=value] ... \n"
return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
"\t [-O file-system-property=value] ... \n"
"\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
case HELP_DESTROY:
Expand Down Expand Up @@ -248,7 +248,7 @@ get_usage(zpool_help_t idx) {
case HELP_ONLINE:
return (gettext("\tonline <pool> <device> ...\n"));
case HELP_REPLACE:
return (gettext("\treplace [-fD] [-o property=value] "
return (gettext("\treplace [-f] [-o property=value] "
"<pool> <device> [new-device]\n"));
case HELP_REMOVE:
return (gettext("\tremove <pool> <device> ...\n"));
Expand All @@ -271,7 +271,7 @@ get_usage(zpool_help_t idx) {
case HELP_SET:
return (gettext("\tset <property=value> <pool> \n"));
case HELP_SPLIT:
return (gettext("\tsplit [-nD] [-R altroot] [-o mntopts]\n"
return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
"\t [-o property=value] <pool> <newpool> "
"[<device> ...]\n"));
case HELP_REGUID:
Expand Down Expand Up @@ -501,12 +501,11 @@ add_prop_list_default(const char *propname, char *propval, nvlist_t **props,
}

/*
* zpool add [-fnD] [-o property=value] <pool> <vdev> ...
* zpool add [-fn] [-o property=value] <pool> <vdev> ...
*
* -f Force addition of devices, even if they appear in use
* -n Do not add the devices, but display the resulting layout if
* they were to be added.
* -D Don't automatically partition the device(s).
* -o Set property=value.
*
* Adds the given vdevs to 'pool'. As with create, the bulk of this work is
Expand All @@ -518,7 +517,6 @@ zpool_do_add(int argc, char **argv)
{
boolean_t force = B_FALSE;
boolean_t dryrun = B_FALSE;
boolean_t auto_partition_device = B_TRUE;
int c;
nvlist_t *nvroot;
char *poolname;
Expand All @@ -529,17 +527,14 @@ zpool_do_add(int argc, char **argv)
char *propval;

/* check options */
while ((c = getopt(argc, argv, "fnDo:")) != -1) {
while ((c = getopt(argc, argv, "fno:")) != -1) {
switch (c) {
case 'f':
force = B_TRUE;
break;
case 'n':
dryrun = B_TRUE;
break;
case 'D':
auto_partition_device = B_FALSE;
break;
case 'o':
if ((propval = strchr(optarg, '=')) == NULL) {
(void) fprintf(stderr, gettext("missing "
Expand All @@ -549,7 +544,8 @@ zpool_do_add(int argc, char **argv)
*propval = '\0';
propval++;

if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
if (((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) &&
(strcmp(optarg, ZPOOL_CONFIG_WHOLE_DISK) != 0)) ||
(add_prop_list(optarg, propval, &props, B_TRUE)))
usage(B_FALSE);
break;
Expand Down Expand Up @@ -590,7 +586,7 @@ zpool_do_add(int argc, char **argv)

/* pass off to get_vdev_spec for processing */
nvroot = make_root_vdev(zhp, props, force, !force, B_FALSE, dryrun,
auto_partition_device, argc, argv);
argc, argv);
if (nvroot == NULL) {
zpool_close(zhp);
return (1);
Expand Down Expand Up @@ -818,7 +814,7 @@ zpool_do_labelclear(int argc, char **argv)
}

/*
* zpool create [-fndD] [-o property=value] ...
* zpool create [-fnd] [-o property=value] ...
* [-O file-system-property=value] ...
* [-R root] [-m mountpoint] <pool> <dev> ...
*
Expand All @@ -831,7 +827,6 @@ zpool_do_labelclear(int argc, char **argv)
* -o Set property=value.
* -d Don't automatically enable all supported pool features
* (individual features can be enabled with -o).
* -D Don't automatically partition the device(s).
* -O Set fsproperty=value in the pool's root file system
*
* Creates the named pool according to the given vdev specification. The
Expand All @@ -845,7 +840,6 @@ zpool_do_create(int argc, char **argv)
boolean_t force = B_FALSE;
boolean_t dryrun = B_FALSE;
boolean_t enable_all_pool_feat = B_TRUE;
boolean_t auto_partition_device = B_TRUE;
int c;
nvlist_t *nvroot = NULL;
char *poolname;
Expand All @@ -858,7 +852,7 @@ zpool_do_create(int argc, char **argv)
char *propval;

/* check options */
while ((c = getopt(argc, argv, ":fndDR:m:o:O:t:")) != -1) {
while ((c = getopt(argc, argv, ":fndR:m:o:O:t:")) != -1) {
switch (c) {
case 'f':
force = B_TRUE;
Expand All @@ -869,9 +863,6 @@ zpool_do_create(int argc, char **argv)
case 'd':
enable_all_pool_feat = B_FALSE;
break;
case 'D':
auto_partition_device = B_FALSE;
break;
case 'R':
altroot = optarg;
if (add_prop_list(zpool_prop_to_name(
Expand Down Expand Up @@ -995,7 +986,7 @@ zpool_do_create(int argc, char **argv)

/* pass off to get_vdev_spec for bulk processing */
nvroot = make_root_vdev(NULL, props, force, !force, B_FALSE, dryrun,
auto_partition_device, argc - 1, argv + 1);
argc - 1, argv + 1);
if (nvroot == NULL)
goto errout;

Expand Down Expand Up @@ -3321,7 +3312,6 @@ static int
zpool_do_attach_or_replace(int argc, char **argv, int replacing)
{
boolean_t force = B_FALSE;
boolean_t auto_partition_device = B_TRUE;
int c;
nvlist_t *nvroot;
char *poolname, *old_disk, *new_disk;
Expand All @@ -3331,14 +3321,11 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
int ret;

/* check options */
while ((c = getopt(argc, argv, "fDo:")) != -1) {
while ((c = getopt(argc, argv, "fo:")) != -1) {
switch (c) {
case 'f':
force = B_TRUE;
break;
case 'D':
auto_partition_device = B_FALSE;
break;
case 'o':
if ((propval = strchr(optarg, '=')) == NULL) {
(void) fprintf(stderr, gettext("missing "
Expand All @@ -3348,7 +3335,8 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
*propval = '\0';
propval++;

if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
if (((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) &&
(strcmp(optarg, ZPOOL_CONFIG_WHOLE_DISK) != 0)) ||
(add_prop_list(optarg, propval, &props, B_TRUE)))
usage(B_FALSE);
break;
Expand Down Expand Up @@ -3409,7 +3397,7 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
}

nvroot = make_root_vdev(zhp, props, force, B_FALSE, replacing, B_FALSE,
auto_partition_device, argc, argv);
argc, argv);
if (nvroot == NULL) {
zpool_close(zhp);
return (1);
Expand Down Expand Up @@ -3521,7 +3509,6 @@ zpool_do_detach(int argc, char **argv)
* it were to be split.
* -o Set property=value, or set mount options.
* -R Mount the split-off pool under an alternate root.
* -D Don't automatically partition the device(s).
*
* Splits the named pool and gives it the new pool name. Devices to be split
* off may be listed, provided that no more than one device is specified
Expand All @@ -3541,13 +3528,12 @@ zpool_do_split(int argc, char **argv)
int c, ret = 0;
zpool_handle_t *zhp;
nvlist_t *config, *props = NULL;
boolean_t auto_partition_device = B_TRUE;

flags.dryrun = B_FALSE;
flags.import = B_FALSE;

/* check options */
while ((c = getopt(argc, argv, ":R:nDo:")) != -1) {
while ((c = getopt(argc, argv, ":R:no:")) != -1) {
switch (c) {
case 'R':
flags.import = B_TRUE;
Expand All @@ -3562,9 +3548,6 @@ zpool_do_split(int argc, char **argv)
case 'n':
flags.dryrun = B_TRUE;
break;
case 'D':
auto_partition_device = B_FALSE;
break;
case 'o':
if ((propval = strchr(optarg, '=')) != NULL) {
*propval = '\0';
Expand Down Expand Up @@ -3619,8 +3602,7 @@ zpool_do_split(int argc, char **argv)
if ((zhp = zpool_open(g_zfs, srcpool)) == NULL)
return (1);

config = split_mirror_vdev(zhp, newpool, props, flags,
auto_partition_device, argc, argv);
config = split_mirror_vdev(zhp, newpool, props, flags, argc, argv);
if (config == NULL) {
ret = 1;
} else {
Expand Down
6 changes: 2 additions & 4 deletions cmd/zpool/zpool_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ uint_t num_logs(nvlist_t *nv);
*/

nvlist_t *make_root_vdev(zpool_handle_t *zhp, nvlist_t *props, int force,
int check_rep, boolean_t replacing, boolean_t dryrun, boolean_t autopart,
int argc, char **argv);
int check_rep, boolean_t replacing, boolean_t dryrun, int argc, char **argv);
nvlist_t *split_mirror_vdev(zpool_handle_t *zhp, char *newname,
nvlist_t *props, splitflags_t flags, boolean_t autopart, int argc,
char **argv);
nvlist_t *props, splitflags_t flags, int argc, char **argv);

/*
* Pool list functions
Expand Down
42 changes: 29 additions & 13 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,7 @@ is_spare(nvlist_t *config, const char *path)
* xxx Shorthand for <zfs_vdev_paths>/xxx
*/
static nvlist_t *
make_leaf_vdev(nvlist_t *props, boolean_t autopart, const char *arg,
uint64_t is_log)
make_leaf_vdev(nvlist_t *props, const char *arg, uint64_t is_log)
{
char path[MAXPATHLEN];
struct stat64 statbuf;
Expand Down Expand Up @@ -667,7 +666,26 @@ make_leaf_vdev(nvlist_t *props, boolean_t autopart, const char *arg,
return (NULL);
}

wholedisk = autopart ? is_whole_disk(path) : B_FALSE;
if (props != NULL) {
char *value = NULL;
if (nvlist_lookup_string(props,
zpool_prop_to_name(ZPOOL_PROP_WHOLE_DISK), &value)
== 0) {
if (strcmp(value, "on") == 0)
/*
* This is somewhat counter-intuitive.
* We've asked for whole disk, but we're
* setting it to false. This because
* when it's false, later checks won't
* partition the device, which is what
* we ACTUALLY wanted.
*/
wholedisk = B_FALSE;
else
wholedisk = is_whole_disk(path);
}
} else
wholedisk = is_whole_disk(path);
if (!wholedisk && (stat64(path, &statbuf) != 0)) {
(void) fprintf(stderr,
gettext("cannot open '%s': %s\n"),
Expand Down Expand Up @@ -1423,7 +1441,7 @@ is_grouping(const char *type, int *mindev, int *maxdev)
* because the program is just going to exit anyway.
*/
nvlist_t *
construct_spec(nvlist_t *props, boolean_t autopart, int argc, char **argv)
construct_spec(nvlist_t *props, int argc, char **argv)
{
nvlist_t *nvroot, *nv, **top, **spares, **l2cache;
int t, toplevels, mindev, maxdev, nspares, nlogs, nl2cache;
Expand Down Expand Up @@ -1512,8 +1530,8 @@ construct_spec(nvlist_t *props, boolean_t autopart, int argc, char **argv)
children * sizeof (nvlist_t *));
if (child == NULL)
zpool_no_memory();
if ((nv = make_leaf_vdev(props, autopart,
argv[c], B_FALSE)) == NULL)
if ((nv = make_leaf_vdev(props, argv[c],
B_FALSE)) == NULL)
return (NULL);
child[children - 1] = nv;
}
Expand Down Expand Up @@ -1568,7 +1586,7 @@ construct_spec(nvlist_t *props, boolean_t autopart, int argc, char **argv)
* We have a device. Pass off to make_leaf_vdev() to
* construct the appropriate nvlist describing the vdev.
*/
if ((nv = make_leaf_vdev(props, autopart, argv[0],
if ((nv = make_leaf_vdev(props, argv[0],
is_log)) == NULL)
return (NULL);
if (is_log)
Expand Down Expand Up @@ -1629,14 +1647,13 @@ construct_spec(nvlist_t *props, boolean_t autopart, int argc, char **argv)

nvlist_t *
split_mirror_vdev(zpool_handle_t *zhp, char *newname, nvlist_t *props,
splitflags_t flags, boolean_t autopart, int argc, char **argv)
splitflags_t flags, int argc, char **argv)
{
nvlist_t *newroot = NULL, **child;
uint_t c, children;

if (argc > 0) {
if ((newroot = construct_spec(props, autopart, argc, argv))
== NULL) {
if ((newroot = construct_spec(props, argc, argv)) == NULL) {
(void) fprintf(stderr, gettext("Unable to build a "
"pool from the specified devices\n"));
return (NULL);
Expand Down Expand Up @@ -1687,8 +1704,7 @@ split_mirror_vdev(zpool_handle_t *zhp, char *newname, nvlist_t *props,
*/
nvlist_t *
make_root_vdev(zpool_handle_t *zhp, nvlist_t *props, int force, int check_rep,
boolean_t replacing, boolean_t dryrun, boolean_t autopart, int argc,
char **argv)
boolean_t replacing, boolean_t dryrun, int argc, char **argv)
{
nvlist_t *newroot;
nvlist_t *poolconfig = NULL;
Expand All @@ -1699,7 +1715,7 @@ make_root_vdev(zpool_handle_t *zhp, nvlist_t *props, int force, int check_rep,
* that we have a valid specification, and that all devices can be
* opened.
*/
if ((newroot = construct_spec(props, autopart, argc, argv)) == NULL)
if ((newroot = construct_spec(props, argc, argv)) == NULL)
return (NULL);

if (zhp && ((poolconfig = zpool_get_config(zhp, NULL)) == NULL)) {
Expand Down
1 change: 1 addition & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ typedef enum {
ZPOOL_PROP_LEAKED,
ZPOOL_PROP_MAXBLOCKSIZE,
ZPOOL_PROP_TNAME,
ZPOOL_PROP_WHOLE_DISK,
ZPOOL_NUM_PROPS
} zpool_prop_t;

Expand Down
Loading

0 comments on commit 1ec7b2f

Please sign in to comment.