diff options
author | Alexander Motin <mav@FreeBSD.org> | 2018-02-21 00:18:57 +0000 |
---|---|---|
committer | Alexander Motin <mav@FreeBSD.org> | 2018-02-21 00:18:57 +0000 |
commit | e5a4a83784d26b3804df1c9519078e64776bf10b (patch) | |
tree | ba06d0fb4b60e26c2b5cc942efdfe2c91db7e262 /cddl/contrib/opensolaris/cmd/zpool/zpool_main.c | |
parent | e73c944fc079f7f08a32270eb83854e3270b05e4 (diff) | |
parent | 9df2d6f729b7642daf9a1d5d3d610959ba894c3d (diff) | |
download | src-e5a4a83784d26b3804df1c9519078e64776bf10b.tar.gz src-e5a4a83784d26b3804df1c9519078e64776bf10b.zip |
Notes
Diffstat (limited to 'cddl/contrib/opensolaris/cmd/zpool/zpool_main.c')
-rw-r--r-- | cddl/contrib/opensolaris/cmd/zpool/zpool_main.c | 98 |
1 files changed, 92 insertions, 6 deletions
diff --git a/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c b/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c index 06c2e253960d..b7b08251e45b 100644 --- a/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c +++ b/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c @@ -212,7 +212,8 @@ get_usage(zpool_help_t idx) case HELP_CLEAR: return (gettext("\tclear [-nF] <pool> [device]\n")); case HELP_CREATE: - return (gettext("\tcreate [-fnd] [-o property=value] ... \n" + return (gettext("\tcreate [-fnd] [-B] " + "[-o property=value] ... \n" "\t [-O file-system-property=value] ... \n" "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n")); case HELP_DESTROY: @@ -499,6 +500,8 @@ zpool_do_add(int argc, char **argv) int c; nvlist_t *nvroot; char *poolname; + zpool_boot_label_t boot_type; + uint64_t boot_size; int ret; zpool_handle_t *zhp; nvlist_t *config; @@ -547,9 +550,15 @@ zpool_do_add(int argc, char **argv) return (1); } + if (zpool_is_bootable(zhp)) + boot_type = ZPOOL_COPY_BOOT_LABEL; + else + boot_type = ZPOOL_NO_BOOT_LABEL; + /* pass off to get_vdev_spec for processing */ + boot_size = zpool_get_prop_int(zhp, ZPOOL_PROP_BOOTSIZE, NULL); nvroot = make_root_vdev(zhp, force, !force, B_FALSE, dryrun, - argc, argv); + boot_type, boot_size, argc, argv); if (nvroot == NULL) { zpool_close(zhp); return (1); @@ -774,10 +783,11 @@ errout: } /* - * zpool create [-fnd] [-o property=value] ... + * zpool create [-fnd] [-B] [-o property=value] ... * [-O file-system-property=value] ... * [-R root] [-m mountpoint] <pool> <dev> ... * + * -B Create boot partition. * -f Force creation, even if devices appear in use * -n Do not create the pool, but display the resulting layout if it * were to be created. @@ -794,12 +804,16 @@ errout: * we get the nvlist back from get_vdev_spec(), we either print out the contents * (if '-n' was specified), or pass it to libzfs to do the creation. */ + +#define SYSTEM256 (256 * 1024 * 1024) int 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; + zpool_boot_label_t boot_type = ZPOOL_NO_BOOT_LABEL; + uint64_t boot_size = 0; int c; nvlist_t *nvroot = NULL; char *poolname; @@ -811,7 +825,7 @@ zpool_do_create(int argc, char **argv) char *propval; /* check options */ - while ((c = getopt(argc, argv, ":fndR:m:o:O:")) != -1) { + while ((c = getopt(argc, argv, ":fndBR:m:o:O:")) != -1) { switch (c) { case 'f': force = B_TRUE; @@ -822,6 +836,22 @@ zpool_do_create(int argc, char **argv) case 'd': enable_all_pool_feat = B_FALSE; break; + case 'B': +#ifdef illumos + /* + * We should create the system partition. + * Also make sure the size is set. + */ + boot_type = ZPOOL_CREATE_BOOT_LABEL; + if (boot_size == 0) + boot_size = SYSTEM256; + break; +#else + (void) fprintf(stderr, + gettext("option '%c' is not supported\n"), + optopt); + goto badusage; +#endif case 'R': altroot = optarg; if (add_prop_list(zpool_prop_to_name( @@ -852,6 +882,20 @@ zpool_do_create(int argc, char **argv) goto errout; /* + * Get bootsize value for make_root_vdev(). + */ + if (zpool_name_to_prop(optarg) == ZPOOL_PROP_BOOTSIZE) { + if (zfs_nicestrtonum(g_zfs, propval, + &boot_size) < 0 || boot_size == 0) { + (void) fprintf(stderr, + gettext("bad boot partition size " + "'%s': %s\n"), propval, + libzfs_error_description(g_zfs)); + goto errout; + } + } + + /* * If the user is creating a pool that doesn't support * feature flags, don't enable any features. */ @@ -928,9 +972,43 @@ zpool_do_create(int argc, char **argv) goto errout; } + /* + * Make sure the bootsize is set when ZPOOL_CREATE_BOOT_LABEL is used, + * and not set otherwise. + */ + if (boot_type == ZPOOL_CREATE_BOOT_LABEL) { + const char *propname; + char *strptr, *buf = NULL; + int rv; + + propname = zpool_prop_to_name(ZPOOL_PROP_BOOTSIZE); + if (nvlist_lookup_string(props, propname, &strptr) != 0) { + (void) asprintf(&buf, "%" PRIu64, boot_size); + if (buf == NULL) { + (void) fprintf(stderr, + gettext("internal error: out of memory\n")); + goto errout; + } + rv = add_prop_list(propname, buf, &props, B_TRUE); + free(buf); + if (rv != 0) + goto errout; + } + } else { + const char *propname; + char *strptr; + + propname = zpool_prop_to_name(ZPOOL_PROP_BOOTSIZE); + if (nvlist_lookup_string(props, propname, &strptr) == 0) { + (void) fprintf(stderr, gettext("error: setting boot " + "partition size requires option '-B'\n")); + goto errout; + } + } + /* pass off to get_vdev_spec for bulk processing */ nvroot = make_root_vdev(NULL, force, !force, B_FALSE, dryrun, - argc - 1, argv + 1); + boot_type, boot_size, argc - 1, argv + 1); if (nvroot == NULL) goto errout; @@ -3209,6 +3287,8 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing) nvlist_t *nvroot; char *poolname, *old_disk, *new_disk; zpool_handle_t *zhp; + zpool_boot_label_t boot_type; + uint64_t boot_size; int ret; /* check options */ @@ -3273,8 +3353,14 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing) return (1); } + if (zpool_is_bootable(zhp)) + boot_type = ZPOOL_COPY_BOOT_LABEL; + else + boot_type = ZPOOL_NO_BOOT_LABEL; + + boot_size = zpool_get_prop_int(zhp, ZPOOL_PROP_BOOTSIZE, NULL); nvroot = make_root_vdev(zhp, force, B_FALSE, replacing, B_FALSE, - argc, argv); + boot_type, boot_size, argc, argv); if (nvroot == NULL) { zpool_close(zhp); return (1); |