zpool_main.c revision 9edf9ebd727ac2046be0269a5e275785e2131bcb
4b22b9337f359bfd063322244f5336cc7c6ffcfars * CDDL HEADER START
4b22b9337f359bfd063322244f5336cc7c6ffcfars * The contents of this file are subject to the terms of the
4b22b9337f359bfd063322244f5336cc7c6ffcfars * Common Development and Distribution License (the "License").
4b22b9337f359bfd063322244f5336cc7c6ffcfars * You may not use this file except in compliance with the License.
4b22b9337f359bfd063322244f5336cc7c6ffcfars * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4b22b9337f359bfd063322244f5336cc7c6ffcfars * See the License for the specific language governing permissions
4b22b9337f359bfd063322244f5336cc7c6ffcfars * and limitations under the License.
4b22b9337f359bfd063322244f5336cc7c6ffcfars * When distributing Covered Code, include this CDDL HEADER in each
4b22b9337f359bfd063322244f5336cc7c6ffcfars * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4b22b9337f359bfd063322244f5336cc7c6ffcfars * If applicable, add the following below this CDDL HEADER, with the
4b22b9337f359bfd063322244f5336cc7c6ffcfars * fields enclosed by brackets "[]" replaced with your own identifying
4b22b9337f359bfd063322244f5336cc7c6ffcfars * information: Portions Copyright [yyyy] [name of copyright owner]
4b22b9337f359bfd063322244f5336cc7c6ffcfars * CDDL HEADER END
4b22b9337f359bfd063322244f5336cc7c6ffcfars * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * Copyright (c) 2012 by Delphix. All rights reserved.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * Copyright (c) 2012 by Frederik Wessels. All rights reserved.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami * Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_create(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_destroy(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_add(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_remove(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_list(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_iostat(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_status(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_online(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_offline(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_clear(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_reopen(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_reguid(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_attach(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_detach(int, char **);
4b22b9337f359bfd063322244f5336cc7c6ffcfarsstatic int zpool_do_replace(int, char **);
static int zpool_do_split(int, char **);
static int zpool_do_scrub(int, char **);
static int zpool_do_import(int, char **);
static int zpool_do_export(int, char **);
static int zpool_do_upgrade(int, char **);
static int zpool_do_history(int, char **);
static int zpool_do_get(int, char **);
static int zpool_do_set(int, char **);
#ifdef DEBUG
_umem_debug_init(void)
_umem_logging_init(void)
} zpool_help_t;
typedef struct zpool_command {
const char *name;
int (*func)(int, char **);
{ NULL },
{ NULL },
{ NULL },
{ NULL },
{ NULL },
{ NULL },
{ NULL },
switch (idx) {
case HELP_ADD:
case HELP_ATTACH:
case HELP_CLEAR:
case HELP_CREATE:
case HELP_DESTROY:
case HELP_DETACH:
case HELP_EXPORT:
case HELP_HISTORY:
case HELP_IMPORT:
case HELP_IOSTAT:
case HELP_LIST:
case HELP_OFFLINE:
case HELP_ONLINE:
case HELP_REPLACE:
case HELP_REMOVE:
case HELP_REOPEN:
case HELP_SCRUB:
case HELP_STATUS:
case HELP_UPGRADE:
case HELP_GET:
case HELP_SET:
case HELP_SPLIT:
case HELP_REGUID:
abort();
return (ZPROP_CONT);
for (i = 0; i < NCOMMAND; i++) {
abort();
char *vname;
for (c = 0; c < children; c++) {
&is_log);
B_FALSE);
static boolean_t
return (B_TRUE);
return (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;
char *end;
goto errout;
propval++;
B_FALSE)) {
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 (ret != 0)
goto errout;
if (dryrun) {
ret = 0;
if (enable_all_pool_feat) {
for (i = 0; i < SPA_FEATURES; i++) {
if (ret != 0)
goto errout;
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_UNSUP_FEAT:
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_UNSUP_FEAT:
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;
char *comment;
&name) == 0);
&guid) == 0);
&pool_state) == 0);
&nvroot) == 0);
switch (reason) {
(void) printf(
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;
searchguid = 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_namewidth;
int cb_iteration;
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 {
int cb_namewidth;
const char *header;
if (!first)
else if (right_justify)
char *propstr;
if (!first) {
sizeof (property)) == 0) {
else if (right_justify)
if (scripted)
char *vname;
if (scripted)
if (scripted)
scripted);
scripted);
scripted);
for (c = 0; c < children; c++) {
if (children > 0) {
for (c = 0; c < children; c++) {
B_FALSE);
&nvroot) == 0);
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);
int ret = 0;
char *pool;
optopt);
argc--;
argv++;
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_first;
int cb_argc;
char **cb_argv;
int ret;
&oldversion) == 0);
if (ret != 0)
return (ret);
count = 0;
for (i = 0; i < SPA_FEATURES; i++) {
char *propname;
if (ret != 0) {
return (ret);
count++;
if (firstff) {
int ret;
&version) == 0);
if (ret != 0)
return (ret);
int count;
if (ret != 0)
return (ret);
if (count > 0) {
if (printnl) {
&version) == 0);
&version) == 0);
for (i = 0; i < SPA_FEATURES; i++) {
if (poolfirst) {
int ret;
if (ret != 0)
return (ret);
int count = 0;
if (ret != 0)
return (ret);
if (count != 0) {
if (printnl) {
int ret = 0;
char *end;
optopt);
if (showversions) {
} else if (upgradeall) {
if (argc != 0) {
if (showversions) {
for (i = 0; i < SPA_FEATURES; i++) {
} else if (argc == 0) {
return (ret);
typedef struct hist_cbdata {
int ret, i;
return (ret);
for (i = 0; i < numrecords; i++) {
struct tm t;
int ievent =
tbuf);
return (ret);
int ret;
optopt);
&cbdata);
return (ret);
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);