zpool_main.c revision e9103aaee0c546d4644791198c54abb03c89969e
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright (c) 2011 by Delphix. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_create(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_destroy(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_add(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_remove(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_list(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_iostat(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_status(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_online(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_offline(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_clear(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_reguid(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_attach(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_detach(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_replace(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_split(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_scrub(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_import(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_export(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_upgrade(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_history(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_get(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int zpool_do_set(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * These libumem hooks provide a reasonable set of defaults for the allocator's
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * debugging facilities.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwconst char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtypedef enum {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtypedef struct zpool_command {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const char *name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int (*func)(int, char **);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Master command table. Each ZFS command has a name, associated function, and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * usage message. The usage messages need to be internationalized, so we have
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to have a function to return the usage message based on a command index.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * These commands are organized according to how they are displayed in the usage
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * message. An empty command (one with a NULL name) indicates an empty line in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the generic usage message.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic const char *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (idx) {
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States "<new-device>\n"));
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (gettext("\tcreate [-fn] [-o property=value] ... \n"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "\t [-O file-system-property=value] ... \n"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United States case HELP_DESTROY:
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (gettext("\texport [-f] <pool> ...\n"));
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (gettext("\thistory [-il] [<pool>] ...\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "\timport [-o mntopts] [-o property=value] ... \n"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "[-R root] [-F [-n]] -a\n"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "\timport [-o mntopts] [-o property=value] ... \n"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "[-R root] [-F [-n]]\n"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "\t <pool | id> [newpool]\n"));
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "[count]]\n"));
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown return (gettext("\tlist [-H] [-o property[,...]] "
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown "[-T d|u] [pool] ... [interval [count]]\n"));
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown return (gettext("\toffline [-t] <pool> <device> ...\n"));
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "[new-device]\n"));
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (gettext("\tstatus [-vx] [-T d|u] [pool] ... [interval "
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "[count]]\n"));
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego "\tupgrade -v\n"
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego "\tupgrade [-V version] <-a | pool ...>\n"));
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (gettext("\tget <\"all\" | property[,...]> "
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego "<pool> ...\n"));
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego return (gettext("\tset <property=value> <pool> \n"));
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "\t [-o property=value] <pool> <newpool> "
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb "[<device> ...]\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States * Callback routine that will print out a pool property value.
eb1d736b1c19f6abeee90c921a9320b67fedd016afshin salek ardakani - Sun Microsystems - Irvine United Statesprint_prop_cb(int prop, void *cb)
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown (void) fprintf(fp, "\t%-15s ", zpool_prop_to_name(prop));
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross * Display usage message. If we're inside a command, display only the usage for
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross * that command. Otherwise, iterate over the entire command table and display
5fd03bc0f2e00e7ba02316c2e08f45d52aab15dbGordon Ross * a complete usage message.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) fprintf(fp, gettext("usage: zpool command args ...\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw gettext("where 'command' is one of the following:\n\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < NCOMMAND; i++) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) fprintf(fp, "%s", get_usage(current_command->usage));
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright (strcmp(current_command->name, "list") == 0))) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw gettext("\nthe following properties are supported:\n"));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Iterate over all properties */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See comments at end of main().
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwprint_vdev_tree(zpool_handle_t *zhp, const char *name, nvlist_t *nv, int indent,
for (c = 0; c < children; c++) {
&is_log);
B_FALSE);
const char *normnm;
char *strval;
if (poolprop) {
char *poolname;
int ret;
optopt);
argc--;
argv++;
poolname);
if (dryrun) {
&poolnvroot) == 0);
ret = 0;
return (ret);
char *poolname;
int i, ret = 0;
argc--;
argv++;
return (ret);
* bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
char *poolname;
char *propval;
goto errout;
&propval) == 0)
goto errout;
goto errout;
propval++;
goto errout;
goto errout;
propval++;
goto errout;
goto badusage;
optopt);
goto badusage;
goto badusage;
goto badusage;
goto errout;
goto errout;
goto errout;
goto errout;
goto errout;
poolname);
goto errout;
} else if (dirp) {
int count = 0;
count++;
goto errout;
if (dryrun) {
ret = 0;
mountpoint) == 0);
return (ret);
char *pool;
int ret;
optopt);
return (ret);
int ret;
optopt);
ret = 0;
for (i = 0; i < argc; i++) {
if (hardforce) {
return (ret);
int ret;
for (c = 0; c < children; c++)
for (c = 0; c < children; c++)
for (c = 0; c < children; c++)
return (max);
typedef struct spare_cbdata {
static boolean_t
return (B_TRUE);
for (c = 0; c < children; c++)
return (B_TRUE);
return (B_FALSE);
&nvroot) == 0);
char *vname;
char *state;
children = 0;
if (isspare) {
if (!isspare) {
¬present) == 0) {
char *path;
case VDEV_AUX_OPEN_FAILED:
case VDEV_AUX_BAD_GUID_SUM:
case VDEV_AUX_NO_REPLICAS:
case VDEV_AUX_VERSION_NEWER:
case VDEV_AUX_SPARED:
case VDEV_AUX_ERR_EXCEEDED:
case VDEV_AUX_IO_FAILURE:
case VDEV_AUX_BAD_LOG:
case VDEV_AUX_EXTERNAL:
case VDEV_AUX_SPLIT_POOL:
for (c = 0; c < children; c++) {
&islog);
&ishole);
case VDEV_AUX_OPEN_FAILED:
case VDEV_AUX_BAD_GUID_SUM:
case VDEV_AUX_NO_REPLICAS:
case VDEV_AUX_VERSION_NEWER:
case VDEV_AUX_ERR_EXCEEDED:
for (c = 0; c < children; c++) {
&is_log);
if (is_log)
for (c = 0; c < children; c++) {
for (c = 0; c < children; c++) {
&children) != 0)
for (c = 0; c < children; c++) {
char *name;
&is_log);
if (!is_log)
if (verbose)
char *name;
char *msgid;
int reason;
const char *health;
int namewidth;
&name) == 0);
&guid) == 0);
&pool_state) == 0);
&nvroot) == 0);
switch (reason) {
case ZPOOL_STATUS_OFFLINE_DEV:
case ZPOOL_STATUS_BAD_LOG:
case ZPOOL_STATUS_RESILVERING:
switch (reason) {
msgid);
char *name;
&name) == 0);
&hostid) == 0) {
char *hostname;
time_t t;
t = timestamp;
(unsigned long)hostid,
int nsearch = 0;
int err = 0;
char *propval;
char *endptr;
propval++;
goto error;
goto error;
&propval) == 0)
goto error;
errno = 0;
optopt);
if (dryrun)
else if (do_rewind)
if (xtreme_rewind)
goto error;
if (do_all) {
if (argc != 0) {
if (argc != 0) {
char *endptr;
errno = 0;
argv[0]);
argv[0]);
if (argc != 0) {
err = 0;
&pool_state) == 0);
policy) == 0);
if (argc == 0) {
if (first)
else if (!do_all)
if (do_all) {
char *name;
typedef struct iostat_cbdata {
int cb_verbose;
int cb_iteration;
int cb_namewidth;
double scale;
char *vname;
if (tdelta == 0)
&oldchild, &c) != 0)
for (c = 0; c < children; c++) {
&ishole);
&islog);
for (c = 0; c < children; c++) {
if (islog) {
B_FALSE);
&oldchild, &c) != 0)
if (children > 0) {
for (c = 0; c < children; c++) {
B_FALSE);
if (missing)
&newnvroot) == 0);
&oldnvroot) == 0);
&nvroot) == 0);
unsigned long *cnt)
char *end;
errno = 0;
if (interval == 0) {
argc--;
interval = 0;
char *end;
errno = 0;
if (interval == 0) {
argc--;
interval = 0;
get_timestamp_arg(char c)
* creation/destruction as well as vdev configuration changes. The bulk of this
* processing is handled by the pool_list_* routines in zpool_iter.c. We rely
int ret;
int npools;
optopt);
ret = 0;
if (verbose)
if (interval == 0)
return (ret);
typedef struct list_cbdata {
const char *header;
if (!first)
else if (right_justify)
char *propstr;
int width;
if (!first) {
if (scripted)
else if (right_justify)
int ret;
static char default_props[] =
optopt);
if (interval == 0)
return (ret);
static nvlist_t *
char *path;
return (nv);
return (NULL);
for (c = 0; c < children; c++)
return (match);
return (NULL);
int ret;
optopt);
if (!replacing) {
poolname);
return (ret);
int ret;
optopt);
return (ret);
int c, ret = 0;
if (add_prop_list(
if (props)
propval++;
if (props)
optopt);
return (ret);
return (ret);
char *poolname;
int ret = 0;
int flags = 0;
optopt);
argv[i]);
return (ret);
char *poolname;
int ret = 0;
optopt);
return (ret);
int ret = 0;
optopt);
if (dryrun)
else if (do_rewind)
if (xtreme_rewind)
return (ret);
char *poolname;
int ret = 0;
optopt);
return (ret);
typedef struct scrub_cbdata {
int cb_type;
int cb_argc;
char **cb_argv;
int err;
return (err != 0);
optopt);
typedef struct status_cbdata {
int cb_count;
double fraction_done;
char *fmt;
char *pathname;
&dsobj) == 0);
&obj) == 0);
int namewidth)
uint_t i;
char *name;
if (nspares == 0)
for (i = 0; i < nspares; i++) {
int namewidth)
uint_t i;
char *name;
if (nl2cache == 0)
for (i = 0; i < nl2cache; i++) {
uint_t c;
char *msgid;
int reason;
const char *health;
uint_t c;
&nvroot) == 0);
switch (reason) {
case ZPOOL_STATUS_FAILING_DEV:
case ZPOOL_STATUS_OFFLINE_DEV:
case ZPOOL_STATUS_REMOVED_DEV:
case ZPOOL_STATUS_RESILVERING:
case ZPOOL_STATUS_BAD_LOG:
msgid);
int namewidth;
&nerr) == 0) {
nerr = 0;
nerr++;
if (nerr == 0)
int ret;
optopt);
if (argc == 0)
if (ret != 0)
return (ret);
if (interval == 0)
typedef struct upgrade_cbdata {
int cb_all;
int cb_first;
int cb_newer;
int cb_argc;
char **cb_argv;
int ret = 0;
&version) == 0);
if (!ret) {
return (ret);
int ret;
if (!ret) {
return (ret != 0);
int ret = 0;
char *end;
optopt);
if (showversions) {
if (argc != 0) {
if (showversions) {
} else if (argc == 0) {
int notfound;
if (ret == 0) {
if (notfound)
return (ret);
typedef struct hist_cbdata {
int longfmt;
int internal;
char *cmdstr;
char *pathstr;
struct tm t;
int ret, i;
char *hostname;
char *zonename;
return (ret);
for (i = 0; i < numrecords; i++) {
&dst_time) != 0)
&cmdstr) != 0) {
sizeof (internalstr),
pathstr);
if (pwd)
(int)who);
return (ret);
int ret;
optopt);
&cbdata);
return (ret);
NULL);
int ret;
ZFS_TYPE_POOL) != 0)
return (ret);
typedef struct set_cbdata {
char *cb_propname;
char *cb_value;
} set_cbdata_t;
int error;
if (!error)
return (error);
int error;
return (error);
for (i = 0; i < NCOMMAND; i++) {
*idx = i;
int ret;
char *cmdname;
opterr = 0;
abort();
return (ret);