* 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.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
- * Copyright (c) 2011, 2020 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2024 by Delphix. All rights reserved.
* Copyright (c) 2012 by Frederik Wessels. All rights reserved.
* Copyright (c) 2012 by Cyril Plisko. All rights reserved.
* Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
static int zpool_do_wait(int, char **);
+static int zpool_do_help(int argc, char **argv);
+
static zpool_compat_status_t zpool_do_load_compat(
const char *, boolean_t *);
+enum zpool_options {
+ ZPOOL_OPTION_POWER = 1024,
+ ZPOOL_OPTION_ALLOW_INUSE,
+ ZPOOL_OPTION_ALLOW_REPLICATION_MISMATCH,
+ ZPOOL_OPTION_ALLOW_ASHIFT_MISMATCH
+};
+
/*
* These libumem hooks provide a reasonable set of defaults for the allocator's
* debugging facilities.
{
switch (idx) {
case HELP_ADD:
- return (gettext("\tadd [-fgLnP] [-o property=value] "
+ return (gettext("\tadd [-afgLnP] [-o property=value] "
"<pool> <vdev> ...\n"));
case HELP_ATTACH:
return (gettext("\tattach [-fsw] [-o property=value] "
"<pool> <device> <new-device>\n"));
case HELP_CLEAR:
- return (gettext("\tclear [-nF] <pool> [device]\n"));
+ return (gettext("\tclear [[--power]|[-nF]] <pool> [device]\n"));
case HELP_CREATE:
return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
"\t [-O file-system-property=value] ... \n"
"[-T d|u] [pool] ... \n"
"\t [interval [count]]\n"));
case HELP_OFFLINE:
- return (gettext("\toffline [-f] [-t] <pool> <device> ...\n"));
+ return (gettext("\toffline [--power]|[[-f][-t]] <pool> "
+ "<device> ...\n"));
case HELP_ONLINE:
- return (gettext("\tonline [-e] <pool> <device> ...\n"));
+ return (gettext("\tonline [--power][-e] <pool> <device> "
+ "...\n"));
case HELP_REPLACE:
return (gettext("\treplace [-fsw] [-o property=value] "
"<pool> <device> [new-device]\n"));
case HELP_REOPEN:
return (gettext("\treopen [-n] <pool>\n"));
case HELP_INITIALIZE:
- return (gettext("\tinitialize [-c | -s] [-w] <pool> "
+ return (gettext("\tinitialize [-c | -s | -u] [-w] <pool> "
"[<device> ...]\n"));
case HELP_SCRUB:
- return (gettext("\tscrub [-s | -p] [-w] <pool> ...\n"));
+ return (gettext("\tscrub [-s | -p] [-w] [-e] <pool> ...\n"));
case HELP_RESILVER:
return (gettext("\tresilver <pool> ...\n"));
case HELP_TRIM:
return (gettext("\ttrim [-dw] [-r <rate>] [-c | -s] <pool> "
"[<device> ...]\n"));
case HELP_STATUS:
- return (gettext("\tstatus [-c [script1,script2,...]] "
- "[-igLpPstvxD] [-T d|u] [pool] ... \n"
+ return (gettext("\tstatus [--power] [-c [script1,script2,...]] "
+ "[-DegiLpPstvx] [-T d|u] [pool] ...\n"
"\t [interval [count]]\n"));
case HELP_UPGRADE:
return (gettext("\tupgrade\n"
return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
"<\"all\" | property[,...]> <pool> ...\n"));
case HELP_SET:
- return (gettext("\tset <property=value> <pool> \n"));
+ return (gettext("\tset <property=value> <pool>\n"
+ "\tset <vdev_property=value> <pool> <vdev>\n"));
case HELP_SPLIT:
return (gettext("\tsplit [-gLnPl] [-R altroot] [-o mntopts]\n"
"\t [-o property=value] <pool> <newpool> "
return (ZPROP_CONT);
}
+/*
+ * Given a leaf vdev name like 'L5' return its VDEV_CONFIG_PATH like
+ * '/dev/disk/by-vdev/L5'.
+ */
+static const char *
+vdev_name_to_path(zpool_handle_t *zhp, char *vdev)
+{
+ nvlist_t *vdev_nv = zpool_find_vdev(zhp, vdev, NULL, NULL, NULL);
+ if (vdev_nv == NULL) {
+ return (NULL);
+ }
+ return (fnvlist_lookup_string(vdev_nv, ZPOOL_CONFIG_PATH));
+}
+
+static int
+zpool_power_on(zpool_handle_t *zhp, char *vdev)
+{
+ return (zpool_power(zhp, vdev, B_TRUE));
+}
+
+static int
+zpool_power_on_and_disk_wait(zpool_handle_t *zhp, char *vdev)
+{
+ int rc;
+
+ rc = zpool_power_on(zhp, vdev);
+ if (rc != 0)
+ return (rc);
+
+ zpool_disk_wait(vdev_name_to_path(zhp, vdev));
+
+ return (0);
+}
+
+static int
+zpool_power_on_pool_and_wait_for_devices(zpool_handle_t *zhp)
+{
+ nvlist_t *nv;
+ const char *path = NULL;
+ int rc;
+
+ /* Power up all the devices first */
+ FOR_EACH_REAL_LEAF_VDEV(zhp, nv) {
+ path = fnvlist_lookup_string(nv, ZPOOL_CONFIG_PATH);
+ if (path != NULL) {
+ rc = zpool_power_on(zhp, (char *)path);
+ if (rc != 0) {
+ return (rc);
+ }
+ }
+ }
+
+ /*
+ * Wait for their devices to show up. Since we powered them on
+ * at roughly the same time, they should all come online around
+ * the same time.
+ */
+ FOR_EACH_REAL_LEAF_VDEV(zhp, nv) {
+ path = fnvlist_lookup_string(nv, ZPOOL_CONFIG_PATH);
+ zpool_disk_wait(path);
+ }
+
+ return (0);
+}
+
+static int
+zpool_power_off(zpool_handle_t *zhp, char *vdev)
+{
+ return (zpool_power(zhp, vdev, B_FALSE));
+}
+
/*
* Display usage message. If we're inside a command, display only the usage for
* that command. Otherwise, iterate over the entire command table and display
(void) fprintf(fp, "%s",
get_usage(command_table[i].usage));
}
+
+ (void) fprintf(fp,
+ gettext("\nFor further help on a command or topic, "
+ "run: %s\n"), "zpool help [<topic>]");
} else {
(void) fprintf(fp, gettext("usage:\n"));
(void) fprintf(fp, "%s", get_usage(current_command->usage));
(strcmp(current_command->name, "get") == 0) ||
(strcmp(current_command->name, "list") == 0))) {
- (void) fprintf(fp,
+ (void) fprintf(fp, "%s",
gettext("\nthe following properties are supported:\n"));
(void) fprintf(fp, "\n\t%-19s %s %s\n\n",
}
/*
- * zpool initialize [-c | -s] [-w] <pool> [<vdev> ...]
+ * zpool initialize [-c | -s | -u] [-w] <pool> [<vdev> ...]
* Initialize all unused blocks in the specified vdevs, or all vdevs in the pool
* if none specified.
*
* -c Cancel. Ends active initializing.
* -s Suspend. Initializing can then be restarted with no flags.
+ * -u Uninitialize. Clears initialization state.
* -w Wait. Blocks until initializing has completed.
*/
int
struct option long_options[] = {
{"cancel", no_argument, NULL, 'c'},
{"suspend", no_argument, NULL, 's'},
+ {"uninit", no_argument, NULL, 'u'},
{"wait", no_argument, NULL, 'w'},
{0, 0, 0, 0}
};
pool_initialize_func_t cmd_type = POOL_INITIALIZE_START;
- while ((c = getopt_long(argc, argv, "csw", long_options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "csuw", long_options,
+ NULL)) != -1) {
switch (c) {
case 'c':
if (cmd_type != POOL_INITIALIZE_START &&
}
cmd_type = POOL_INITIALIZE_SUSPEND;
break;
+ case 'u':
+ if (cmd_type != POOL_INITIALIZE_START &&
+ cmd_type != POOL_INITIALIZE_UNINIT) {
+ (void) fprintf(stderr, gettext("-u cannot be "
+ "combined with other options\n"));
+ usage(B_FALSE);
+ }
+ cmd_type = POOL_INITIALIZE_UNINIT;
+ break;
case 'w':
wait = B_TRUE;
break;
}
if (wait && (cmd_type != POOL_INITIALIZE_START)) {
- (void) fprintf(stderr, gettext("-w cannot be used with -c or "
- "-s\n"));
+ (void) fprintf(stderr, gettext("-w cannot be used with -c, -s"
+ "or -u\n"));
usage(B_FALSE);
}
for (c = 0; c < children; c++) {
uint64_t is_log = B_FALSE, is_hole = B_FALSE;
- char *class = (char *)"";
+ const char *class = "";
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE,
&is_hole);
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
&is_log);
if (is_log)
- class = (char *)VDEV_ALLOC_BIAS_LOG;
+ class = VDEV_ALLOC_BIAS_LOG;
(void) nvlist_lookup_string(child[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, &class);
if (strcmp(match, class) != 0)
zpool_prop_t prop = ZPOOL_PROP_INVAL;
nvlist_t *proplist;
const char *normnm;
- char *strval;
+ const char *strval;
if (*props == NULL &&
nvlist_alloc(props, NV_UNIQUE_NAME, 0) != 0) {
add_prop_list_default(const char *propname, const char *propval,
nvlist_t **props)
{
- char *pval;
+ const char *pval;
if (nvlist_lookup_string(*props, propname, &pval) == 0)
return (0);
}
/*
- * zpool add [-fgLnP] [-o property=value] <pool> <vdev> ...
+ * zpool add [-afgLnP] [-o property=value] <pool> <vdev> ...
*
+ * -a Disable the ashift validation checks
* -f Force addition of devices, even if they appear in use
* -g Display guid for individual vdev name.
* -L Follow links when resolving vdev path name.
int
zpool_do_add(int argc, char **argv)
{
- boolean_t force = B_FALSE;
+ boolean_t check_replication = B_TRUE;
+ boolean_t check_inuse = B_TRUE;
boolean_t dryrun = B_FALSE;
+ boolean_t check_ashift = B_TRUE;
+ boolean_t force = B_FALSE;
int name_flags = 0;
int c;
nvlist_t *nvroot;
nvlist_t *props = NULL;
char *propval;
+ struct option long_options[] = {
+ {"allow-in-use", no_argument, NULL, ZPOOL_OPTION_ALLOW_INUSE},
+ {"allow-replication-mismatch", no_argument, NULL,
+ ZPOOL_OPTION_ALLOW_REPLICATION_MISMATCH},
+ {"allow-ashift-mismatch", no_argument, NULL,
+ ZPOOL_OPTION_ALLOW_ASHIFT_MISMATCH},
+ {0, 0, 0, 0}
+ };
+
/* check options */
- while ((c = getopt(argc, argv, "fgLno:P")) != -1) {
+ while ((c = getopt_long(argc, argv, "fgLno:P", long_options, NULL))
+ != -1) {
switch (c) {
case 'f':
force = B_TRUE;
case 'P':
name_flags |= VDEV_NAME_PATH;
break;
+ case ZPOOL_OPTION_ALLOW_INUSE:
+ check_inuse = B_FALSE;
+ break;
+ case ZPOOL_OPTION_ALLOW_REPLICATION_MISMATCH:
+ check_replication = B_FALSE;
+ break;
+ case ZPOOL_OPTION_ALLOW_ASHIFT_MISMATCH:
+ check_ashift = B_FALSE;
+ break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
usage(B_FALSE);
}
+ if (force) {
+ if (!check_inuse || !check_replication || !check_ashift) {
+ (void) fprintf(stderr, gettext("'-f' option is not "
+ "allowed with '--allow-replication-mismatch', "
+ "'--allow-ashift-mismatch', or "
+ "'--allow-in-use'\n"));
+ usage(B_FALSE);
+ }
+ check_inuse = B_FALSE;
+ check_replication = B_FALSE;
+ check_ashift = B_FALSE;
+ }
+
poolname = argv[0];
argc--;
}
/* pass off to make_root_vdev for processing */
- nvroot = make_root_vdev(zhp, props, force, !force, B_FALSE, dryrun,
- argc, argv);
+ nvroot = make_root_vdev(zhp, props, !check_inuse,
+ check_replication, B_FALSE, dryrun, argc, argv);
if (nvroot == NULL) {
zpool_close(zhp);
return (1);
ret = 0;
} else {
- ret = (zpool_add(zhp, nvroot) != 0);
+ ret = (zpool_add(zhp, nvroot, check_ashift) != 0);
}
nvlist_free(props);
return (1);
if (stop && noop) {
+ zpool_close(zhp);
(void) fprintf(stderr, gettext("stop request ignored\n"));
return (0);
}
{
char vdev[MAXPATHLEN];
char *name = NULL;
- struct stat st;
int c, fd = -1, ret = 0;
nvlist_t *config;
pool_state_t state;
usage(B_FALSE);
}
+ (void) strlcpy(vdev, argv[0], sizeof (vdev));
+
/*
- * Check if we were given absolute path and use it as is.
+ * If we cannot open an absolute path, we quit.
* Otherwise if the provided vdev name doesn't point to a file,
* try prepending expected disk paths and partition numbers.
*/
- (void) strlcpy(vdev, argv[0], sizeof (vdev));
- if (vdev[0] != '/' && stat(vdev, &st) != 0) {
+ if ((fd = open(vdev, O_RDWR)) < 0) {
int error;
+ if (vdev[0] == '/') {
+ (void) fprintf(stderr, gettext("failed to open "
+ "%s: %s\n"), vdev, strerror(errno));
+ return (1);
+ }
error = zfs_resolve_shortname(argv[0], vdev, MAXPATHLEN);
if (error == 0 && zfs_dev_is_whole_disk(vdev)) {
error = ENOENT;
}
- if (error || (stat(vdev, &st) != 0)) {
- (void) fprintf(stderr, gettext(
- "failed to find device %s, try specifying absolute "
- "path instead\n"), argv[0]);
+ if (error || ((fd = open(vdev, O_RDWR)) < 0)) {
+ if (errno == ENOENT) {
+ (void) fprintf(stderr, gettext(
+ "failed to find device %s, try "
+ "specifying absolute path instead\n"),
+ argv[0]);
+ return (1);
+ }
+
+ (void) fprintf(stderr, gettext("failed to open %s:"
+ " %s\n"), vdev, strerror(errno));
return (1);
}
}
- if ((fd = open(vdev, O_RDWR)) < 0) {
- (void) fprintf(stderr, gettext("failed to open %s: %s\n"),
- vdev, strerror(errno));
- return (1);
- }
-
/*
* Flush all dirty pages for the block device. This should not be
* fatal when the device does not support BLKFLSBUF as would be the
*/
for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
char propname[MAXPATHLEN];
- char *propval;
+ const char *propval;
zfeature_info_t *feat = &spa_feature_table[i];
(void) snprintf(propname, sizeof (propname),
boolean_t cb_explain;
boolean_t cb_first;
boolean_t cb_dedup_stats;
+ boolean_t cb_print_unhealthy;
boolean_t cb_print_status;
boolean_t cb_print_slow_ios;
boolean_t cb_print_vdev_init;
boolean_t cb_print_vdev_trim;
vdev_cmd_data_list_t *vcdl;
+ boolean_t cb_print_power;
} status_cbdata_t;
/* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
/* Print command output lines for specific vdev in a specific pool */
static void
-zpool_print_cmd(vdev_cmd_data_list_t *vcdl, const char *pool, char *path)
+zpool_print_cmd(vdev_cmd_data_list_t *vcdl, const char *pool, const char *path)
{
vdev_cmd_data_t *data;
int i, j;
!vs->vs_scan_removing) {
char zbuf[1024];
char tbuf[256];
- struct tm zaction_ts;
time_t t = vs->vs_initialize_action_time;
int initialize_pct = 100;
100 / (vs->vs_initialize_bytes_est + 1));
}
- (void) localtime_r(&t, &zaction_ts);
- (void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
+ (void) ctime_r(&t, tbuf);
+ tbuf[24] = 0;
switch (vs->vs_initialize_state) {
case VDEV_INITIALIZE_SUSPENDED:
!vs->vs_scan_removing) {
char zbuf[1024];
char tbuf[256];
- struct tm zaction_ts;
time_t t = vs->vs_trim_action_time;
int trim_pct = 100;
100 / (vs->vs_trim_bytes_est + 1));
}
- (void) localtime_r(&t, &zaction_ts);
- (void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
+ (void) ctime_r(&t, tbuf);
+ tbuf[24] = 0;
switch (vs->vs_trim_state) {
case VDEV_TRIM_SUSPENDED:
return (NULL);
}
+/*
+ * Called for each leaf vdev. Returns 0 if the vdev is healthy.
+ * A vdev is unhealthy if any of the following are true:
+ * 1) there are read, write, or checksum errors,
+ * 2) its state is not ONLINE, or
+ * 3) slow IO reporting was requested (-s) and there are slow IOs.
+ */
+static int
+vdev_health_check_cb(void *hdl_data, nvlist_t *nv, void *data)
+{
+ status_cbdata_t *cb = data;
+ vdev_stat_t *vs;
+ uint_t vsc;
+ (void) hdl_data;
+
+ if (nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
+ (uint64_t **)&vs, &vsc) != 0)
+ return (1);
+
+ if (vs->vs_checksum_errors || vs->vs_read_errors ||
+ vs->vs_write_errors || vs->vs_state != VDEV_STATE_HEALTHY)
+ return (1);
+
+ if (cb->cb_print_slow_ios && vs->vs_slow_ios)
+ return (1);
+
+ return (0);
+}
+
/*
* Print out configuration state as requested by status_callback.
*/
uint64_t notpresent;
spare_cbdata_t spare_cb;
const char *state;
- char *type;
- char *path = NULL;
- const char *rcolor = NULL, *wcolor = NULL, *ccolor = NULL;
+ const char *type;
+ const char *path = NULL;
+ const char *rcolor = NULL, *wcolor = NULL, *ccolor = NULL,
+ *scolor = NULL;
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
&child, &children) != 0)
state = gettext("AVAIL");
}
+ /*
+ * If '-e' is specified then top-level vdevs and their children
+ * can be pruned if all of their leaves are healthy.
+ */
+ if (cb->cb_print_unhealthy && depth > 0 &&
+ for_each_vdev_in_nvlist(nv, vdev_health_check_cb, cb) == 0) {
+ return;
+ }
+
printf_color(health_str_to_color(state),
"\t%*s%-*s %-8s", depth, "", cb->cb_namewidth - depth,
name, state);
if (vs->vs_checksum_errors)
ccolor = ANSI_RED;
+ if (vs->vs_slow_ios)
+ scolor = ANSI_BLUE;
+
if (cb->cb_literal) {
fputc(' ', stdout);
printf_color(rcolor, "%5llu",
}
if (cb->cb_literal)
- printf(" %5llu", (u_longlong_t)vs->vs_slow_ios);
+ printf_color(scolor, " %5llu",
+ (u_longlong_t)vs->vs_slow_ios);
else
- printf(" %5s", rbuf);
+ printf_color(scolor, " %5s", rbuf);
+ }
+ if (cb->cb_print_power) {
+ if (children == 0) {
+ /* Only leaf vdevs have physical slots */
+ switch (zpool_power_current_state(zhp, (char *)
+ fnvlist_lookup_string(nv,
+ ZPOOL_CONFIG_PATH))) {
+ case 0:
+ printf_color(ANSI_RED, " %5s",
+ gettext("off"));
+ break;
+ case 1:
+ printf(" %5s", gettext("on"));
+ break;
+ default:
+ printf(" %5s", "-");
+ }
+ } else {
+ printf(" %5s", "-");
+ }
}
}
break;
case VDEV_AUX_ERR_EXCEEDED:
- (void) printf(gettext("too many errors"));
+ if (vs->vs_read_errors + vs->vs_write_errors +
+ vs->vs_checksum_errors == 0 && children == 0 &&
+ vs->vs_slow_ios > 0) {
+ (void) printf(gettext("too many slow I/Os"));
+ } else {
+ (void) printf(gettext("too many errors"));
+ }
break;
case VDEV_AUX_IO_FAILURE:
(void) nvlist_lookup_uint64_array(root, ZPOOL_CONFIG_SCAN_STATS,
(uint64_t **)&ps, &c);
- if (ps != NULL && ps->pss_state == DSS_SCANNING && children == 0) {
+ /*
+ * If you force fault a drive that's resilvering, its scan stats can
+ * get frozen in time, giving the false impression that it's
+ * being resilvered. That's why we check the state to see if the vdev
+ * is healthy before reporting "resilvering" or "repairing".
+ */
+ if (ps != NULL && ps->pss_state == DSS_SCANNING && children == 0 &&
+ vs->vs_state == VDEV_STATE_HEALTHY) {
if (vs->vs_scan_processed != 0) {
(void) printf(gettext(" (%s)"),
(ps->pss_func == POOL_SCAN_RESILVER) ?
/* The top-level vdevs have the rebuild stats */
if (vrs != NULL && vrs->vrs_state == VDEV_REBUILD_ACTIVE &&
- children == 0) {
+ children == 0 && vs->vs_state == VDEV_STATE_HEALTHY) {
if (vs->vs_rebuild_processed != 0) {
(void) printf(gettext(" (resilvering)"));
}
nvlist_t **child;
uint_t c, children;
vdev_stat_t *vs;
- char *type, *vname;
+ const char *type;
+ char *vname;
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
if (strcmp(type, VDEV_TYPE_MISSING) == 0 ||
for (c = 0; c < children; c++) {
uint64_t is_log = B_FALSE;
- char *bias = NULL;
- char *type = NULL;
+ const char *bias = NULL;
+ const char *type = NULL;
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
&is_log);
{
uint64_t pool_state;
vdev_stat_t *vs;
- char *name;
+ const char *name;
uint64_t guid;
uint64_t hostid = 0;
const char *msgid;
zpool_errata_t errata;
const char *health;
uint_t vsc;
- char *comment;
+ const char *comment;
status_cbdata_t cb = { 0 };
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
nvlist_t *nvinfo;
state = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE);
- (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
+ nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
+
+ /*
+ * The hostid on LOAD_INFO comes from the MOS label via
+ * spa_tryimport(). If its not there then we're likely talking to an
+ * older kernel, so use the top one, which will be from the label
+ * discovered in zpool_find_import(), or if a cachefile is in use, the
+ * local hostid.
+ */
+ if (nvlist_lookup_uint64(nvinfo, ZPOOL_CONFIG_HOSTID, &hostid) != 0)
+ (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
+ &hostid);
if (state != POOL_STATE_EXPORTED && hostid != get_system_hostid())
return (B_TRUE);
- nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_STATE)) {
mmp_state_t mmp_state = fnvlist_lookup_uint64(nvinfo,
ZPOOL_CONFIG_MMP_STATE);
nvlist_t *props, int flags)
{
int ret = 0;
+ int ms_status = 0;
zpool_handle_t *zhp;
const char *name;
uint64_t version;
time_t timestamp = 0;
uint64_t hostid = 0;
- if (nvlist_exists(config, ZPOOL_CONFIG_HOSTNAME))
+ if (nvlist_exists(nvinfo, ZPOOL_CONFIG_HOSTNAME))
+ hostname = fnvlist_lookup_string(nvinfo,
+ ZPOOL_CONFIG_HOSTNAME);
+ else if (nvlist_exists(config, ZPOOL_CONFIG_HOSTNAME))
hostname = fnvlist_lookup_string(config,
ZPOOL_CONFIG_HOSTNAME);
timestamp = fnvlist_lookup_uint64(config,
ZPOOL_CONFIG_TIMESTAMP);
- if (nvlist_exists(config, ZPOOL_CONFIG_HOSTID))
+ if (nvlist_exists(nvinfo, ZPOOL_CONFIG_HOSTID))
+ hostid = fnvlist_lookup_uint64(nvinfo,
+ ZPOOL_CONFIG_HOSTID);
+ else if (nvlist_exists(config, ZPOOL_CONFIG_HOSTID))
hostid = fnvlist_lookup_uint64(config,
ZPOOL_CONFIG_HOSTID);
ret = 1;
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
- !(flags & ZFS_IMPORT_ONLY) &&
- zpool_enable_datasets(zhp, mntopts, 0) != 0) {
- zpool_close(zhp);
- return (1);
+ !(flags & ZFS_IMPORT_ONLY)) {
+ ms_status = zpool_enable_datasets(zhp, mntopts, 0);
+ if (ms_status == EZFS_SHAREFAILED) {
+ (void) fprintf(stderr, gettext("Import was "
+ "successful, but unable to share some datasets"));
+ } else if (ms_status == EZFS_MOUNTFAILED) {
+ (void) fprintf(stderr, gettext("Import was "
+ "successful, but unable to mount some datasets"));
+ }
}
zpool_close(zhp);
(void) show_import(config, B_TRUE);
}
} else if (import->poolname != NULL) {
- char *name;
+ const char *name;
/*
* We are searching for a pool based on name.
return (0);
if (args->poolname != NULL) {
- char *pool_name;
+ const char *pool_name;
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
&pool_name) == 0);
idata.scan = do_scan;
idata.policy = policy;
- pools = zpool_search_import(g_zfs, &idata, &libzfs_config_ops);
+ libpc_handle_t lpch = {
+ .lpc_lib_handle = g_zfs,
+ .lpc_ops = &libzfs_config_ops,
+ .lpc_printerr = B_TRUE
+ };
+ pools = zpool_search_import(&lpch, &idata);
if (pools != NULL && pool_exists &&
(argc == 1 || strcmp(argv[0], argv[1]) == 0)) {
*/
idata.scan = B_TRUE;
nvlist_free(pools);
- pools = zpool_search_import(g_zfs, &idata, &libzfs_config_ops);
+ pools = zpool_search_import(&lpch, &idata);
err = import_pools(pools, props, mntopts, flags,
argc >= 1 ? argv[0] : NULL,
unsigned int namewidth;
const char *title;
+ color_start(ANSI_BOLD);
+
if (cb->cb_flags & IOS_ANYHISTO_M) {
title = histo_to_title[IOS_HISTO_IDX(cb->cb_flags)];
} else if (cb->cb_vdevs.cb_names_count) {
if (cb->vcdl != NULL)
print_cmd_columns(cb->vcdl, 1);
+ color_end();
+
printf("\n");
}
print_iostat_header_impl(cb, 0, NULL);
}
+/*
+ * Prints a size string (i.e. 120M) with the suffix ("M") colored
+ * by order of magnitude. Uses column_size to add padding.
+ */
+static void
+print_stat_color(const char *statbuf, unsigned int column_size)
+{
+ fputs(" ", stdout);
+ size_t len = strlen(statbuf);
+ while (len < column_size) {
+ fputc(' ', stdout);
+ column_size--;
+ }
+ if (*statbuf == '0') {
+ color_start(ANSI_GRAY);
+ fputc('0', stdout);
+ } else {
+ for (; *statbuf; statbuf++) {
+ if (*statbuf == 'K') color_start(ANSI_GREEN);
+ else if (*statbuf == 'M') color_start(ANSI_YELLOW);
+ else if (*statbuf == 'G') color_start(ANSI_RED);
+ else if (*statbuf == 'T') color_start(ANSI_BOLD_BLUE);
+ else if (*statbuf == 'P') color_start(ANSI_MAGENTA);
+ else if (*statbuf == 'E') color_start(ANSI_CYAN);
+ fputc(*statbuf, stdout);
+ if (--column_size <= 0)
+ break;
+ }
+ }
+ color_end();
+}
/*
* Display a single statistic.
if (scripted)
printf("\t%s", buf);
else
- printf(" %*s", column_size, buf);
+ print_stat_color(buf, column_size);
}
/*
}
if (cb->vcdl != NULL) {
- char *path;
+ const char *path;
if (nvlist_lookup_string(newnv, ZPOOL_CONFIG_PATH,
&path) == 0) {
printf(" ");
for (c = 0; c < children; c++) {
uint64_t islog = B_FALSE;
- char *bias = NULL;
- char *type = NULL;
+ const char *bias = NULL;
+ const char *type = NULL;
(void) nvlist_lookup_uint64(newchild[c],
ZPOOL_CONFIG_IS_LOG, &islog);
if (islog) {
- bias = (char *)VDEV_ALLOC_CLASS_LOGS;
+ bias = VDEV_ALLOC_CLASS_LOGS;
} else {
(void) nvlist_lookup_string(newchild[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
static int
is_vdev_cb(void *zhp_data, nvlist_t *nv, void *cb_data)
{
+ uint64_t guid;
vdev_cbdata_t *cb = cb_data;
- char *name = NULL;
- int ret = 1; /* assume match */
zpool_handle_t *zhp = zhp_data;
- name = zpool_vdev_name(g_zfs, zhp, nv, cb->cb_name_flags);
-
- if (strcmp(name, cb->cb_names[0])) {
- free(name);
- name = zpool_vdev_name(g_zfs, zhp, nv, VDEV_NAME_GUID);
- ret = (strcmp(name, cb->cb_names[0]) == 0);
- }
- free(name);
+ if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
+ return (0);
- return (ret);
+ return (guid == zpool_vdev_path_to_guid(zhp, cb->cb_names[0]));
}
/*
interval, count);
}
-/*
- * Floating point sleep(). Allows you to pass in a floating point value for
- * seconds.
- */
-static void
-fsleep(float sec)
-{
- struct timespec req;
- req.tv_sec = floor(sec);
- req.tv_nsec = (sec - (float)req.tv_sec) * NANOSEC;
- nanosleep(&req, NULL);
-}
-
/*
* Terminal height, in rows. Returns -1 if stdout is not connected to a TTY or
* if we were unable to determine its size.
if ((dir = opendir(dirpath)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir(dir)) != NULL) {
- sprintf(fullpath, "%s/%s", dirpath, ent->d_name);
+ if (snprintf(fullpath, sizeof (fullpath), "%s/%s",
+ dirpath, ent->d_name) >= sizeof (fullpath)) {
+ (void) fprintf(stderr,
+ gettext("internal error: "
+ "ZPOOL_SCRIPTS_PATH too large.\n"));
+ exit(1);
+ }
/* Print the scripts */
if (stat(fullpath, &dir_stat) == 0)
* get_namewidth() returns the maximum width of any name in that column
* for any pool/vdev/device line that will be output.
*/
- width = get_namewidth(zhp, cb->cb_namewidth, cb->cb_vdevs.cb_name_flags,
- cb->cb_verbose);
+ width = get_namewidth(zhp, cb->cb_namewidth,
+ cb->cb_vdevs.cb_name_flags | VDEV_NAME_TYPE_ID, cb->cb_verbose);
/*
* The width we are calculating is the width of the header and also the
print_iostat_header(&cb);
if (skip) {
+ (void) fflush(stdout);
(void) fsleep(interval);
continue;
}
}
- /*
- * Flush the output so that redirection to a file isn't buffered
- * indefinitely.
- */
- (void) fflush(stdout);
-
if (interval == 0)
break;
if (count != 0 && --count == 0)
break;
+ (void) fflush(stdout);
(void) fsleep(interval);
}
zpool_prop_get_feature(zhp, pl->pl_user_prop, property,
sizeof (property)) == 0) {
propstr = property;
+ } else if (zfs_prop_user(pl->pl_user_prop) &&
+ zpool_get_userprop(zhp, pl->pl_user_prop, property,
+ sizeof (property), NULL) == 0) {
+ propstr = property;
} else {
propstr = "-";
}
-
/*
* If this is being called in scripted mode, or if this is the
* last column and it is left-justified, don't include a width
boolean_t printed = B_FALSE;
for (c = 0; c < children; c++) {
- char *bias = NULL;
- char *type = NULL;
+ const char *bias = NULL;
+ const char *type = NULL;
if (nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
&islog) == 0 && islog) {
- bias = (char *)VDEV_ALLOC_CLASS_LOGS;
+ bias = VDEV_ALLOC_CLASS_LOGS;
} else {
(void) nvlist_lookup_string(child[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
list_cbdata_t *cb = data;
int width;
- width = get_namewidth(zhp, cb->cb_namewidth, cb->cb_name_flags,
- cb->cb_verbose);
+ width = get_namewidth(zhp, cb->cb_namewidth,
+ cb->cb_name_flags | VDEV_NAME_TYPE_ID, cb->cb_verbose);
if (width < 9)
width = 9;
break;
pool_list_free(list);
+
+ (void) fflush(stdout);
(void) fsleep(interval);
}
ret = zpool_vdev_attach(zhp, old_disk, new_disk, nvroot, replacing,
rebuild);
- if (ret == 0 && wait)
- ret = zpool_wait(zhp,
- replacing ? ZPOOL_WAIT_REPLACE : ZPOOL_WAIT_RESILVER);
+ if (ret == 0 && wait) {
+ zpool_wait_activity_t activity = ZPOOL_WAIT_RESILVER;
+ char raidz_prefix[] = "raidz";
+ if (replacing) {
+ activity = ZPOOL_WAIT_REPLACE;
+ } else if (strncmp(old_disk,
+ raidz_prefix, strlen(raidz_prefix)) == 0) {
+ activity = ZPOOL_WAIT_RAIDZ_EXPAND;
+ }
+ ret = zpool_wait(zhp, activity);
+ }
nvlist_free(props);
nvlist_free(nvroot);
}
/*
- * zpool attach [-fsw] [-o property=value] <pool> <device> <new_device>
+ * zpool attach [-fsw] [-o property=value] <pool> <device>|<vdev> <new_device>
*
* -f Force attach, even if <new_device> appears to be in use.
* -s Use sequential instead of healing reconstruction for resilver.
* -o Set property=value.
- * -w Wait for resilvering to complete before returning
+ * -w Wait for resilvering (mirror) or expansion (raidz) to complete
+ * before returning.
*
- * Attach <new_device> to the mirror containing <device>. If <device> is not
- * part of a mirror, then <device> will be transformed into a mirror of
- * <device> and <new_device>. In either case, <new_device> will begin life
- * with a DTL of [0, now], and will immediately begin to resilver itself.
+ * Attach <new_device> to a <device> or <vdev>, where the vdev can be of type
+ * mirror or raidz. If <device> is not part of a mirror, then <device> will
+ * be transformed into a mirror of <device> and <new_device>. When a mirror
+ * is involved, <new_device> will begin life with a DTL of [0, now], and will
+ * immediately begin to resilver itself. For the raidz case, a expansion will
+ * commence and reflow the raidz data across all the disks including the
+ * <new_device>.
*/
int
zpool_do_attach(int argc, char **argv)
char *mntopts = NULL;
splitflags_t flags;
int c, ret = 0;
+ int ms_status = 0;
boolean_t loadkeys = B_FALSE;
zpool_handle_t *zhp;
nvlist_t *config, *props = NULL;
ret = 1;
}
- if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
- zpool_enable_datasets(zhp, mntopts, 0) != 0) {
- ret = 1;
- (void) fprintf(stderr, gettext("Split was successful, but "
- "the datasets could not all be mounted\n"));
- (void) fprintf(stderr, gettext("Try doing '%s' with a "
- "different altroot\n"), "zpool import");
+ if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL) {
+ ms_status = zpool_enable_datasets(zhp, mntopts, 0);
+ if (ms_status == EZFS_SHAREFAILED) {
+ (void) fprintf(stderr, gettext("Split was successful, "
+ "datasets are mounted but sharing of some datasets "
+ "has failed\n"));
+ } else if (ms_status == EZFS_MOUNTFAILED) {
+ (void) fprintf(stderr, gettext("Split was successful"
+ ", but some datasets could not be mounted\n"));
+ (void) fprintf(stderr, gettext("Try doing '%s' with a "
+ "different altroot\n"), "zpool import");
+ }
}
zpool_close(zhp);
nvlist_free(config);
}
-
/*
- * zpool online <pool> <device> ...
+ * zpool online [--power] <pool> <device> ...
+ *
+ * --power: Power on the enclosure slot to the drive (if possible)
*/
int
zpool_do_online(int argc, char **argv)
int ret = 0;
vdev_state_t newstate;
int flags = 0;
+ boolean_t is_power_on = B_FALSE;
+ struct option long_options[] = {
+ {"power", no_argument, NULL, ZPOOL_OPTION_POWER},
+ {0, 0, 0, 0}
+ };
/* check options */
- while ((c = getopt(argc, argv, "e")) != -1) {
+ while ((c = getopt_long(argc, argv, "e", long_options, NULL)) != -1) {
switch (c) {
case 'e':
flags |= ZFS_ONLINE_EXPAND;
break;
+ case ZPOOL_OPTION_POWER:
+ is_power_on = B_TRUE;
+ break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
}
}
+ if (libzfs_envvar_is_set("ZPOOL_AUTO_POWER_ON_SLOT"))
+ is_power_on = B_TRUE;
+
argc -= optind;
argv += optind;
return (1);
for (i = 1; i < argc; i++) {
+ vdev_state_t oldstate;
+ boolean_t avail_spare, l2cache;
+ int rc;
+
+ if (is_power_on) {
+ rc = zpool_power_on_and_disk_wait(zhp, argv[i]);
+ if (rc == ENOTSUP) {
+ (void) fprintf(stderr,
+ gettext("Power control not supported\n"));
+ }
+ if (rc != 0)
+ return (rc);
+ }
+
+ nvlist_t *tgt = zpool_find_vdev(zhp, argv[i], &avail_spare,
+ &l2cache, NULL);
+ if (tgt == NULL) {
+ ret = 1;
+ continue;
+ }
+ uint_t vsc;
+ oldstate = ((vdev_stat_t *)fnvlist_lookup_uint64_array(tgt,
+ ZPOOL_CONFIG_VDEV_STATS, &vsc))->vs_state;
if (zpool_vdev_online(zhp, argv[i], flags, &newstate) == 0) {
if (newstate != VDEV_STATE_HEALTHY) {
(void) printf(gettext("warning: device '%s' "
(void) printf(gettext("use 'zpool "
"replace' to replace devices "
"that are no longer present\n"));
+ if ((flags & ZFS_ONLINE_EXPAND)) {
+ (void) printf(gettext("%s: failed "
+ "to expand usable space on "
+ "unhealthy device '%s'\n"),
+ (oldstate >= VDEV_STATE_DEGRADED ?
+ "error" : "warning"), argv[i]);
+ if (oldstate >= VDEV_STATE_DEGRADED) {
+ ret = 1;
+ break;
+ }
+ }
}
} else {
ret = 1;
}
/*
- * zpool offline [-ft] <pool> <device> ...
+ * zpool offline [-ft]|[--power] <pool> <device> ...
+ *
*
* -f Force the device into a faulted state.
*
* -t Only take the device off-line temporarily. The offline/faulted
* state will not be persistent across reboots.
+ *
+ * --power Power off the enclosure slot to the drive (if possible)
*/
int
zpool_do_offline(int argc, char **argv)
int ret = 0;
boolean_t istmp = B_FALSE;
boolean_t fault = B_FALSE;
+ boolean_t is_power_off = B_FALSE;
+
+ struct option long_options[] = {
+ {"power", no_argument, NULL, ZPOOL_OPTION_POWER},
+ {0, 0, 0, 0}
+ };
/* check options */
- while ((c = getopt(argc, argv, "ft")) != -1) {
+ while ((c = getopt_long(argc, argv, "ft", long_options, NULL)) != -1) {
switch (c) {
case 'f':
fault = B_TRUE;
case 't':
istmp = B_TRUE;
break;
+ case ZPOOL_OPTION_POWER:
+ is_power_off = B_TRUE;
+ break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
}
}
+ if (is_power_off && fault) {
+ (void) fprintf(stderr,
+ gettext("-0 and -f cannot be used together\n"));
+ usage(B_FALSE);
+ return (1);
+ }
+
+ if (is_power_off && istmp) {
+ (void) fprintf(stderr,
+ gettext("-0 and -t cannot be used together\n"));
+ usage(B_FALSE);
+ return (1);
+ }
+
argc -= optind;
argv += optind;
return (1);
for (i = 1; i < argc; i++) {
- if (fault) {
- uint64_t guid = zpool_vdev_path_to_guid(zhp, argv[i]);
+ uint64_t guid = zpool_vdev_path_to_guid(zhp, argv[i]);
+ if (is_power_off) {
+ /*
+ * Note: we have to power off first, then set REMOVED,
+ * or else zpool_vdev_set_removed_state() returns
+ * EAGAIN.
+ */
+ ret = zpool_power_off(zhp, argv[i]);
+ if (ret != 0) {
+ (void) fprintf(stderr, "%s %s %d\n",
+ gettext("unable to power off slot for"),
+ argv[i], ret);
+ }
+ zpool_vdev_set_removed_state(zhp, guid, VDEV_AUX_NONE);
+
+ } else if (fault) {
vdev_aux_t aux;
if (istmp == B_FALSE) {
/* Force the fault to persist across imports */
}
/*
- * zpool clear <pool> [device]
+ * zpool clear [-nF]|[--power] <pool> [device]
*
* Clear all errors associated with a pool or a particular device.
*/
boolean_t dryrun = B_FALSE;
boolean_t do_rewind = B_FALSE;
boolean_t xtreme_rewind = B_FALSE;
+ boolean_t is_power_on = B_FALSE;
uint32_t rewind_policy = ZPOOL_NO_REWIND;
nvlist_t *policy = NULL;
zpool_handle_t *zhp;
char *pool, *device;
+ struct option long_options[] = {
+ {"power", no_argument, NULL, ZPOOL_OPTION_POWER},
+ {0, 0, 0, 0}
+ };
+
/* check options */
- while ((c = getopt(argc, argv, "FnX")) != -1) {
+ while ((c = getopt_long(argc, argv, "FnX", long_options,
+ NULL)) != -1) {
switch (c) {
case 'F':
do_rewind = B_TRUE;
case 'X':
xtreme_rewind = B_TRUE;
break;
+ case ZPOOL_OPTION_POWER:
+ is_power_on = B_TRUE;
+ break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
}
}
+ if (libzfs_envvar_is_set("ZPOOL_AUTO_POWER_ON_SLOT"))
+ is_power_on = B_TRUE;
+
argc -= optind;
argv += optind;
return (1);
}
+ if (is_power_on) {
+ if (device == NULL) {
+ zpool_power_on_pool_and_wait_for_devices(zhp);
+ } else {
+ zpool_power_on_and_disk_wait(zhp, device);
+ }
+ }
+
if (zpool_clear(zhp, device, policy) != 0)
ret = 1;
}
/*
- * zpool scrub [-s | -p] [-w] <pool> ...
+ * zpool scrub [-s | -p] [-w] [-e] <pool> ...
*
+ * -e Only scrub blocks in the error log.
* -s Stop. Stops any in-progress scrub.
* -p Pause. Pause in-progress scrub.
* -w Wait. Blocks until scrub has completed.
cb.cb_type = POOL_SCAN_SCRUB;
cb.cb_scrub_cmd = POOL_SCRUB_NORMAL;
+ boolean_t is_error_scrub = B_FALSE;
+ boolean_t is_pause = B_FALSE;
+ boolean_t is_stop = B_FALSE;
+
/* check options */
- while ((c = getopt(argc, argv, "spw")) != -1) {
+ while ((c = getopt(argc, argv, "spwe")) != -1) {
switch (c) {
+ case 'e':
+ is_error_scrub = B_TRUE;
+ break;
case 's':
- cb.cb_type = POOL_SCAN_NONE;
+ is_stop = B_TRUE;
break;
case 'p':
- cb.cb_scrub_cmd = POOL_SCRUB_PAUSE;
+ is_pause = B_TRUE;
break;
case 'w':
wait = B_TRUE;
}
}
- if (cb.cb_type == POOL_SCAN_NONE &&
- cb.cb_scrub_cmd == POOL_SCRUB_PAUSE) {
- (void) fprintf(stderr, gettext("invalid option combination: "
- "-s and -p are mutually exclusive\n"));
+ if (is_pause && is_stop) {
+ (void) fprintf(stderr, gettext("invalid option "
+ "combination :-s and -p are mutually exclusive\n"));
usage(B_FALSE);
+ } else {
+ if (is_error_scrub)
+ cb.cb_type = POOL_SCAN_ERRORSCRUB;
+
+ if (is_pause) {
+ cb.cb_scrub_cmd = POOL_SCRUB_PAUSE;
+ } else if (is_stop) {
+ cb.cb_type = POOL_SCAN_NONE;
+ } else {
+ cb.cb_scrub_cmd = POOL_SCRUB_NORMAL;
+ }
}
if (wait && (cb.cb_type == POOL_SCAN_NONE ||
}
}
+/*
+ * Print out detailed error scrub status.
+ */
+static void
+print_err_scrub_status(pool_scan_stat_t *ps)
+{
+ time_t start, end, pause;
+ uint64_t total_secs_left;
+ uint64_t secs_left, mins_left, hours_left, days_left;
+ uint64_t examined, to_be_examined;
+
+ if (ps == NULL || ps->pss_error_scrub_func != POOL_SCAN_ERRORSCRUB) {
+ return;
+ }
+
+ (void) printf(gettext(" scrub: "));
+
+ start = ps->pss_error_scrub_start;
+ end = ps->pss_error_scrub_end;
+ pause = ps->pss_pass_error_scrub_pause;
+ examined = ps->pss_error_scrub_examined;
+ to_be_examined = ps->pss_error_scrub_to_be_examined;
+
+ assert(ps->pss_error_scrub_func == POOL_SCAN_ERRORSCRUB);
+
+ if (ps->pss_error_scrub_state == DSS_FINISHED) {
+ total_secs_left = end - start;
+ days_left = total_secs_left / 60 / 60 / 24;
+ hours_left = (total_secs_left / 60 / 60) % 24;
+ mins_left = (total_secs_left / 60) % 60;
+ secs_left = (total_secs_left % 60);
+
+ (void) printf(gettext("scrubbed %llu error blocks in %llu days "
+ "%02llu:%02llu:%02llu on %s"), (u_longlong_t)examined,
+ (u_longlong_t)days_left, (u_longlong_t)hours_left,
+ (u_longlong_t)mins_left, (u_longlong_t)secs_left,
+ ctime(&end));
+
+ return;
+ } else if (ps->pss_error_scrub_state == DSS_CANCELED) {
+ (void) printf(gettext("error scrub canceled on %s"),
+ ctime(&end));
+ return;
+ }
+ assert(ps->pss_error_scrub_state == DSS_ERRORSCRUBBING);
+
+ /* Error scrub is in progress. */
+ if (pause == 0) {
+ (void) printf(gettext("error scrub in progress since %s"),
+ ctime(&start));
+ } else {
+ (void) printf(gettext("error scrub paused since %s"),
+ ctime(&pause));
+ (void) printf(gettext("\terror scrub started on %s"),
+ ctime(&start));
+ }
+
+ double fraction_done = (double)examined / (to_be_examined + examined);
+ (void) printf(gettext("\t%.2f%% done, issued I/O for %llu error"
+ " blocks"), 100 * fraction_done, (u_longlong_t)examined);
+
+ (void) printf("\n");
+}
+
/*
* Print out detailed scrub status.
*/
print_scan_scrub_resilver_status(pool_scan_stat_t *ps)
{
time_t start, end, pause;
- uint64_t pass_scanned, scanned, pass_issued, issued, total;
+ uint64_t pass_scanned, scanned, pass_issued, issued, total_s, total_i;
uint64_t elapsed, scan_rate, issue_rate;
double fraction_done;
- char processed_buf[7], scanned_buf[7], issued_buf[7], total_buf[7];
- char srate_buf[7], irate_buf[7], time_buf[32];
+ char processed_buf[7], scanned_buf[7], issued_buf[7], total_s_buf[7];
+ char total_i_buf[7], srate_buf[7], irate_buf[7], time_buf[32];
printf(" ");
printf_color(ANSI_BOLD, gettext("scan:"));
zfs_nicebytes(ps->pss_processed, processed_buf, sizeof (processed_buf));
- assert(ps->pss_func == POOL_SCAN_SCRUB ||
- ps->pss_func == POOL_SCAN_RESILVER);
+ int is_resilver = ps->pss_func == POOL_SCAN_RESILVER;
+ int is_scrub = ps->pss_func == POOL_SCAN_SCRUB;
+ assert(is_resilver || is_scrub);
/* Scan is finished or canceled. */
if (ps->pss_state == DSS_FINISHED) {
secs_to_dhms(end - start, time_buf);
- if (ps->pss_func == POOL_SCAN_SCRUB) {
+ if (is_scrub) {
(void) printf(gettext("scrub repaired %s "
"in %s with %llu errors on %s"), processed_buf,
time_buf, (u_longlong_t)ps->pss_errors,
ctime(&end));
- } else if (ps->pss_func == POOL_SCAN_RESILVER) {
+ } else if (is_resilver) {
(void) printf(gettext("resilvered %s "
"in %s with %llu errors on %s"), processed_buf,
time_buf, (u_longlong_t)ps->pss_errors,
}
return;
} else if (ps->pss_state == DSS_CANCELED) {
- if (ps->pss_func == POOL_SCAN_SCRUB) {
+ if (is_scrub) {
(void) printf(gettext("scrub canceled on %s"),
ctime(&end));
- } else if (ps->pss_func == POOL_SCAN_RESILVER) {
+ } else if (is_resilver) {
(void) printf(gettext("resilver canceled on %s"),
ctime(&end));
}
assert(ps->pss_state == DSS_SCANNING);
/* Scan is in progress. Resilvers can't be paused. */
- if (ps->pss_func == POOL_SCAN_SCRUB) {
+ if (is_scrub) {
if (pause == 0) {
(void) printf(gettext("scrub in progress since %s"),
ctime(&start));
(void) printf(gettext("\tscrub started on %s"),
ctime(&start));
}
- } else if (ps->pss_func == POOL_SCAN_RESILVER) {
+ } else if (is_resilver) {
(void) printf(gettext("resilver in progress since %s"),
ctime(&start));
}
pass_scanned = ps->pss_pass_exam;
issued = ps->pss_issued;
pass_issued = ps->pss_pass_issued;
- total = ps->pss_to_examine;
+ total_s = ps->pss_to_examine;
+ total_i = ps->pss_to_examine - ps->pss_skipped;
/* we are only done with a block once we have issued the IO for it */
- fraction_done = (double)issued / total;
+ fraction_done = (double)issued / total_i;
/* elapsed time for this pass, rounding up to 1 if it's 0 */
elapsed = time(NULL) - ps->pss_pass_start;
scan_rate = pass_scanned / elapsed;
issue_rate = pass_issued / elapsed;
- uint64_t total_secs_left = (issue_rate != 0 && total >= issued) ?
- ((total - issued) / issue_rate) : UINT64_MAX;
- secs_to_dhms(total_secs_left, time_buf);
/* format all of the numbers we will be reporting */
zfs_nicebytes(scanned, scanned_buf, sizeof (scanned_buf));
zfs_nicebytes(issued, issued_buf, sizeof (issued_buf));
- zfs_nicebytes(total, total_buf, sizeof (total_buf));
- zfs_nicebytes(scan_rate, srate_buf, sizeof (srate_buf));
- zfs_nicebytes(issue_rate, irate_buf, sizeof (irate_buf));
+ zfs_nicebytes(total_s, total_s_buf, sizeof (total_s_buf));
+ zfs_nicebytes(total_i, total_i_buf, sizeof (total_i_buf));
/* do not print estimated time if we have a paused scrub */
- if (pause == 0) {
- (void) printf(gettext("\t%s scanned at %s/s, "
- "%s issued at %s/s, %s total\n"),
- scanned_buf, srate_buf, issued_buf, irate_buf, total_buf);
- } else {
- (void) printf(gettext("\t%s scanned, %s issued, %s total\n"),
- scanned_buf, issued_buf, total_buf);
+ (void) printf(gettext("\t%s / %s scanned"), scanned_buf, total_s_buf);
+ if (pause == 0 && scan_rate > 0) {
+ zfs_nicebytes(scan_rate, srate_buf, sizeof (srate_buf));
+ (void) printf(gettext(" at %s/s"), srate_buf);
}
+ (void) printf(gettext(", %s / %s issued"), issued_buf, total_i_buf);
+ if (pause == 0 && issue_rate > 0) {
+ zfs_nicebytes(issue_rate, irate_buf, sizeof (irate_buf));
+ (void) printf(gettext(" at %s/s"), irate_buf);
+ }
+ (void) printf(gettext("\n"));
- if (ps->pss_func == POOL_SCAN_RESILVER) {
+ if (is_resilver) {
(void) printf(gettext("\t%s resilvered, %.2f%% done"),
processed_buf, 100 * fraction_done);
- } else if (ps->pss_func == POOL_SCAN_SCRUB) {
+ } else if (is_scrub) {
(void) printf(gettext("\t%s repaired, %.2f%% done"),
processed_buf, 100 * fraction_done);
}
if (pause == 0) {
- if (total_secs_left != UINT64_MAX &&
- issue_rate >= 10 * 1024 * 1024) {
+ /*
+ * Only provide an estimate iff:
+ * 1) we haven't yet issued all we expected, and
+ * 2) the issue rate exceeds 10 MB/s, and
+ * 3) it's either:
+ * a) a resilver which has started repairs, or
+ * b) a scrub which has entered the issue phase.
+ */
+ if (total_i >= issued && issue_rate >= 10 * 1024 * 1024 &&
+ ((is_resilver && ps->pss_processed > 0) ||
+ (is_scrub && issued > 0))) {
+ secs_to_dhms((total_i - issued) / issue_rate, time_buf);
(void) printf(gettext(", %s to go\n"), time_buf);
} else {
(void) printf(gettext(", no estimated "
}
static void
-print_rebuild_status_impl(vdev_rebuild_stat_t *vrs, char *vdev_name)
+print_rebuild_status_impl(vdev_rebuild_stat_t *vrs, uint_t c, char *vdev_name)
{
if (vrs == NULL || vrs->vrs_state == VDEV_REBUILD_NONE)
return;
uint64_t bytes_scanned = vrs->vrs_bytes_scanned;
uint64_t bytes_issued = vrs->vrs_bytes_issued;
uint64_t bytes_rebuilt = vrs->vrs_bytes_rebuilt;
- uint64_t bytes_est = vrs->vrs_bytes_est;
+ uint64_t bytes_est_s = vrs->vrs_bytes_est;
+ uint64_t bytes_est_i = vrs->vrs_bytes_est;
+ if (c > offsetof(vdev_rebuild_stat_t, vrs_pass_bytes_skipped) / 8)
+ bytes_est_i -= vrs->vrs_pass_bytes_skipped;
uint64_t scan_rate = (vrs->vrs_pass_bytes_scanned /
(vrs->vrs_pass_time_ms + 1)) * 1000;
uint64_t issue_rate = (vrs->vrs_pass_bytes_issued /
(vrs->vrs_pass_time_ms + 1)) * 1000;
double scan_pct = MIN((double)bytes_scanned * 100 /
- (bytes_est + 1), 100);
+ (bytes_est_s + 1), 100);
/* Format all of the numbers we will be reporting */
char bytes_scanned_buf[7], bytes_issued_buf[7];
- char bytes_rebuilt_buf[7], bytes_est_buf[7];
+ char bytes_rebuilt_buf[7], bytes_est_s_buf[7], bytes_est_i_buf[7];
char scan_rate_buf[7], issue_rate_buf[7], time_buf[32];
zfs_nicebytes(bytes_scanned, bytes_scanned_buf,
sizeof (bytes_scanned_buf));
sizeof (bytes_issued_buf));
zfs_nicebytes(bytes_rebuilt, bytes_rebuilt_buf,
sizeof (bytes_rebuilt_buf));
- zfs_nicebytes(bytes_est, bytes_est_buf, sizeof (bytes_est_buf));
- zfs_nicebytes(scan_rate, scan_rate_buf, sizeof (scan_rate_buf));
- zfs_nicebytes(issue_rate, issue_rate_buf, sizeof (issue_rate_buf));
+ zfs_nicebytes(bytes_est_s, bytes_est_s_buf, sizeof (bytes_est_s_buf));
+ zfs_nicebytes(bytes_est_i, bytes_est_i_buf, sizeof (bytes_est_i_buf));
time_t start = vrs->vrs_start_time;
time_t end = vrs->vrs_end_time;
assert(vrs->vrs_state == VDEV_REBUILD_ACTIVE);
- secs_to_dhms(MAX((int64_t)bytes_est - (int64_t)bytes_scanned, 0) /
- MAX(scan_rate, 1), time_buf);
+ (void) printf(gettext("\t%s / %s scanned"), bytes_scanned_buf,
+ bytes_est_s_buf);
+ if (scan_rate > 0) {
+ zfs_nicebytes(scan_rate, scan_rate_buf, sizeof (scan_rate_buf));
+ (void) printf(gettext(" at %s/s"), scan_rate_buf);
+ }
+ (void) printf(gettext(", %s / %s issued"), bytes_issued_buf,
+ bytes_est_i_buf);
+ if (issue_rate > 0) {
+ zfs_nicebytes(issue_rate, issue_rate_buf,
+ sizeof (issue_rate_buf));
+ (void) printf(gettext(" at %s/s"), issue_rate_buf);
+ }
+ (void) printf(gettext("\n"));
- (void) printf(gettext("\t%s scanned at %s/s, %s issued %s/s, "
- "%s total\n"), bytes_scanned_buf, scan_rate_buf,
- bytes_issued_buf, issue_rate_buf, bytes_est_buf);
(void) printf(gettext("\t%s resilvered, %.2f%% done"),
bytes_rebuilt_buf, scan_pct);
if (vrs->vrs_state == VDEV_REBUILD_ACTIVE) {
- if (scan_rate >= 10 * 1024 * 1024) {
+ if (bytes_est_s >= bytes_scanned &&
+ scan_rate >= 10 * 1024 * 1024) {
+ secs_to_dhms((bytes_est_s - bytes_scanned) / scan_rate,
+ time_buf);
(void) printf(gettext(", %s to go\n"), time_buf);
} else {
(void) printf(gettext(", no estimated "
ZPOOL_CONFIG_REBUILD_STATS, (uint64_t **)&vrs, &i) == 0) {
char *name = zpool_vdev_name(g_zfs, zhp,
child[c], VDEV_NAME_TYPE_ID);
- print_rebuild_status_impl(vrs, name);
+ print_rebuild_status_impl(vrs, i, name);
free(name);
}
}
{
uint64_t rebuild_end_time = 0, resilver_end_time = 0;
boolean_t have_resilver = B_FALSE, have_scrub = B_FALSE;
+ boolean_t have_errorscrub = B_FALSE;
boolean_t active_resilver = B_FALSE;
pool_checkpoint_stat_t *pcs = NULL;
pool_scan_stat_t *ps = NULL;
uint_t c;
+ time_t scrub_start = 0, errorscrub_start = 0;
if (nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS,
(uint64_t **)&ps, &c) == 0) {
have_resilver = (ps->pss_func == POOL_SCAN_RESILVER);
have_scrub = (ps->pss_func == POOL_SCAN_SCRUB);
+ scrub_start = ps->pss_start_time;
+ if (c > offsetof(pool_scan_stat_t,
+ pss_pass_error_scrub_pause) / 8) {
+ have_errorscrub = (ps->pss_error_scrub_func ==
+ POOL_SCAN_ERRORSCRUB);
+ errorscrub_start = ps->pss_error_scrub_start;
+ }
}
boolean_t active_rebuild = check_rebuilding(nvroot, &rebuild_end_time);
boolean_t have_rebuild = (active_rebuild || (rebuild_end_time > 0));
/* Always print the scrub status when available. */
- if (have_scrub)
+ if (have_scrub && scrub_start > errorscrub_start)
print_scan_scrub_resilver_status(ps);
+ else if (have_errorscrub && errorscrub_start >= scrub_start)
+ print_err_scrub_status(ps);
/*
* When there is an active resilver or rebuild print its status.
}
}
+/*
+ * Print out detailed raidz expansion status.
+ */
+static void
+print_raidz_expand_status(zpool_handle_t *zhp, pool_raidz_expand_stat_t *pres)
+{
+ char copied_buf[7];
+
+ if (pres == NULL || pres->pres_state == DSS_NONE)
+ return;
+
+ /*
+ * Determine name of vdev.
+ */
+ nvlist_t *config = zpool_get_config(zhp, NULL);
+ nvlist_t *nvroot = fnvlist_lookup_nvlist(config,
+ ZPOOL_CONFIG_VDEV_TREE);
+ nvlist_t **child;
+ uint_t children;
+ verify(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
+ &child, &children) == 0);
+ assert(pres->pres_expanding_vdev < children);
+
+ printf_color(ANSI_BOLD, gettext("expand: "));
+
+ time_t start = pres->pres_start_time;
+ time_t end = pres->pres_end_time;
+ char *vname =
+ zpool_vdev_name(g_zfs, zhp, child[pres->pres_expanding_vdev], 0);
+ zfs_nicenum(pres->pres_reflowed, copied_buf, sizeof (copied_buf));
+
+ /*
+ * Expansion is finished or canceled.
+ */
+ if (pres->pres_state == DSS_FINISHED) {
+ char time_buf[32];
+ secs_to_dhms(end - start, time_buf);
+
+ (void) printf(gettext("expanded %s-%u copied %s in %s, "
+ "on %s"), vname, (int)pres->pres_expanding_vdev,
+ copied_buf, time_buf, ctime((time_t *)&end));
+ } else {
+ char examined_buf[7], total_buf[7], rate_buf[7];
+ uint64_t copied, total, elapsed, secs_left;
+ double fraction_done;
+ uint_t rate;
+
+ assert(pres->pres_state == DSS_SCANNING);
+
+ /*
+ * Expansion is in progress.
+ */
+ (void) printf(gettext(
+ "expansion of %s-%u in progress since %s"),
+ vname, (int)pres->pres_expanding_vdev, ctime(&start));
+
+ copied = pres->pres_reflowed > 0 ? pres->pres_reflowed : 1;
+ total = pres->pres_to_reflow;
+ fraction_done = (double)copied / total;
+
+ /* elapsed time for this pass */
+ elapsed = time(NULL) - pres->pres_start_time;
+ elapsed = elapsed > 0 ? elapsed : 1;
+ rate = copied / elapsed;
+ rate = rate > 0 ? rate : 1;
+ secs_left = (total - copied) / rate;
+
+ zfs_nicenum(copied, examined_buf, sizeof (examined_buf));
+ zfs_nicenum(total, total_buf, sizeof (total_buf));
+ zfs_nicenum(rate, rate_buf, sizeof (rate_buf));
+
+ /*
+ * do not print estimated time if hours_left is more than
+ * 30 days
+ */
+ (void) printf(gettext("\t%s / %s copied at %s/s, %.2f%% done"),
+ examined_buf, total_buf, rate_buf, 100 * fraction_done);
+ if (pres->pres_waiting_for_resilver) {
+ (void) printf(gettext(", paused for resilver or "
+ "clear\n"));
+ } else if (secs_left < (30 * 24 * 3600)) {
+ char time_buf[32];
+ secs_to_dhms(secs_left, time_buf);
+ (void) printf(gettext(", %s to go\n"), time_buf);
+ } else {
+ (void) printf(gettext(
+ ", (copy is slow, no estimated time)\n"));
+ }
+ }
+ free(vname);
+}
static void
print_checkpoint_status(pool_checkpoint_stat_t *pcs)
{
uint64_t nerr;
nvlist_t **spares, **l2cache;
uint_t nspares, nl2cache;
- pool_checkpoint_stat_t *pcs = NULL;
- pool_removal_stat_t *prs = NULL;
print_scan_status(zhp, nvroot);
+ pool_removal_stat_t *prs = NULL;
(void) nvlist_lookup_uint64_array(nvroot,
ZPOOL_CONFIG_REMOVAL_STATS, (uint64_t **)&prs, &c);
print_removal_status(zhp, prs);
+ pool_checkpoint_stat_t *pcs = NULL;
(void) nvlist_lookup_uint64_array(nvroot,
ZPOOL_CONFIG_CHECKPOINT_STATS, (uint64_t **)&pcs, &c);
print_checkpoint_status(pcs);
+ pool_raidz_expand_stat_t *pres = NULL;
+ (void) nvlist_lookup_uint64_array(nvroot,
+ ZPOOL_CONFIG_RAIDZ_EXPAND_STATS, (uint64_t **)&pres, &c);
+ print_raidz_expand_status(zhp, pres);
+
cbp->cb_namewidth = max_width(zhp, nvroot, 0, 0,
cbp->cb_name_flags | VDEV_NAME_TYPE_ID);
if (cbp->cb_namewidth < 10)
printf_color(ANSI_BOLD, " %5s", gettext("SLOW"));
}
+ if (cbp->cb_print_power) {
+ printf_color(ANSI_BOLD, " %5s", gettext("POWER"));
+ }
+
if (cbp->vcdl != NULL)
print_cmd_columns(cbp->vcdl, 0);
if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
&nerr) == 0) {
- nvlist_t *nverrlist = NULL;
-
- /*
- * If the approximate error count is small, get a
- * precise count by fetching the entire log and
- * uniquifying the results.
- */
- if (nerr > 0 && nerr < 100 && !cbp->cb_verbose &&
- zpool_get_errlog(zhp, &nverrlist) == 0) {
- nvpair_t *elem;
-
- elem = NULL;
- nerr = 0;
- while ((elem = nvlist_next_nvpair(nverrlist,
- elem)) != NULL) {
- nerr++;
- }
- }
- nvlist_free(nverrlist);
-
(void) printf("\n");
-
- if (nerr == 0)
- (void) printf(gettext("errors: No known data "
- "errors\n"));
- else if (!cbp->cb_verbose)
+ if (nerr == 0) {
+ (void) printf(gettext(
+ "errors: No known data errors\n"));
+ } else if (!cbp->cb_verbose) {
+ color_start(ANSI_RED);
(void) printf(gettext("errors: %llu data "
"errors, use '-v' for a list\n"),
(u_longlong_t)nerr);
- else
+ color_end();
+ } else {
print_error_log(zhp);
+ }
}
if (cbp->cb_dedup_stats)
}
/*
- * zpool status [-c [script1,script2,...]] [-igLpPstvx] [-T d|u] [pool] ...
- * [interval [count]]
+ * zpool status [-c [script1,script2,...]] [-DegiLpPstvx] [--power] [-T d|u] ...
+ * [pool] [interval [count]]
*
* -c CMD For each vdev, run command CMD
- * -i Display vdev initialization status.
+ * -D Display dedup status (undocumented)
+ * -e Display only unhealthy vdevs
* -g Display guid for individual vdev name.
+ * -i Display vdev initialization status.
* -L Follow links when resolving vdev path name.
* -p Display values in parsable (exact) format.
* -P Display full path for vdev name.
* -s Display slow IOs column.
- * -v Display complete error logs
- * -x Display only pools with potential problems
- * -D Display dedup status (undocumented)
* -t Display vdev TRIM status.
* -T Display a timestamp in date(1) or Unix format
+ * -v Display complete error logs
+ * -x Display only pools with potential problems
+ * --power Display vdev enclosure slot power status
*
* Describes the health status of all pools or some subset.
*/
status_cbdata_t cb = { 0 };
char *cmd = NULL;
+ struct option long_options[] = {
+ {"power", no_argument, NULL, ZPOOL_OPTION_POWER},
+ {0, 0, 0, 0}
+ };
+
/* check options */
- while ((c = getopt(argc, argv, "c:igLpPsvxDtT:")) != -1) {
+ while ((c = getopt_long(argc, argv, "c:DegiLpPstT:vx", long_options,
+ NULL)) != -1) {
switch (c) {
case 'c':
if (cmd != NULL) {
}
cmd = optarg;
break;
- case 'i':
- cb.cb_print_vdev_init = B_TRUE;
+ case 'D':
+ cb.cb_dedup_stats = B_TRUE;
+ break;
+ case 'e':
+ cb.cb_print_unhealthy = B_TRUE;
break;
case 'g':
cb.cb_name_flags |= VDEV_NAME_GUID;
break;
+ case 'i':
+ cb.cb_print_vdev_init = B_TRUE;
+ break;
case 'L':
cb.cb_name_flags |= VDEV_NAME_FOLLOW_LINKS;
break;
case 's':
cb.cb_print_slow_ios = B_TRUE;
break;
+ case 't':
+ cb.cb_print_vdev_trim = B_TRUE;
+ break;
+ case 'T':
+ get_timestamp_arg(*optarg);
+ break;
case 'v':
cb.cb_verbose = B_TRUE;
break;
case 'x':
cb.cb_explain = B_TRUE;
break;
- case 'D':
- cb.cb_dedup_stats = B_TRUE;
- break;
- case 't':
- cb.cb_print_vdev_trim = B_TRUE;
- break;
- case 'T':
- get_timestamp_arg(*optarg);
+ case ZPOOL_OPTION_POWER:
+ cb.cb_print_power = B_TRUE;
break;
case '?':
if (optopt == 'c') {
if (cb.vcdl != NULL)
free_vdev_cmd_data_list(cb.vcdl);
-
if (argc == 0 && cb.cb_count == 0)
(void) fprintf(stderr, gettext("no pools available\n"));
else if (cb.cb_explain && cb.cb_first && cb.cb_allpools)
if (count != 0 && --count == 0)
break;
+ (void) fflush(stdout);
(void) fsleep(interval);
}
(*count)++;
}
- zfs_iter_filesystems(zhp, check_unsupp_fs, unsupp_fs);
+ zfs_iter_filesystems_v2(zhp, 0, check_unsupp_fs, unsupp_fs);
zfs_close(zhp);
static void
zpool_do_events_short(nvlist_t *nvl, ev_opts_t *opts)
{
- char ctime_str[26], str[32], *ptr;
+ char ctime_str[26], str[32];
+ const char *ptr;
int64_t *tv;
uint_t n;
uint16_t i16;
uint32_t i32;
uint64_t i64;
- char *str;
+ const char *str;
nvlist_t *cnv;
printf(gettext("%*s%s = "), depth, "", name);
}
case DATA_TYPE_STRING_ARRAY: {
- char **str;
+ const char **str;
uint_t i, nelem;
(void) nvpair_value_string_array(nvp, &str, &nelem);
{
nvlist_t *nvl;
int zevent_fd, ret, dropped;
- char *pool;
+ const char *pool;
zevent_fd = open(ZFS_DEV, O_RDWR);
VERIFY(zevent_fd >= 0);
}
static int
-get_callback_vdev_width_cb(void *zhp_data, nvlist_t *nv, void *data)
+get_callback_vdev_cb(void *zhp_data, nvlist_t *nv, void *data)
{
zpool_handle_t *zhp = zhp_data;
zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
- char *vdevname = zpool_vdev_name(g_zfs, zhp, nv,
- cbp->cb_vdevs.cb_name_flags);
+ char *vdevname;
+ const char *type;
int ret;
- /* Adjust the column widths for the vdev properties */
- ret = vdev_expand_proplist(zhp, vdevname, &cbp->cb_proplist);
-
- return (ret);
-}
+ /*
+ * zpool_vdev_name() transforms the root vdev name (i.e., root-0) to the
+ * pool name for display purposes, which is not desired. Fallback to
+ * zpool_vdev_name() when not dealing with the root vdev.
+ */
+ type = fnvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE);
+ if (zhp != NULL && strcmp(type, "root") == 0)
+ vdevname = strdup("root-0");
+ else
+ vdevname = zpool_vdev_name(g_zfs, zhp, nv,
+ cbp->cb_vdevs.cb_name_flags);
-static int
-get_callback_vdev_cb(void *zhp_data, nvlist_t *nv, void *data)
-{
- zpool_handle_t *zhp = zhp_data;
- zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
- char *vdevname = zpool_vdev_name(g_zfs, zhp, nv,
- cbp->cb_vdevs.cb_name_flags);
- int ret;
+ (void) vdev_expand_proplist(zhp, vdevname, &cbp->cb_proplist);
- /* Display the properties */
ret = get_callback_vdev(zhp, vdevname, data);
+ free(vdevname);
+
return (ret);
}
get_callback(zpool_handle_t *zhp, void *data)
{
zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
- char value[MAXNAMELEN];
+ char value[ZFS_MAXPROPLEN];
zprop_source_t srctype;
zprop_list_t *pl;
int vid;
if (cbp->cb_type == ZFS_TYPE_VDEV) {
if (strcmp(cbp->cb_vdevs.cb_names[0], "all-vdevs") == 0) {
- for_each_vdev(zhp, get_callback_vdev_width_cb, data);
for_each_vdev(zhp, get_callback_vdev_cb, data);
} else {
/* Adjust column widths for vdev properties */
continue;
if (pl->pl_prop == ZPROP_INVAL &&
+ zfs_prop_user(pl->pl_user_prop)) {
+ srctype = ZPROP_SRC_LOCAL;
+
+ if (zpool_get_userprop(zhp, pl->pl_user_prop,
+ value, sizeof (value), &srctype) != 0)
+ continue;
+
+ zprop_print_one_property(zpool_get_name(zhp),
+ cbp, pl->pl_user_prop, value, srctype,
+ NULL, NULL);
+ } else if (pl->pl_prop == ZPROP_INVAL &&
(zpool_prop_feature(pl->pl_user_prop) ||
zpool_prop_unsupported(pl->pl_user_prop))) {
srctype = ZPROP_SRC_LOCAL;
int ret;
int c, i;
char *propstr = NULL;
+ char *vdev = NULL;
cb.cb_first = B_TRUE;
} else if (are_all_pools(1, argv)) {
/* The first arg is a pool name */
if ((argc == 2 && strcmp(argv[1], "all-vdevs") == 0) ||
+ (argc == 2 && strcmp(argv[1], "root") == 0) ||
are_vdevs_in_pool(argc - 1, argv + 1, argv[0],
&cb.cb_vdevs)) {
+
+ if (strcmp(argv[1], "root") == 0)
+ vdev = strdup("root-0");
+ else
+ vdev = strdup(argv[1]);
+
/* ... and the rest are vdev names */
- cb.cb_vdevs.cb_names = argv + 1;
+ cb.cb_vdevs.cb_names = &vdev;
cb.cb_vdevs.cb_names_count = argc - 1;
cb.cb_type = ZFS_TYPE_VDEV;
argc = 1; /* One pool to process */
}
} else {
/*
- * The first arg isn't a pool name,
+ * The first arg isn't the name of a valid pool.
*/
- fprintf(stderr, gettext("missing pool name.\n"));
- fprintf(stderr, "\n");
- usage(B_FALSE);
+ fprintf(stderr, gettext("Cannot get properties of %s: "
+ "no such pool available.\n"), argv[0]);
return (1);
}
else
zprop_free_list(cb.cb_proplist);
+ if (vdev != NULL)
+ free(vdev);
+
return (ret);
}
{
set_cbdata_t cb = { 0 };
int error;
+ char *vdev = NULL;
current_prop_type = ZFS_TYPE_POOL;
if (argc > 1 && argv[1][0] == '-') {
argc -= 2;
argv += 2;
- if (are_vdevs_in_pool(argc, argv, NULL, &cb.cb_vdevs)) {
- /* Argument is a vdev */
- cb.cb_vdevs.cb_names = argv;
+ /* argv[0] is pool name */
+ if (!is_pool(argv[0])) {
+ (void) fprintf(stderr,
+ gettext("cannot open '%s': is not a pool\n"), argv[0]);
+ return (EINVAL);
+ }
+
+ /* argv[1], when supplied, is vdev name */
+ if (argc == 2) {
+
+ if (strcmp(argv[1], "root") == 0)
+ vdev = strdup("root-0");
+ else
+ vdev = strdup(argv[1]);
+
+ if (!are_vdevs_in_pool(1, &vdev, argv[0], &cb.cb_vdevs)) {
+ (void) fprintf(stderr, gettext(
+ "cannot find '%s' in '%s': device not in pool\n"),
+ vdev, argv[0]);
+ free(vdev);
+ return (EINVAL);
+ }
+ cb.cb_vdevs.cb_names = &vdev;
cb.cb_vdevs.cb_names_count = 1;
cb.cb_type = ZFS_TYPE_VDEV;
- argc = 0; /* No pools to process */
- } else if (are_all_pools(1, argv)) {
- /* The first arg is a pool name */
- if (are_vdevs_in_pool(argc - 1, argv + 1, argv[0],
- &cb.cb_vdevs)) {
- /* 2nd argument is a vdev */
- cb.cb_vdevs.cb_names = argv + 1;
- cb.cb_vdevs.cb_names_count = 1;
- cb.cb_type = ZFS_TYPE_VDEV;
- argc = 1; /* One pool to process */
- } else if (argc > 1) {
- (void) fprintf(stderr,
- gettext("too many pool names\n"));
- usage(B_FALSE);
- }
}
- error = for_each_pool(argc, argv, B_TRUE, NULL, ZFS_TYPE_POOL,
+ error = for_each_pool(1, argv, B_TRUE, NULL, ZFS_TYPE_POOL,
B_FALSE, set_callback, &cb);
+ if (vdev != NULL)
+ free(vdev);
+
return (error);
}
{
nvlist_t **child;
uint_t c, children;
- char *vdev_type;
+ const char *vdev_type;
(void) nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &vdev_type);
pool_checkpoint_stat_t *pcs = NULL;
pool_scan_stat_t *pss = NULL;
pool_removal_stat_t *prs = NULL;
+ pool_raidz_expand_stat_t *pres = NULL;
const char *const headers[] = {"DISCARD", "FREE", "INITIALIZE",
- "REPLACE", "REMOVE", "RESILVER", "SCRUB", "TRIM"};
+ "REPLACE", "REMOVE", "RESILVER", "SCRUB", "TRIM", "RAIDZ_EXPAND"};
int col_widths[ZPOOL_WAIT_NUM_ACTIVITIES];
/* Calculate the width of each column */
col_widths[i] = MAX(strlen(headers[i]), 6) + 2;
}
+ if (timestamp_fmt != NODATE)
+ print_timestamp(timestamp_fmt);
+
/* Print header if appropriate */
int term_height = terminal_height();
boolean_t reprint_header = (!wd->wd_headers_once && term_height > 0 &&
vdev_activity_top_remaining(nvroot);
}
+ (void) nvlist_lookup_uint64_array(nvroot,
+ ZPOOL_CONFIG_RAIDZ_EXPAND_STATS, (uint64_t **)&pres, &c);
+ if (pres != NULL && pres->pres_state == DSS_SCANNING) {
+ int64_t rem = pres->pres_to_reflow - pres->pres_reflowed;
+ bytes_rem[ZPOOL_WAIT_RAIDZ_EXPAND] = rem;
+ }
+
bytes_rem[ZPOOL_WAIT_INITIALIZE] =
vdev_activity_remaining(nvroot, ZPOOL_WAIT_INITIALIZE);
bytes_rem[ZPOOL_WAIT_TRIM] =
if (vdev_any_spare_replacing(nvroot))
bytes_rem[ZPOOL_WAIT_REPLACE] = bytes_rem[ZPOOL_WAIT_RESILVER];
- if (timestamp_fmt != NODATE)
- print_timestamp(timestamp_fmt);
-
for (i = 0; i < ZPOOL_WAIT_NUM_ACTIVITIES; i++) {
char buf[64];
if (!wd->wd_enabled[i])
continue;
- if (wd->wd_exact)
+ if (wd->wd_exact) {
(void) snprintf(buf, sizeof (buf), "%" PRIi64,
bytes_rem[i]);
- else
+ } else {
zfs_nicenum(bytes_rem[i], buf, sizeof (buf));
+ }
if (wd->wd_scripted)
(void) printf(i == 0 ? "%s" : "\t%s", buf);
for (char *tok; (tok = strsep(&optarg, ",")); ) {
static const char *const col_opts[] = {
"discard", "free", "initialize", "replace",
- "remove", "resilver", "scrub", "trim" };
+ "remove", "resilver", "scrub", "trim",
+ "raidz_expand" };
for (i = 0; i < ARRAY_SIZE(col_opts); ++i)
if (strcmp(tok, col_opts[i]) == 0) {
return (zfs_version_print() != 0);
}
+/* Display documentation */
+static int
+zpool_do_help(int argc, char **argv)
+{
+ char page[MAXNAMELEN];
+ if (argc < 3 || strcmp(argv[2], "zpool") == 0)
+ strcpy(page, "zpool");
+ else if (strcmp(argv[2], "concepts") == 0 ||
+ strcmp(argv[2], "props") == 0)
+ snprintf(page, sizeof (page), "zpool%s", argv[2]);
+ else
+ snprintf(page, sizeof (page), "zpool-%s", argv[2]);
+
+ execlp("man", "man", page, NULL);
+
+ fprintf(stderr, "couldn't run man program: %s", strerror(errno));
+ return (-1);
+}
+
/*
* Do zpool_load_compat() and print error message on failure
*/
if ((strcmp(cmdname, "-V") == 0) || (strcmp(cmdname, "--version") == 0))
return (zpool_do_version(argc, argv));
+ /*
+ * Special case 'help'
+ */
+ if (strcmp(cmdname, "help") == 0)
+ return (zpool_do_help(argc, argv));
+
if ((g_zfs = libzfs_init()) == NULL) {
(void) fprintf(stderr, "%s\n", libzfs_error_init(errno));
return (1);