summaryrefslogtreecommitdiffstats
path: root/cddl/contrib/opensolaris/cmd
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2018-03-22 23:54:14 +0000
committermav <mav@FreeBSD.org>2018-03-22 23:54:14 +0000
commit99b95157db09016a55bc5ee65f3aebd952373bf8 (patch)
tree05a0eae8bdbb861189c08de14bafdb55856e1c2e /cddl/contrib/opensolaris/cmd
parent4dfbe8b3ac42df8d0b6664fd64b5abd36a56d1a2 (diff)
downloadFreeBSD-src-99b95157db09016a55bc5ee65f3aebd952373bf8.zip
FreeBSD-src-99b95157db09016a55bc5ee65f3aebd952373bf8.tar.gz
MFC r329681: MFV r318941: 7446 zpool create should support efi system partition
illumos/illumos-gate@7855d95b30fd903e3918bad5a29b777e765db821 https://github.com/illumos/illumos-gate/commit/7855d95b30fd903e3918bad5a29b777e765db821 https://www.illumos.org/issues/7446 Since we support whole-disk configuration for boot pool, we also will need whole disk support with UEFI boot and for this, zpool create should create efi- system partition. I have borrowed the idea from oracle solaris, and introducing zpool create - B switch to provide an way to specify that boot partition should be created. However, there is still an question, how big should the system partition be. For time being, I have set default size 256MB (thats minimum size for FAT32 with 4k blocks). To support custom size, the set on creation "bootsize" property is created and so the custom size can be set as: zpool create B - o bootsize=34MB rpool c0t0d0 After pool is created, the "bootsize" property is read only. When -B switch is not used, the bootsize defaults to 0 and is shown in zpool get output with value ''. Older zfs/zpool implementations are ignoring this property. https://www.illumos.org/rb/r/219/ Reviewed by: Andrew Stormont <andyjstormont@gmail.com> Reviewed by: Yuri Pankov <yuri.pankov@gmail.com> Approved by: Dan McDonald <danmcd@kebe.com> Author: Toomas Soome <tsoome@me.com> This commit makes no sense for FreeBSD, that is why I blocked the option, but it should be good to stay closer to upstream.
Diffstat (limited to 'cddl/contrib/opensolaris/cmd')
-rw-r--r--cddl/contrib/opensolaris/cmd/zpool/zpool_main.c98
-rw-r--r--cddl/contrib/opensolaris/cmd/zpool/zpool_util.h3
-rw-r--r--cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c79
3 files changed, 155 insertions, 25 deletions
diff --git a/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c b/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
index 06c2e25..b7b0825 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);
diff --git a/cddl/contrib/opensolaris/cmd/zpool/zpool_util.h b/cddl/contrib/opensolaris/cmd/zpool/zpool_util.h
index 134c730..8777edc 100644
--- a/cddl/contrib/opensolaris/cmd/zpool/zpool_util.h
+++ b/cddl/contrib/opensolaris/cmd/zpool/zpool_util.h
@@ -44,7 +44,8 @@ uint_t num_logs(nvlist_t *nv);
*/
nvlist_t *make_root_vdev(zpool_handle_t *zhp, int force, int check_rep,
- boolean_t replacing, boolean_t dryrun, int argc, char **argv);
+ boolean_t replacing, boolean_t dryrun, zpool_boot_label_t boot_type,
+ uint64_t boot_size, int argc, char **argv);
nvlist_t *split_mirror_vdev(zpool_handle_t *zhp, char *newname,
nvlist_t *props, splitflags_t flags, int argc, char **argv);
diff --git a/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c b/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c
index d860afc..f72e3f7 100644
--- a/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c
+++ b/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c
@@ -935,14 +935,15 @@ check_replication(nvlist_t *config, nvlist_t *newroot)
* Go through and find any whole disks in the vdev specification, labelling them
* as appropriate. When constructing the vdev spec, we were unable to open this
* device in order to provide a devid. Now that we have labelled the disk and
- * know that slice 0 is valid, we can construct the devid now.
+ * know the pool slice is valid, we can construct the devid now.
*
* If the disk was already labeled with an EFI label, we will have gotten the
* devid already (because we were able to open the whole disk). Otherwise, we
* need to get the devid after we label the disk.
*/
static int
-make_disks(zpool_handle_t *zhp, nvlist_t *nv)
+make_disks(zpool_handle_t *zhp, nvlist_t *nv, zpool_boot_label_t boot_type,
+ uint64_t boot_size)
{
nvlist_t **child;
uint_t c, children;
@@ -951,6 +952,7 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
uint64_t wholedisk;
int fd;
int ret;
+ int slice;
ddi_devid_t devid;
char *minor = NULL, *devid_str = NULL;
@@ -968,20 +970,36 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
* slice and stat()ing the device.
*/
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
- if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
- &wholedisk) != 0 || !wholedisk)
- return (0);
diskname = strrchr(path, '/');
assert(diskname != NULL);
diskname++;
- if (zpool_label_disk(g_zfs, zhp, diskname) == -1)
- return (-1);
+
+ if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
+ &wholedisk) != 0 || !wholedisk) {
+ /*
+ * This is not whole disk, return error if
+ * boot partition creation was requested
+ */
+ if (boot_type == ZPOOL_CREATE_BOOT_LABEL) {
+ (void) fprintf(stderr,
+ gettext("creating boot partition is only "
+ "supported on whole disk vdevs: %s\n"),
+ diskname);
+ return (-1);
+ }
+ return (0);
+ }
+
+ ret = zpool_label_disk(g_zfs, zhp, diskname, boot_type,
+ boot_size, &slice);
+ if (ret == -1)
+ return (ret);
/*
* Fill in the devid, now that we've labeled the disk.
*/
- (void) snprintf(buf, sizeof (buf), "%ss0", path);
+ (void) snprintf(buf, sizeof (buf), "%ss%d", path, slice);
if ((fd = open(buf, O_RDONLY)) < 0) {
(void) fprintf(stderr,
gettext("cannot open '%s': %s\n"),
@@ -1004,7 +1022,7 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
}
/*
- * Update the path to refer to the 's0' slice. The presence of
+ * Update the path to refer to the pool slice. The presence of
* the 'whole_disk' field indicates to the CLI that we should
* chop off the slice number when displaying the device in
* future output.
@@ -1016,21 +1034,36 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
return (0);
}
- for (c = 0; c < children; c++)
- if ((ret = make_disks(zhp, child[c])) != 0)
+ /* illumos kernel does not support booting from multi-vdev pools. */
+ if ((boot_type == ZPOOL_CREATE_BOOT_LABEL)) {
+ if ((strcmp(type, VDEV_TYPE_ROOT) == 0) && children > 1) {
+ (void) fprintf(stderr, gettext("boot pool "
+ "can not have more than one vdev\n"));
+ return (-1);
+ }
+ }
+
+ for (c = 0; c < children; c++) {
+ ret = make_disks(zhp, child[c], boot_type, boot_size);
+ if (ret != 0)
return (ret);
+ }
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
&child, &children) == 0)
- for (c = 0; c < children; c++)
- if ((ret = make_disks(zhp, child[c])) != 0)
+ for (c = 0; c < children; c++) {
+ ret = make_disks(zhp, child[c], boot_type, boot_size);
+ if (ret != 0)
return (ret);
+ }
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
&child, &children) == 0)
- for (c = 0; c < children; c++)
- if ((ret = make_disks(zhp, child[c])) != 0)
+ for (c = 0; c < children; c++) {
+ ret = make_disks(zhp, child[c], boot_type, boot_size);
+ if (ret != 0)
return (ret);
+ }
return (0);
}
@@ -1429,6 +1462,9 @@ split_mirror_vdev(zpool_handle_t *zhp, char *newname, nvlist_t *props,
{
nvlist_t *newroot = NULL, **child;
uint_t c, children;
+#ifdef illumos
+ zpool_boot_label_t boot_type;
+#endif
if (argc > 0) {
if ((newroot = construct_spec(argc, argv)) == NULL) {
@@ -1438,7 +1474,13 @@ split_mirror_vdev(zpool_handle_t *zhp, char *newname, nvlist_t *props,
}
#ifdef illumos
- if (!flags.dryrun && make_disks(zhp, newroot) != 0) {
+ if (zpool_is_bootable(zhp))
+ boot_type = ZPOOL_COPY_BOOT_LABEL;
+ else
+ boot_type = ZPOOL_NO_BOOT_LABEL;
+
+ if (!flags.dryrun &&
+ make_disks(zhp, newroot, boot_type, 0) != 0) {
nvlist_free(newroot);
return (NULL);
}
@@ -1483,7 +1525,8 @@ split_mirror_vdev(zpool_handle_t *zhp, char *newname, nvlist_t *props,
*/
nvlist_t *
make_root_vdev(zpool_handle_t *zhp, int force, int check_rep,
- boolean_t replacing, boolean_t dryrun, int argc, char **argv)
+ boolean_t replacing, boolean_t dryrun, zpool_boot_label_t boot_type,
+ uint64_t boot_size, int argc, char **argv)
{
nvlist_t *newroot;
nvlist_t *poolconfig = NULL;
@@ -1525,7 +1568,7 @@ make_root_vdev(zpool_handle_t *zhp, int force, int check_rep,
/*
* Run through the vdev specification and label any whole disks found.
*/
- if (!dryrun && make_disks(zhp, newroot) != 0) {
+ if (!dryrun && make_disks(zhp, newroot, boot_type, boot_size) != 0) {
nvlist_free(newroot);
return (NULL);
}
OpenPOWER on IntegriCloud