From df83110856950c8e7b16a7e94cdf42b8531b9cc8 Mon Sep 17 00:00:00 2001 From: Cyril Plisko Date: Tue, 6 Nov 2012 14:39:00 +0200 Subject: [PATCH] Add "-o ashift" to zpool add and zpool attach When adding devices to an existing pool "ashift" property is auto-detected. However, if this property was overridden at the pool creation time (i.e. zpool create -o ashift=12 tank ...) this may not be what the user wants. This commit lets the user specify the value of "ashift" property to be used with newly added drives. For example, zpool add -o ashift=12 tank disk1 zpool attach -o ashift=12 tank disk1 disk2 Signed-off-by: Cyril Plisko Signed-off-by: Brian Behlendorf Closes #566 --- cmd/zpool/zpool_main.c | 51 ++++++++++++++++++++++++++++++++++++++++++-------- man/man8/zpool.8 | 31 ++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 96798c4..a684f3b 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -24,6 +24,7 @@ * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2012 by Delphix. All rights reserved. * Copyright (c) 2012 by Frederik Wessels. All rights reserved. + * Copyright (c) 2012 by Cyril Plisko. All rights reserved. */ #include @@ -199,10 +200,11 @@ static const char * get_usage(zpool_help_t idx) { switch (idx) { case HELP_ADD: - return (gettext("\tadd [-fn] ...\n")); + return (gettext("\tadd [-fn] [-o property=value] " + " ...\n")); case HELP_ATTACH: - return (gettext("\tattach [-f] " - "\n")); + return (gettext("\tattach [-f] [-o property=value] " + " \n")); case HELP_CLEAR: return (gettext("\tclear [-nF] [device]\n")); case HELP_CREATE: @@ -436,11 +438,12 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props, } /* - * zpool add [-fn] ... + * zpool add [-fn] [-o property=value] ... * * -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. + * -o Set property=value. * * Adds the given vdevs to 'pool'. As with create, the bulk of this work is * handled by get_vdev_spec(), which constructs the nvlist needed to pass to @@ -457,9 +460,11 @@ zpool_do_add(int argc, char **argv) int ret; zpool_handle_t *zhp; nvlist_t *config; + nvlist_t *props = NULL; + char *propval; /* check options */ - while ((c = getopt(argc, argv, "fn")) != -1) { + while ((c = getopt(argc, argv, "fno:")) != -1) { switch (c) { case 'f': force = B_TRUE; @@ -467,6 +472,19 @@ zpool_do_add(int argc, char **argv) case 'n': dryrun = B_TRUE; break; + case 'o': + if ((propval = strchr(optarg, '=')) == NULL) { + (void) fprintf(stderr, gettext("missing " + "'=' for -o option\n")); + usage(B_FALSE); + } + *propval = '\0'; + propval++; + + if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) || + (add_prop_list(optarg, propval, &props, B_TRUE))) + usage(B_FALSE); + break; case '?': (void) fprintf(stderr, gettext("invalid option '%c'\n"), optopt); @@ -503,7 +521,7 @@ zpool_do_add(int argc, char **argv) } /* pass off to get_vdev_spec for processing */ - nvroot = make_root_vdev(zhp, NULL, force, !force, B_FALSE, dryrun, + nvroot = make_root_vdev(zhp, props, force, !force, B_FALSE, dryrun, argc, argv); if (nvroot == NULL) { zpool_close(zhp); @@ -536,6 +554,7 @@ zpool_do_add(int argc, char **argv) ret = (zpool_add(zhp, nvroot) != 0); } + nvlist_free(props); nvlist_free(nvroot); zpool_close(zhp); @@ -2865,6 +2884,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; + nvlist_t *props = NULL; + char *propval; int ret; /* check options */ @@ -2873,6 +2894,19 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing) case 'f': force = B_TRUE; break; + case 'o': + if ((propval = strchr(optarg, '=')) == NULL) { + (void) fprintf(stderr, gettext("missing " + "'=' for -o option\n")); + usage(B_FALSE); + } + *propval = '\0'; + propval++; + + if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) || + (add_prop_list(optarg, propval, &props, B_TRUE))) + usage(B_FALSE); + break; case '?': (void) fprintf(stderr, gettext("invalid option '%c'\n"), optopt); @@ -2929,7 +2963,7 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing) return (1); } - nvroot = make_root_vdev(zhp, NULL, force, B_FALSE, replacing, B_FALSE, + nvroot = make_root_vdev(zhp, props, force, B_FALSE, replacing, B_FALSE, argc, argv); if (nvroot == NULL) { zpool_close(zhp); @@ -2959,9 +2993,10 @@ zpool_do_replace(int argc, char **argv) } /* - * zpool attach [-f] + * zpool attach [-f] [-o property=value] * * -f Force attach, even if appears to be in use. + * -o Set property=value. * * Attach to the mirror containing . If is not * part of a mirror, then will be transformed into a mirror of diff --git a/man/man8/zpool.8 b/man/man8/zpool.8 index 1ac3050..826a6e7 100644 --- a/man/man8/zpool.8 +++ b/man/man8/zpool.8 @@ -2,6 +2,7 @@ .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 2011 Nexenta Systems, Inc. All rights reserved. .\" Copyright (c) 2012 by Delphix. All Rights Reserved. +.\" Copyright (c) 2012 Cyril Plisko. All Rights Reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the .\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] @@ -16,12 +17,12 @@ zpool \- configures ZFS storage pools .LP .nf -\fBzpool add\fR [\fB-fn\fR] \fIpool\fR \fIvdev\fR ... +\fBzpool add\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] \fIpool\fR \fIvdev\fR ... .fi .LP .nf -\fBzpool attach\fR [\fB-f\fR] \fIpool\fR \fIdevice\fR \fInew_device\fR +\fBzpool attach\fR [\fB-f\fR] [\fB-o\fR \fIproperty=value\fR] \fIpool\fR \fIdevice\fR \fInew_device\fR .fi .LP @@ -711,7 +712,7 @@ Displays a help message. .ne 2 .mk .na -\fB\fBzpool add\fR [\fB-fn\fR] \fIpool\fR \fIvdev\fR ...\fR +\fB\fBzpool add\fR [\fB-fn\fR] [\fB-o\fR \fIproperty=value\fR] \fIpool\fR \fIvdev\fR ...\fR .ad .sp .6 .RS 4n @@ -738,6 +739,17 @@ Forces use of \fBvdev\fRs, even if they appear in use or specify a conflicting r Displays the configuration that would be used without actually adding the \fBvdev\fRs. The actual pool creation can still fail due to insufficient privileges or device sharing. .RE +.sp +.ne 2 +.mk +.na +\fB\fB-o\fR \fIproperty=value\fR +.ad +.sp .6 +.RS 4n +Sets the given pool properties. See the "Properties" section for a list of valid properties that can be set. The only property supported at the moment is "ashift". +.RE + Do not add a disk that is currently configured as a quorum device to a zpool. After a disk is in the pool, that disk can then be configured as a quorum device. .RE @@ -745,7 +757,7 @@ Do not add a disk that is currently configured as a quorum device to a zpool. Af .ne 2 .mk .na -\fB\fBzpool attach\fR [\fB-f\fR] \fIpool\fR \fIdevice\fR \fInew_device\fR\fR +\fB\fBzpool attach\fR [\fB-f\fR] [\fB-o\fR \fIproperty=value\fR] \fIpool\fR \fIdevice\fR \fInew_device\fR\fR .ad .sp .6 .RS 4n @@ -761,6 +773,17 @@ Attaches \fInew_device\fR to an existing \fBzpool\fR device. The existing device Forces use of \fInew_device\fR, even if its appears to be in use. Not all devices can be overridden in this manner. .RE +.sp +.ne 2 +.mk +.na +\fB\fB-o\fR \fIproperty=value\fR +.ad +.sp .6 +.RS 4n +Sets the given pool properties. See the "Properties" section for a list of valid properties that can be set. The only property supported at the moment is "ashift". +.RE + .RE .sp -- 1.8.3.1