2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* 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]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2012-04-24 11:59:56 +00:00
|
|
|
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
|
2014-07-15 18:58:41 +00:00
|
|
|
* Copyright (c) 2011, 2014 by Delphix. All rights reserved.
|
2012-04-24 11:59:56 +00:00
|
|
|
* Copyright (c) 2012 by Frederik Wessels. All rights reserved.
|
2012-11-06 12:39:00 +00:00
|
|
|
* Copyright (c) 2012 by Cyril Plisko. All rights reserved.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <libintl.h>
|
|
|
|
#include <libuutil.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <priv.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <zone.h>
|
2012-01-24 02:43:32 +00:00
|
|
|
#include <zfs_prop.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
#include <sys/stat.h>
|
2010-08-26 18:42:43 +00:00
|
|
|
#include <sys/fm/util.h>
|
|
|
|
#include <sys/fm/protocol.h>
|
2014-02-12 18:30:18 +00:00
|
|
|
#include <sys/zfs_ioctl.h>
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
#include <libzfs.h>
|
|
|
|
|
|
|
|
#include "zpool_util.h"
|
|
|
|
#include "zfs_comutil.h"
|
2012-12-13 23:24:15 +00:00
|
|
|
#include "zfeature_common.h"
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
#include "statcommon.h"
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
static int zpool_do_create(int, char **);
|
|
|
|
static int zpool_do_destroy(int, char **);
|
|
|
|
|
|
|
|
static int zpool_do_add(int, char **);
|
|
|
|
static int zpool_do_remove(int, char **);
|
2013-07-05 11:01:44 +00:00
|
|
|
static int zpool_do_labelclear(int, char **);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
static int zpool_do_list(int, char **);
|
|
|
|
static int zpool_do_iostat(int, char **);
|
|
|
|
static int zpool_do_status(int, char **);
|
|
|
|
|
|
|
|
static int zpool_do_online(int, char **);
|
|
|
|
static int zpool_do_offline(int, char **);
|
|
|
|
static int zpool_do_clear(int, char **);
|
2012-01-24 02:43:32 +00:00
|
|
|
static int zpool_do_reopen(int, char **);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-11-11 22:07:54 +00:00
|
|
|
static int zpool_do_reguid(int, char **);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
static int zpool_do_attach(int, char **);
|
|
|
|
static int zpool_do_detach(int, char **);
|
|
|
|
static int zpool_do_replace(int, char **);
|
2010-05-28 20:45:14 +00:00
|
|
|
static int zpool_do_split(int, char **);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
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 **);
|
2010-08-26 18:42:43 +00:00
|
|
|
static int zpool_do_events(int, char **);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
static int zpool_do_get(int, char **);
|
|
|
|
static int zpool_do_set(int, char **);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These libumem hooks provide a reasonable set of defaults for the allocator's
|
|
|
|
* debugging facilities.
|
|
|
|
*/
|
2008-12-03 20:09:06 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2008-11-20 20:01:55 +00:00
|
|
|
const char *
|
|
|
|
_umem_debug_init(void)
|
|
|
|
{
|
|
|
|
return ("default,verbose"); /* $UMEM_DEBUG setting */
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
_umem_logging_init(void)
|
|
|
|
{
|
|
|
|
return ("fail,contents"); /* $UMEM_LOGGING setting */
|
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
#endif
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
HELP_ADD,
|
|
|
|
HELP_ATTACH,
|
|
|
|
HELP_CLEAR,
|
|
|
|
HELP_CREATE,
|
|
|
|
HELP_DESTROY,
|
|
|
|
HELP_DETACH,
|
|
|
|
HELP_EXPORT,
|
|
|
|
HELP_HISTORY,
|
|
|
|
HELP_IMPORT,
|
|
|
|
HELP_IOSTAT,
|
2013-07-05 11:01:44 +00:00
|
|
|
HELP_LABELCLEAR,
|
2008-11-20 20:01:55 +00:00
|
|
|
HELP_LIST,
|
|
|
|
HELP_OFFLINE,
|
|
|
|
HELP_ONLINE,
|
|
|
|
HELP_REPLACE,
|
|
|
|
HELP_REMOVE,
|
|
|
|
HELP_SCRUB,
|
|
|
|
HELP_STATUS,
|
|
|
|
HELP_UPGRADE,
|
2010-08-26 18:42:43 +00:00
|
|
|
HELP_EVENTS,
|
2008-11-20 20:01:55 +00:00
|
|
|
HELP_GET,
|
2010-05-28 20:45:14 +00:00
|
|
|
HELP_SET,
|
2011-11-11 22:07:54 +00:00
|
|
|
HELP_SPLIT,
|
2012-01-24 02:43:32 +00:00
|
|
|
HELP_REGUID,
|
|
|
|
HELP_REOPEN
|
2008-11-20 20:01:55 +00:00
|
|
|
} zpool_help_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct zpool_command {
|
|
|
|
const char *name;
|
|
|
|
int (*func)(int, char **);
|
|
|
|
zpool_help_t usage;
|
|
|
|
} zpool_command_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Master command table. Each ZFS command has a name, associated function, and
|
|
|
|
* usage message. The usage messages need to be internationalized, so we have
|
|
|
|
* to have a function to return the usage message based on a command index.
|
|
|
|
*
|
|
|
|
* These commands are organized according to how they are displayed in the usage
|
|
|
|
* message. An empty command (one with a NULL name) indicates an empty line in
|
|
|
|
* the generic usage message.
|
|
|
|
*/
|
|
|
|
static zpool_command_t command_table[] = {
|
|
|
|
{ "create", zpool_do_create, HELP_CREATE },
|
|
|
|
{ "destroy", zpool_do_destroy, HELP_DESTROY },
|
|
|
|
{ NULL },
|
|
|
|
{ "add", zpool_do_add, HELP_ADD },
|
|
|
|
{ "remove", zpool_do_remove, HELP_REMOVE },
|
|
|
|
{ NULL },
|
2013-07-05 11:01:44 +00:00
|
|
|
{ "labelclear", zpool_do_labelclear, HELP_LABELCLEAR },
|
|
|
|
{ NULL },
|
2008-11-20 20:01:55 +00:00
|
|
|
{ "list", zpool_do_list, HELP_LIST },
|
|
|
|
{ "iostat", zpool_do_iostat, HELP_IOSTAT },
|
|
|
|
{ "status", zpool_do_status, HELP_STATUS },
|
|
|
|
{ NULL },
|
|
|
|
{ "online", zpool_do_online, HELP_ONLINE },
|
|
|
|
{ "offline", zpool_do_offline, HELP_OFFLINE },
|
|
|
|
{ "clear", zpool_do_clear, HELP_CLEAR },
|
2012-01-24 02:43:32 +00:00
|
|
|
{ "reopen", zpool_do_reopen, HELP_REOPEN },
|
2008-11-20 20:01:55 +00:00
|
|
|
{ NULL },
|
|
|
|
{ "attach", zpool_do_attach, HELP_ATTACH },
|
|
|
|
{ "detach", zpool_do_detach, HELP_DETACH },
|
|
|
|
{ "replace", zpool_do_replace, HELP_REPLACE },
|
2010-05-28 20:45:14 +00:00
|
|
|
{ "split", zpool_do_split, HELP_SPLIT },
|
2008-11-20 20:01:55 +00:00
|
|
|
{ NULL },
|
|
|
|
{ "scrub", zpool_do_scrub, HELP_SCRUB },
|
|
|
|
{ NULL },
|
|
|
|
{ "import", zpool_do_import, HELP_IMPORT },
|
|
|
|
{ "export", zpool_do_export, HELP_EXPORT },
|
|
|
|
{ "upgrade", zpool_do_upgrade, HELP_UPGRADE },
|
2011-11-11 22:07:54 +00:00
|
|
|
{ "reguid", zpool_do_reguid, HELP_REGUID },
|
2008-11-20 20:01:55 +00:00
|
|
|
{ NULL },
|
|
|
|
{ "history", zpool_do_history, HELP_HISTORY },
|
2010-08-26 18:42:43 +00:00
|
|
|
{ "events", zpool_do_events, HELP_EVENTS },
|
|
|
|
{ NULL },
|
2008-11-20 20:01:55 +00:00
|
|
|
{ "get", zpool_do_get, HELP_GET },
|
|
|
|
{ "set", zpool_do_set, HELP_SET },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
|
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
static zpool_command_t *current_command;
|
2008-11-20 20:01:55 +00:00
|
|
|
static char history_str[HIS_MAX_RECORD_LEN];
|
2013-08-28 11:45:09 +00:00
|
|
|
static boolean_t log_history = B_TRUE;
|
2010-05-28 20:45:14 +00:00
|
|
|
static uint_t timestamp_fmt = NODATE;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
static const char *
|
|
|
|
get_usage(zpool_help_t idx) {
|
|
|
|
switch (idx) {
|
|
|
|
case HELP_ADD:
|
2012-11-06 12:39:00 +00:00
|
|
|
return (gettext("\tadd [-fn] [-o property=value] "
|
|
|
|
"<pool> <vdev> ...\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_ATTACH:
|
2012-11-06 12:39:00 +00:00
|
|
|
return (gettext("\tattach [-f] [-o property=value] "
|
|
|
|
"<pool> <device> <new-device>\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_CLEAR:
|
2010-05-28 20:45:14 +00:00
|
|
|
return (gettext("\tclear [-nF] <pool> [device]\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_CREATE:
|
2012-12-13 23:24:15 +00:00
|
|
|
return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
|
2008-12-03 20:09:06 +00:00
|
|
|
"\t [-O file-system-property=value] ... \n"
|
2008-11-20 20:01:55 +00:00
|
|
|
"\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
|
|
|
|
case HELP_DESTROY:
|
|
|
|
return (gettext("\tdestroy [-f] <pool>\n"));
|
|
|
|
case HELP_DETACH:
|
|
|
|
return (gettext("\tdetach <pool> <device>\n"));
|
|
|
|
case HELP_EXPORT:
|
|
|
|
return (gettext("\texport [-f] <pool> ...\n"));
|
|
|
|
case HELP_HISTORY:
|
|
|
|
return (gettext("\thistory [-il] [<pool>] ...\n"));
|
|
|
|
case HELP_IMPORT:
|
|
|
|
return (gettext("\timport [-d dir] [-D]\n"
|
2010-08-26 21:24:34 +00:00
|
|
|
"\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
|
2008-11-20 20:01:55 +00:00
|
|
|
"\timport [-o mntopts] [-o property=value] ... \n"
|
2010-08-26 21:24:34 +00:00
|
|
|
"\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
|
|
|
|
"[-R root] [-F [-n]] -a\n"
|
2008-11-20 20:01:55 +00:00
|
|
|
"\timport [-o mntopts] [-o property=value] ... \n"
|
2010-08-26 21:24:34 +00:00
|
|
|
"\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
|
|
|
|
"[-R root] [-F [-n]]\n"
|
|
|
|
"\t <pool | id> [newpool]\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_IOSTAT:
|
2010-05-28 20:45:14 +00:00
|
|
|
return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
|
2008-11-20 20:01:55 +00:00
|
|
|
"[count]]\n"));
|
2013-07-05 11:01:44 +00:00
|
|
|
case HELP_LABELCLEAR:
|
|
|
|
return (gettext("\tlabelclear [-f] <vdev>\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_LIST:
|
2013-07-20 22:04:33 +00:00
|
|
|
return (gettext("\tlist [-Hv] [-o property[,...]] "
|
2010-05-28 20:45:14 +00:00
|
|
|
"[-T d|u] [pool] ... [interval [count]]\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_OFFLINE:
|
|
|
|
return (gettext("\toffline [-t] <pool> <device> ...\n"));
|
|
|
|
case HELP_ONLINE:
|
|
|
|
return (gettext("\tonline <pool> <device> ...\n"));
|
|
|
|
case HELP_REPLACE:
|
2014-06-25 11:59:32 +00:00
|
|
|
return (gettext("\treplace [-f] [-o property=value] "
|
|
|
|
"<pool> <device> [new-device]\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_REMOVE:
|
|
|
|
return (gettext("\tremove <pool> <device> ...\n"));
|
2012-01-24 02:43:32 +00:00
|
|
|
case HELP_REOPEN:
|
2013-05-02 23:36:32 +00:00
|
|
|
return (gettext("\treopen <pool>\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_SCRUB:
|
|
|
|
return (gettext("\tscrub [-s] <pool> ...\n"));
|
|
|
|
case HELP_STATUS:
|
2013-10-13 16:36:15 +00:00
|
|
|
return (gettext("\tstatus [-vxD] [-T d|u] [pool] ... [interval "
|
2010-05-28 20:45:14 +00:00
|
|
|
"[count]]\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_UPGRADE:
|
|
|
|
return (gettext("\tupgrade\n"
|
|
|
|
"\tupgrade -v\n"
|
|
|
|
"\tupgrade [-V version] <-a | pool ...>\n"));
|
2010-08-26 18:42:43 +00:00
|
|
|
case HELP_EVENTS:
|
2010-09-28 23:30:54 +00:00
|
|
|
return (gettext("\tevents [-vHfc]\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
case HELP_GET:
|
2014-07-23 10:14:09 +00:00
|
|
|
return (gettext("\tget [-pH] <\"all\" | property[,...]> "
|
2008-11-20 20:01:55 +00:00
|
|
|
"<pool> ...\n"));
|
|
|
|
case HELP_SET:
|
|
|
|
return (gettext("\tset <property=value> <pool> \n"));
|
2010-05-28 20:45:14 +00:00
|
|
|
case HELP_SPLIT:
|
|
|
|
return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
|
|
|
|
"\t [-o property=value] <pool> <newpool> "
|
|
|
|
"[<device> ...]\n"));
|
2011-11-11 22:07:54 +00:00
|
|
|
case HELP_REGUID:
|
|
|
|
return (gettext("\treguid <pool>\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
abort();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback routine that will print out a pool property value.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
print_prop_cb(int prop, void *cb)
|
|
|
|
{
|
|
|
|
FILE *fp = cb;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) fprintf(fp, "\t%-15s ", zpool_prop_to_name(prop));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (zpool_prop_readonly(prop))
|
|
|
|
(void) fprintf(fp, " NO ");
|
|
|
|
else
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) fprintf(fp, " YES ");
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (zpool_prop_values(prop) == NULL)
|
|
|
|
(void) fprintf(fp, "-\n");
|
|
|
|
else
|
|
|
|
(void) fprintf(fp, "%s\n", zpool_prop_values(prop));
|
|
|
|
|
|
|
|
return (ZPROP_CONT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* a complete usage message.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
usage(boolean_t requested)
|
|
|
|
{
|
|
|
|
FILE *fp = requested ? stdout : stderr;
|
|
|
|
|
|
|
|
if (current_command == NULL) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
(void) fprintf(fp, gettext("usage: zpool command args ...\n"));
|
|
|
|
(void) fprintf(fp,
|
|
|
|
gettext("where 'command' is one of the following:\n\n"));
|
|
|
|
|
|
|
|
for (i = 0; i < NCOMMAND; i++) {
|
|
|
|
if (command_table[i].name == NULL)
|
|
|
|
(void) fprintf(fp, "\n");
|
|
|
|
else
|
|
|
|
(void) fprintf(fp, "%s",
|
|
|
|
get_usage(command_table[i].usage));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
(void) fprintf(fp, gettext("usage:\n"));
|
|
|
|
(void) fprintf(fp, "%s", get_usage(current_command->usage));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_command != NULL &&
|
|
|
|
((strcmp(current_command->name, "set") == 0) ||
|
|
|
|
(strcmp(current_command->name, "get") == 0) ||
|
|
|
|
(strcmp(current_command->name, "list") == 0))) {
|
|
|
|
|
|
|
|
(void) fprintf(fp,
|
|
|
|
gettext("\nthe following properties are supported:\n"));
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) fprintf(fp, "\n\t%-15s %s %s\n\n",
|
2008-11-20 20:01:55 +00:00
|
|
|
"PROPERTY", "EDIT", "VALUES");
|
|
|
|
|
|
|
|
/* Iterate over all properties */
|
|
|
|
(void) zprop_iter(print_prop_cb, fp, B_FALSE, B_TRUE,
|
|
|
|
ZFS_TYPE_POOL);
|
2012-12-13 23:24:15 +00:00
|
|
|
|
|
|
|
(void) fprintf(fp, "\t%-15s ", "feature@...");
|
|
|
|
(void) fprintf(fp, "YES disabled | enabled | active\n");
|
|
|
|
|
|
|
|
(void) fprintf(fp, gettext("\nThe feature@ properties must be "
|
|
|
|
"appended with a feature name.\nSee zpool-features(5).\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See comments at end of main().
|
|
|
|
*/
|
|
|
|
if (getenv("ZFS_ABORT") != NULL) {
|
|
|
|
(void) printf("dumping core by request\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(requested ? 0 : 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_vdev_tree(zpool_handle_t *zhp, const char *name, nvlist_t *nv, int indent,
|
|
|
|
boolean_t print_logs)
|
|
|
|
{
|
|
|
|
nvlist_t **child;
|
|
|
|
uint_t c, children;
|
|
|
|
char *vname;
|
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
(void) printf("\t%*s%s\n", indent, "", name);
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&child, &children) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
|
|
|
uint64_t is_log = B_FALSE;
|
|
|
|
|
|
|
|
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
|
|
|
|
&is_log);
|
|
|
|
if ((is_log && !print_logs) || (!is_log && print_logs))
|
|
|
|
continue;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
print_vdev_tree(zhp, vname, child[c], indent + 2,
|
|
|
|
B_FALSE);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
static boolean_t
|
|
|
|
prop_list_contains_feature(nvlist_t *proplist)
|
|
|
|
{
|
|
|
|
nvpair_t *nvp;
|
|
|
|
for (nvp = nvlist_next_nvpair(proplist, NULL); NULL != nvp;
|
|
|
|
nvp = nvlist_next_nvpair(proplist, nvp)) {
|
|
|
|
if (zpool_prop_feature(nvpair_name(nvp)))
|
|
|
|
return (B_TRUE);
|
|
|
|
}
|
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Add a property pair (name, string-value) into a property nvlist.
|
|
|
|
*/
|
|
|
|
static int
|
2008-12-03 20:09:06 +00:00
|
|
|
add_prop_list(const char *propname, char *propval, nvlist_t **props,
|
|
|
|
boolean_t poolprop)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2008-12-03 20:09:06 +00:00
|
|
|
zpool_prop_t prop = ZPROP_INVAL;
|
|
|
|
zfs_prop_t fprop;
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_t *proplist;
|
2008-12-03 20:09:06 +00:00
|
|
|
const char *normnm;
|
|
|
|
char *strval;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (*props == NULL &&
|
|
|
|
nvlist_alloc(props, NV_UNIQUE_NAME, 0) != 0) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("internal error: out of memory\n"));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
proplist = *props;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (poolprop) {
|
2012-12-14 23:00:45 +00:00
|
|
|
const char *vname = zpool_prop_to_name(ZPOOL_PROP_VERSION);
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL &&
|
|
|
|
!zpool_prop_feature(propname)) {
|
2008-12-03 20:09:06 +00:00
|
|
|
(void) fprintf(stderr, gettext("property '%s' is "
|
|
|
|
"not a valid pool property\n"), propname);
|
|
|
|
return (2);
|
|
|
|
}
|
2012-12-14 23:00:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* feature@ properties and version should not be specified
|
|
|
|
* at the same time.
|
|
|
|
*/
|
|
|
|
if ((prop == ZPROP_INVAL && zpool_prop_feature(propname) &&
|
|
|
|
nvlist_exists(proplist, vname)) ||
|
|
|
|
(prop == ZPOOL_PROP_VERSION &&
|
|
|
|
prop_list_contains_feature(proplist))) {
|
|
|
|
(void) fprintf(stderr, gettext("'feature@' and "
|
|
|
|
"'version' properties cannot be specified "
|
|
|
|
"together\n"));
|
|
|
|
return (2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
if (zpool_prop_feature(propname))
|
|
|
|
normnm = propname;
|
|
|
|
else
|
|
|
|
normnm = zpool_prop_to_name(prop);
|
2008-12-03 20:09:06 +00:00
|
|
|
} else {
|
2009-07-02 22:44:48 +00:00
|
|
|
if ((fprop = zfs_name_to_prop(propname)) != ZPROP_INVAL) {
|
|
|
|
normnm = zfs_prop_to_name(fprop);
|
|
|
|
} else {
|
|
|
|
normnm = propname;
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (nvlist_lookup_string(proplist, normnm, &strval) == 0 &&
|
|
|
|
prop != ZPOOL_PROP_CACHEFILE) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr, gettext("property '%s' "
|
|
|
|
"specified multiple times\n"), propname);
|
|
|
|
return (2);
|
|
|
|
}
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (nvlist_add_string(proplist, normnm, propval) != 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr, gettext("internal "
|
|
|
|
"error: out of memory\n"));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-11-06 12:39:00 +00:00
|
|
|
* zpool add [-fn] [-o property=value] <pool> <vdev> ...
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* -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.
|
2012-11-06 12:39:00 +00:00
|
|
|
* -o Set property=value.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* libzfs.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_add(int argc, char **argv)
|
|
|
|
{
|
|
|
|
boolean_t force = B_FALSE;
|
|
|
|
boolean_t dryrun = B_FALSE;
|
|
|
|
int c;
|
|
|
|
nvlist_t *nvroot;
|
|
|
|
char *poolname;
|
|
|
|
int ret;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
nvlist_t *config;
|
2012-11-06 12:39:00 +00:00
|
|
|
nvlist_t *props = NULL;
|
|
|
|
char *propval;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* check options */
|
2012-11-06 12:39:00 +00:00
|
|
|
while ((c = getopt(argc, argv, "fno:")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
force = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
dryrun = B_TRUE;
|
|
|
|
break;
|
2012-11-06 12:39:00 +00:00
|
|
|
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;
|
2008-11-20 20:01:55 +00:00
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("missing vdev specification\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
|
|
|
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if ((config = zpool_get_config(zhp, NULL)) == NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
|
|
|
|
poolname);
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pass off to get_vdev_spec for processing */
|
2012-11-06 12:39:00 +00:00
|
|
|
nvroot = make_root_vdev(zhp, props, force, !force, B_FALSE, dryrun,
|
2008-12-03 20:09:06 +00:00
|
|
|
argc, argv);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (nvroot == NULL) {
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dryrun) {
|
|
|
|
nvlist_t *poolnvroot;
|
|
|
|
|
|
|
|
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&poolnvroot) == 0);
|
|
|
|
|
|
|
|
(void) printf(gettext("would update '%s' to the following "
|
|
|
|
"configuration:\n"), zpool_get_name(zhp));
|
|
|
|
|
|
|
|
/* print original main pool and new tree */
|
|
|
|
print_vdev_tree(zhp, poolname, poolnvroot, 0, B_FALSE);
|
|
|
|
print_vdev_tree(zhp, NULL, nvroot, 0, B_FALSE);
|
|
|
|
|
|
|
|
/* Do the same for the logs */
|
|
|
|
if (num_logs(poolnvroot) > 0) {
|
|
|
|
print_vdev_tree(zhp, "logs", poolnvroot, 0, B_TRUE);
|
|
|
|
print_vdev_tree(zhp, NULL, nvroot, 0, B_TRUE);
|
|
|
|
} else if (num_logs(nvroot) > 0) {
|
|
|
|
print_vdev_tree(zhp, "logs", nvroot, 0, B_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
ret = (zpool_add(zhp, nvroot) != 0);
|
|
|
|
}
|
|
|
|
|
2012-11-06 12:39:00 +00:00
|
|
|
nvlist_free(props);
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_free(nvroot);
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* zpool remove <pool> <vdev> ...
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Removes the given vdev from the pool. Currently, this supports removing
|
|
|
|
* spares, cache, and log devices from the pool.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_remove(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *poolname;
|
|
|
|
int i, ret = 0;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("missing device\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
|
|
|
|
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (zpool_vdev_remove(zhp, argv[i]) != 0)
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2013-07-05 11:01:44 +00:00
|
|
|
/*
|
|
|
|
* zpool labelclear <vdev>
|
|
|
|
*
|
|
|
|
* Verifies that the vdev is not active and zeros out the label information
|
|
|
|
* on the device.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_labelclear(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *vdev, *name;
|
|
|
|
int c, fd = -1, ret = 0;
|
|
|
|
pool_state_t state;
|
|
|
|
boolean_t inuse = B_FALSE;
|
|
|
|
boolean_t force = B_FALSE;
|
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "f")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
force = B_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get vdev name */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing vdev device name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
vdev = argv[0];
|
|
|
|
if ((fd = open(vdev, O_RDWR)) < 0) {
|
|
|
|
(void) fprintf(stderr, gettext("Unable to open %s\n"), vdev);
|
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
name = NULL;
|
|
|
|
if (zpool_in_use(g_zfs, fd, &state, &name, &inuse) != 0) {
|
|
|
|
if (force)
|
|
|
|
goto wipe_label;
|
|
|
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("Unable to determine pool state for %s\n"
|
|
|
|
"Use -f to force the clearing any label data\n"), vdev);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inuse) {
|
|
|
|
switch (state) {
|
|
|
|
default:
|
|
|
|
case POOL_STATE_ACTIVE:
|
|
|
|
case POOL_STATE_SPARE:
|
|
|
|
case POOL_STATE_L2CACHE:
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("labelclear operation failed.\n"
|
|
|
|
"\tVdev %s is a member (%s), of pool \"%s\".\n"
|
|
|
|
"\tTo remove label information from this device, "
|
|
|
|
"export or destroy\n\tthe pool, or remove %s from "
|
|
|
|
"the configuration of this pool\n\tand retry the "
|
|
|
|
"labelclear operation.\n"),
|
|
|
|
vdev, zpool_pool_state_to_name(state), name, vdev);
|
|
|
|
ret = 1;
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
case POOL_STATE_EXPORTED:
|
|
|
|
if (force)
|
|
|
|
break;
|
|
|
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("labelclear operation failed.\n\tVdev "
|
|
|
|
"%s is a member of the exported pool \"%s\".\n"
|
|
|
|
"\tUse \"zpool labelclear -f %s\" to force the "
|
|
|
|
"removal of label\n\tinformation.\n"),
|
|
|
|
vdev, name, vdev);
|
|
|
|
ret = 1;
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
case POOL_STATE_POTENTIALLY_ACTIVE:
|
|
|
|
if (force)
|
|
|
|
break;
|
|
|
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("labelclear operation failed.\n"
|
|
|
|
"\tVdev %s is a member of the pool \"%s\".\n"
|
|
|
|
"\tThis pool is unknown to this system, but may "
|
|
|
|
"be active on\n\tanother system. Use "
|
|
|
|
"\'zpool labelclear -f %s\' to force the\n"
|
|
|
|
"\tremoval of label information.\n"),
|
|
|
|
vdev, name, vdev);
|
|
|
|
ret = 1;
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
case POOL_STATE_DESTROYED:
|
|
|
|
/* inuse should never be set for a destroyed pool... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wipe_label:
|
|
|
|
if (zpool_clear_label(fd) != 0) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("Label clear failed on vdev %s\n"), vdev);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
errout:
|
|
|
|
close(fd);
|
|
|
|
if (name != NULL)
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
2012-12-13 23:24:15 +00:00
|
|
|
* zpool create [-fnd] [-o property=value] ...
|
2008-12-03 20:09:06 +00:00
|
|
|
* [-O file-system-property=value] ...
|
|
|
|
* [-R root] [-m mountpoint] <pool> <dev> ...
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* -f Force creation, even if devices appear in use
|
|
|
|
* -n Do not create the pool, but display the resulting layout if it
|
|
|
|
* were to be created.
|
|
|
|
* -R Create a pool under an alternate root
|
|
|
|
* -m Set default mountpoint for the root dataset. By default it's
|
2012-12-13 23:24:15 +00:00
|
|
|
* '/<pool>'
|
2008-11-20 20:01:55 +00:00
|
|
|
* -o Set property=value.
|
2012-12-13 23:24:15 +00:00
|
|
|
* -d Don't automatically enable all supported pool features
|
|
|
|
* (individual features can be enabled with -o).
|
2008-12-03 20:09:06 +00:00
|
|
|
* -O Set fsproperty=value in the pool's root file system
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Creates the named pool according to the given vdev specification. The
|
|
|
|
* bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
|
|
|
|
* we get the nvlist back from get_vdev_spec(), we either print out the contents
|
|
|
|
* (if '-n' was specified), or pass it to libzfs to do the creation.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_create(int argc, char **argv)
|
|
|
|
{
|
|
|
|
boolean_t force = B_FALSE;
|
|
|
|
boolean_t dryrun = B_FALSE;
|
2012-12-13 23:24:15 +00:00
|
|
|
boolean_t enable_all_pool_feat = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
int c;
|
|
|
|
nvlist_t *nvroot = NULL;
|
|
|
|
char *poolname;
|
|
|
|
int ret = 1;
|
|
|
|
char *altroot = NULL;
|
|
|
|
char *mountpoint = NULL;
|
2008-12-03 20:09:06 +00:00
|
|
|
nvlist_t *fsprops = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_t *props = NULL;
|
|
|
|
char *propval;
|
|
|
|
|
|
|
|
/* check options */
|
2012-12-13 23:24:15 +00:00
|
|
|
while ((c = getopt(argc, argv, ":fndR:m:o:O:")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
force = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
dryrun = B_TRUE;
|
|
|
|
break;
|
2012-12-13 23:24:15 +00:00
|
|
|
case 'd':
|
|
|
|
enable_all_pool_feat = B_FALSE;
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case 'R':
|
|
|
|
altroot = optarg;
|
|
|
|
if (add_prop_list(zpool_prop_to_name(
|
2008-12-03 20:09:06 +00:00
|
|
|
ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
|
2008-11-20 20:01:55 +00:00
|
|
|
goto errout;
|
|
|
|
if (nvlist_lookup_string(props,
|
|
|
|
zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
|
|
|
|
&propval) == 0)
|
|
|
|
break;
|
|
|
|
if (add_prop_list(zpool_prop_to_name(
|
2008-12-03 20:09:06 +00:00
|
|
|
ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
|
2008-11-20 20:01:55 +00:00
|
|
|
goto errout;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2013-06-11 17:13:47 +00:00
|
|
|
/* Equivalent to -O mountpoint=optarg */
|
2008-11-20 20:01:55 +00:00
|
|
|
mountpoint = optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if ((propval = strchr(optarg, '=')) == NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("missing "
|
|
|
|
"'=' for -o option\n"));
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
*propval = '\0';
|
|
|
|
propval++;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
if (add_prop_list(optarg, propval, &props, B_TRUE))
|
|
|
|
goto errout;
|
2012-12-13 23:24:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user is creating a pool that doesn't support
|
|
|
|
* feature flags, don't enable any features.
|
|
|
|
*/
|
|
|
|
if (zpool_name_to_prop(optarg) == ZPOOL_PROP_VERSION) {
|
|
|
|
char *end;
|
|
|
|
u_longlong_t ver;
|
|
|
|
|
|
|
|
ver = strtoull(propval, &end, 10);
|
|
|
|
if (*end == '\0' &&
|
|
|
|
ver < SPA_VERSION_FEATURES) {
|
|
|
|
enable_all_pool_feat = B_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-12-03 20:09:06 +00:00
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
if ((propval = strchr(optarg, '=')) == NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("missing "
|
|
|
|
"'=' for -O option\n"));
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
*propval = '\0';
|
|
|
|
propval++;
|
|
|
|
|
2013-06-11 17:13:47 +00:00
|
|
|
/*
|
|
|
|
* Mountpoints are checked and then added later.
|
|
|
|
* Uniquely among properties, they can be specified
|
|
|
|
* more than once, to avoid conflict with -m.
|
|
|
|
*/
|
|
|
|
if (0 == strcmp(optarg,
|
|
|
|
zfs_prop_to_name(ZFS_PROP_MOUNTPOINT))) {
|
|
|
|
mountpoint = propval;
|
|
|
|
} else if (add_prop_list(optarg, propval, &fsprops,
|
|
|
|
B_FALSE)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
goto errout;
|
2013-06-11 17:13:47 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
(void) fprintf(stderr, gettext("missing argument for "
|
|
|
|
"'%c' option\n"), optopt);
|
|
|
|
goto badusage;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
goto badusage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name argument\n"));
|
|
|
|
goto badusage;
|
|
|
|
}
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("missing vdev specification\n"));
|
|
|
|
goto badusage;
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As a special case, check for use of '/' in the name, and direct the
|
|
|
|
* user to use 'zfs create' instead.
|
|
|
|
*/
|
|
|
|
if (strchr(poolname, '/') != NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("cannot create '%s': invalid "
|
|
|
|
"character '/' in pool name\n"), poolname);
|
|
|
|
(void) fprintf(stderr, gettext("use 'zfs create' to "
|
|
|
|
"create a dataset\n"));
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pass off to get_vdev_spec for bulk processing */
|
2011-06-16 19:56:38 +00:00
|
|
|
nvroot = make_root_vdev(NULL, props, force, !force, B_FALSE, dryrun,
|
2008-12-03 20:09:06 +00:00
|
|
|
argc - 1, argv + 1);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (nvroot == NULL)
|
2008-12-03 20:09:06 +00:00
|
|
|
goto errout;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* make_root_vdev() allows 0 toplevel children if there are spares */
|
|
|
|
if (!zfs_allocatable_devs(nvroot)) {
|
|
|
|
(void) fprintf(stderr, gettext("invalid vdev "
|
|
|
|
"specification: at least one toplevel vdev must be "
|
|
|
|
"specified\n"));
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (altroot != NULL && altroot[0] != '/') {
|
|
|
|
(void) fprintf(stderr, gettext("invalid alternate root '%s': "
|
|
|
|
"must be an absolute path\n"), altroot);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the validity of the mountpoint and direct the user to use the
|
|
|
|
* '-m' mountpoint option if it looks like its in use.
|
|
|
|
*/
|
|
|
|
if (mountpoint == NULL ||
|
|
|
|
(strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) != 0 &&
|
|
|
|
strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) != 0)) {
|
|
|
|
char buf[MAXPATHLEN];
|
|
|
|
DIR *dirp;
|
|
|
|
|
|
|
|
if (mountpoint && mountpoint[0] != '/') {
|
|
|
|
(void) fprintf(stderr, gettext("invalid mountpoint "
|
|
|
|
"'%s': must be an absolute path, 'legacy', or "
|
|
|
|
"'none'\n"), mountpoint);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mountpoint == NULL) {
|
|
|
|
if (altroot != NULL)
|
|
|
|
(void) snprintf(buf, sizeof (buf), "%s/%s",
|
|
|
|
altroot, poolname);
|
|
|
|
else
|
|
|
|
(void) snprintf(buf, sizeof (buf), "/%s",
|
|
|
|
poolname);
|
|
|
|
} else {
|
|
|
|
if (altroot != NULL)
|
|
|
|
(void) snprintf(buf, sizeof (buf), "%s%s",
|
|
|
|
altroot, mountpoint);
|
|
|
|
else
|
|
|
|
(void) snprintf(buf, sizeof (buf), "%s",
|
|
|
|
mountpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dirp = opendir(buf)) == NULL && errno != ENOENT) {
|
|
|
|
(void) fprintf(stderr, gettext("mountpoint '%s' : "
|
|
|
|
"%s\n"), buf, strerror(errno));
|
|
|
|
(void) fprintf(stderr, gettext("use '-m' "
|
|
|
|
"option to provide a different default\n"));
|
|
|
|
goto errout;
|
|
|
|
} else if (dirp) {
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while (count < 3 && readdir(dirp) != NULL)
|
|
|
|
count++;
|
|
|
|
(void) closedir(dirp);
|
|
|
|
|
|
|
|
if (count > 2) {
|
|
|
|
(void) fprintf(stderr, gettext("mountpoint "
|
|
|
|
"'%s' exists and is not empty\n"), buf);
|
|
|
|
(void) fprintf(stderr, gettext("use '-m' "
|
|
|
|
"option to provide a "
|
|
|
|
"different default\n"));
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 17:13:47 +00:00
|
|
|
/*
|
|
|
|
* Now that the mountpoint's validity has been checked, ensure that
|
|
|
|
* the property is set appropriately prior to creating the pool.
|
|
|
|
*/
|
|
|
|
if (mountpoint != NULL) {
|
|
|
|
ret = add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
|
|
|
|
mountpoint, &fsprops, B_FALSE);
|
|
|
|
if (ret != 0)
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 1;
|
2008-11-20 20:01:55 +00:00
|
|
|
if (dryrun) {
|
|
|
|
/*
|
|
|
|
* For a dry run invocation, print out a basic message and run
|
|
|
|
* through all the vdevs in the list and print out in an
|
|
|
|
* appropriate hierarchy.
|
|
|
|
*/
|
|
|
|
(void) printf(gettext("would create '%s' with the "
|
|
|
|
"following layout:\n\n"), poolname);
|
|
|
|
|
|
|
|
print_vdev_tree(NULL, poolname, nvroot, 0, B_FALSE);
|
|
|
|
if (num_logs(nvroot) > 0)
|
|
|
|
print_vdev_tree(NULL, "logs", nvroot, 0, B_TRUE);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Hand off to libzfs.
|
|
|
|
*/
|
2012-12-13 23:24:15 +00:00
|
|
|
if (enable_all_pool_feat) {
|
2013-10-08 17:13:05 +00:00
|
|
|
spa_feature_t i;
|
2012-12-13 23:24:15 +00:00
|
|
|
for (i = 0; i < SPA_FEATURES; i++) {
|
|
|
|
char propname[MAXPATHLEN];
|
|
|
|
zfeature_info_t *feat = &spa_feature_table[i];
|
|
|
|
|
|
|
|
(void) snprintf(propname, sizeof (propname),
|
|
|
|
"feature@%s", feat->fi_uname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip feature if user specified it manually
|
|
|
|
* on the command line.
|
|
|
|
*/
|
|
|
|
if (nvlist_exists(props, propname))
|
|
|
|
continue;
|
|
|
|
|
2013-06-11 17:13:47 +00:00
|
|
|
ret = add_prop_list(propname,
|
|
|
|
ZFS_FEATURE_ENABLED, &props, B_TRUE);
|
|
|
|
if (ret != 0)
|
2012-12-13 23:24:15 +00:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 17:13:47 +00:00
|
|
|
|
|
|
|
ret = 1;
|
2008-12-03 20:09:06 +00:00
|
|
|
if (zpool_create(g_zfs, poolname,
|
|
|
|
nvroot, props, fsprops) == 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
zfs_handle_t *pool = zfs_open(g_zfs, poolname,
|
|
|
|
ZFS_TYPE_FILESYSTEM);
|
|
|
|
if (pool != NULL) {
|
|
|
|
if (zfs_mount(pool, NULL, 0) == 0)
|
|
|
|
ret = zfs_shareall(pool);
|
|
|
|
zfs_close(pool);
|
|
|
|
}
|
|
|
|
} else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {
|
|
|
|
(void) fprintf(stderr, gettext("pool name may have "
|
|
|
|
"been omitted\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errout:
|
|
|
|
nvlist_free(nvroot);
|
2008-12-03 20:09:06 +00:00
|
|
|
nvlist_free(fsprops);
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_free(props);
|
|
|
|
return (ret);
|
|
|
|
badusage:
|
2008-12-03 20:09:06 +00:00
|
|
|
nvlist_free(fsprops);
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_free(props);
|
|
|
|
usage(B_FALSE);
|
|
|
|
return (2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool destroy <pool>
|
|
|
|
*
|
|
|
|
* -f Forcefully unmount any datasets
|
|
|
|
*
|
|
|
|
* Destroy the given pool. Automatically unmounts any datasets in the pool.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_destroy(int argc, char **argv)
|
|
|
|
{
|
|
|
|
boolean_t force = B_FALSE;
|
|
|
|
int c;
|
|
|
|
char *pool;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "f")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
force = B_TRUE;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* check arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (argc > 1) {
|
|
|
|
(void) fprintf(stderr, gettext("too many arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
pool = argv[0];
|
|
|
|
|
|
|
|
if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
|
|
|
|
/*
|
|
|
|
* As a special case, check for use of '/' in the name, and
|
|
|
|
* direct the user to use 'zfs destroy' instead.
|
|
|
|
*/
|
|
|
|
if (strchr(pool, '/') != NULL)
|
|
|
|
(void) fprintf(stderr, gettext("use 'zfs destroy' to "
|
|
|
|
"destroy a dataset\n"));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zpool_disable_datasets(zhp, force) != 0) {
|
|
|
|
(void) fprintf(stderr, gettext("could not destroy '%s': "
|
|
|
|
"could not unmount datasets\n"), zpool_get_name(zhp));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
/* The history must be logged as part of the export */
|
|
|
|
log_history = B_FALSE;
|
|
|
|
|
|
|
|
ret = (zpool_destroy(zhp, history_str) != 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool export [-f] <pool> ...
|
|
|
|
*
|
|
|
|
* -f Forcefully unmount datasets
|
|
|
|
*
|
|
|
|
* Export the given pools. By default, the command will attempt to cleanly
|
|
|
|
* unmount any active datasets within the pool. If the '-f' flag is specified,
|
|
|
|
* then the datasets will be forcefully unmounted.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_export(int argc, char **argv)
|
|
|
|
{
|
|
|
|
boolean_t force = B_FALSE;
|
2009-01-15 21:59:39 +00:00
|
|
|
boolean_t hardforce = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
int c;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* check options */
|
2009-01-15 21:59:39 +00:00
|
|
|
while ((c = getopt(argc, argv, "fF")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
force = B_TRUE;
|
|
|
|
break;
|
2009-01-15 21:59:39 +00:00
|
|
|
case 'F':
|
|
|
|
hardforce = B_TRUE;
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* check arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
if ((zhp = zpool_open_canfail(g_zfs, argv[i])) == NULL) {
|
|
|
|
ret = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zpool_disable_datasets(zhp, force) != 0) {
|
|
|
|
ret = 1;
|
|
|
|
zpool_close(zhp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
/* The history must be logged as part of the export */
|
|
|
|
log_history = B_FALSE;
|
|
|
|
|
2009-01-15 21:59:39 +00:00
|
|
|
if (hardforce) {
|
2013-08-28 11:45:09 +00:00
|
|
|
if (zpool_export_force(zhp, history_str) != 0)
|
2009-01-15 21:59:39 +00:00
|
|
|
ret = 1;
|
2013-08-28 11:45:09 +00:00
|
|
|
} else if (zpool_export(zhp, force, history_str) != 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
ret = 1;
|
2009-01-15 21:59:39 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a vdev configuration, determine the maximum width needed for the device
|
|
|
|
* name column.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
char *name = zpool_vdev_name(g_zfs, zhp, nv, B_TRUE);
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_t **child;
|
|
|
|
uint_t c, children;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (strlen(name) + depth > max)
|
|
|
|
max = strlen(name) + depth;
|
|
|
|
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
|
|
|
|
&child, &children) == 0) {
|
|
|
|
for (c = 0; c < children; c++)
|
|
|
|
if ((ret = max_width(zhp, child[c], depth + 2,
|
|
|
|
max)) > max)
|
|
|
|
max = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
|
|
|
|
&child, &children) == 0) {
|
|
|
|
for (c = 0; c < children; c++)
|
|
|
|
if ((ret = max_width(zhp, child[c], depth + 2,
|
|
|
|
max)) > max)
|
|
|
|
max = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&child, &children) == 0) {
|
|
|
|
for (c = 0; c < children; c++)
|
|
|
|
if ((ret = max_width(zhp, child[c], depth + 2,
|
|
|
|
max)) > max)
|
|
|
|
max = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (max);
|
|
|
|
}
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
typedef struct spare_cbdata {
|
|
|
|
uint64_t cb_guid;
|
|
|
|
zpool_handle_t *cb_zhp;
|
|
|
|
} spare_cbdata_t;
|
|
|
|
|
|
|
|
static boolean_t
|
|
|
|
find_vdev(nvlist_t *nv, uint64_t search)
|
|
|
|
{
|
|
|
|
uint64_t guid;
|
|
|
|
nvlist_t **child;
|
|
|
|
uint_t c, children;
|
|
|
|
|
|
|
|
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) == 0 &&
|
|
|
|
search == guid)
|
|
|
|
return (B_TRUE);
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&child, &children) == 0) {
|
|
|
|
for (c = 0; c < children; c++)
|
|
|
|
if (find_vdev(child[c], search))
|
|
|
|
return (B_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_spare(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
spare_cbdata_t *cbp = data;
|
|
|
|
nvlist_t *config, *nvroot;
|
|
|
|
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
|
|
|
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&nvroot) == 0);
|
|
|
|
|
|
|
|
if (find_vdev(nvroot, cbp->cb_guid)) {
|
|
|
|
cbp->cb_zhp = zhp;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out configuration state as requested by status_callback.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
|
|
|
|
int namewidth, int depth, boolean_t isspare)
|
|
|
|
{
|
|
|
|
nvlist_t **child;
|
|
|
|
uint_t c, children;
|
2010-05-28 20:45:14 +00:00
|
|
|
pool_scan_stat_t *ps = NULL;
|
2009-07-02 22:44:48 +00:00
|
|
|
vdev_stat_t *vs;
|
2010-05-28 20:45:14 +00:00
|
|
|
char rbuf[6], wbuf[6], cbuf[6];
|
2009-07-02 22:44:48 +00:00
|
|
|
char *vname;
|
|
|
|
uint64_t notpresent;
|
|
|
|
spare_cbdata_t cb;
|
|
|
|
char *state;
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&child, &children) != 0)
|
|
|
|
children = 0;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
|
|
|
|
(uint64_t **)&vs, &c) == 0);
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
state = zpool_state_to_name(vs->vs_state, vs->vs_aux);
|
|
|
|
if (isspare) {
|
|
|
|
/*
|
|
|
|
* For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
|
|
|
|
* online drives.
|
|
|
|
*/
|
|
|
|
if (vs->vs_aux == VDEV_AUX_SPARED)
|
|
|
|
state = "INUSE";
|
|
|
|
else if (vs->vs_state == VDEV_STATE_HEALTHY)
|
|
|
|
state = "AVAIL";
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf("\t%*s%-*s %-8s", depth, "", namewidth - depth,
|
|
|
|
name, state);
|
|
|
|
|
|
|
|
if (!isspare) {
|
|
|
|
zfs_nicenum(vs->vs_read_errors, rbuf, sizeof (rbuf));
|
|
|
|
zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
|
|
|
|
zfs_nicenum(vs->vs_checksum_errors, cbuf, sizeof (cbuf));
|
|
|
|
(void) printf(" %5s %5s %5s", rbuf, wbuf, cbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
|
|
|
|
¬present) == 0) {
|
|
|
|
char *path;
|
|
|
|
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
|
|
|
|
(void) printf(" was %s", path);
|
|
|
|
} else if (vs->vs_aux != 0) {
|
|
|
|
(void) printf(" ");
|
|
|
|
|
|
|
|
switch (vs->vs_aux) {
|
|
|
|
case VDEV_AUX_OPEN_FAILED:
|
|
|
|
(void) printf(gettext("cannot open"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_BAD_GUID_SUM:
|
|
|
|
(void) printf(gettext("missing device"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_NO_REPLICAS:
|
|
|
|
(void) printf(gettext("insufficient replicas"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_VERSION_NEWER:
|
|
|
|
(void) printf(gettext("newer version"));
|
|
|
|
break;
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
case VDEV_AUX_UNSUP_FEAT:
|
|
|
|
(void) printf(gettext("unsupported feature(s)"));
|
|
|
|
break;
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
case VDEV_AUX_SPARED:
|
|
|
|
verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
|
|
|
|
&cb.cb_guid) == 0);
|
|
|
|
if (zpool_iter(g_zfs, find_spare, &cb) == 1) {
|
|
|
|
if (strcmp(zpool_get_name(cb.cb_zhp),
|
|
|
|
zpool_get_name(zhp)) == 0)
|
|
|
|
(void) printf(gettext("currently in "
|
|
|
|
"use"));
|
|
|
|
else
|
|
|
|
(void) printf(gettext("in use by "
|
|
|
|
"pool '%s'"),
|
|
|
|
zpool_get_name(cb.cb_zhp));
|
|
|
|
zpool_close(cb.cb_zhp);
|
|
|
|
} else {
|
|
|
|
(void) printf(gettext("currently in use"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_ERR_EXCEEDED:
|
|
|
|
(void) printf(gettext("too many errors"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_IO_FAILURE:
|
|
|
|
(void) printf(gettext("experienced I/O failures"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_BAD_LOG:
|
|
|
|
(void) printf(gettext("bad intent log"));
|
|
|
|
break;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
case VDEV_AUX_EXTERNAL:
|
|
|
|
(void) printf(gettext("external device fault"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_SPLIT_POOL:
|
|
|
|
(void) printf(gettext("split into new pool"));
|
|
|
|
break;
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
default:
|
|
|
|
(void) printf(gettext("corrupted data"));
|
|
|
|
break;
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(void) nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_SCAN_STATS,
|
|
|
|
(uint64_t **)&ps, &c);
|
|
|
|
|
|
|
|
if (ps && ps->pss_state == DSS_SCANNING &&
|
|
|
|
vs->vs_scan_processed != 0 && children == 0) {
|
|
|
|
(void) printf(gettext(" (%s)"),
|
|
|
|
(ps->pss_func == POOL_SCAN_RESILVER) ?
|
|
|
|
"resilvering" : "repairing");
|
2009-07-02 22:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf("\n");
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t islog = B_FALSE, ishole = B_FALSE;
|
2009-07-02 22:44:48 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* Don't print logs or holes here */
|
2009-07-02 22:44:48 +00:00
|
|
|
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
|
2010-05-28 20:45:14 +00:00
|
|
|
&islog);
|
|
|
|
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE,
|
|
|
|
&ishole);
|
|
|
|
if (islog || ishole)
|
2009-07-02 22:44:48 +00:00
|
|
|
continue;
|
2010-05-28 20:45:14 +00:00
|
|
|
vname = zpool_vdev_name(g_zfs, zhp, child[c], B_TRUE);
|
2009-07-02 22:44:48 +00:00
|
|
|
print_status_config(zhp, vname, child[c],
|
|
|
|
namewidth, depth + 2, isspare);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the configuration of an exported pool. Iterate over all vdevs in the
|
|
|
|
* pool, printing out the name and status for each one.
|
|
|
|
*/
|
|
|
|
void
|
2009-07-02 22:44:48 +00:00
|
|
|
print_import_config(const char *name, nvlist_t *nv, int namewidth, int depth)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
nvlist_t **child;
|
|
|
|
uint_t c, children;
|
|
|
|
vdev_stat_t *vs;
|
|
|
|
char *type, *vname;
|
|
|
|
|
|
|
|
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
if (strcmp(type, VDEV_TYPE_MISSING) == 0 ||
|
|
|
|
strcmp(type, VDEV_TYPE_HOLE) == 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
|
2008-11-20 20:01:55 +00:00
|
|
|
(uint64_t **)&vs, &c) == 0);
|
|
|
|
|
|
|
|
(void) printf("\t%*s%-*s", depth, "", namewidth - depth, name);
|
|
|
|
(void) printf(" %s", zpool_state_to_name(vs->vs_state, vs->vs_aux));
|
|
|
|
|
|
|
|
if (vs->vs_aux != 0) {
|
|
|
|
(void) printf(" ");
|
|
|
|
|
|
|
|
switch (vs->vs_aux) {
|
|
|
|
case VDEV_AUX_OPEN_FAILED:
|
|
|
|
(void) printf(gettext("cannot open"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_BAD_GUID_SUM:
|
|
|
|
(void) printf(gettext("missing device"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_NO_REPLICAS:
|
|
|
|
(void) printf(gettext("insufficient replicas"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VDEV_AUX_VERSION_NEWER:
|
|
|
|
(void) printf(gettext("newer version"));
|
|
|
|
break;
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
case VDEV_AUX_UNSUP_FEAT:
|
|
|
|
(void) printf(gettext("unsupported feature(s)"));
|
|
|
|
break;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
case VDEV_AUX_ERR_EXCEEDED:
|
|
|
|
(void) printf(gettext("too many errors"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
(void) printf(gettext("corrupted data"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(void) printf("\n");
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&child, &children) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
|
|
|
uint64_t is_log = B_FALSE;
|
|
|
|
|
|
|
|
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
|
|
|
|
&is_log);
|
2009-07-02 22:44:48 +00:00
|
|
|
if (is_log)
|
2008-11-20 20:01:55 +00:00
|
|
|
continue;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
vname = zpool_vdev_name(g_zfs, NULL, child[c], B_TRUE);
|
2009-07-02 22:44:48 +00:00
|
|
|
print_import_config(vname, child[c], namewidth, depth + 2);
|
2008-11-20 20:01:55 +00:00
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
|
|
|
|
&child, &children) == 0) {
|
|
|
|
(void) printf(gettext("\tcache\n"));
|
|
|
|
for (c = 0; c < children; c++) {
|
2010-05-28 20:45:14 +00:00
|
|
|
vname = zpool_vdev_name(g_zfs, NULL, child[c], B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf("\t %s\n", vname);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
|
|
|
|
&child, &children) == 0) {
|
|
|
|
(void) printf(gettext("\tspares\n"));
|
|
|
|
for (c = 0; c < children; c++) {
|
2010-05-28 20:45:14 +00:00
|
|
|
vname = zpool_vdev_name(g_zfs, NULL, child[c], B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf("\t %s\n", vname);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
/*
|
|
|
|
* Print log vdevs.
|
|
|
|
* Logs are recorded as top level vdevs in the main pool child array
|
|
|
|
* but with "is_log" set to 1. We use either print_status_config() or
|
|
|
|
* print_import_config() to print the top level logs then any log
|
|
|
|
* children (eg mirrored slogs) are printed recursively - which
|
|
|
|
* works because only the top level vdev is marked "is_log"
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
print_logs(zpool_handle_t *zhp, nvlist_t *nv, int namewidth, boolean_t verbose)
|
|
|
|
{
|
|
|
|
uint_t c, children;
|
|
|
|
nvlist_t **child;
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, &child,
|
|
|
|
&children) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(void) printf(gettext("\tlogs\n"));
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
|
|
|
uint64_t is_log = B_FALSE;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
|
|
|
|
&is_log);
|
|
|
|
if (!is_log)
|
|
|
|
continue;
|
2010-05-28 20:45:14 +00:00
|
|
|
name = zpool_vdev_name(g_zfs, zhp, child[c], B_TRUE);
|
2009-07-02 22:44:48 +00:00
|
|
|
if (verbose)
|
|
|
|
print_status_config(zhp, name, child[c], namewidth,
|
|
|
|
2, B_FALSE);
|
|
|
|
else
|
|
|
|
print_import_config(name, child[c], namewidth, 2);
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Display the status for the given pool.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
show_import(nvlist_t *config)
|
|
|
|
{
|
|
|
|
uint64_t pool_state;
|
|
|
|
vdev_stat_t *vs;
|
|
|
|
char *name;
|
|
|
|
uint64_t guid;
|
|
|
|
char *msgid;
|
|
|
|
nvlist_t *nvroot;
|
2014-02-21 03:42:15 +00:00
|
|
|
zpool_status_t reason;
|
2014-02-21 03:57:17 +00:00
|
|
|
zpool_errata_t errata;
|
2008-11-20 20:01:55 +00:00
|
|
|
const char *health;
|
|
|
|
uint_t vsc;
|
|
|
|
int namewidth;
|
2011-11-15 19:01:27 +00:00
|
|
|
char *comment;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
|
|
|
|
&name) == 0);
|
|
|
|
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
|
|
|
|
&guid) == 0);
|
|
|
|
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
|
|
|
|
&pool_state) == 0);
|
|
|
|
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&nvroot) == 0);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
|
2008-11-20 20:01:55 +00:00
|
|
|
(uint64_t **)&vs, &vsc) == 0);
|
|
|
|
health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
|
|
|
|
|
2014-02-21 03:57:17 +00:00
|
|
|
reason = zpool_import_status(config, &msgid, &errata);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" pool: %s\n"), name);
|
|
|
|
(void) printf(gettext(" id: %llu\n"), (u_longlong_t)guid);
|
|
|
|
(void) printf(gettext(" state: %s"), health);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (pool_state == POOL_STATE_DESTROYED)
|
|
|
|
(void) printf(gettext(" (DESTROYED)"));
|
|
|
|
(void) printf("\n");
|
|
|
|
|
|
|
|
switch (reason) {
|
|
|
|
case ZPOOL_STATUS_MISSING_DEV_R:
|
|
|
|
case ZPOOL_STATUS_MISSING_DEV_NR:
|
|
|
|
case ZPOOL_STATUS_BAD_GUID_SUM:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: One or more devices are "
|
|
|
|
"missing from the system.\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_CORRUPT_LABEL_R:
|
|
|
|
case ZPOOL_STATUS_CORRUPT_LABEL_NR:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: One or more devices contains "
|
2008-11-20 20:01:55 +00:00
|
|
|
"corrupted data.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_CORRUPT_DATA:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(
|
|
|
|
gettext(" status: The pool data is corrupted.\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_OFFLINE_DEV:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: One or more devices "
|
2008-11-20 20:01:55 +00:00
|
|
|
"are offlined.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_CORRUPT_POOL:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: The pool metadata is "
|
2008-11-20 20:01:55 +00:00
|
|
|
"corrupted.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_VERSION_OLDER:
|
2012-12-14 23:00:45 +00:00
|
|
|
(void) printf(gettext(" status: The pool is formatted using a "
|
|
|
|
"legacy on-disk version.\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_VERSION_NEWER:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: The pool is formatted using an "
|
2008-11-20 20:01:55 +00:00
|
|
|
"incompatible version.\n"));
|
|
|
|
break;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
case ZPOOL_STATUS_FEAT_DISABLED:
|
|
|
|
(void) printf(gettext(" status: Some supported features are "
|
|
|
|
"not enabled on the pool.\n"));
|
|
|
|
break;
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
case ZPOOL_STATUS_UNSUP_FEAT_READ:
|
|
|
|
(void) printf(gettext("status: The pool uses the following "
|
|
|
|
"feature(s) not supported on this sytem:\n"));
|
|
|
|
zpool_print_unsup_feat(config);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
|
|
|
|
(void) printf(gettext("status: The pool can only be accessed "
|
|
|
|
"in read-only mode on this system. It\n\tcannot be "
|
|
|
|
"accessed in read-write mode because it uses the "
|
|
|
|
"following\n\tfeature(s) not supported on this system:\n"));
|
|
|
|
zpool_print_unsup_feat(config);
|
|
|
|
break;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
case ZPOOL_STATUS_HOSTID_MISMATCH:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: The pool was last accessed by "
|
2008-11-20 20:01:55 +00:00
|
|
|
"another system.\n"));
|
|
|
|
break;
|
2008-12-03 20:09:06 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
case ZPOOL_STATUS_FAULTED_DEV_R:
|
|
|
|
case ZPOOL_STATUS_FAULTED_DEV_NR:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: One or more devices are "
|
2008-11-20 20:01:55 +00:00
|
|
|
"faulted.\n"));
|
|
|
|
break;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
case ZPOOL_STATUS_BAD_LOG:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: An intent log record cannot be "
|
2008-12-03 20:09:06 +00:00
|
|
|
"read.\n"));
|
|
|
|
break;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
case ZPOOL_STATUS_RESILVERING:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" status: One or more devices were being "
|
2010-05-28 20:45:14 +00:00
|
|
|
"resilvered.\n"));
|
|
|
|
break;
|
|
|
|
|
2014-02-21 03:57:17 +00:00
|
|
|
case ZPOOL_STATUS_ERRATA:
|
|
|
|
(void) printf(gettext(" status: Errata #%d detected.\n"),
|
|
|
|
errata);
|
|
|
|
break;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* No other status can be seen when importing pools.
|
|
|
|
*/
|
|
|
|
assert(reason == ZPOOL_STATUS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out an action according to the overall state of the pool.
|
|
|
|
*/
|
|
|
|
if (vs->vs_state == VDEV_STATE_HEALTHY) {
|
2012-12-14 23:00:45 +00:00
|
|
|
if (reason == ZPOOL_STATUS_VERSION_OLDER ||
|
|
|
|
reason == ZPOOL_STATUS_FEAT_DISABLED) {
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" action: The pool can be "
|
2008-11-20 20:01:55 +00:00
|
|
|
"imported using its name or numeric identifier, "
|
|
|
|
"though\n\tsome features will not be available "
|
|
|
|
"without an explicit 'zpool upgrade'.\n"));
|
2012-12-14 23:00:45 +00:00
|
|
|
} else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH) {
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" action: The pool can be "
|
2008-11-20 20:01:55 +00:00
|
|
|
"imported using its name or numeric "
|
|
|
|
"identifier and\n\tthe '-f' flag.\n"));
|
2014-02-21 03:57:17 +00:00
|
|
|
} else if (reason == ZPOOL_STATUS_ERRATA) {
|
|
|
|
switch (errata) {
|
|
|
|
case ZPOOL_ERRATA_NONE:
|
|
|
|
break;
|
|
|
|
|
Add erratum for issue #2094
ZoL commit 1421c89 unintentionally changed the disk format in a forward-
compatible, but not backward compatible way. This was accomplished by
adding an entry to zbookmark_t, which is included in a couple of
on-disk structures. That lead to the creation of pools with incorrect
dsl_scan_phys_t objects that could only be imported by versions of ZoL
containing that commit. Such pools cannot be imported by other versions
of ZFS or past versions of ZoL.
The additional field has been removed by the previous commit. However,
affected pools must be imported and scrubbed using a version of ZoL with
this commit applied. This will return the pools to a state in which they
may be imported by other implementations.
The 'zpool import' or 'zpool status' command can be used to determine if
a pool is impacted. A message similar to one of the following means your
pool must be scrubbed to restore compatibility.
$ zpool import
pool: zol-0.6.2-173
id: 1165955789558693437
state: ONLINE
status: Errata #1 detected.
action: The pool can be imported using its name or numeric identifier,
however there is a compatibility issue which should be corrected
by running 'zpool scrub'
see: http://zfsonlinux.org/msg/ZFS-8000-ER
config:
...
$ zpool status
pool: zol-0.6.2-173
state: ONLINE
scan: pool compatibility issue detected.
see: https://github.com/zfsonlinux/zfs/issues/2094
action: To correct the issue run 'zpool scrub'.
config:
...
If there was an async destroy in progress 'zpool import' will prevent
the pool from being imported. Further advice on how to proceed will be
provided by the error message as follows.
$ zpool import
pool: zol-0.6.2-173
id: 1165955789558693437
state: ONLINE
status: Errata #2 detected.
action: The pool can not be imported with this version of ZFS due to an
active asynchronous destroy. Revert to an earlier version and
allow the destroy to complete before updating.
see: http://zfsonlinux.org/msg/ZFS-8000-ER
config:
...
Pools affected by the damaged dsl_scan_phys_t can be detected prior to
an upgrade by running the following command as root:
zdb -dddd poolname 1 | grep -P '^\t\tscan = ' | sed -e 's;scan = ;;' | wc -w
Note that `poolname` must be replaced with the name of the pool you wish
to check. A value of 25 indicates the dsl_scan_phys_t has been damaged.
A value of 24 indicates that the dsl_scan_phys_t is normal. A value of 0
indicates that there has never been a scrub run on the pool.
The regression caused by the change to zbookmark_t never made it into a
tagged release, Gentoo backports, Ubuntu, Debian, Fedora, or EPEL
stable respositorys. Only those using the HEAD version directly from
Github after the 0.6.2 but before the 0.6.3 tag are affected.
This patch does have one limitation that should be mentioned. It will not
detect errata #2 on a pool unless errata #1 is also present. It expected
this will not be a significant problem because pools impacted by errata #2
have a high probably of being impacted by errata #1.
End users can ensure they do no hit this unlikely case by waiting for all
asynchronous destroy operations to complete before updating ZoL. The
presence of any background destroys on any imported pools can be checked
by running `zpool get freeing` as root. This will display a non-zero
value for any pool with an active asynchronous destroy.
Lastly, it is expected that no user data has been lost as a result of
this erratum.
Original-patch-by: Tim Chase <tim@chase2k.com>
Reworked-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #2094
2014-02-21 04:28:33 +00:00
|
|
|
case ZPOOL_ERRATA_ZOL_2094_SCRUB:
|
|
|
|
(void) printf(gettext(" action: The pool can "
|
|
|
|
"be imported using its name or numeric "
|
|
|
|
"identifier,\n\thowever there is a compat"
|
|
|
|
"ibility issue which should be corrected"
|
|
|
|
"\n\tby running 'zpool scrub'\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY:
|
|
|
|
(void) printf(gettext(" action: The pool can"
|
|
|
|
"not be imported with this version of ZFS "
|
|
|
|
"due to\n\tan active asynchronous destroy. "
|
|
|
|
"Revert to an earlier version\n\tand "
|
|
|
|
"allow the destroy to complete before "
|
|
|
|
"updating.\n"));
|
|
|
|
break;
|
|
|
|
|
2014-02-21 03:57:17 +00:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* All errata must contain an action message.
|
|
|
|
*/
|
|
|
|
assert(0);
|
|
|
|
}
|
2012-12-14 23:00:45 +00:00
|
|
|
} else {
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" action: The pool can be "
|
2008-11-20 20:01:55 +00:00
|
|
|
"imported using its name or numeric "
|
|
|
|
"identifier.\n"));
|
2012-12-14 23:00:45 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
} else if (vs->vs_state == VDEV_STATE_DEGRADED) {
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" action: The pool can be imported "
|
2008-11-20 20:01:55 +00:00
|
|
|
"despite missing or damaged devices. The\n\tfault "
|
|
|
|
"tolerance of the pool may be compromised if imported.\n"));
|
|
|
|
} else {
|
|
|
|
switch (reason) {
|
|
|
|
case ZPOOL_STATUS_VERSION_NEWER:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" action: The pool cannot be "
|
2008-11-20 20:01:55 +00:00
|
|
|
"imported. Access the pool on a system running "
|
|
|
|
"newer\n\tsoftware, or recreate the pool from "
|
|
|
|
"backup.\n"));
|
|
|
|
break;
|
2012-12-13 23:24:15 +00:00
|
|
|
case ZPOOL_STATUS_UNSUP_FEAT_READ:
|
|
|
|
(void) printf(gettext("action: The pool cannot be "
|
|
|
|
"imported. Access the pool on a system that "
|
|
|
|
"supports\n\tthe required feature(s), or recreate "
|
|
|
|
"the pool from backup.\n"));
|
|
|
|
break;
|
|
|
|
case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
|
|
|
|
(void) printf(gettext("action: The pool cannot be "
|
|
|
|
"imported in read-write mode. Import the pool "
|
|
|
|
"with\n"
|
|
|
|
"\t\"-o readonly=on\", access the pool on a system "
|
|
|
|
"that supports the\n\trequired feature(s), or "
|
|
|
|
"recreate the pool from backup.\n"));
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case ZPOOL_STATUS_MISSING_DEV_R:
|
|
|
|
case ZPOOL_STATUS_MISSING_DEV_NR:
|
|
|
|
case ZPOOL_STATUS_BAD_GUID_SUM:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" action: The pool cannot be "
|
2008-11-20 20:01:55 +00:00
|
|
|
"imported. Attach the missing\n\tdevices and try "
|
|
|
|
"again.\n"));
|
|
|
|
break;
|
|
|
|
default:
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" action: The pool cannot be "
|
2008-11-20 20:01:55 +00:00
|
|
|
"imported due to damaged devices or data.\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-15 19:01:27 +00:00
|
|
|
/* Print the comment attached to the pool. */
|
|
|
|
if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0)
|
|
|
|
(void) printf(gettext("comment: %s\n"), comment);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* If the state is "closed" or "can't open", and the aux state
|
|
|
|
* is "corrupt data":
|
|
|
|
*/
|
|
|
|
if (((vs->vs_state == VDEV_STATE_CLOSED) ||
|
|
|
|
(vs->vs_state == VDEV_STATE_CANT_OPEN)) &&
|
|
|
|
(vs->vs_aux == VDEV_AUX_CORRUPT_DATA)) {
|
|
|
|
if (pool_state == POOL_STATE_DESTROYED)
|
|
|
|
(void) printf(gettext("\tThe pool was destroyed, "
|
|
|
|
"but can be imported using the '-Df' flags.\n"));
|
|
|
|
else if (pool_state != POOL_STATE_EXPORTED)
|
|
|
|
(void) printf(gettext("\tThe pool may be active on "
|
|
|
|
"another system, but can be imported using\n\t"
|
|
|
|
"the '-f' flag.\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msgid != NULL)
|
2011-10-22 15:44:03 +00:00
|
|
|
(void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
|
2008-11-20 20:01:55 +00:00
|
|
|
msgid);
|
|
|
|
|
2011-11-15 19:01:27 +00:00
|
|
|
(void) printf(gettext(" config:\n\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
namewidth = max_width(NULL, nvroot, 0, 0);
|
|
|
|
if (namewidth < 10)
|
|
|
|
namewidth = 10;
|
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
print_import_config(name, nvroot, namewidth, 0);
|
|
|
|
if (num_logs(nvroot) > 0)
|
|
|
|
print_logs(NULL, nvroot, namewidth, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
|
|
|
|
(void) printf(gettext("\n\tAdditional devices are known to "
|
|
|
|
"be part of this pool, though their\n\texact "
|
|
|
|
"configuration cannot be determined.\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform the import for the given configuration. This passes the heavy
|
|
|
|
* lifting off to zpool_import_props(), and then mounts the datasets contained
|
|
|
|
* within the pool.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
do_import(nvlist_t *config, const char *newname, const char *mntopts,
|
2010-08-26 21:24:34 +00:00
|
|
|
nvlist_t *props, int flags)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
char *name;
|
|
|
|
uint64_t state;
|
|
|
|
uint64_t version;
|
|
|
|
|
|
|
|
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
|
|
|
|
&name) == 0);
|
|
|
|
|
|
|
|
verify(nvlist_lookup_uint64(config,
|
|
|
|
ZPOOL_CONFIG_POOL_STATE, &state) == 0);
|
|
|
|
verify(nvlist_lookup_uint64(config,
|
|
|
|
ZPOOL_CONFIG_VERSION, &version) == 0);
|
2012-12-13 23:24:15 +00:00
|
|
|
if (!SPA_VERSION_IS_SUPPORTED(version)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr, gettext("cannot import '%s': pool "
|
2012-12-13 23:24:15 +00:00
|
|
|
"is formatted using an unsupported ZFS version\n"), name);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (1);
|
2010-08-26 21:24:34 +00:00
|
|
|
} else if (state != POOL_STATE_EXPORTED &&
|
|
|
|
!(flags & ZFS_IMPORT_ANY_HOST)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
uint64_t hostid;
|
|
|
|
|
|
|
|
if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
|
|
|
|
&hostid) == 0) {
|
2011-04-25 15:18:07 +00:00
|
|
|
unsigned long system_hostid = gethostid() & 0xffffffff;
|
|
|
|
|
|
|
|
if ((unsigned long)hostid != system_hostid) {
|
2008-11-20 20:01:55 +00:00
|
|
|
char *hostname;
|
|
|
|
uint64_t timestamp;
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
verify(nvlist_lookup_string(config,
|
|
|
|
ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
|
|
|
|
verify(nvlist_lookup_uint64(config,
|
|
|
|
ZPOOL_CONFIG_TIMESTAMP, ×tamp) == 0);
|
|
|
|
t = timestamp;
|
|
|
|
(void) fprintf(stderr, gettext("cannot import "
|
|
|
|
"'%s': pool may be in use from other "
|
|
|
|
"system, it was last accessed by %s "
|
|
|
|
"(hostid: 0x%lx) on %s"), name, hostname,
|
|
|
|
(unsigned long)hostid,
|
|
|
|
asctime(localtime(&t)));
|
|
|
|
(void) fprintf(stderr, gettext("use '-f' to "
|
|
|
|
"import anyway\n"));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr, gettext("cannot import '%s': "
|
|
|
|
"pool may be in use from other system\n"), name);
|
|
|
|
(void) fprintf(stderr, gettext("use '-f' to import "
|
|
|
|
"anyway\n"));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
if (zpool_import_props(g_zfs, config, newname, props, flags) != 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (newname != NULL)
|
|
|
|
name = (char *)newname;
|
|
|
|
|
2009-08-18 18:43:27 +00:00
|
|
|
if ((zhp = zpool_open_canfail(g_zfs, name)) == NULL)
|
|
|
|
return (1);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-02-18 20:51:31 +00:00
|
|
|
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
|
2010-08-26 21:24:34 +00:00
|
|
|
!(flags & ZFS_IMPORT_ONLY) &&
|
2009-02-18 20:51:31 +00:00
|
|
|
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
zpool_close(zhp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
2010-05-28 20:45:14 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool import [-d dir] [-D]
|
|
|
|
* import [-o mntopts] [-o prop=value] ... [-R root] [-D]
|
|
|
|
* [-d dir | -c cachefile] [-f] -a
|
|
|
|
* import [-o mntopts] [-o prop=value] ... [-R root] [-D]
|
2010-05-28 20:45:14 +00:00
|
|
|
* [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* -c Read pool information from a cachefile instead of searching
|
|
|
|
* devices.
|
|
|
|
*
|
2010-08-26 18:56:53 +00:00
|
|
|
* -d Scan in a specific directory, other than /dev/. More than
|
2008-11-20 20:01:55 +00:00
|
|
|
* one directory can be specified using multiple '-d' options.
|
|
|
|
*
|
|
|
|
* -D Scan for previously destroyed pools or import all or only
|
|
|
|
* specified destroyed pools.
|
|
|
|
*
|
|
|
|
* -R Temporarily import the pool, with all mountpoints relative to
|
|
|
|
* the given root. The pool will remain exported when the machine
|
|
|
|
* is rebooted.
|
|
|
|
*
|
2010-05-28 20:45:14 +00:00
|
|
|
* -V Import even in the presence of faulted vdevs. This is an
|
2008-12-03 20:09:06 +00:00
|
|
|
* intentionally undocumented option for testing purposes, and
|
|
|
|
* treats the pool configuration as complete, leaving any bad
|
2009-08-18 18:43:27 +00:00
|
|
|
* vdevs in the FAULTED state. In other words, it does verbatim
|
|
|
|
* import.
|
2008-12-03 20:09:06 +00:00
|
|
|
*
|
2010-05-28 20:45:14 +00:00
|
|
|
* -f Force import, even if it appears that the pool is active.
|
|
|
|
*
|
|
|
|
* -F Attempt rewind if necessary.
|
|
|
|
*
|
|
|
|
* -n See if rewind would work, but don't actually rewind.
|
|
|
|
*
|
2010-08-26 21:24:34 +00:00
|
|
|
* -N Import the pool but don't mount datasets.
|
|
|
|
*
|
|
|
|
* -T Specify a starting txg to use for import. This option is
|
|
|
|
* intentionally undocumented option for testing purposes.
|
|
|
|
*
|
2008-11-20 20:01:55 +00:00
|
|
|
* -a Import all pools found.
|
|
|
|
*
|
|
|
|
* -o Set property=value and/or temporary mount options (without '=').
|
|
|
|
*
|
|
|
|
* The import command scans for pools to import, and import pools based on pool
|
|
|
|
* name and GUID. The pool can also be renamed as part of the import process.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_import(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char **searchdirs = NULL;
|
2012-09-15 20:25:21 +00:00
|
|
|
char *env, *envdup = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
int nsearch = 0;
|
|
|
|
int c;
|
2010-05-28 20:45:14 +00:00
|
|
|
int err = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_t *pools = NULL;
|
|
|
|
boolean_t do_all = B_FALSE;
|
|
|
|
boolean_t do_destroyed = B_FALSE;
|
|
|
|
char *mntopts = NULL;
|
|
|
|
nvpair_t *elem;
|
|
|
|
nvlist_t *config;
|
2008-12-03 20:09:06 +00:00
|
|
|
uint64_t searchguid = 0;
|
|
|
|
char *searchname = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
char *propval;
|
|
|
|
nvlist_t *found_config;
|
2010-05-28 20:45:14 +00:00
|
|
|
nvlist_t *policy = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
nvlist_t *props = NULL;
|
|
|
|
boolean_t first;
|
2010-08-26 21:24:34 +00:00
|
|
|
int flags = ZFS_IMPORT_NORMAL;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint32_t rewind_policy = ZPOOL_NO_REWIND;
|
|
|
|
boolean_t dryrun = B_FALSE;
|
|
|
|
boolean_t do_rewind = B_FALSE;
|
|
|
|
boolean_t xtreme_rewind = B_FALSE;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t pool_state, txg = -1ULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
char *cachefile = NULL;
|
2010-05-28 20:45:14 +00:00
|
|
|
importargs_t idata = { 0 };
|
2010-08-26 21:24:34 +00:00
|
|
|
char *endptr;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* check options */
|
2013-07-01 14:57:04 +00:00
|
|
|
while ((c = getopt(argc, argv, ":aCc:d:DEfFmnNo:R:tT:VX")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'a':
|
|
|
|
do_all = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cachefile = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
if (searchdirs == NULL) {
|
|
|
|
searchdirs = safe_malloc(sizeof (char *));
|
|
|
|
} else {
|
|
|
|
char **tmp = safe_malloc((nsearch + 1) *
|
|
|
|
sizeof (char *));
|
|
|
|
bcopy(searchdirs, tmp, nsearch *
|
|
|
|
sizeof (char *));
|
|
|
|
free(searchdirs);
|
|
|
|
searchdirs = tmp;
|
|
|
|
}
|
|
|
|
searchdirs[nsearch++] = optarg;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
do_destroyed = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'f':
|
2010-08-26 21:24:34 +00:00
|
|
|
flags |= ZFS_IMPORT_ANY_HOST;
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
2008-12-03 20:09:06 +00:00
|
|
|
case 'F':
|
2010-05-28 20:45:14 +00:00
|
|
|
do_rewind = B_TRUE;
|
|
|
|
break;
|
2010-08-26 21:24:34 +00:00
|
|
|
case 'm':
|
|
|
|
flags |= ZFS_IMPORT_MISSING_LOG;
|
|
|
|
break;
|
2010-05-28 20:45:14 +00:00
|
|
|
case 'n':
|
|
|
|
dryrun = B_TRUE;
|
2008-12-03 20:09:06 +00:00
|
|
|
break;
|
2010-08-26 21:24:34 +00:00
|
|
|
case 'N':
|
|
|
|
flags |= ZFS_IMPORT_ONLY;
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case 'o':
|
|
|
|
if ((propval = strchr(optarg, '=')) != NULL) {
|
|
|
|
*propval = '\0';
|
|
|
|
propval++;
|
2008-12-03 20:09:06 +00:00
|
|
|
if (add_prop_list(optarg, propval,
|
|
|
|
&props, B_TRUE))
|
2008-11-20 20:01:55 +00:00
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
mntopts = optarg;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
if (add_prop_list(zpool_prop_to_name(
|
2008-12-03 20:09:06 +00:00
|
|
|
ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
|
2008-11-20 20:01:55 +00:00
|
|
|
goto error;
|
|
|
|
if (nvlist_lookup_string(props,
|
|
|
|
zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
|
|
|
|
&propval) == 0)
|
|
|
|
break;
|
|
|
|
if (add_prop_list(zpool_prop_to_name(
|
2008-12-03 20:09:06 +00:00
|
|
|
ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
|
2008-11-20 20:01:55 +00:00
|
|
|
goto error;
|
|
|
|
break;
|
2013-07-01 14:57:04 +00:00
|
|
|
case 't':
|
|
|
|
flags |= ZFS_IMPORT_TEMP_NAME;
|
|
|
|
break;
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
case 'T':
|
|
|
|
errno = 0;
|
2014-07-15 18:58:41 +00:00
|
|
|
txg = strtoull(optarg, &endptr, 0);
|
2010-08-26 21:24:34 +00:00
|
|
|
if (errno != 0 || *endptr != '\0') {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("invalid txg value\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
rewind_policy = ZPOOL_DO_REWIND | ZPOOL_EXTREME_REWIND;
|
|
|
|
break;
|
2010-05-28 20:45:14 +00:00
|
|
|
case 'V':
|
2010-08-26 21:24:34 +00:00
|
|
|
flags |= ZFS_IMPORT_VERBATIM;
|
2010-05-28 20:45:14 +00:00
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
xtreme_rewind = B_TRUE;
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case ':':
|
|
|
|
(void) fprintf(stderr, gettext("missing argument for "
|
|
|
|
"'%c' option\n"), optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (cachefile && nsearch != 0) {
|
|
|
|
(void) fprintf(stderr, gettext("-c is incompatible with -d\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((dryrun || xtreme_rewind) && !do_rewind) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("-n or -X only meaningful with -F\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (dryrun)
|
|
|
|
rewind_policy = ZPOOL_TRY_REWIND;
|
|
|
|
else if (do_rewind)
|
|
|
|
rewind_policy = ZPOOL_DO_REWIND;
|
|
|
|
if (xtreme_rewind)
|
|
|
|
rewind_policy |= ZPOOL_EXTREME_REWIND;
|
|
|
|
|
|
|
|
/* In the future, we can capture further policy and include it here */
|
|
|
|
if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
|
2010-08-26 21:24:34 +00:00
|
|
|
nvlist_add_uint64(policy, ZPOOL_REWIND_REQUEST_TXG, txg) != 0 ||
|
2010-05-28 20:45:14 +00:00
|
|
|
nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind_policy) != 0)
|
|
|
|
goto error;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/* check argument count */
|
|
|
|
if (do_all) {
|
|
|
|
if (argc != 0) {
|
|
|
|
(void) fprintf(stderr, gettext("too many arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (argc > 2) {
|
|
|
|
(void) fprintf(stderr, gettext("too many arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for the SYS_CONFIG privilege. We do this explicitly
|
|
|
|
* here because otherwise any attempt to discover pools will
|
|
|
|
* silently fail.
|
|
|
|
*/
|
|
|
|
if (argc == 0 && !priv_ineffect(PRIV_SYS_CONFIG)) {
|
|
|
|
(void) fprintf(stderr, gettext("cannot "
|
|
|
|
"discover pools: permission denied\n"));
|
2010-08-26 18:56:53 +00:00
|
|
|
if (searchdirs != NULL)
|
|
|
|
free(searchdirs);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
nvlist_free(policy);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Depending on the arguments given, we do one of the following:
|
|
|
|
*
|
|
|
|
* <none> Iterate through all pools and display information about
|
|
|
|
* each one.
|
|
|
|
*
|
|
|
|
* -a Iterate through all pools and try to import each one.
|
|
|
|
*
|
|
|
|
* <id> Find the pool that corresponds to the given GUID/pool
|
|
|
|
* name and import that one.
|
|
|
|
*
|
|
|
|
* -D Above options applies only to destroyed pools.
|
|
|
|
*/
|
|
|
|
if (argc != 0) {
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
searchguid = strtoull(argv[0], &endptr, 10);
|
|
|
|
if (errno != 0 || *endptr != '\0')
|
|
|
|
searchname = argv[0];
|
|
|
|
found_config = NULL;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* User specified a name or guid. Ensure it's unique.
|
2008-12-03 20:09:06 +00:00
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
idata.unique = B_TRUE;
|
2008-12-03 20:09:06 +00:00
|
|
|
}
|
|
|
|
|
2012-09-15 20:25:21 +00:00
|
|
|
/*
|
|
|
|
* Check the environment for the preferred search path.
|
|
|
|
*/
|
|
|
|
if ((searchdirs == NULL) && (env = getenv("ZPOOL_IMPORT_PATH"))) {
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
envdup = strdup(env);
|
|
|
|
|
|
|
|
dir = strtok(envdup, ":");
|
|
|
|
while (dir != NULL) {
|
|
|
|
if (searchdirs == NULL) {
|
|
|
|
searchdirs = safe_malloc(sizeof (char *));
|
|
|
|
} else {
|
|
|
|
char **tmp = safe_malloc((nsearch + 1) *
|
|
|
|
sizeof (char *));
|
|
|
|
bcopy(searchdirs, tmp, nsearch *
|
|
|
|
sizeof (char *));
|
|
|
|
free(searchdirs);
|
|
|
|
searchdirs = tmp;
|
|
|
|
}
|
|
|
|
searchdirs[nsearch++] = dir;
|
|
|
|
dir = strtok(NULL, ":");
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
idata.path = searchdirs;
|
|
|
|
idata.paths = nsearch;
|
|
|
|
idata.poolname = searchname;
|
|
|
|
idata.guid = searchguid;
|
|
|
|
idata.cachefile = cachefile;
|
|
|
|
|
|
|
|
pools = zpool_search_import(g_zfs, &idata);
|
|
|
|
|
|
|
|
if (pools != NULL && idata.exists &&
|
|
|
|
(argc == 1 || strcmp(argv[0], argv[1]) == 0)) {
|
|
|
|
(void) fprintf(stderr, gettext("cannot import '%s': "
|
|
|
|
"a pool with that name already exists\n"),
|
|
|
|
argv[0]);
|
|
|
|
(void) fprintf(stderr, gettext("use the form '%s "
|
|
|
|
"<pool | id> <newpool>' to give it a new name\n"),
|
|
|
|
"zpool import");
|
|
|
|
err = 1;
|
|
|
|
} else if (pools == NULL && idata.exists) {
|
|
|
|
(void) fprintf(stderr, gettext("cannot import '%s': "
|
|
|
|
"a pool with that name is already created/imported,\n"),
|
|
|
|
argv[0]);
|
|
|
|
(void) fprintf(stderr, gettext("and no additional pools "
|
|
|
|
"with that name were found\n"));
|
|
|
|
err = 1;
|
|
|
|
} else if (pools == NULL) {
|
2008-12-03 20:09:06 +00:00
|
|
|
if (argc != 0) {
|
|
|
|
(void) fprintf(stderr, gettext("cannot import '%s': "
|
|
|
|
"no such pool available\n"), argv[0]);
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
err = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == 1) {
|
2010-08-26 18:56:53 +00:00
|
|
|
if (searchdirs != NULL)
|
|
|
|
free(searchdirs);
|
2012-09-15 20:25:21 +00:00
|
|
|
if (envdup != NULL)
|
|
|
|
free(envdup);
|
2010-05-28 20:45:14 +00:00
|
|
|
nvlist_free(policy);
|
2008-12-03 20:09:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point we have a list of import candidate configs. Even if
|
|
|
|
* we were searching by pool name or guid, we still need to
|
|
|
|
* post-process the list to deal with pool state and possible
|
|
|
|
* duplicate names.
|
|
|
|
*/
|
2008-11-20 20:01:55 +00:00
|
|
|
err = 0;
|
|
|
|
elem = NULL;
|
|
|
|
first = B_TRUE;
|
|
|
|
while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
|
|
|
|
|
|
|
|
verify(nvpair_value_nvlist(elem, &config) == 0);
|
|
|
|
|
|
|
|
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
|
|
|
|
&pool_state) == 0);
|
|
|
|
if (!do_destroyed && pool_state == POOL_STATE_DESTROYED)
|
|
|
|
continue;
|
|
|
|
if (do_destroyed && pool_state != POOL_STATE_DESTROYED)
|
|
|
|
continue;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
verify(nvlist_add_nvlist(config, ZPOOL_REWIND_POLICY,
|
|
|
|
policy) == 0);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (argc == 0) {
|
|
|
|
if (first)
|
|
|
|
first = B_FALSE;
|
|
|
|
else if (!do_all)
|
|
|
|
(void) printf("\n");
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (do_all) {
|
2008-11-20 20:01:55 +00:00
|
|
|
err |= do_import(config, NULL, mntopts,
|
2010-08-26 21:24:34 +00:00
|
|
|
props, flags);
|
2010-05-28 20:45:14 +00:00
|
|
|
} else {
|
2008-11-20 20:01:55 +00:00
|
|
|
show_import(config);
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
} else if (searchname != NULL) {
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are searching for a pool based on name.
|
|
|
|
*/
|
|
|
|
verify(nvlist_lookup_string(config,
|
|
|
|
ZPOOL_CONFIG_POOL_NAME, &name) == 0);
|
|
|
|
|
|
|
|
if (strcmp(name, searchname) == 0) {
|
|
|
|
if (found_config != NULL) {
|
|
|
|
(void) fprintf(stderr, gettext(
|
|
|
|
"cannot import '%s': more than "
|
|
|
|
"one matching pool\n"), searchname);
|
|
|
|
(void) fprintf(stderr, gettext(
|
|
|
|
"import by numeric ID instead\n"));
|
|
|
|
err = B_TRUE;
|
|
|
|
}
|
|
|
|
found_config = config;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint64_t guid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for a pool by guid.
|
|
|
|
*/
|
|
|
|
verify(nvlist_lookup_uint64(config,
|
|
|
|
ZPOOL_CONFIG_POOL_GUID, &guid) == 0);
|
|
|
|
|
|
|
|
if (guid == searchguid)
|
|
|
|
found_config = config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we were searching for a specific pool, verify that we found a
|
|
|
|
* pool, and then do the import.
|
|
|
|
*/
|
|
|
|
if (argc != 0 && err == 0) {
|
|
|
|
if (found_config == NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("cannot import '%s': "
|
|
|
|
"no such pool available\n"), argv[0]);
|
|
|
|
err = B_TRUE;
|
|
|
|
} else {
|
|
|
|
err |= do_import(found_config, argc == 1 ? NULL :
|
2010-08-26 21:24:34 +00:00
|
|
|
argv[1], mntopts, props, flags);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we were just looking for pools, report an error if none were
|
|
|
|
* found.
|
|
|
|
*/
|
|
|
|
if (argc == 0 && first)
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("no pools available to import\n"));
|
|
|
|
|
|
|
|
error:
|
|
|
|
nvlist_free(props);
|
|
|
|
nvlist_free(pools);
|
2010-05-28 20:45:14 +00:00
|
|
|
nvlist_free(policy);
|
2010-08-26 18:56:53 +00:00
|
|
|
if (searchdirs != NULL)
|
|
|
|
free(searchdirs);
|
2012-09-15 20:25:21 +00:00
|
|
|
if (envdup != NULL)
|
|
|
|
free(envdup);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (err ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct iostat_cbdata {
|
2012-01-24 02:43:32 +00:00
|
|
|
boolean_t cb_verbose;
|
2008-11-20 20:01:55 +00:00
|
|
|
int cb_namewidth;
|
2012-01-24 02:43:32 +00:00
|
|
|
int cb_iteration;
|
|
|
|
zpool_list_t *cb_list;
|
2008-11-20 20:01:55 +00:00
|
|
|
} iostat_cbdata_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_iostat_separator(iostat_cbdata_t *cb)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < cb->cb_namewidth; i++)
|
|
|
|
(void) printf("-");
|
|
|
|
(void) printf(" ----- ----- ----- ----- ----- -----\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_iostat_header(iostat_cbdata_t *cb)
|
|
|
|
{
|
|
|
|
(void) printf("%*s capacity operations bandwidth\n",
|
|
|
|
cb->cb_namewidth, "");
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) printf("%-*s alloc free read write read write\n",
|
2008-11-20 20:01:55 +00:00
|
|
|
cb->cb_namewidth, "pool");
|
|
|
|
print_iostat_separator(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display a single statistic.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
print_one_stat(uint64_t value)
|
|
|
|
{
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
zfs_nicenum(value, buf, sizeof (buf));
|
|
|
|
(void) printf(" %5s", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out all the statistics for the given vdev. This can either be the
|
|
|
|
* toplevel configuration, or called recursively. If 'name' is NULL, then this
|
|
|
|
* is a verbose output, and we don't want to display the toplevel pool stats.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
|
|
|
|
nvlist_t *newnv, iostat_cbdata_t *cb, int depth)
|
|
|
|
{
|
|
|
|
nvlist_t **oldchild, **newchild;
|
|
|
|
uint_t c, children;
|
|
|
|
vdev_stat_t *oldvs, *newvs;
|
|
|
|
vdev_stat_t zerovs = { 0 };
|
|
|
|
uint64_t tdelta;
|
|
|
|
double scale;
|
|
|
|
char *vname;
|
|
|
|
|
|
|
|
if (oldnv != NULL) {
|
2010-05-28 20:45:14 +00:00
|
|
|
verify(nvlist_lookup_uint64_array(oldnv,
|
|
|
|
ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&oldvs, &c) == 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
oldvs = &zerovs;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
verify(nvlist_lookup_uint64_array(newnv, ZPOOL_CONFIG_VDEV_STATS,
|
2008-11-20 20:01:55 +00:00
|
|
|
(uint64_t **)&newvs, &c) == 0);
|
|
|
|
|
|
|
|
if (strlen(name) + depth > cb->cb_namewidth)
|
|
|
|
(void) printf("%*s%s", depth, "", name);
|
|
|
|
else
|
|
|
|
(void) printf("%*s%s%*s", depth, "", name,
|
|
|
|
(int)(cb->cb_namewidth - strlen(name) - depth), "");
|
|
|
|
|
|
|
|
tdelta = newvs->vs_timestamp - oldvs->vs_timestamp;
|
|
|
|
|
|
|
|
if (tdelta == 0)
|
|
|
|
scale = 1.0;
|
|
|
|
else
|
|
|
|
scale = (double)NANOSEC / tdelta;
|
|
|
|
|
|
|
|
/* only toplevel vdevs have capacity stats */
|
|
|
|
if (newvs->vs_space == 0) {
|
|
|
|
(void) printf(" - -");
|
|
|
|
} else {
|
|
|
|
print_one_stat(newvs->vs_alloc);
|
|
|
|
print_one_stat(newvs->vs_space - newvs->vs_alloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_READ] -
|
|
|
|
oldvs->vs_ops[ZIO_TYPE_READ])));
|
|
|
|
|
|
|
|
print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_WRITE] -
|
|
|
|
oldvs->vs_ops[ZIO_TYPE_WRITE])));
|
|
|
|
|
|
|
|
print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_READ] -
|
|
|
|
oldvs->vs_bytes[ZIO_TYPE_READ])));
|
|
|
|
|
|
|
|
print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_WRITE] -
|
|
|
|
oldvs->vs_bytes[ZIO_TYPE_WRITE])));
|
|
|
|
|
|
|
|
(void) printf("\n");
|
|
|
|
|
|
|
|
if (!cb->cb_verbose)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&newchild, &children) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&oldchild, &c) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
2012-04-23 21:52:50 +00:00
|
|
|
uint64_t ishole = B_FALSE, islog = B_FALSE;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2012-04-23 21:52:50 +00:00
|
|
|
(void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_HOLE,
|
|
|
|
&ishole);
|
|
|
|
|
|
|
|
(void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_LOG,
|
|
|
|
&islog);
|
|
|
|
|
|
|
|
if (ishole || islog)
|
2010-05-28 20:45:14 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
vname = zpool_vdev_name(g_zfs, zhp, newchild[c], B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
|
|
|
|
newchild[c], cb, depth + 2);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
|
2012-04-23 21:52:50 +00:00
|
|
|
/*
|
|
|
|
* Log device section
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (num_logs(newnv) > 0) {
|
|
|
|
(void) printf("%-*s - - - - - "
|
|
|
|
"-\n", cb->cb_namewidth, "logs");
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
|
|
|
uint64_t islog = B_FALSE;
|
|
|
|
(void) nvlist_lookup_uint64(newchild[c],
|
|
|
|
ZPOOL_CONFIG_IS_LOG, &islog);
|
|
|
|
|
|
|
|
if (islog) {
|
|
|
|
vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
|
|
|
|
B_FALSE);
|
|
|
|
print_vdev_stats(zhp, vname, oldnv ?
|
|
|
|
oldchild[c] : NULL, newchild[c],
|
|
|
|
cb, depth + 2);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Include level 2 ARC devices in iostat output
|
|
|
|
*/
|
|
|
|
if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_L2CACHE,
|
|
|
|
&newchild, &children) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_L2CACHE,
|
|
|
|
&oldchild, &c) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (children > 0) {
|
|
|
|
(void) printf("%-*s - - - - - "
|
|
|
|
"-\n", cb->cb_namewidth, "cache");
|
|
|
|
for (c = 0; c < children; c++) {
|
2010-05-28 20:45:14 +00:00
|
|
|
vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
|
|
|
|
B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
|
|
|
|
newchild[c], cb, depth + 2);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
refresh_iostat(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
iostat_cbdata_t *cb = data;
|
|
|
|
boolean_t missing;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the pool has disappeared, remove it from the list and continue.
|
|
|
|
*/
|
|
|
|
if (zpool_refresh_stats(zhp, &missing) != 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (missing)
|
|
|
|
pool_list_remove(cb->cb_list, zhp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback to print out the iostats for the given pool.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
print_iostat(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
iostat_cbdata_t *cb = data;
|
|
|
|
nvlist_t *oldconfig, *newconfig;
|
|
|
|
nvlist_t *oldnvroot, *newnvroot;
|
|
|
|
|
|
|
|
newconfig = zpool_get_config(zhp, &oldconfig);
|
|
|
|
|
|
|
|
if (cb->cb_iteration == 1)
|
|
|
|
oldconfig = NULL;
|
|
|
|
|
|
|
|
verify(nvlist_lookup_nvlist(newconfig, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&newnvroot) == 0);
|
|
|
|
|
|
|
|
if (oldconfig == NULL)
|
|
|
|
oldnvroot = NULL;
|
|
|
|
else
|
|
|
|
verify(nvlist_lookup_nvlist(oldconfig, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&oldnvroot) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out the statistics for the pool.
|
|
|
|
*/
|
|
|
|
print_vdev_stats(zhp, zpool_get_name(zhp), oldnvroot, newnvroot, cb, 0);
|
|
|
|
|
|
|
|
if (cb->cb_verbose)
|
|
|
|
print_iostat_separator(cb);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-03-27 10:37:41 +00:00
|
|
|
static int
|
|
|
|
get_columns(void)
|
|
|
|
{
|
|
|
|
struct winsize ws;
|
|
|
|
int columns = 80;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (isatty(STDOUT_FILENO)) {
|
|
|
|
error = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
|
|
|
|
if (error == 0)
|
|
|
|
columns = ws.ws_col;
|
|
|
|
} else {
|
|
|
|
columns = 999;
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
return (columns);
|
2012-03-27 10:37:41 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
int
|
|
|
|
get_namewidth(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
iostat_cbdata_t *cb = data;
|
|
|
|
nvlist_t *config, *nvroot;
|
2012-03-27 10:37:41 +00:00
|
|
|
int columns;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if ((config = zpool_get_config(zhp, NULL)) != NULL) {
|
|
|
|
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&nvroot) == 0);
|
|
|
|
if (!cb->cb_verbose)
|
|
|
|
cb->cb_namewidth = strlen(zpool_get_name(zhp));
|
|
|
|
else
|
2012-04-24 11:59:56 +00:00
|
|
|
cb->cb_namewidth = max_width(zhp, nvroot, 0,
|
|
|
|
cb->cb_namewidth);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-27 10:37:41 +00:00
|
|
|
* The width must be at least 10, but may be as large as the
|
|
|
|
* column width - 42 so that we can still fit in one line.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2012-03-27 10:37:41 +00:00
|
|
|
columns = get_columns();
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (cb->cb_namewidth < 10)
|
|
|
|
cb->cb_namewidth = 10;
|
2012-03-27 10:37:41 +00:00
|
|
|
if (cb->cb_namewidth > columns - 42)
|
|
|
|
cb->cb_namewidth = columns - 42;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* Parse the input string, get the 'interval' and 'count' value if there is one.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
static void
|
|
|
|
get_interval_count(int *argcp, char **argv, unsigned long *iv,
|
|
|
|
unsigned long *cnt)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
unsigned long interval = 0, count = 0;
|
2010-08-26 16:53:00 +00:00
|
|
|
int argc = *argcp;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine if the last argument is an integer or a pool name
|
|
|
|
*/
|
|
|
|
if (argc > 0 && isdigit(argv[argc - 1][0])) {
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
interval = strtoul(argv[argc - 1], &end, 10);
|
|
|
|
|
|
|
|
if (*end == '\0' && errno == 0) {
|
|
|
|
if (interval == 0) {
|
|
|
|
(void) fprintf(stderr, gettext("interval "
|
|
|
|
"cannot be zero\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Ignore the last parameter
|
|
|
|
*/
|
|
|
|
argc--;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If this is not a valid number, just plow on. The
|
|
|
|
* user will get a more informative error message later
|
|
|
|
* on.
|
|
|
|
*/
|
|
|
|
interval = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the last argument is also an integer, then we have both a count
|
2010-05-28 20:45:14 +00:00
|
|
|
* and an interval.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
if (argc > 0 && isdigit(argv[argc - 1][0])) {
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
count = interval;
|
|
|
|
interval = strtoul(argv[argc - 1], &end, 10);
|
|
|
|
|
|
|
|
if (*end == '\0' && errno == 0) {
|
|
|
|
if (interval == 0) {
|
|
|
|
(void) fprintf(stderr, gettext("interval "
|
|
|
|
"cannot be zero\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore the last parameter
|
|
|
|
*/
|
|
|
|
argc--;
|
|
|
|
} else {
|
|
|
|
interval = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
*iv = interval;
|
|
|
|
*cnt = count;
|
|
|
|
*argcp = argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_timestamp_arg(char c)
|
|
|
|
{
|
|
|
|
if (c == 'u')
|
|
|
|
timestamp_fmt = UDATE;
|
|
|
|
else if (c == 'd')
|
|
|
|
timestamp_fmt = DDATE;
|
|
|
|
else
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
|
|
|
|
*
|
|
|
|
* -v Display statistics for individual vdevs
|
|
|
|
* -T Display a timestamp in date(1) or Unix format
|
|
|
|
*
|
|
|
|
* This command can be tricky because we want to be able to deal with pool
|
|
|
|
* 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
|
|
|
|
* on pool_list_update() to detect the addition of new pools. Configuration
|
|
|
|
* changes are all handled within libzfs.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_iostat(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int ret;
|
|
|
|
int npools;
|
|
|
|
unsigned long interval = 0, count = 0;
|
|
|
|
zpool_list_t *list;
|
|
|
|
boolean_t verbose = B_FALSE;
|
|
|
|
iostat_cbdata_t cb;
|
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "T:v")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'T':
|
|
|
|
get_timestamp_arg(*optarg);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = B_TRUE;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
get_interval_count(&argc, argv, &interval, &count);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Construct the list of all interesting pools.
|
|
|
|
*/
|
|
|
|
ret = 0;
|
|
|
|
if ((list = pool_list_get(argc, argv, NULL, &ret)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (pool_list_count(list) == 0 && argc != 0) {
|
|
|
|
pool_list_free(list);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool_list_count(list) == 0 && interval == 0) {
|
|
|
|
pool_list_free(list);
|
|
|
|
(void) fprintf(stderr, gettext("no pools available\n"));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enter the main iostat loop.
|
|
|
|
*/
|
|
|
|
cb.cb_list = list;
|
|
|
|
cb.cb_verbose = verbose;
|
|
|
|
cb.cb_iteration = 0;
|
|
|
|
cb.cb_namewidth = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
pool_list_update(list);
|
|
|
|
|
|
|
|
if ((npools = pool_list_count(list)) == 0)
|
2012-03-14 13:34:00 +00:00
|
|
|
(void) fprintf(stderr, gettext("no pools available\n"));
|
2011-07-04 22:45:35 +00:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Refresh all statistics. This is done as an
|
|
|
|
* explicit step before calculating the maximum name
|
|
|
|
* width, so that any * configuration changes are
|
|
|
|
* properly accounted for.
|
|
|
|
*/
|
|
|
|
(void) pool_list_iter(list, B_FALSE, refresh_iostat,
|
|
|
|
&cb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-07-04 22:45:35 +00:00
|
|
|
/*
|
|
|
|
* Iterate over all pools to determine the maximum width
|
|
|
|
* for the pool / device name column across all pools.
|
|
|
|
*/
|
|
|
|
cb.cb_namewidth = 0;
|
|
|
|
(void) pool_list_iter(list, B_FALSE, get_namewidth,
|
|
|
|
&cb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-07-04 22:45:35 +00:00
|
|
|
if (timestamp_fmt != NODATE)
|
|
|
|
print_timestamp(timestamp_fmt);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2011-07-04 22:45:35 +00:00
|
|
|
/*
|
|
|
|
* If it's the first time, or verbose mode, print the
|
|
|
|
* header.
|
|
|
|
*/
|
|
|
|
if (++cb.cb_iteration == 1 || verbose)
|
|
|
|
print_iostat_header(&cb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-07-04 22:45:35 +00:00
|
|
|
(void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-07-04 22:45:35 +00:00
|
|
|
/*
|
|
|
|
* If there's more than one pool, and we're not in
|
|
|
|
* verbose mode (which prints a separator for us),
|
|
|
|
* then print a separator.
|
|
|
|
*/
|
|
|
|
if (npools > 1 && !verbose)
|
|
|
|
print_iostat_separator(&cb);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-07-04 22:45:35 +00:00
|
|
|
if (verbose)
|
|
|
|
(void) printf("\n");
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) sleep(interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
pool_list_free(list);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct list_cbdata {
|
2012-01-24 02:43:32 +00:00
|
|
|
boolean_t cb_verbose;
|
|
|
|
int cb_namewidth;
|
2008-11-20 20:01:55 +00:00
|
|
|
boolean_t cb_scripted;
|
|
|
|
zprop_list_t *cb_proplist;
|
|
|
|
} list_cbdata_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a list of columns to display, output appropriate headers for each one.
|
|
|
|
*/
|
|
|
|
static void
|
2012-01-24 02:43:32 +00:00
|
|
|
print_header(list_cbdata_t *cb)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2012-01-24 02:43:32 +00:00
|
|
|
zprop_list_t *pl = cb->cb_proplist;
|
2012-12-13 23:24:15 +00:00
|
|
|
char headerbuf[ZPOOL_MAXPROPLEN];
|
2008-11-20 20:01:55 +00:00
|
|
|
const char *header;
|
|
|
|
boolean_t first = B_TRUE;
|
|
|
|
boolean_t right_justify;
|
2012-01-24 02:43:32 +00:00
|
|
|
size_t width = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
for (; pl != NULL; pl = pl->pl_next) {
|
2012-01-24 02:43:32 +00:00
|
|
|
width = pl->pl_width;
|
|
|
|
if (first && cb->cb_verbose) {
|
|
|
|
/*
|
|
|
|
* Reset the width to accommodate the verbose listing
|
|
|
|
* of devices.
|
|
|
|
*/
|
|
|
|
width = cb->cb_namewidth;
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (!first)
|
|
|
|
(void) printf(" ");
|
|
|
|
else
|
|
|
|
first = B_FALSE;
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
right_justify = B_FALSE;
|
|
|
|
if (pl->pl_prop != ZPROP_INVAL) {
|
|
|
|
header = zpool_prop_column_name(pl->pl_prop);
|
|
|
|
right_justify = zpool_prop_align_right(pl->pl_prop);
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; pl->pl_user_prop[i] != '\0'; i++)
|
|
|
|
headerbuf[i] = toupper(pl->pl_user_prop[i]);
|
|
|
|
headerbuf[i] = '\0';
|
|
|
|
header = headerbuf;
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (pl->pl_next == NULL && !right_justify)
|
|
|
|
(void) printf("%s", header);
|
|
|
|
else if (right_justify)
|
2012-01-24 02:43:32 +00:00
|
|
|
(void) printf("%*s", (int)width, header);
|
2008-11-20 20:01:55 +00:00
|
|
|
else
|
2012-01-24 02:43:32 +00:00
|
|
|
(void) printf("%-*s", (int)width, header);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a pool and a list of properties, print out all the properties according
|
|
|
|
* to the described layout.
|
|
|
|
*/
|
|
|
|
static void
|
2012-01-24 02:43:32 +00:00
|
|
|
print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2012-01-24 02:43:32 +00:00
|
|
|
zprop_list_t *pl = cb->cb_proplist;
|
2008-11-20 20:01:55 +00:00
|
|
|
boolean_t first = B_TRUE;
|
|
|
|
char property[ZPOOL_MAXPROPLEN];
|
|
|
|
char *propstr;
|
|
|
|
boolean_t right_justify;
|
2012-01-24 02:43:32 +00:00
|
|
|
size_t width;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
for (; pl != NULL; pl = pl->pl_next) {
|
2012-01-24 02:43:32 +00:00
|
|
|
|
|
|
|
width = pl->pl_width;
|
|
|
|
if (first && cb->cb_verbose) {
|
|
|
|
/*
|
|
|
|
* Reset the width to accommodate the verbose listing
|
|
|
|
* of devices.
|
|
|
|
*/
|
|
|
|
width = cb->cb_namewidth;
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (!first) {
|
2012-01-24 02:43:32 +00:00
|
|
|
if (cb->cb_scripted)
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf("\t");
|
|
|
|
else
|
|
|
|
(void) printf(" ");
|
|
|
|
} else {
|
|
|
|
first = B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
right_justify = B_FALSE;
|
|
|
|
if (pl->pl_prop != ZPROP_INVAL) {
|
2014-09-12 03:07:20 +00:00
|
|
|
if (zpool_get_prop(zhp, pl->pl_prop, property,
|
2008-11-20 20:01:55 +00:00
|
|
|
sizeof (property), NULL) != 0)
|
|
|
|
propstr = "-";
|
|
|
|
else
|
|
|
|
propstr = property;
|
|
|
|
|
|
|
|
right_justify = zpool_prop_align_right(pl->pl_prop);
|
2012-12-13 23:24:15 +00:00
|
|
|
} else if ((zpool_prop_feature(pl->pl_user_prop) ||
|
|
|
|
zpool_prop_unsupported(pl->pl_user_prop)) &&
|
|
|
|
zpool_prop_get_feature(zhp, pl->pl_user_prop, property,
|
|
|
|
sizeof (property)) == 0) {
|
|
|
|
propstr = property;
|
2008-11-20 20:01:55 +00:00
|
|
|
} 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
|
|
|
|
* format specifier.
|
|
|
|
*/
|
2012-01-24 02:43:32 +00:00
|
|
|
if (cb->cb_scripted || (pl->pl_next == NULL && !right_justify))
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf("%s", propstr);
|
|
|
|
else if (right_justify)
|
2012-01-24 02:43:32 +00:00
|
|
|
(void) printf("%*s", (int)width, propstr);
|
2008-11-20 20:01:55 +00:00
|
|
|
else
|
2012-01-24 02:43:32 +00:00
|
|
|
(void) printf("%-*s", (int)width, propstr);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf("\n");
|
|
|
|
}
|
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
static void
|
2014-09-12 03:07:20 +00:00
|
|
|
print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted,
|
|
|
|
boolean_t valid)
|
2012-01-24 02:43:32 +00:00
|
|
|
{
|
|
|
|
char propval[64];
|
|
|
|
boolean_t fixed;
|
|
|
|
size_t width = zprop_width(prop, &fixed, ZFS_TYPE_POOL);
|
|
|
|
|
2014-09-12 03:07:20 +00:00
|
|
|
switch (prop) {
|
|
|
|
case ZPOOL_PROP_EXPANDSZ:
|
|
|
|
if (value == 0)
|
|
|
|
(void) strlcpy(propval, "-", sizeof (propval));
|
|
|
|
else
|
|
|
|
zfs_nicenum(value, propval, sizeof (propval));
|
|
|
|
break;
|
|
|
|
case ZPOOL_PROP_FRAGMENTATION:
|
|
|
|
if (value == ZFS_FRAG_INVALID) {
|
|
|
|
(void) strlcpy(propval, "-", sizeof (propval));
|
|
|
|
} else {
|
|
|
|
(void) snprintf(propval, sizeof (propval), "%llu%%",
|
|
|
|
(unsigned long long)value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ZPOOL_PROP_CAPACITY:
|
2014-07-19 20:19:24 +00:00
|
|
|
(void) snprintf(propval, sizeof (propval), "%llu%%",
|
|
|
|
(unsigned long long)value);
|
2014-09-12 03:07:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-07-19 20:19:24 +00:00
|
|
|
zfs_nicenum(value, propval, sizeof (propval));
|
2014-09-12 03:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid)
|
|
|
|
(void) strlcpy(propval, "-", sizeof (propval));
|
2012-01-24 02:43:32 +00:00
|
|
|
|
|
|
|
if (scripted)
|
|
|
|
(void) printf("\t%s", propval);
|
|
|
|
else
|
|
|
|
(void) printf(" %*s", (int)width, propval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
|
|
|
|
list_cbdata_t *cb, int depth)
|
|
|
|
{
|
|
|
|
nvlist_t **child;
|
|
|
|
vdev_stat_t *vs;
|
|
|
|
uint_t c, children;
|
|
|
|
char *vname;
|
|
|
|
boolean_t scripted = cb->cb_scripted;
|
|
|
|
|
|
|
|
verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
|
|
|
|
(uint64_t **)&vs, &c) == 0);
|
|
|
|
|
|
|
|
if (name != NULL) {
|
2014-09-12 03:07:20 +00:00
|
|
|
boolean_t toplevel = (vs->vs_space != 0);
|
|
|
|
uint64_t cap;
|
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
if (scripted)
|
|
|
|
(void) printf("\t%s", name);
|
|
|
|
else if (strlen(name) + depth > cb->cb_namewidth)
|
|
|
|
(void) printf("%*s%s", depth, "", name);
|
|
|
|
else
|
|
|
|
(void) printf("%*s%s%*s", depth, "", name,
|
|
|
|
(int)(cb->cb_namewidth - strlen(name) - depth), "");
|
|
|
|
|
2014-09-12 03:07:20 +00:00
|
|
|
/*
|
|
|
|
* Print the properties for the individual vdevs. Some
|
|
|
|
* properties are only applicable to toplevel vdevs. The
|
|
|
|
* 'toplevel' boolean value is passed to the print_one_column()
|
|
|
|
* to indicate that the value is valid.
|
|
|
|
*/
|
|
|
|
print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, scripted,
|
|
|
|
toplevel);
|
|
|
|
print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, scripted,
|
|
|
|
toplevel);
|
|
|
|
print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc,
|
|
|
|
scripted, toplevel);
|
|
|
|
print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, scripted,
|
|
|
|
B_TRUE);
|
|
|
|
print_one_column(ZPOOL_PROP_FRAGMENTATION,
|
|
|
|
vs->vs_fragmentation, scripted,
|
|
|
|
(vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel));
|
|
|
|
cap = (vs->vs_space == 0) ? 0 :
|
|
|
|
(vs->vs_alloc * 100 / vs->vs_space);
|
|
|
|
print_one_column(ZPOOL_PROP_CAPACITY, cap, scripted, toplevel);
|
2012-01-24 02:43:32 +00:00
|
|
|
(void) printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
|
|
|
|
&child, &children) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (c = 0; c < children; c++) {
|
|
|
|
uint64_t ishole = B_FALSE;
|
|
|
|
|
|
|
|
if (nvlist_lookup_uint64(child[c],
|
|
|
|
ZPOOL_CONFIG_IS_HOLE, &ishole) == 0 && ishole)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
|
|
|
|
print_list_stats(zhp, vname, child[c], cb, depth + 2);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include level 2 ARC devices in iostat output
|
|
|
|
*/
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
|
|
|
|
&child, &children) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (children > 0) {
|
|
|
|
(void) printf("%-*s - - - - - "
|
|
|
|
"-\n", cb->cb_namewidth, "cache");
|
|
|
|
for (c = 0; c < children; c++) {
|
|
|
|
vname = zpool_vdev_name(g_zfs, zhp, child[c],
|
|
|
|
B_FALSE);
|
|
|
|
print_list_stats(zhp, vname, child[c], cb, depth + 2);
|
|
|
|
free(vname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Generic callback function to list a pool.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
list_callback(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
list_cbdata_t *cbp = data;
|
2012-01-24 02:43:32 +00:00
|
|
|
nvlist_t *config;
|
|
|
|
nvlist_t *nvroot;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
config = zpool_get_config(zhp, NULL);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
print_pool(zhp, cbp);
|
|
|
|
if (!cbp->cb_verbose)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&nvroot) == 0);
|
|
|
|
print_list_stats(zhp, NULL, nvroot, cbp, 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* zpool list [-H] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* -H Scripted mode. Don't display headers, and separate properties
|
|
|
|
* by a single tab.
|
|
|
|
* -o List of properties to display. Defaults to
|
2014-09-12 03:07:20 +00:00
|
|
|
* "name,size,allocated,free,expandsize,fragmentation,capacity,"
|
|
|
|
* "dedupratio,health,altroot"
|
2010-05-28 20:45:14 +00:00
|
|
|
* -T Display a timestamp in date(1) or Unix format
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* List all pools in the system, whether or not they're healthy. Output space
|
|
|
|
* statistics for each one, as well as health status summary.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_list(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
2013-07-23 19:37:14 +00:00
|
|
|
int ret = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
list_cbdata_t cb = { 0 };
|
|
|
|
static char default_props[] =
|
2014-09-12 03:07:20 +00:00
|
|
|
"name,size,allocated,free,expandsize,fragmentation,capacity,"
|
2014-07-19 20:19:24 +00:00
|
|
|
"dedupratio,health,altroot";
|
2008-11-20 20:01:55 +00:00
|
|
|
char *props = default_props;
|
2010-05-28 20:45:14 +00:00
|
|
|
unsigned long interval = 0, count = 0;
|
2012-01-24 02:43:32 +00:00
|
|
|
zpool_list_t *list;
|
|
|
|
boolean_t first = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* check options */
|
2012-01-24 02:43:32 +00:00
|
|
|
while ((c = getopt(argc, argv, ":Ho:T:v")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'H':
|
|
|
|
cb.cb_scripted = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
props = optarg;
|
|
|
|
break;
|
2010-05-28 20:45:14 +00:00
|
|
|
case 'T':
|
|
|
|
get_timestamp_arg(*optarg);
|
|
|
|
break;
|
2012-01-24 02:43:32 +00:00
|
|
|
case 'v':
|
|
|
|
cb.cb_verbose = B_TRUE;
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case ':':
|
|
|
|
(void) fprintf(stderr, gettext("missing argument for "
|
|
|
|
"'%c' option\n"), optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
get_interval_count(&argc, argv, &interval, &count);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (zprop_get_list(g_zfs, props, &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
|
|
|
|
usage(B_FALSE);
|
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
if ((list = pool_list_get(argc, argv, &cb.cb_proplist, &ret)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (argc == 0 && !cb.cb_scripted && pool_list_count(list) == 0) {
|
|
|
|
(void) printf(gettext("no pools available\n"));
|
|
|
|
zprop_free_list(cb.cb_proplist);
|
|
|
|
return (0);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
for (;;) {
|
2012-01-24 02:43:32 +00:00
|
|
|
pool_list_update(list);
|
|
|
|
|
|
|
|
if (pool_list_count(list) == 0)
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (timestamp_fmt != NODATE)
|
|
|
|
print_timestamp(timestamp_fmt);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
if (!cb.cb_scripted && (first || cb.cb_verbose)) {
|
|
|
|
print_header(&cb);
|
|
|
|
first = B_FALSE;
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2012-01-24 02:43:32 +00:00
|
|
|
ret = pool_list_iter(list, B_TRUE, list_callback, &cb);
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (interval == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (count != 0 && --count == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
(void) sleep(interval);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_free_list(cb.cb_proplist);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zpool_do_attach_or_replace(int argc, char **argv, int replacing)
|
|
|
|
{
|
|
|
|
boolean_t force = B_FALSE;
|
|
|
|
int c;
|
|
|
|
nvlist_t *nvroot;
|
|
|
|
char *poolname, *old_disk, *new_disk;
|
|
|
|
zpool_handle_t *zhp;
|
2012-11-06 12:39:00 +00:00
|
|
|
nvlist_t *props = NULL;
|
|
|
|
char *propval;
|
2008-11-20 20:01:55 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* check options */
|
2012-11-30 21:13:28 +00:00
|
|
|
while ((c = getopt(argc, argv, "fo:")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
force = B_TRUE;
|
|
|
|
break;
|
2012-11-06 12:39:00 +00:00
|
|
|
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;
|
2008-11-20 20:01:55 +00:00
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("missing <device> specification\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
old_disk = argv[1];
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
if (!replacing) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("missing <new_device> specification\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
new_disk = old_disk;
|
|
|
|
argc -= 1;
|
|
|
|
argv += 1;
|
|
|
|
} else {
|
|
|
|
new_disk = argv[2];
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
(void) fprintf(stderr, gettext("too many arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (zpool_get_config(zhp, NULL) == NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
|
|
|
|
poolname);
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2012-11-06 12:39:00 +00:00
|
|
|
nvroot = make_root_vdev(zhp, props, force, B_FALSE, replacing, B_FALSE,
|
2008-12-03 20:09:06 +00:00
|
|
|
argc, argv);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (nvroot == NULL) {
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = zpool_vdev_attach(zhp, old_disk, new_disk, nvroot, replacing);
|
|
|
|
|
|
|
|
nvlist_free(nvroot);
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool replace [-f] <pool> <device> <new_device>
|
|
|
|
*
|
|
|
|
* -f Force attach, even if <new_device> appears to be in use.
|
|
|
|
*
|
|
|
|
* Replace <device> with <new_device>.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
zpool_do_replace(int argc, char **argv)
|
|
|
|
{
|
|
|
|
return (zpool_do_attach_or_replace(argc, argv, B_TRUE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-11-06 12:39:00 +00:00
|
|
|
* zpool attach [-f] [-o property=value] <pool> <device> <new_device>
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* -f Force attach, even if <new_device> appears to be in use.
|
2012-11-06 12:39:00 +00:00
|
|
|
* -o Set property=value.
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_attach(int argc, char **argv)
|
|
|
|
{
|
|
|
|
return (zpool_do_attach_or_replace(argc, argv, B_FALSE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool detach [-f] <pool> <device>
|
|
|
|
*
|
|
|
|
* -f Force detach of <device>, even if DTLs argue against it
|
|
|
|
* (not supported yet)
|
|
|
|
*
|
|
|
|
* Detach a device from a mirror. The operation will be refused if <device>
|
|
|
|
* is the last device in the mirror, or if the DTLs indicate that this device
|
|
|
|
* has the only valid copy of some data.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
zpool_do_detach(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
char *poolname, *path;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "f")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("missing <device> specification\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
path = argv[1];
|
|
|
|
|
|
|
|
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
ret = zpool_vdev_detach(zhp, path);
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* zpool split [-n] [-o prop=val] ...
|
|
|
|
* [-o mntopt] ...
|
|
|
|
* [-R altroot] <pool> <newpool> [<device> ...]
|
|
|
|
*
|
|
|
|
* -n Do not split the pool, but display the resulting layout if
|
|
|
|
* it were to be split.
|
|
|
|
* -o Set property=value, or set mount options.
|
|
|
|
* -R Mount the split-off pool under an alternate root.
|
|
|
|
*
|
|
|
|
* Splits the named pool and gives it the new pool name. Devices to be split
|
|
|
|
* off may be listed, provided that no more than one device is specified
|
|
|
|
* per top-level vdev mirror. The newly split pool is left in an exported
|
|
|
|
* state unless -R is specified.
|
|
|
|
*
|
|
|
|
* Restrictions: the top-level of the pool pool must only be made up of
|
|
|
|
* mirrors; all devices in the pool must be healthy; no device may be
|
|
|
|
* undergoing a resilvering operation.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_split(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *srcpool, *newpool, *propval;
|
|
|
|
char *mntopts = NULL;
|
|
|
|
splitflags_t flags;
|
|
|
|
int c, ret = 0;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
nvlist_t *config, *props = NULL;
|
|
|
|
|
|
|
|
flags.dryrun = B_FALSE;
|
|
|
|
flags.import = B_FALSE;
|
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, ":R:no:")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'R':
|
|
|
|
flags.import = B_TRUE;
|
|
|
|
if (add_prop_list(
|
|
|
|
zpool_prop_to_name(ZPOOL_PROP_ALTROOT), optarg,
|
|
|
|
&props, B_TRUE) != 0) {
|
|
|
|
if (props)
|
|
|
|
nvlist_free(props);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
flags.dryrun = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if ((propval = strchr(optarg, '=')) != NULL) {
|
|
|
|
*propval = '\0';
|
|
|
|
propval++;
|
|
|
|
if (add_prop_list(optarg, propval,
|
|
|
|
&props, B_TRUE) != 0) {
|
|
|
|
if (props)
|
|
|
|
nvlist_free(props);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mntopts = optarg;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
(void) fprintf(stderr, gettext("missing argument for "
|
|
|
|
"'%c' option\n"), optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flags.import && mntopts != NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("setting mntopts is only "
|
|
|
|
"valid when importing the pool\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("Missing pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("Missing new pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
srcpool = argv[0];
|
|
|
|
newpool = argv[1];
|
|
|
|
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
|
|
|
|
|
|
|
if ((zhp = zpool_open(g_zfs, srcpool)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
config = split_mirror_vdev(zhp, newpool, props, flags, argc, argv);
|
|
|
|
if (config == NULL) {
|
|
|
|
ret = 1;
|
|
|
|
} else {
|
|
|
|
if (flags.dryrun) {
|
|
|
|
(void) printf(gettext("would create '%s' with the "
|
|
|
|
"following layout:\n\n"), newpool);
|
|
|
|
print_vdev_tree(NULL, newpool, config, 0, B_FALSE);
|
|
|
|
}
|
|
|
|
nvlist_free(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
if (ret != 0 || flags.dryrun || !flags.import)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The split was successful. Now we need to open the new
|
|
|
|
* pool and import it.
|
|
|
|
*/
|
|
|
|
if ((zhp = zpool_open_canfail(g_zfs, newpool)) == NULL)
|
|
|
|
return (1);
|
|
|
|
if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
|
|
|
|
zpool_enable_datasets(zhp, mntopts, 0) != 0) {
|
|
|
|
ret = 1;
|
2012-08-08 06:59:53 +00:00
|
|
|
(void) fprintf(stderr, gettext("Split was successful, but "
|
2010-05-28 20:45:14 +00:00
|
|
|
"the datasets could not all be mounted\n"));
|
|
|
|
(void) fprintf(stderr, gettext("Try doing '%s' with a "
|
|
|
|
"different altroot\n"), "zpool import");
|
|
|
|
}
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* zpool online <pool> <device> ...
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_online(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c, i;
|
|
|
|
char *poolname;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
int ret = 0;
|
|
|
|
vdev_state_t newstate;
|
2009-07-02 22:44:48 +00:00
|
|
|
int flags = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* check options */
|
2009-07-02 22:44:48 +00:00
|
|
|
while ((c = getopt(argc, argv, "et")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
2009-07-02 22:44:48 +00:00
|
|
|
case 'e':
|
|
|
|
flags |= ZFS_ONLINE_EXPAND;
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case 't':
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("missing device name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
|
|
|
|
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2009-07-02 22:44:48 +00:00
|
|
|
if (zpool_vdev_online(zhp, argv[i], flags, &newstate) == 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if (newstate != VDEV_STATE_HEALTHY) {
|
|
|
|
(void) printf(gettext("warning: device '%s' "
|
|
|
|
"onlined, but remains in faulted state\n"),
|
|
|
|
argv[i]);
|
|
|
|
if (newstate == VDEV_STATE_FAULTED)
|
|
|
|
(void) printf(gettext("use 'zpool "
|
|
|
|
"clear' to restore a faulted "
|
|
|
|
"device\n"));
|
|
|
|
else
|
|
|
|
(void) printf(gettext("use 'zpool "
|
|
|
|
"replace' to replace devices "
|
|
|
|
"that are no longer present\n"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool offline [-ft] <pool> <device> ...
|
|
|
|
*
|
|
|
|
* -f Force the device into the offline state, even if doing
|
|
|
|
* so would appear to compromise pool availability.
|
|
|
|
* (not supported yet)
|
|
|
|
*
|
|
|
|
* -t Only take the device off-line temporarily. The offline
|
|
|
|
* state will not be persistent across reboots.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
zpool_do_offline(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c, i;
|
|
|
|
char *poolname;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
int ret = 0;
|
|
|
|
boolean_t istmp = B_FALSE;
|
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "ft")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 't':
|
|
|
|
istmp = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("missing device name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
|
|
|
|
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (zpool_vdev_offline(zhp, argv[i], istmp) != 0)
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool clear <pool> [device]
|
|
|
|
*
|
|
|
|
* Clear all errors associated with a pool or a particular device.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_clear(int argc, char **argv)
|
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
int c;
|
2008-11-20 20:01:55 +00:00
|
|
|
int ret = 0;
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t dryrun = B_FALSE;
|
|
|
|
boolean_t do_rewind = B_FALSE;
|
|
|
|
boolean_t xtreme_rewind = B_FALSE;
|
|
|
|
uint32_t rewind_policy = ZPOOL_NO_REWIND;
|
|
|
|
nvlist_t *policy = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
zpool_handle_t *zhp;
|
|
|
|
char *pool, *device;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "FnX")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'F':
|
|
|
|
do_rewind = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
dryrun = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
xtreme_rewind = B_TRUE;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr, gettext("missing pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (argc > 2) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr, gettext("too many arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((dryrun || xtreme_rewind) && !do_rewind) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("-n or -X only meaningful with -F\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
if (dryrun)
|
|
|
|
rewind_policy = ZPOOL_TRY_REWIND;
|
|
|
|
else if (do_rewind)
|
|
|
|
rewind_policy = ZPOOL_DO_REWIND;
|
|
|
|
if (xtreme_rewind)
|
|
|
|
rewind_policy |= ZPOOL_EXTREME_REWIND;
|
|
|
|
|
|
|
|
/* In future, further rewind policy choices can be passed along here */
|
|
|
|
if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
|
|
|
|
nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind_policy) != 0)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
pool = argv[0];
|
|
|
|
device = argc == 2 ? argv[1] : NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
|
|
|
|
nvlist_free(policy);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (1);
|
2010-05-28 20:45:14 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
if (zpool_clear(zhp, device, policy) != 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
nvlist_free(policy);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2011-11-11 22:07:54 +00:00
|
|
|
/*
|
|
|
|
* zpool reguid <pool>
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_reguid(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
char *poolname;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* get pool name and check number of arguments */
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
(void) fprintf(stderr, gettext("too many arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolname = argv[0];
|
|
|
|
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
ret = zpool_reguid(zhp);
|
|
|
|
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
/*
|
|
|
|
* zpool reopen <pool>
|
|
|
|
*
|
|
|
|
* Reopen the pool so that the kernel can update the sizes of all vdevs.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_reopen(int argc, char **argv)
|
|
|
|
{
|
2013-05-02 23:36:32 +00:00
|
|
|
int c;
|
2012-01-24 02:43:32 +00:00
|
|
|
int ret = 0;
|
|
|
|
zpool_handle_t *zhp;
|
|
|
|
char *pool;
|
|
|
|
|
2013-05-02 23:36:32 +00:00
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 02:43:32 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
2013-05-02 23:36:32 +00:00
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
(void) fprintf(stderr, gettext("too many arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
2012-01-24 02:43:32 +00:00
|
|
|
|
|
|
|
pool = argv[0];
|
|
|
|
if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
ret = zpool_reopen(zhp);
|
|
|
|
zpool_close(zhp);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
typedef struct scrub_cbdata {
|
|
|
|
int cb_type;
|
|
|
|
int cb_argc;
|
|
|
|
char **cb_argv;
|
|
|
|
} scrub_cbdata_t;
|
|
|
|
|
|
|
|
int
|
|
|
|
scrub_callback(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
scrub_cbdata_t *cb = data;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore faulted pools.
|
|
|
|
*/
|
|
|
|
if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
|
|
|
|
(void) fprintf(stderr, gettext("cannot scrub '%s': pool is "
|
|
|
|
"currently unavailable\n"), zpool_get_name(zhp));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
err = zpool_scan(zhp, cb->cb_type);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
return (err != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool scrub [-s] <pool> ...
|
|
|
|
*
|
|
|
|
* -s Stop. Stops any in-progress scrub.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_scrub(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
scrub_cbdata_t cb;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
cb.cb_type = POOL_SCAN_SCRUB;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "s")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 's':
|
2010-05-28 20:45:14 +00:00
|
|
|
cb.cb_type = POOL_SCAN_NONE;
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cb.cb_argc = argc;
|
|
|
|
cb.cb_argv = argv;
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (for_each_pool(argc, argv, B_TRUE, NULL, scrub_callback, &cb));
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct status_cbdata {
|
|
|
|
int cb_count;
|
|
|
|
boolean_t cb_allpools;
|
|
|
|
boolean_t cb_verbose;
|
|
|
|
boolean_t cb_explain;
|
|
|
|
boolean_t cb_first;
|
2010-05-28 20:45:14 +00:00
|
|
|
boolean_t cb_dedup_stats;
|
2008-11-20 20:01:55 +00:00
|
|
|
} status_cbdata_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out detailed scrub status.
|
|
|
|
*/
|
|
|
|
void
|
2010-05-28 20:45:14 +00:00
|
|
|
print_scan_status(pool_scan_stat_t *ps)
|
2008-11-20 20:01:55 +00:00
|
|
|
{
|
2010-05-28 20:45:14 +00:00
|
|
|
time_t start, end;
|
2010-08-26 21:24:34 +00:00
|
|
|
uint64_t elapsed, mins_left, hours_left;
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t pass_exam, examined, total;
|
|
|
|
uint_t rate;
|
2008-11-20 20:01:55 +00:00
|
|
|
double fraction_done;
|
2010-05-28 20:45:14 +00:00
|
|
|
char processed_buf[7], examined_buf[7], total_buf[7], rate_buf[7];
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2013-01-11 17:11:09 +00:00
|
|
|
(void) printf(gettext(" scan: "));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
/* If there's never been a scan, there's not much to say. */
|
|
|
|
if (ps == NULL || ps->pss_func == POOL_SCAN_NONE ||
|
|
|
|
ps->pss_func >= POOL_SCAN_FUNCS) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf(gettext("none requested\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
start = ps->pss_start_time;
|
|
|
|
end = ps->pss_end_time;
|
|
|
|
zfs_nicenum(ps->pss_processed, processed_buf, sizeof (processed_buf));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
assert(ps->pss_func == POOL_SCAN_SCRUB ||
|
|
|
|
ps->pss_func == POOL_SCAN_RESILVER);
|
|
|
|
/*
|
|
|
|
* Scan is finished or canceled.
|
|
|
|
*/
|
|
|
|
if (ps->pss_state == DSS_FINISHED) {
|
|
|
|
uint64_t minutes_taken = (end - start) / 60;
|
2010-08-26 16:58:04 +00:00
|
|
|
char *fmt = NULL;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (ps->pss_func == POOL_SCAN_SCRUB) {
|
|
|
|
fmt = gettext("scrub repaired %s in %lluh%um with "
|
|
|
|
"%llu errors on %s");
|
|
|
|
} else if (ps->pss_func == POOL_SCAN_RESILVER) {
|
|
|
|
fmt = gettext("resilvered %s in %lluh%um with "
|
|
|
|
"%llu errors on %s");
|
|
|
|
}
|
|
|
|
/* LINTED */
|
|
|
|
(void) printf(fmt, processed_buf,
|
2008-11-20 20:01:55 +00:00
|
|
|
(u_longlong_t)(minutes_taken / 60),
|
|
|
|
(uint_t)(minutes_taken % 60),
|
2010-05-28 20:45:14 +00:00
|
|
|
(u_longlong_t)ps->pss_errors,
|
|
|
|
ctime((time_t *)&end));
|
|
|
|
return;
|
|
|
|
} else if (ps->pss_state == DSS_CANCELED) {
|
|
|
|
if (ps->pss_func == POOL_SCAN_SCRUB) {
|
|
|
|
(void) printf(gettext("scrub canceled on %s"),
|
|
|
|
ctime(&end));
|
|
|
|
} else if (ps->pss_func == POOL_SCAN_RESILVER) {
|
|
|
|
(void) printf(gettext("resilver canceled on %s"),
|
|
|
|
ctime(&end));
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
assert(ps->pss_state == DSS_SCANNING);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan is in progress.
|
|
|
|
*/
|
|
|
|
if (ps->pss_func == POOL_SCAN_SCRUB) {
|
|
|
|
(void) printf(gettext("scrub in progress since %s"),
|
|
|
|
ctime(&start));
|
|
|
|
} else if (ps->pss_func == POOL_SCAN_RESILVER) {
|
|
|
|
(void) printf(gettext("resilver in progress since %s"),
|
|
|
|
ctime(&start));
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
examined = ps->pss_examined ? ps->pss_examined : 1;
|
|
|
|
total = ps->pss_to_examine;
|
2008-11-20 20:01:55 +00:00
|
|
|
fraction_done = (double)examined / total;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
/* elapsed time for this pass */
|
|
|
|
elapsed = time(NULL) - ps->pss_pass_start;
|
|
|
|
elapsed = elapsed ? elapsed : 1;
|
|
|
|
pass_exam = ps->pss_pass_exam ? ps->pss_pass_exam : 1;
|
|
|
|
rate = pass_exam / elapsed;
|
|
|
|
rate = rate ? rate : 1;
|
|
|
|
mins_left = ((total - examined) / rate) / 60;
|
2010-08-26 21:24:34 +00:00
|
|
|
hours_left = mins_left / 60;
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
zfs_nicenum(examined, examined_buf, sizeof (examined_buf));
|
|
|
|
zfs_nicenum(total, total_buf, sizeof (total_buf));
|
|
|
|
zfs_nicenum(rate, rate_buf, sizeof (rate_buf));
|
|
|
|
|
2010-08-26 21:24:34 +00:00
|
|
|
/*
|
|
|
|
* do not print estimated time if hours_left is more than 30 days
|
|
|
|
*/
|
|
|
|
(void) printf(gettext(" %s scanned out of %s at %s/s"),
|
|
|
|
examined_buf, total_buf, rate_buf);
|
|
|
|
if (hours_left < (30 * 24)) {
|
|
|
|
(void) printf(gettext(", %lluh%um to go\n"),
|
|
|
|
(u_longlong_t)hours_left, (uint_t)(mins_left % 60));
|
|
|
|
} else {
|
|
|
|
(void) printf(gettext(
|
|
|
|
", (scan is slow, no estimated time)\n"));
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (ps->pss_func == POOL_SCAN_RESILVER) {
|
|
|
|
(void) printf(gettext(" %s resilvered, %.2f%% done\n"),
|
|
|
|
processed_buf, 100 * fraction_done);
|
|
|
|
} else if (ps->pss_func == POOL_SCAN_SCRUB) {
|
|
|
|
(void) printf(gettext(" %s repaired, %.2f%% done\n"),
|
|
|
|
processed_buf, 100 * fraction_done);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_error_log(zpool_handle_t *zhp)
|
|
|
|
{
|
|
|
|
nvlist_t *nverrlist = NULL;
|
|
|
|
nvpair_t *elem;
|
|
|
|
char *pathname;
|
|
|
|
size_t len = MAXPATHLEN * 2;
|
|
|
|
|
|
|
|
if (zpool_get_errlog(zhp, &nverrlist) != 0) {
|
|
|
|
(void) printf("errors: List of errors unavailable "
|
|
|
|
"(insufficient privileges)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf("errors: Permanent errors have been "
|
|
|
|
"detected in the following files:\n\n");
|
|
|
|
|
|
|
|
pathname = safe_malloc(len);
|
|
|
|
elem = NULL;
|
|
|
|
while ((elem = nvlist_next_nvpair(nverrlist, elem)) != NULL) {
|
|
|
|
nvlist_t *nv;
|
|
|
|
uint64_t dsobj, obj;
|
|
|
|
|
|
|
|
verify(nvpair_value_nvlist(elem, &nv) == 0);
|
|
|
|
verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_DATASET,
|
|
|
|
&dsobj) == 0);
|
|
|
|
verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_OBJECT,
|
|
|
|
&obj) == 0);
|
|
|
|
zpool_obj_to_path(zhp, dsobj, obj, pathname, len);
|
|
|
|
(void) printf("%7s %s\n", "", pathname);
|
|
|
|
}
|
|
|
|
free(pathname);
|
|
|
|
nvlist_free(nverrlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_spares(zpool_handle_t *zhp, nvlist_t **spares, uint_t nspares,
|
|
|
|
int namewidth)
|
|
|
|
{
|
|
|
|
uint_t i;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
if (nspares == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(void) printf(gettext("\tspares\n"));
|
|
|
|
|
|
|
|
for (i = 0; i < nspares; i++) {
|
2010-05-28 20:45:14 +00:00
|
|
|
name = zpool_vdev_name(g_zfs, zhp, spares[i], B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
print_status_config(zhp, name, spares[i],
|
2009-07-02 22:44:48 +00:00
|
|
|
namewidth, 2, B_TRUE);
|
2008-11-20 20:01:55 +00:00
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_l2cache(zpool_handle_t *zhp, nvlist_t **l2cache, uint_t nl2cache,
|
|
|
|
int namewidth)
|
|
|
|
{
|
|
|
|
uint_t i;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
if (nl2cache == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(void) printf(gettext("\tcache\n"));
|
|
|
|
|
|
|
|
for (i = 0; i < nl2cache; i++) {
|
2010-05-28 20:45:14 +00:00
|
|
|
name = zpool_vdev_name(g_zfs, zhp, l2cache[i], B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
print_status_config(zhp, name, l2cache[i],
|
2009-07-02 22:44:48 +00:00
|
|
|
namewidth, 2, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
static void
|
|
|
|
print_dedup_stats(nvlist_t *config)
|
|
|
|
{
|
|
|
|
ddt_histogram_t *ddh;
|
|
|
|
ddt_stat_t *dds;
|
|
|
|
ddt_object_t *ddo;
|
|
|
|
uint_t c;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the pool was faulted then we may not have been able to
|
2012-05-03 12:49:19 +00:00
|
|
|
* obtain the config. Otherwise, if we have anything in the dedup
|
2010-05-28 20:45:14 +00:00
|
|
|
* table continue processing the stats.
|
|
|
|
*/
|
|
|
|
if (nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_OBJ_STATS,
|
2013-01-11 17:11:09 +00:00
|
|
|
(uint64_t **)&ddo, &c) != 0)
|
2010-05-28 20:45:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
(void) printf("\n");
|
2013-01-11 17:11:09 +00:00
|
|
|
(void) printf(gettext(" dedup: "));
|
|
|
|
if (ddo->ddo_count == 0) {
|
|
|
|
(void) printf(gettext("no DDT entries\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
|
|
|
|
(u_longlong_t)ddo->ddo_count,
|
|
|
|
(u_longlong_t)ddo->ddo_dspace,
|
|
|
|
(u_longlong_t)ddo->ddo_mspace);
|
|
|
|
|
|
|
|
verify(nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_STATS,
|
|
|
|
(uint64_t **)&dds, &c) == 0);
|
|
|
|
verify(nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_HISTOGRAM,
|
|
|
|
(uint64_t **)&ddh, &c) == 0);
|
|
|
|
zpool_dump_ddt(dds, ddh);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* Display a summary of pool status. Displays a summary such as:
|
|
|
|
*
|
|
|
|
* pool: tank
|
|
|
|
* status: DEGRADED
|
|
|
|
* reason: One or more devices ...
|
2011-10-22 15:44:03 +00:00
|
|
|
* see: http://zfsonlinux.org/msg/ZFS-xxxx-01
|
2008-11-20 20:01:55 +00:00
|
|
|
* config:
|
|
|
|
* mirror DEGRADED
|
|
|
|
* c1t0d0 OK
|
|
|
|
* c2t0d0 UNAVAIL
|
|
|
|
*
|
|
|
|
* When given the '-v' option, we print out the complete config. If the '-e'
|
|
|
|
* option is specified, then we print out error rate information as well.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
status_callback(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
status_cbdata_t *cbp = data;
|
|
|
|
nvlist_t *config, *nvroot;
|
|
|
|
char *msgid;
|
2014-02-21 03:42:15 +00:00
|
|
|
zpool_status_t reason;
|
2014-02-21 03:57:17 +00:00
|
|
|
zpool_errata_t errata;
|
2008-11-20 20:01:55 +00:00
|
|
|
const char *health;
|
|
|
|
uint_t c;
|
|
|
|
vdev_stat_t *vs;
|
|
|
|
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
2014-02-21 03:57:17 +00:00
|
|
|
reason = zpool_get_status(zhp, &msgid, &errata);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
cbp->cb_count++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we were given 'zpool status -x', only report those pools with
|
|
|
|
* problems.
|
|
|
|
*/
|
2013-02-25 21:00:45 +00:00
|
|
|
if (cbp->cb_explain &&
|
|
|
|
(reason == ZPOOL_STATUS_OK ||
|
|
|
|
reason == ZPOOL_STATUS_VERSION_OLDER ||
|
|
|
|
reason == ZPOOL_STATUS_FEAT_DISABLED)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if (!cbp->cb_allpools) {
|
|
|
|
(void) printf(gettext("pool '%s' is healthy\n"),
|
|
|
|
zpool_get_name(zhp));
|
|
|
|
if (cbp->cb_first)
|
|
|
|
cbp->cb_first = B_FALSE;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbp->cb_first)
|
|
|
|
cbp->cb_first = B_FALSE;
|
|
|
|
else
|
|
|
|
(void) printf("\n");
|
|
|
|
|
|
|
|
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
|
|
&nvroot) == 0);
|
2010-05-28 20:45:14 +00:00
|
|
|
verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
|
2008-11-20 20:01:55 +00:00
|
|
|
(uint64_t **)&vs, &c) == 0);
|
|
|
|
health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
|
|
|
|
|
|
|
|
(void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp));
|
|
|
|
(void) printf(gettext(" state: %s\n"), health);
|
|
|
|
|
|
|
|
switch (reason) {
|
|
|
|
case ZPOOL_STATUS_MISSING_DEV_R:
|
|
|
|
(void) printf(gettext("status: One or more devices could not "
|
|
|
|
"be opened. Sufficient replicas exist for\n\tthe pool to "
|
|
|
|
"continue functioning in a degraded state.\n"));
|
|
|
|
(void) printf(gettext("action: Attach the missing device and "
|
|
|
|
"online it using 'zpool online'.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_MISSING_DEV_NR:
|
|
|
|
(void) printf(gettext("status: One or more devices could not "
|
|
|
|
"be opened. There are insufficient\n\treplicas for the "
|
|
|
|
"pool to continue functioning.\n"));
|
|
|
|
(void) printf(gettext("action: Attach the missing device and "
|
|
|
|
"online it using 'zpool online'.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_CORRUPT_LABEL_R:
|
|
|
|
(void) printf(gettext("status: One or more devices could not "
|
|
|
|
"be used because the label is missing or\n\tinvalid. "
|
|
|
|
"Sufficient replicas exist for the pool to continue\n\t"
|
|
|
|
"functioning in a degraded state.\n"));
|
|
|
|
(void) printf(gettext("action: Replace the device using "
|
|
|
|
"'zpool replace'.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_CORRUPT_LABEL_NR:
|
|
|
|
(void) printf(gettext("status: One or more devices could not "
|
|
|
|
"be used because the label is missing \n\tor invalid. "
|
|
|
|
"There are insufficient replicas for the pool to "
|
|
|
|
"continue\n\tfunctioning.\n"));
|
2010-05-28 20:45:14 +00:00
|
|
|
zpool_explain_recover(zpool_get_handle(zhp),
|
|
|
|
zpool_get_name(zhp), reason, config);
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_FAILING_DEV:
|
|
|
|
(void) printf(gettext("status: One or more devices has "
|
|
|
|
"experienced an unrecoverable error. An\n\tattempt was "
|
|
|
|
"made to correct the error. Applications are "
|
|
|
|
"unaffected.\n"));
|
|
|
|
(void) printf(gettext("action: Determine if the device needs "
|
|
|
|
"to be replaced, and clear the errors\n\tusing "
|
|
|
|
"'zpool clear' or replace the device with 'zpool "
|
|
|
|
"replace'.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_OFFLINE_DEV:
|
|
|
|
(void) printf(gettext("status: One or more devices has "
|
|
|
|
"been taken offline by the administrator.\n\tSufficient "
|
|
|
|
"replicas exist for the pool to continue functioning in "
|
|
|
|
"a\n\tdegraded state.\n"));
|
|
|
|
(void) printf(gettext("action: Online the device using "
|
|
|
|
"'zpool online' or replace the device with\n\t'zpool "
|
|
|
|
"replace'.\n"));
|
|
|
|
break;
|
|
|
|
|
2009-08-18 18:43:27 +00:00
|
|
|
case ZPOOL_STATUS_REMOVED_DEV:
|
|
|
|
(void) printf(gettext("status: One or more devices has "
|
|
|
|
"been removed by the administrator.\n\tSufficient "
|
|
|
|
"replicas exist for the pool to continue functioning in "
|
|
|
|
"a\n\tdegraded state.\n"));
|
|
|
|
(void) printf(gettext("action: Online the device using "
|
|
|
|
"'zpool online' or replace the device with\n\t'zpool "
|
|
|
|
"replace'.\n"));
|
|
|
|
break;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
case ZPOOL_STATUS_RESILVERING:
|
|
|
|
(void) printf(gettext("status: One or more devices is "
|
|
|
|
"currently being resilvered. The pool will\n\tcontinue "
|
|
|
|
"to function, possibly in a degraded state.\n"));
|
|
|
|
(void) printf(gettext("action: Wait for the resilver to "
|
|
|
|
"complete.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_CORRUPT_DATA:
|
|
|
|
(void) printf(gettext("status: One or more devices has "
|
|
|
|
"experienced an error resulting in data\n\tcorruption. "
|
|
|
|
"Applications may be affected.\n"));
|
|
|
|
(void) printf(gettext("action: Restore the file in question "
|
|
|
|
"if possible. Otherwise restore the\n\tentire pool from "
|
|
|
|
"backup.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_CORRUPT_POOL:
|
|
|
|
(void) printf(gettext("status: The pool metadata is corrupted "
|
|
|
|
"and the pool cannot be opened.\n"));
|
2010-05-28 20:45:14 +00:00
|
|
|
zpool_explain_recover(zpool_get_handle(zhp),
|
|
|
|
zpool_get_name(zhp), reason, config);
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_VERSION_OLDER:
|
2012-12-14 23:00:45 +00:00
|
|
|
(void) printf(gettext("status: The pool is formatted using a "
|
|
|
|
"legacy on-disk format. The pool can\n\tstill be used, "
|
|
|
|
"but some features are unavailable.\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf(gettext("action: Upgrade the pool using 'zpool "
|
|
|
|
"upgrade'. Once this is done, the\n\tpool will no longer "
|
2013-01-31 19:02:21 +00:00
|
|
|
"be accessible on software that does not support\n\t"
|
|
|
|
"feature flags.\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_VERSION_NEWER:
|
|
|
|
(void) printf(gettext("status: The pool has been upgraded to a "
|
|
|
|
"newer, incompatible on-disk version.\n\tThe pool cannot "
|
|
|
|
"be accessed on this system.\n"));
|
|
|
|
(void) printf(gettext("action: Access the pool from a system "
|
|
|
|
"running more recent software, or\n\trestore the pool from "
|
|
|
|
"backup.\n"));
|
|
|
|
break;
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
case ZPOOL_STATUS_FEAT_DISABLED:
|
|
|
|
(void) printf(gettext("status: Some supported features are not "
|
|
|
|
"enabled on the pool. The pool can\n\tstill be used, but "
|
|
|
|
"some features are unavailable.\n"));
|
|
|
|
(void) printf(gettext("action: Enable all features using "
|
|
|
|
"'zpool upgrade'. Once this is done,\n\tthe pool may no "
|
|
|
|
"longer be accessible by software that does not support\n\t"
|
|
|
|
"the features. See zpool-features(5) for details.\n"));
|
|
|
|
break;
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
case ZPOOL_STATUS_UNSUP_FEAT_READ:
|
|
|
|
(void) printf(gettext("status: The pool cannot be accessed on "
|
|
|
|
"this system because it uses the\n\tfollowing feature(s) "
|
|
|
|
"not supported on this system:\n"));
|
|
|
|
zpool_print_unsup_feat(config);
|
|
|
|
(void) printf("\n");
|
|
|
|
(void) printf(gettext("action: Access the pool from a system "
|
|
|
|
"that supports the required feature(s),\n\tor restore the "
|
|
|
|
"pool from backup.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
|
|
|
|
(void) printf(gettext("status: The pool can only be accessed "
|
|
|
|
"in read-only mode on this system. It\n\tcannot be "
|
|
|
|
"accessed in read-write mode because it uses the "
|
|
|
|
"following\n\tfeature(s) not supported on this system:\n"));
|
|
|
|
zpool_print_unsup_feat(config);
|
|
|
|
(void) printf("\n");
|
|
|
|
(void) printf(gettext("action: The pool cannot be accessed in "
|
|
|
|
"read-write mode. Import the pool with\n"
|
|
|
|
"\t\"-o readonly=on\", access the pool from a system that "
|
|
|
|
"supports the\n\trequired feature(s), or restore the "
|
|
|
|
"pool from backup.\n"));
|
|
|
|
break;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
case ZPOOL_STATUS_FAULTED_DEV_R:
|
|
|
|
(void) printf(gettext("status: One or more devices are "
|
|
|
|
"faulted in response to persistent errors.\n\tSufficient "
|
|
|
|
"replicas exist for the pool to continue functioning "
|
|
|
|
"in a\n\tdegraded state.\n"));
|
|
|
|
(void) printf(gettext("action: Replace the faulted device, "
|
|
|
|
"or use 'zpool clear' to mark the device\n\trepaired.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_FAULTED_DEV_NR:
|
|
|
|
(void) printf(gettext("status: One or more devices are "
|
|
|
|
"faulted in response to persistent errors. There are "
|
|
|
|
"insufficient replicas for the pool to\n\tcontinue "
|
|
|
|
"functioning.\n"));
|
|
|
|
(void) printf(gettext("action: Destroy and re-create the pool "
|
|
|
|
"from a backup source. Manually marking the device\n"
|
|
|
|
"\trepaired using 'zpool clear' may allow some data "
|
|
|
|
"to be recovered.\n"));
|
|
|
|
break;
|
|
|
|
|
2008-12-03 20:09:06 +00:00
|
|
|
case ZPOOL_STATUS_IO_FAILURE_WAIT:
|
|
|
|
case ZPOOL_STATUS_IO_FAILURE_CONTINUE:
|
|
|
|
(void) printf(gettext("status: One or more devices are "
|
|
|
|
"faulted in response to IO failures.\n"));
|
|
|
|
(void) printf(gettext("action: Make sure the affected devices "
|
|
|
|
"are connected, then run 'zpool clear'.\n"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZPOOL_STATUS_BAD_LOG:
|
|
|
|
(void) printf(gettext("status: An intent log record "
|
|
|
|
"could not be read.\n"
|
|
|
|
"\tWaiting for adminstrator intervention to fix the "
|
|
|
|
"faulted pool.\n"));
|
|
|
|
(void) printf(gettext("action: Either restore the affected "
|
|
|
|
"device(s) and run 'zpool online',\n"
|
|
|
|
"\tor ignore the intent log records by running "
|
|
|
|
"'zpool clear'.\n"));
|
|
|
|
break;
|
|
|
|
|
2014-05-17 13:35:10 +00:00
|
|
|
case ZPOOL_STATUS_HOSTID_MISMATCH:
|
|
|
|
(void) printf(gettext("status: Mismatch between pool hostid "
|
|
|
|
"and system hostid on imported pool.\n\tThis pool was "
|
|
|
|
"previously imported into a system with a different "
|
|
|
|
"hostid,\n\tand then was verbatim imported into this "
|
|
|
|
"system.\n"));
|
|
|
|
(void) printf(gettext("action: Export this pool on all systems "
|
|
|
|
"on which it is imported.\n"
|
|
|
|
"\tThen import it to correct the mismatch.\n"));
|
|
|
|
break;
|
|
|
|
|
2014-02-21 03:57:17 +00:00
|
|
|
case ZPOOL_STATUS_ERRATA:
|
|
|
|
(void) printf(gettext("status: Errata #%d detected.\n"),
|
|
|
|
errata);
|
|
|
|
|
|
|
|
switch (errata) {
|
|
|
|
case ZPOOL_ERRATA_NONE:
|
|
|
|
break;
|
|
|
|
|
Add erratum for issue #2094
ZoL commit 1421c89 unintentionally changed the disk format in a forward-
compatible, but not backward compatible way. This was accomplished by
adding an entry to zbookmark_t, which is included in a couple of
on-disk structures. That lead to the creation of pools with incorrect
dsl_scan_phys_t objects that could only be imported by versions of ZoL
containing that commit. Such pools cannot be imported by other versions
of ZFS or past versions of ZoL.
The additional field has been removed by the previous commit. However,
affected pools must be imported and scrubbed using a version of ZoL with
this commit applied. This will return the pools to a state in which they
may be imported by other implementations.
The 'zpool import' or 'zpool status' command can be used to determine if
a pool is impacted. A message similar to one of the following means your
pool must be scrubbed to restore compatibility.
$ zpool import
pool: zol-0.6.2-173
id: 1165955789558693437
state: ONLINE
status: Errata #1 detected.
action: The pool can be imported using its name or numeric identifier,
however there is a compatibility issue which should be corrected
by running 'zpool scrub'
see: http://zfsonlinux.org/msg/ZFS-8000-ER
config:
...
$ zpool status
pool: zol-0.6.2-173
state: ONLINE
scan: pool compatibility issue detected.
see: https://github.com/zfsonlinux/zfs/issues/2094
action: To correct the issue run 'zpool scrub'.
config:
...
If there was an async destroy in progress 'zpool import' will prevent
the pool from being imported. Further advice on how to proceed will be
provided by the error message as follows.
$ zpool import
pool: zol-0.6.2-173
id: 1165955789558693437
state: ONLINE
status: Errata #2 detected.
action: The pool can not be imported with this version of ZFS due to an
active asynchronous destroy. Revert to an earlier version and
allow the destroy to complete before updating.
see: http://zfsonlinux.org/msg/ZFS-8000-ER
config:
...
Pools affected by the damaged dsl_scan_phys_t can be detected prior to
an upgrade by running the following command as root:
zdb -dddd poolname 1 | grep -P '^\t\tscan = ' | sed -e 's;scan = ;;' | wc -w
Note that `poolname` must be replaced with the name of the pool you wish
to check. A value of 25 indicates the dsl_scan_phys_t has been damaged.
A value of 24 indicates that the dsl_scan_phys_t is normal. A value of 0
indicates that there has never been a scrub run on the pool.
The regression caused by the change to zbookmark_t never made it into a
tagged release, Gentoo backports, Ubuntu, Debian, Fedora, or EPEL
stable respositorys. Only those using the HEAD version directly from
Github after the 0.6.2 but before the 0.6.3 tag are affected.
This patch does have one limitation that should be mentioned. It will not
detect errata #2 on a pool unless errata #1 is also present. It expected
this will not be a significant problem because pools impacted by errata #2
have a high probably of being impacted by errata #1.
End users can ensure they do no hit this unlikely case by waiting for all
asynchronous destroy operations to complete before updating ZoL. The
presence of any background destroys on any imported pools can be checked
by running `zpool get freeing` as root. This will display a non-zero
value for any pool with an active asynchronous destroy.
Lastly, it is expected that no user data has been lost as a result of
this erratum.
Original-patch-by: Tim Chase <tim@chase2k.com>
Reworked-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #2094
2014-02-21 04:28:33 +00:00
|
|
|
case ZPOOL_ERRATA_ZOL_2094_SCRUB:
|
|
|
|
(void) printf(gettext("action: To correct the issue "
|
|
|
|
"run 'zpool scrub'.\n"));
|
|
|
|
break;
|
|
|
|
|
2014-02-21 03:57:17 +00:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* All errata which allow the pool to be imported
|
|
|
|
* must contain an action message.
|
|
|
|
*/
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* The remaining errors can't actually be generated, yet.
|
|
|
|
*/
|
|
|
|
assert(reason == ZPOOL_STATUS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msgid != NULL)
|
2011-10-22 15:44:03 +00:00
|
|
|
(void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
|
2008-11-20 20:01:55 +00:00
|
|
|
msgid);
|
|
|
|
|
|
|
|
if (config != NULL) {
|
|
|
|
int namewidth;
|
|
|
|
uint64_t nerr;
|
|
|
|
nvlist_t **spares, **l2cache;
|
|
|
|
uint_t nspares, nl2cache;
|
2010-05-28 20:45:14 +00:00
|
|
|
pool_scan_stat_t *ps = NULL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) nvlist_lookup_uint64_array(nvroot,
|
|
|
|
ZPOOL_CONFIG_SCAN_STATS, (uint64_t **)&ps, &c);
|
|
|
|
print_scan_status(ps);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
namewidth = max_width(zhp, nvroot, 0, 0);
|
|
|
|
if (namewidth < 10)
|
|
|
|
namewidth = 10;
|
|
|
|
|
|
|
|
(void) printf(gettext("config:\n\n"));
|
|
|
|
(void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth,
|
|
|
|
"NAME", "STATE", "READ", "WRITE", "CKSUM");
|
|
|
|
print_status_config(zhp, zpool_get_name(zhp), nvroot,
|
2009-07-02 22:44:48 +00:00
|
|
|
namewidth, 0, B_FALSE);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2009-07-02 22:44:48 +00:00
|
|
|
if (num_logs(nvroot) > 0)
|
|
|
|
print_logs(zhp, nvroot, namewidth, B_TRUE);
|
2008-11-20 20:01:55 +00:00
|
|
|
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
|
|
|
|
&l2cache, &nl2cache) == 0)
|
|
|
|
print_l2cache(zhp, l2cache, nl2cache, namewidth);
|
|
|
|
|
|
|
|
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
|
|
|
|
&spares, &nspares) == 0)
|
|
|
|
print_spares(zhp, spares, nspares, namewidth);
|
|
|
|
|
|
|
|
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)
|
|
|
|
(void) printf(gettext("errors: %llu data "
|
|
|
|
"errors, use '-v' for a list\n"),
|
|
|
|
(u_longlong_t)nerr);
|
|
|
|
else
|
|
|
|
print_error_log(zhp);
|
|
|
|
}
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
if (cbp->cb_dedup_stats)
|
|
|
|
print_dedup_stats(config);
|
2008-11-20 20:01:55 +00:00
|
|
|
} else {
|
|
|
|
(void) printf(gettext("config: The configuration cannot be "
|
|
|
|
"determined.\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-05-28 20:45:14 +00:00
|
|
|
* zpool status [-vx] [-T d|u] [pool] ... [interval [count]]
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* -v Display complete error logs
|
|
|
|
* -x Display only pools with potential problems
|
2010-05-28 20:45:14 +00:00
|
|
|
* -D Display dedup status (undocumented)
|
|
|
|
* -T Display a timestamp in date(1) or Unix format
|
2008-11-20 20:01:55 +00:00
|
|
|
*
|
|
|
|
* Describes the health status of all pools or some subset.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_status(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int ret;
|
2010-05-28 20:45:14 +00:00
|
|
|
unsigned long interval = 0, count = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
status_cbdata_t cb = { 0 };
|
|
|
|
|
|
|
|
/* check options */
|
2010-05-28 20:45:14 +00:00
|
|
|
while ((c = getopt(argc, argv, "vxDT:")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
cb.cb_verbose = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
cb.cb_explain = B_TRUE;
|
|
|
|
break;
|
2010-05-28 20:45:14 +00:00
|
|
|
case 'D':
|
|
|
|
cb.cb_dedup_stats = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
get_timestamp_arg(*optarg);
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
get_interval_count(&argc, argv, &interval, &count);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
cb.cb_allpools = B_TRUE;
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
cb.cb_first = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
for (;;) {
|
|
|
|
if (timestamp_fmt != NODATE)
|
|
|
|
print_timestamp(timestamp_fmt);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
ret = for_each_pool(argc, argv, B_TRUE, NULL,
|
|
|
|
status_callback, &cb);
|
|
|
|
|
|
|
|
if (argc == 0 && cb.cb_count == 0)
|
2012-03-14 13:34:00 +00:00
|
|
|
(void) fprintf(stderr, gettext("no pools available\n"));
|
2010-05-28 20:45:14 +00:00
|
|
|
else if (cb.cb_explain && cb.cb_first && cb.cb_allpools)
|
|
|
|
(void) printf(gettext("all pools are healthy\n"));
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
if (interval == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (count != 0 && --count == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
(void) sleep(interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct upgrade_cbdata {
|
|
|
|
int cb_first;
|
|
|
|
int cb_argc;
|
|
|
|
uint64_t cb_version;
|
|
|
|
char **cb_argv;
|
|
|
|
} upgrade_cbdata_t;
|
|
|
|
|
2014-08-29 19:12:21 +00:00
|
|
|
static int
|
|
|
|
check_unsupp_fs(zfs_handle_t *zhp, void *unsupp_fs)
|
|
|
|
{
|
|
|
|
int zfs_version = (int) zfs_prop_get_int(zhp, ZFS_PROP_VERSION);
|
|
|
|
int *count = (int *)unsupp_fs;
|
|
|
|
|
|
|
|
if (zfs_version > ZPL_VERSION) {
|
|
|
|
(void) printf(gettext("%s (v%d) is not supported by this "
|
|
|
|
"implementation of ZFS.\n"),
|
|
|
|
zfs_get_name(zhp), zfs_version);
|
|
|
|
(*count)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
zfs_iter_filesystems(zhp, check_unsupp_fs, unsupp_fs);
|
|
|
|
|
|
|
|
zfs_close(zhp);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
static int
|
|
|
|
upgrade_version(zpool_handle_t *zhp, uint64_t version)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
nvlist_t *config;
|
|
|
|
uint64_t oldversion;
|
2014-08-29 19:12:21 +00:00
|
|
|
int unsupp_fs = 0;
|
2012-12-14 23:00:45 +00:00
|
|
|
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
|
|
|
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
|
|
|
|
&oldversion) == 0);
|
|
|
|
|
|
|
|
assert(SPA_VERSION_IS_SUPPORTED(oldversion));
|
|
|
|
assert(oldversion < version);
|
|
|
|
|
2014-08-29 19:12:21 +00:00
|
|
|
ret = zfs_iter_root(zpool_get_handle(zhp), check_unsupp_fs, &unsupp_fs);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
if (unsupp_fs) {
|
|
|
|
(void) printf(gettext("Upgrade not performed due to %d "
|
|
|
|
"unsupported filesystems (max v%d).\n"),
|
|
|
|
unsupp_fs, (int) ZPL_VERSION);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
ret = zpool_upgrade(zhp, version);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
if (version >= SPA_VERSION_FEATURES) {
|
|
|
|
(void) printf(gettext("Successfully upgraded "
|
|
|
|
"'%s' from version %llu to feature flags.\n"),
|
|
|
|
zpool_get_name(zhp), (u_longlong_t) oldversion);
|
|
|
|
} else {
|
|
|
|
(void) printf(gettext("Successfully upgraded "
|
|
|
|
"'%s' from version %llu to version %llu.\n"),
|
|
|
|
zpool_get_name(zhp), (u_longlong_t) oldversion,
|
|
|
|
(u_longlong_t) version);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
upgrade_enable_all(zpool_handle_t *zhp, int *countp)
|
|
|
|
{
|
|
|
|
int i, ret, count;
|
|
|
|
boolean_t firstff = B_TRUE;
|
|
|
|
nvlist_t *enabled = zpool_get_features(zhp);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < SPA_FEATURES; i++) {
|
|
|
|
const char *fname = spa_feature_table[i].fi_uname;
|
|
|
|
const char *fguid = spa_feature_table[i].fi_guid;
|
|
|
|
if (!nvlist_exists(enabled, fguid)) {
|
|
|
|
char *propname;
|
|
|
|
verify(-1 != asprintf(&propname, "feature@%s", fname));
|
|
|
|
ret = zpool_set_prop(zhp, propname,
|
|
|
|
ZFS_FEATURE_ENABLED);
|
|
|
|
if (ret != 0) {
|
|
|
|
free(propname);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (firstff) {
|
|
|
|
(void) printf(gettext("Enabled the "
|
|
|
|
"following features on '%s':\n"),
|
|
|
|
zpool_get_name(zhp));
|
|
|
|
firstff = B_FALSE;
|
|
|
|
}
|
|
|
|
(void) printf(gettext(" %s\n"), fname);
|
|
|
|
free(propname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (countp != NULL)
|
|
|
|
*countp = count;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
static int
|
|
|
|
upgrade_cb(zpool_handle_t *zhp, void *arg)
|
|
|
|
{
|
|
|
|
upgrade_cbdata_t *cbp = arg;
|
|
|
|
nvlist_t *config;
|
|
|
|
uint64_t version;
|
2012-12-14 23:00:45 +00:00
|
|
|
boolean_t printnl = B_FALSE;
|
|
|
|
int ret;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
|
|
|
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
|
|
|
|
&version) == 0);
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
assert(SPA_VERSION_IS_SUPPORTED(version));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
if (version < cbp->cb_version) {
|
|
|
|
cbp->cb_first = B_FALSE;
|
|
|
|
ret = upgrade_version(zhp, cbp->cb_version);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
printnl = B_TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If they did "zpool upgrade -a", then we could
|
|
|
|
* be doing ioctls to different pools. We need
|
|
|
|
* to log this history once to each pool, and bypass
|
|
|
|
* the normal history logging that happens in main().
|
|
|
|
*/
|
|
|
|
(void) zpool_log_history(g_zfs, history_str);
|
|
|
|
log_history = B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbp->cb_version >= SPA_VERSION_FEATURES) {
|
|
|
|
int count;
|
|
|
|
ret = upgrade_enable_all(zhp, &count);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
if (count > 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
cbp->cb_first = B_FALSE;
|
2012-12-14 23:00:45 +00:00
|
|
|
printnl = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2012-12-14 23:00:45 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
if (printnl) {
|
|
|
|
(void) printf(gettext("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
upgrade_list_older_cb(zpool_handle_t *zhp, void *arg)
|
|
|
|
{
|
|
|
|
upgrade_cbdata_t *cbp = arg;
|
|
|
|
nvlist_t *config;
|
|
|
|
uint64_t version;
|
|
|
|
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
|
|
|
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
|
|
|
|
&version) == 0);
|
|
|
|
|
|
|
|
assert(SPA_VERSION_IS_SUPPORTED(version));
|
|
|
|
|
|
|
|
if (version < SPA_VERSION_FEATURES) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if (cbp->cb_first) {
|
|
|
|
(void) printf(gettext("The following pools are "
|
2012-12-14 23:00:45 +00:00
|
|
|
"formatted with legacy version numbers and can\n"
|
|
|
|
"be upgraded to use feature flags. After "
|
|
|
|
"being upgraded, these pools\nwill no "
|
|
|
|
"longer be accessible by software that does not "
|
|
|
|
"support feature\nflags.\n\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf(gettext("VER POOL\n"));
|
|
|
|
(void) printf(gettext("--- ------------\n"));
|
|
|
|
cbp->cb_first = B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf("%2llu %s\n", (u_longlong_t)version,
|
|
|
|
zpool_get_name(zhp));
|
|
|
|
}
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
upgrade_list_disabled_cb(zpool_handle_t *zhp, void *arg)
|
|
|
|
{
|
|
|
|
upgrade_cbdata_t *cbp = arg;
|
|
|
|
nvlist_t *config;
|
|
|
|
uint64_t version;
|
|
|
|
|
|
|
|
config = zpool_get_config(zhp, NULL);
|
|
|
|
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
|
|
|
|
&version) == 0);
|
|
|
|
|
|
|
|
if (version >= SPA_VERSION_FEATURES) {
|
|
|
|
int i;
|
|
|
|
boolean_t poolfirst = B_TRUE;
|
|
|
|
nvlist_t *enabled = zpool_get_features(zhp);
|
|
|
|
|
|
|
|
for (i = 0; i < SPA_FEATURES; i++) {
|
|
|
|
const char *fguid = spa_feature_table[i].fi_guid;
|
|
|
|
const char *fname = spa_feature_table[i].fi_uname;
|
|
|
|
if (!nvlist_exists(enabled, fguid)) {
|
|
|
|
if (cbp->cb_first) {
|
|
|
|
(void) printf(gettext("\nSome "
|
|
|
|
"supported features are not "
|
|
|
|
"enabled on the following pools. "
|
|
|
|
"Once a\nfeature is enabled the "
|
|
|
|
"pool may become incompatible with "
|
|
|
|
"software\nthat does not support "
|
|
|
|
"the feature. See "
|
|
|
|
"zpool-features(5) for "
|
|
|
|
"details.\n\n"));
|
|
|
|
(void) printf(gettext("POOL "
|
|
|
|
"FEATURE\n"));
|
|
|
|
(void) printf(gettext("------"
|
|
|
|
"---------\n"));
|
|
|
|
cbp->cb_first = B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (poolfirst) {
|
|
|
|
(void) printf(gettext("%s\n"),
|
|
|
|
zpool_get_name(zhp));
|
|
|
|
poolfirst = B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf(gettext(" %s\n"), fname);
|
|
|
|
}
|
2013-08-28 11:45:09 +00:00
|
|
|
/*
|
|
|
|
* If they did "zpool upgrade -a", then we could
|
|
|
|
* be doing ioctls to different pools. We need
|
|
|
|
* to log this history once to each pool, and bypass
|
|
|
|
* the normal history logging that happens in main().
|
|
|
|
*/
|
|
|
|
(void) zpool_log_history(g_zfs, history_str);
|
|
|
|
log_history = B_FALSE;
|
2012-12-14 23:00:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
upgrade_one(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
2012-12-14 23:00:45 +00:00
|
|
|
boolean_t printnl = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
upgrade_cbdata_t *cbp = data;
|
|
|
|
uint64_t cur_version;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (strcmp("log", zpool_get_name(zhp)) == 0) {
|
|
|
|
(void) printf(gettext("'log' is now a reserved word\n"
|
|
|
|
"Pool 'log' must be renamed using export and import"
|
|
|
|
" to upgrade.\n"));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL);
|
|
|
|
if (cur_version > cbp->cb_version) {
|
|
|
|
(void) printf(gettext("Pool '%s' is already formatted "
|
2012-12-14 23:00:45 +00:00
|
|
|
"using more current version '%llu'.\n\n"),
|
2010-08-26 16:52:39 +00:00
|
|
|
zpool_get_name(zhp), (u_longlong_t) cur_version);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2012-12-14 23:00:45 +00:00
|
|
|
|
|
|
|
if (cbp->cb_version != SPA_VERSION && cur_version == cbp->cb_version) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) printf(gettext("Pool '%s' is already formatted "
|
2012-12-14 23:00:45 +00:00
|
|
|
"using version %llu.\n\n"), zpool_get_name(zhp),
|
|
|
|
(u_longlong_t) cbp->cb_version);
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
if (cur_version != cbp->cb_version) {
|
|
|
|
printnl = B_TRUE;
|
|
|
|
ret = upgrade_version(zhp, cbp->cb_version);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
if (cbp->cb_version >= SPA_VERSION_FEATURES) {
|
|
|
|
int count = 0;
|
|
|
|
ret = upgrade_enable_all(zhp, &count);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
if (count != 0) {
|
|
|
|
printnl = B_TRUE;
|
|
|
|
} else if (cur_version == SPA_VERSION) {
|
|
|
|
(void) printf(gettext("Pool '%s' already has all "
|
|
|
|
"supported features enabled.\n"),
|
|
|
|
zpool_get_name(zhp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (printnl) {
|
|
|
|
(void) printf(gettext("\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
return (0);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool upgrade
|
|
|
|
* zpool upgrade -v
|
|
|
|
* zpool upgrade [-V version] <-a | pool ...>
|
|
|
|
*
|
|
|
|
* With no arguments, display downrev'd ZFS pool available for upgrade.
|
|
|
|
* Individual pools can be upgraded by specifying the pool, and '-a' will
|
|
|
|
* upgrade all pools.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_upgrade(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
upgrade_cbdata_t cb = { 0 };
|
|
|
|
int ret = 0;
|
|
|
|
boolean_t showversions = B_FALSE;
|
2012-12-14 23:00:45 +00:00
|
|
|
boolean_t upgradeall = B_FALSE;
|
2008-11-20 20:01:55 +00:00
|
|
|
char *end;
|
|
|
|
|
|
|
|
|
|
|
|
/* check options */
|
2009-07-02 22:44:48 +00:00
|
|
|
while ((c = getopt(argc, argv, ":avV:")) != -1) {
|
2008-11-20 20:01:55 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'a':
|
2012-12-14 23:00:45 +00:00
|
|
|
upgradeall = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
showversions = B_TRUE;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
cb.cb_version = strtoll(optarg, &end, 10);
|
2012-12-13 23:24:15 +00:00
|
|
|
if (*end != '\0' ||
|
|
|
|
!SPA_VERSION_IS_SUPPORTED(cb.cb_version)) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr,
|
|
|
|
gettext("invalid version '%s'\n"), optarg);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
break;
|
2009-07-02 22:44:48 +00:00
|
|
|
case ':':
|
|
|
|
(void) fprintf(stderr, gettext("missing argument for "
|
|
|
|
"'%c' option\n"), optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
break;
|
2008-11-20 20:01:55 +00:00
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cb.cb_argc = argc;
|
|
|
|
cb.cb_argv = argv;
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (cb.cb_version == 0) {
|
|
|
|
cb.cb_version = SPA_VERSION;
|
2012-12-14 23:00:45 +00:00
|
|
|
} else if (!upgradeall && argc == 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr, gettext("-V option is "
|
|
|
|
"incompatible with other arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showversions) {
|
2012-12-14 23:00:45 +00:00
|
|
|
if (upgradeall || argc != 0) {
|
2008-11-20 20:01:55 +00:00
|
|
|
(void) fprintf(stderr, gettext("-v option is "
|
|
|
|
"incompatible with other arguments\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
2012-12-14 23:00:45 +00:00
|
|
|
} else if (upgradeall) {
|
2008-11-20 20:01:55 +00:00
|
|
|
if (argc != 0) {
|
|
|
|
(void) fprintf(stderr, gettext("-a option should not "
|
|
|
|
"be used along with a pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
(void) printf(gettext("This system supports ZFS pool feature "
|
|
|
|
"flags.\n\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
if (showversions) {
|
2012-12-14 23:00:45 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
(void) printf(gettext("The following features are "
|
|
|
|
"supported:\n\n"));
|
|
|
|
(void) printf(gettext("FEAT DESCRIPTION\n"));
|
|
|
|
(void) printf("----------------------------------------------"
|
|
|
|
"---------------\n");
|
|
|
|
for (i = 0; i < SPA_FEATURES; i++) {
|
|
|
|
zfeature_info_t *fi = &spa_feature_table[i];
|
|
|
|
const char *ro = fi->fi_can_readonly ?
|
|
|
|
" (read-only compatible)" : "";
|
|
|
|
|
|
|
|
(void) printf("%-37s%s\n", fi->fi_uname, ro);
|
|
|
|
(void) printf(" %s\n", fi->fi_desc);
|
|
|
|
}
|
|
|
|
(void) printf("\n");
|
|
|
|
|
|
|
|
(void) printf(gettext("The following legacy versions are also "
|
2008-11-20 20:01:55 +00:00
|
|
|
"supported:\n\n"));
|
|
|
|
(void) printf(gettext("VER DESCRIPTION\n"));
|
|
|
|
(void) printf("--- -----------------------------------------"
|
|
|
|
"---------------\n");
|
|
|
|
(void) printf(gettext(" 1 Initial ZFS version\n"));
|
|
|
|
(void) printf(gettext(" 2 Ditto blocks "
|
|
|
|
"(replicated metadata)\n"));
|
|
|
|
(void) printf(gettext(" 3 Hot spares and double parity "
|
|
|
|
"RAID-Z\n"));
|
|
|
|
(void) printf(gettext(" 4 zpool history\n"));
|
|
|
|
(void) printf(gettext(" 5 Compression using the gzip "
|
|
|
|
"algorithm\n"));
|
|
|
|
(void) printf(gettext(" 6 bootfs pool property\n"));
|
|
|
|
(void) printf(gettext(" 7 Separate intent log devices\n"));
|
|
|
|
(void) printf(gettext(" 8 Delegated administration\n"));
|
|
|
|
(void) printf(gettext(" 9 refquota and refreservation "
|
|
|
|
"properties\n"));
|
|
|
|
(void) printf(gettext(" 10 Cache devices\n"));
|
2008-12-03 20:09:06 +00:00
|
|
|
(void) printf(gettext(" 11 Improved scrub performance\n"));
|
|
|
|
(void) printf(gettext(" 12 Snapshot properties\n"));
|
|
|
|
(void) printf(gettext(" 13 snapused property\n"));
|
2009-07-02 22:44:48 +00:00
|
|
|
(void) printf(gettext(" 14 passthrough-x aclinherit\n"));
|
|
|
|
(void) printf(gettext(" 15 user/group space accounting\n"));
|
|
|
|
(void) printf(gettext(" 16 stmf property support\n"));
|
2009-08-18 18:43:27 +00:00
|
|
|
(void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) printf(gettext(" 18 Snapshot user holds\n"));
|
|
|
|
(void) printf(gettext(" 19 Log device removal\n"));
|
|
|
|
(void) printf(gettext(" 20 Compression using zle "
|
|
|
|
"(zero-length encoding)\n"));
|
|
|
|
(void) printf(gettext(" 21 Deduplication\n"));
|
|
|
|
(void) printf(gettext(" 22 Received properties\n"));
|
|
|
|
(void) printf(gettext(" 23 Slim ZIL\n"));
|
|
|
|
(void) printf(gettext(" 24 System attributes\n"));
|
|
|
|
(void) printf(gettext(" 25 Improved scrub stats\n"));
|
|
|
|
(void) printf(gettext(" 26 Improved snapshot deletion "
|
|
|
|
"performance\n"));
|
2010-08-26 21:24:34 +00:00
|
|
|
(void) printf(gettext(" 27 Improved snapshot creation "
|
|
|
|
"performance\n"));
|
|
|
|
(void) printf(gettext(" 28 Multiple vdev replacements\n"));
|
2010-05-28 20:45:14 +00:00
|
|
|
(void) printf(gettext("\nFor more information on a particular "
|
|
|
|
"version, including supported releases,\n"));
|
|
|
|
(void) printf(gettext("see the ZFS Administration Guide.\n\n"));
|
2012-12-14 23:00:45 +00:00
|
|
|
} else if (argc == 0 && upgradeall) {
|
|
|
|
cb.cb_first = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
ret = zpool_iter(g_zfs, upgrade_cb, &cb);
|
2012-12-14 23:00:45 +00:00
|
|
|
if (ret == 0 && cb.cb_first) {
|
|
|
|
if (cb.cb_version == SPA_VERSION) {
|
|
|
|
(void) printf(gettext("All pools are already "
|
|
|
|
"formatted using feature flags.\n\n"));
|
|
|
|
(void) printf(gettext("Every feature flags "
|
|
|
|
"pool already has all supported features "
|
|
|
|
"enabled.\n"));
|
|
|
|
} else {
|
|
|
|
(void) printf(gettext("All pools are already "
|
|
|
|
"formatted with version %llu or higher.\n"),
|
|
|
|
(u_longlong_t) cb.cb_version);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-14 23:00:45 +00:00
|
|
|
} else if (argc == 0) {
|
|
|
|
cb.cb_first = B_TRUE;
|
|
|
|
ret = zpool_iter(g_zfs, upgrade_list_older_cb, &cb);
|
|
|
|
assert(ret == 0);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-12-14 23:00:45 +00:00
|
|
|
if (cb.cb_first) {
|
|
|
|
(void) printf(gettext("All pools are formatted "
|
|
|
|
"using feature flags.\n\n"));
|
|
|
|
} else {
|
|
|
|
(void) printf(gettext("\nUse 'zpool upgrade -v' "
|
|
|
|
"for a list of available legacy versions.\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
cb.cb_first = B_TRUE;
|
|
|
|
ret = zpool_iter(g_zfs, upgrade_list_disabled_cb, &cb);
|
|
|
|
assert(ret == 0);
|
|
|
|
|
|
|
|
if (cb.cb_first) {
|
|
|
|
(void) printf(gettext("Every feature flags pool has "
|
|
|
|
"all supported features enabled.\n"));
|
|
|
|
} else {
|
|
|
|
(void) printf(gettext("\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = for_each_pool(argc, argv, B_FALSE, NULL,
|
|
|
|
upgrade_one, &cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct hist_cbdata {
|
|
|
|
boolean_t first;
|
2013-08-28 11:45:09 +00:00
|
|
|
boolean_t longfmt;
|
|
|
|
boolean_t internal;
|
2008-11-20 20:01:55 +00:00
|
|
|
} hist_cbdata_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out the command history for a specific pool.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_history_one(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
nvlist_t *nvhis;
|
|
|
|
nvlist_t **records;
|
|
|
|
uint_t numrecords;
|
|
|
|
int ret, i;
|
|
|
|
hist_cbdata_t *cb = (hist_cbdata_t *)data;
|
|
|
|
|
|
|
|
cb->first = B_FALSE;
|
|
|
|
|
|
|
|
(void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp));
|
|
|
|
|
|
|
|
if ((ret = zpool_get_history(zhp, &nvhis)) != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
verify(nvlist_lookup_nvlist_array(nvhis, ZPOOL_HIST_RECORD,
|
|
|
|
&records, &numrecords) == 0);
|
|
|
|
for (i = 0; i < numrecords; i++) {
|
2013-08-28 11:45:09 +00:00
|
|
|
nvlist_t *rec = records[i];
|
|
|
|
char tbuf[30] = "";
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_TIME)) {
|
|
|
|
time_t tsec;
|
|
|
|
struct tm t;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
tsec = fnvlist_lookup_uint64(records[i],
|
|
|
|
ZPOOL_HIST_TIME);
|
|
|
|
(void) localtime_r(&tsec, &t);
|
|
|
|
(void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_CMD)) {
|
|
|
|
(void) printf("%s %s", tbuf,
|
|
|
|
fnvlist_lookup_string(rec, ZPOOL_HIST_CMD));
|
|
|
|
} else if (nvlist_exists(rec, ZPOOL_HIST_INT_EVENT)) {
|
|
|
|
int ievent =
|
|
|
|
fnvlist_lookup_uint64(rec, ZPOOL_HIST_INT_EVENT);
|
|
|
|
if (!cb->internal)
|
2008-11-20 20:01:55 +00:00
|
|
|
continue;
|
2013-08-28 11:45:09 +00:00
|
|
|
if (ievent >= ZFS_NUM_LEGACY_HISTORY_EVENTS) {
|
|
|
|
(void) printf("%s unrecognized record:\n",
|
|
|
|
tbuf);
|
|
|
|
dump_nvlist(rec, 4);
|
2008-11-20 20:01:55 +00:00
|
|
|
continue;
|
2013-08-28 11:45:09 +00:00
|
|
|
}
|
|
|
|
(void) printf("%s [internal %s txg:%lld] %s", tbuf,
|
|
|
|
zfs_history_event_names[ievent],
|
2013-11-01 19:26:11 +00:00
|
|
|
(longlong_t) fnvlist_lookup_uint64(
|
|
|
|
rec, ZPOOL_HIST_TXG),
|
2013-08-28 11:45:09 +00:00
|
|
|
fnvlist_lookup_string(rec, ZPOOL_HIST_INT_STR));
|
|
|
|
} else if (nvlist_exists(rec, ZPOOL_HIST_INT_NAME)) {
|
|
|
|
if (!cb->internal)
|
|
|
|
continue;
|
|
|
|
(void) printf("%s [txg:%lld] %s", tbuf,
|
2013-11-01 19:26:11 +00:00
|
|
|
(longlong_t) fnvlist_lookup_uint64(
|
|
|
|
rec, ZPOOL_HIST_TXG),
|
2013-08-28 11:45:09 +00:00
|
|
|
fnvlist_lookup_string(rec, ZPOOL_HIST_INT_NAME));
|
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_DSNAME)) {
|
|
|
|
(void) printf(" %s (%llu)",
|
|
|
|
fnvlist_lookup_string(rec,
|
|
|
|
ZPOOL_HIST_DSNAME),
|
2013-11-01 19:26:11 +00:00
|
|
|
(u_longlong_t)fnvlist_lookup_uint64(rec,
|
2013-08-28 11:45:09 +00:00
|
|
|
ZPOOL_HIST_DSID));
|
|
|
|
}
|
|
|
|
(void) printf(" %s", fnvlist_lookup_string(rec,
|
|
|
|
ZPOOL_HIST_INT_STR));
|
|
|
|
} else if (nvlist_exists(rec, ZPOOL_HIST_IOCTL)) {
|
|
|
|
if (!cb->internal)
|
|
|
|
continue;
|
|
|
|
(void) printf("%s ioctl %s\n", tbuf,
|
|
|
|
fnvlist_lookup_string(rec, ZPOOL_HIST_IOCTL));
|
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_INPUT_NVL)) {
|
|
|
|
(void) printf(" input:\n");
|
|
|
|
dump_nvlist(fnvlist_lookup_nvlist(rec,
|
|
|
|
ZPOOL_HIST_INPUT_NVL), 8);
|
|
|
|
}
|
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_OUTPUT_NVL)) {
|
|
|
|
(void) printf(" output:\n");
|
|
|
|
dump_nvlist(fnvlist_lookup_nvlist(rec,
|
|
|
|
ZPOOL_HIST_OUTPUT_NVL), 8);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!cb->internal)
|
|
|
|
continue;
|
|
|
|
(void) printf("%s unrecognized record:\n", tbuf);
|
|
|
|
dump_nvlist(rec, 4);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cb->longfmt) {
|
|
|
|
(void) printf("\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
(void) printf(" [");
|
2013-08-28 11:45:09 +00:00
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_WHO)) {
|
|
|
|
uid_t who = fnvlist_lookup_uint64(rec, ZPOOL_HIST_WHO);
|
|
|
|
struct passwd *pwd = getpwuid(who);
|
|
|
|
(void) printf("user %d ", (int)who);
|
|
|
|
if (pwd != NULL)
|
|
|
|
(void) printf("(%s) ", pwd->pw_name);
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2013-08-28 11:45:09 +00:00
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_HOST)) {
|
|
|
|
(void) printf("on %s",
|
|
|
|
fnvlist_lookup_string(rec, ZPOOL_HIST_HOST));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
2013-08-28 11:45:09 +00:00
|
|
|
if (nvlist_exists(rec, ZPOOL_HIST_ZONE)) {
|
|
|
|
(void) printf(":%s",
|
|
|
|
fnvlist_lookup_string(rec, ZPOOL_HIST_ZONE));
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(void) printf("]");
|
|
|
|
(void) printf("\n");
|
|
|
|
}
|
|
|
|
(void) printf("\n");
|
|
|
|
nvlist_free(nvhis);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool history <pool>
|
|
|
|
*
|
|
|
|
* Displays the history of commands that modified pools.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_history(int argc, char **argv)
|
|
|
|
{
|
|
|
|
hist_cbdata_t cbdata = { 0 };
|
|
|
|
int ret;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
cbdata.first = B_TRUE;
|
|
|
|
/* check options */
|
|
|
|
while ((c = getopt(argc, argv, "li")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'l':
|
2013-08-28 11:45:09 +00:00
|
|
|
cbdata.longfmt = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
2013-08-28 11:45:09 +00:00
|
|
|
cbdata.internal = B_TRUE;
|
2008-11-20 20:01:55 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
ret = for_each_pool(argc, argv, B_FALSE, NULL, get_history_one,
|
|
|
|
&cbdata);
|
|
|
|
|
|
|
|
if (argc == 0 && cbdata.first == B_TRUE) {
|
2012-03-14 13:34:00 +00:00
|
|
|
(void) fprintf(stderr, gettext("no pools available\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-08-26 18:42:43 +00:00
|
|
|
typedef struct ev_opts {
|
|
|
|
int verbose;
|
2010-09-28 23:30:54 +00:00
|
|
|
int scripted;
|
2010-08-26 18:42:43 +00:00
|
|
|
int follow;
|
|
|
|
int clear;
|
|
|
|
} ev_opts_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
zpool_do_events_short(nvlist_t *nvl)
|
|
|
|
{
|
|
|
|
char ctime_str[26], str[32], *ptr;
|
|
|
|
int64_t *tv;
|
|
|
|
uint_t n;
|
|
|
|
|
|
|
|
verify(nvlist_lookup_int64_array(nvl, FM_EREPORT_TIME, &tv, &n) == 0);
|
|
|
|
memset(str, ' ', 32);
|
|
|
|
(void) ctime_r((const time_t *)&tv[0], ctime_str);
|
2013-11-01 19:26:11 +00:00
|
|
|
(void) strncpy(str, ctime_str+4, 6); /* 'Jun 30' */
|
|
|
|
(void) strncpy(str+7, ctime_str+20, 4); /* '1993' */
|
|
|
|
(void) strncpy(str+12, ctime_str+11, 8); /* '21:49:08' */
|
|
|
|
(void) sprintf(str+20, ".%09lld", (longlong_t)tv[1]); /* '.123456789' */
|
2010-08-26 18:42:43 +00:00
|
|
|
(void) printf(gettext("%s "), str);
|
|
|
|
|
|
|
|
verify(nvlist_lookup_string(nvl, FM_CLASS, &ptr) == 0);
|
|
|
|
(void) printf(gettext("%s\n"), ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zpool_do_events_nvprint(nvlist_t *nvl, int depth)
|
|
|
|
{
|
|
|
|
nvpair_t *nvp;
|
|
|
|
|
|
|
|
for (nvp = nvlist_next_nvpair(nvl, NULL);
|
|
|
|
nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) {
|
|
|
|
|
|
|
|
data_type_t type = nvpair_type(nvp);
|
|
|
|
const char *name = nvpair_name(nvp);
|
|
|
|
|
|
|
|
boolean_t b;
|
|
|
|
uint8_t i8;
|
|
|
|
uint16_t i16;
|
|
|
|
uint32_t i32;
|
|
|
|
uint64_t i64;
|
|
|
|
char *str;
|
|
|
|
nvlist_t *cnv;
|
|
|
|
|
|
|
|
printf(gettext("%*s%s = "), depth, "", name);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DATA_TYPE_BOOLEAN:
|
|
|
|
printf(gettext("%s"), "1");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BOOLEAN_VALUE:
|
|
|
|
(void) nvpair_value_boolean_value(nvp, &b);
|
|
|
|
printf(gettext("%s"), b ? "1" : "0");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_BYTE:
|
|
|
|
(void) nvpair_value_byte(nvp, &i8);
|
|
|
|
printf(gettext("0x%x"), i8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT8:
|
|
|
|
(void) nvpair_value_int8(nvp, (void *)&i8);
|
|
|
|
printf(gettext("0x%x"), i8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT8:
|
|
|
|
(void) nvpair_value_uint8(nvp, &i8);
|
|
|
|
printf(gettext("0x%x"), i8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT16:
|
|
|
|
(void) nvpair_value_int16(nvp, (void *)&i16);
|
|
|
|
printf(gettext("0x%x"), i16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT16:
|
|
|
|
(void) nvpair_value_uint16(nvp, &i16);
|
|
|
|
printf(gettext("0x%x"), i16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT32:
|
|
|
|
(void) nvpair_value_int32(nvp, (void *)&i32);
|
|
|
|
printf(gettext("0x%x"), i32);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT32:
|
|
|
|
(void) nvpair_value_uint32(nvp, &i32);
|
|
|
|
printf(gettext("0x%x"), i32);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT64:
|
|
|
|
(void) nvpair_value_int64(nvp, (void *)&i64);
|
|
|
|
printf(gettext("0x%llx"), (u_longlong_t)i64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT64:
|
|
|
|
(void) nvpair_value_uint64(nvp, &i64);
|
|
|
|
printf(gettext("0x%llx"), (u_longlong_t)i64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_HRTIME:
|
|
|
|
(void) nvpair_value_hrtime(nvp, (void *)&i64);
|
|
|
|
printf(gettext("0x%llx"), (u_longlong_t)i64);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_STRING:
|
|
|
|
(void) nvpair_value_string(nvp, &str);
|
|
|
|
printf(gettext("\"%s\""), str ? str : "<NULL>");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_NVLIST:
|
|
|
|
printf(gettext("(embedded nvlist)\n"));
|
|
|
|
(void) nvpair_value_nvlist(nvp, &cnv);
|
|
|
|
zpool_do_events_nvprint(cnv, depth + 8);
|
2010-09-28 23:30:54 +00:00
|
|
|
printf(gettext("%*s(end %s)"), depth, "", name);
|
2010-08-26 18:42:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_NVLIST_ARRAY: {
|
|
|
|
nvlist_t **val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_nvlist_array(nvp, &val, &nelem);
|
|
|
|
printf(gettext("(%d embedded nvlists)\n"), nelem);
|
|
|
|
for (i = 0; i < nelem; i++) {
|
|
|
|
printf(gettext("%*s%s[%d] = %s\n"),
|
2013-11-01 19:26:11 +00:00
|
|
|
depth, "", name, i, "(embedded nvlist)");
|
2010-08-26 18:42:43 +00:00
|
|
|
zpool_do_events_nvprint(val[i], depth + 8);
|
|
|
|
printf(gettext("%*s(end %s[%i])\n"),
|
2013-11-01 19:26:11 +00:00
|
|
|
depth, "", name, i);
|
2010-08-26 18:42:43 +00:00
|
|
|
}
|
|
|
|
printf(gettext("%*s(end %s)\n"), depth, "", name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DATA_TYPE_INT8_ARRAY: {
|
|
|
|
int8_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_int8_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
|
|
|
printf(gettext("0x%x "), val[i]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT8_ARRAY: {
|
|
|
|
uint8_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_uint8_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
|
|
|
printf(gettext("0x%x "), val[i]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_INT16_ARRAY: {
|
|
|
|
int16_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_int16_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
|
|
|
printf(gettext("0x%x "), val[i]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT16_ARRAY: {
|
|
|
|
uint16_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_uint16_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
|
|
|
printf(gettext("0x%x "), val[i]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_INT32_ARRAY: {
|
|
|
|
int32_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_int32_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
|
|
|
printf(gettext("0x%x "), val[i]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT32_ARRAY: {
|
|
|
|
uint32_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_uint32_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
|
|
|
printf(gettext("0x%x "), val[i]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_INT64_ARRAY: {
|
|
|
|
int64_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_int64_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 19:26:11 +00:00
|
|
|
printf(gettext("0x%llx "),
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 18:42:43 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATA_TYPE_UINT64_ARRAY: {
|
|
|
|
uint64_t *val;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_uint64_array(nvp, &val, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
2013-11-01 19:26:11 +00:00
|
|
|
printf(gettext("0x%llx "),
|
|
|
|
(u_longlong_t)val[i]);
|
2010-08-26 18:42:43 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-24 23:43:07 +00:00
|
|
|
case DATA_TYPE_STRING_ARRAY: {
|
|
|
|
char **str;
|
|
|
|
uint_t i, nelem;
|
|
|
|
|
|
|
|
(void) nvpair_value_string_array(nvp, &str, &nelem);
|
|
|
|
for (i = 0; i < nelem; i++)
|
|
|
|
printf(gettext("\"%s\" "),
|
|
|
|
str[i] ? str[i] : "<NULL>");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-08-26 18:42:43 +00:00
|
|
|
case DATA_TYPE_BOOLEAN_ARRAY:
|
|
|
|
case DATA_TYPE_BYTE_ARRAY:
|
|
|
|
case DATA_TYPE_DOUBLE:
|
|
|
|
case DATA_TYPE_UNKNOWN:
|
|
|
|
printf(gettext("<unknown>"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(gettext("\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zpool_do_events_next(ev_opts_t *opts)
|
|
|
|
{
|
|
|
|
nvlist_t *nvl;
|
2013-11-23 00:00:39 +00:00
|
|
|
int zevent_fd, ret, dropped;
|
2010-08-26 18:42:43 +00:00
|
|
|
|
2013-11-23 00:00:39 +00:00
|
|
|
zevent_fd = open(ZFS_DEV, O_RDWR);
|
|
|
|
VERIFY(zevent_fd >= 0);
|
2010-08-26 18:42:43 +00:00
|
|
|
|
2010-09-28 23:30:54 +00:00
|
|
|
if (!opts->scripted)
|
|
|
|
(void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
|
2010-08-26 18:42:43 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ret = zpool_events_next(g_zfs, &nvl, &dropped,
|
2014-02-12 18:30:18 +00:00
|
|
|
(opts->follow ? ZEVENT_NONE : ZEVENT_NONBLOCK), zevent_fd);
|
2010-08-26 18:42:43 +00:00
|
|
|
if (ret || nvl == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (dropped > 0)
|
|
|
|
(void) printf(gettext("dropped %d events\n"), dropped);
|
|
|
|
|
|
|
|
zpool_do_events_short(nvl);
|
|
|
|
|
|
|
|
if (opts->verbose) {
|
|
|
|
zpool_do_events_nvprint(nvl, 8);
|
|
|
|
printf(gettext("\n"));
|
|
|
|
}
|
2013-07-05 14:51:36 +00:00
|
|
|
(void) fflush(stdout);
|
2010-08-26 18:42:43 +00:00
|
|
|
|
|
|
|
nvlist_free(nvl);
|
|
|
|
}
|
|
|
|
|
2013-11-23 00:00:39 +00:00
|
|
|
VERIFY(0 == close(zevent_fd));
|
2010-08-26 18:42:43 +00:00
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zpool_do_events_clear(ev_opts_t *opts)
|
|
|
|
{
|
|
|
|
int count, ret;
|
|
|
|
|
|
|
|
ret = zpool_events_clear(g_zfs, &count);
|
|
|
|
if (!ret)
|
|
|
|
(void) printf(gettext("cleared %d events\n"), count);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zpool events [-vfc]
|
|
|
|
*
|
|
|
|
* Displays events logs by ZFS.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zpool_do_events(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ev_opts_t opts = { 0 };
|
|
|
|
int ret;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
/* check options */
|
2010-09-28 23:30:54 +00:00
|
|
|
while ((c = getopt(argc, argv, "vHfc")) != -1) {
|
2010-08-26 18:42:43 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
opts.verbose = 1;
|
2010-09-28 23:30:54 +00:00
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
opts.scripted = 1;
|
2010-08-26 18:42:43 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
opts.follow = 1;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
opts.clear = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (opts.clear)
|
|
|
|
ret = zpool_do_events_clear(&opts);
|
|
|
|
else
|
|
|
|
ret = zpool_do_events_next(&opts);
|
|
|
|
|
2013-11-01 19:26:11 +00:00
|
|
|
return (ret);
|
2010-08-26 18:42:43 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
static int
|
|
|
|
get_callback(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
|
|
|
|
char value[MAXNAMELEN];
|
|
|
|
zprop_source_t srctype;
|
|
|
|
zprop_list_t *pl;
|
|
|
|
|
|
|
|
for (pl = cbp->cb_proplist; pl != NULL; pl = pl->pl_next) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip the special fake placeholder. This will also skip
|
|
|
|
* over the name property when 'all' is specified.
|
|
|
|
*/
|
|
|
|
if (pl->pl_prop == ZPOOL_PROP_NAME &&
|
|
|
|
pl == cbp->cb_proplist)
|
|
|
|
continue;
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
if (pl->pl_prop == ZPROP_INVAL &&
|
|
|
|
(zpool_prop_feature(pl->pl_user_prop) ||
|
|
|
|
zpool_prop_unsupported(pl->pl_user_prop))) {
|
|
|
|
srctype = ZPROP_SRC_LOCAL;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
if (zpool_prop_get_feature(zhp, pl->pl_user_prop,
|
|
|
|
value, sizeof (value)) == 0) {
|
|
|
|
zprop_print_one_property(zpool_get_name(zhp),
|
|
|
|
cbp, pl->pl_user_prop, value, srctype,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
} else {
|
2013-10-23 08:50:48 +00:00
|
|
|
if (zpool_get_prop_literal(zhp, pl->pl_prop, value,
|
|
|
|
sizeof (value), &srctype, cbp->cb_literal) != 0)
|
2012-12-13 23:24:15 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
zprop_print_one_property(zpool_get_name(zhp), cbp,
|
|
|
|
zpool_prop_to_name(pl->pl_prop), value, srctype,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zpool_do_get(int argc, char **argv)
|
|
|
|
{
|
|
|
|
zprop_get_cbdata_t cb = { 0 };
|
|
|
|
zprop_list_t fake_name = { 0 };
|
2013-10-23 08:50:48 +00:00
|
|
|
int c, ret;
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2013-10-23 08:50:48 +00:00
|
|
|
/* check options */
|
2014-07-23 10:14:09 +00:00
|
|
|
while ((c = getopt(argc, argv, "pH")) != -1) {
|
2013-10-23 08:50:48 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'p':
|
|
|
|
cb.cb_literal = B_TRUE;
|
|
|
|
break;
|
|
|
|
|
2014-07-23 10:14:09 +00:00
|
|
|
case 'H':
|
|
|
|
cb.cb_scripted = B_TRUE;
|
|
|
|
break;
|
|
|
|
|
2013-10-23 08:50:48 +00:00
|
|
|
case '?':
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
optopt);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
2012-12-13 23:24:15 +00:00
|
|
|
(void) fprintf(stderr, gettext("missing property "
|
|
|
|
"argument\n"));
|
2008-11-20 20:01:55 +00:00
|
|
|
usage(B_FALSE);
|
2012-12-13 23:24:15 +00:00
|
|
|
}
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
cb.cb_first = B_TRUE;
|
|
|
|
cb.cb_sources = ZPROP_SRC_ALL;
|
|
|
|
cb.cb_columns[0] = GET_COL_NAME;
|
|
|
|
cb.cb_columns[1] = GET_COL_PROPERTY;
|
|
|
|
cb.cb_columns[2] = GET_COL_VALUE;
|
|
|
|
cb.cb_columns[3] = GET_COL_SOURCE;
|
|
|
|
cb.cb_type = ZFS_TYPE_POOL;
|
|
|
|
|
2013-10-23 08:50:48 +00:00
|
|
|
if (zprop_get_list(g_zfs, argv[0], &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
usage(B_FALSE);
|
|
|
|
|
2013-10-23 08:50:48 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
if (cb.cb_proplist != NULL) {
|
|
|
|
fake_name.pl_prop = ZPOOL_PROP_NAME;
|
|
|
|
fake_name.pl_width = strlen(gettext("NAME"));
|
|
|
|
fake_name.pl_next = cb.cb_proplist;
|
|
|
|
cb.cb_proplist = &fake_name;
|
|
|
|
}
|
|
|
|
|
2013-10-23 08:50:48 +00:00
|
|
|
ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
|
2008-11-20 20:01:55 +00:00
|
|
|
get_callback, &cb);
|
|
|
|
|
|
|
|
if (cb.cb_proplist == &fake_name)
|
|
|
|
zprop_free_list(fake_name.pl_next);
|
|
|
|
else
|
|
|
|
zprop_free_list(cb.cb_proplist);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct set_cbdata {
|
|
|
|
char *cb_propname;
|
|
|
|
char *cb_value;
|
|
|
|
boolean_t cb_any_successful;
|
|
|
|
} set_cbdata_t;
|
|
|
|
|
|
|
|
int
|
|
|
|
set_callback(zpool_handle_t *zhp, void *data)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
set_cbdata_t *cb = (set_cbdata_t *)data;
|
|
|
|
|
|
|
|
error = zpool_set_prop(zhp, cb->cb_propname, cb->cb_value);
|
|
|
|
|
|
|
|
if (!error)
|
|
|
|
cb->cb_any_successful = B_TRUE;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zpool_do_set(int argc, char **argv)
|
|
|
|
{
|
|
|
|
set_cbdata_t cb = { 0 };
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (argc > 1 && argv[1][0] == '-') {
|
|
|
|
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
|
|
|
argv[1][1]);
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("missing property=value "
|
|
|
|
"argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
(void) fprintf(stderr, gettext("missing pool name\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 3) {
|
|
|
|
(void) fprintf(stderr, gettext("too many pool names\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
cb.cb_propname = argv[1];
|
|
|
|
cb.cb_value = strchr(cb.cb_propname, '=');
|
|
|
|
if (cb.cb_value == NULL) {
|
|
|
|
(void) fprintf(stderr, gettext("missing value in "
|
|
|
|
"property=value argument\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
*(cb.cb_value) = '\0';
|
|
|
|
cb.cb_value++;
|
|
|
|
|
|
|
|
error = for_each_pool(argc - 2, argv + 2, B_TRUE, NULL,
|
|
|
|
set_callback, &cb);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_command_idx(char *command, int *idx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NCOMMAND; i++) {
|
|
|
|
if (command_table[i].name == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(command, command_table[i].name) == 0) {
|
|
|
|
*idx = i;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
2010-08-26 16:58:04 +00:00
|
|
|
int i = 0;
|
2008-11-20 20:01:55 +00:00
|
|
|
char *cmdname;
|
|
|
|
|
|
|
|
(void) setlocale(LC_ALL, "");
|
|
|
|
(void) textdomain(TEXT_DOMAIN);
|
|
|
|
|
|
|
|
opterr = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the user has specified some command.
|
|
|
|
*/
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, gettext("missing command\n"));
|
|
|
|
usage(B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdname = argv[1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special case '-?'
|
|
|
|
*/
|
2013-11-01 19:26:11 +00:00
|
|
|
if ((strcmp(cmdname, "-?") == 0) || strcmp(cmdname, "--help") == 0)
|
2008-11-20 20:01:55 +00:00
|
|
|
usage(B_TRUE);
|
|
|
|
|
2010-08-26 18:57:29 +00:00
|
|
|
if ((g_zfs = libzfs_init()) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
libzfs_print_on_error(g_zfs, B_TRUE);
|
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
zfs_save_arguments(argc, argv, history_str, sizeof (history_str));
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the appropriate command.
|
|
|
|
*/
|
|
|
|
if (find_command_idx(cmdname, &i) == 0) {
|
|
|
|
current_command = &command_table[i];
|
|
|
|
ret = command_table[i].func(argc - 1, argv + 1);
|
|
|
|
} else if (strchr(cmdname, '=')) {
|
|
|
|
verify(find_command_idx("set", &i) == 0);
|
|
|
|
current_command = &command_table[i];
|
|
|
|
ret = command_table[i].func(argc, argv);
|
|
|
|
} else if (strcmp(cmdname, "freeze") == 0 && argc == 3) {
|
|
|
|
/*
|
|
|
|
* 'freeze' is a vile debugging abomination, so we treat
|
|
|
|
* it as such.
|
|
|
|
*/
|
|
|
|
char buf[16384];
|
|
|
|
int fd = open(ZFS_DEV, O_RDWR);
|
|
|
|
(void) strcpy((void *)buf, argv[2]);
|
|
|
|
return (!!ioctl(fd, ZFS_IOC_POOL_FREEZE, buf));
|
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr, gettext("unrecognized "
|
|
|
|
"command '%s'\n"), cmdname);
|
|
|
|
usage(B_FALSE);
|
2010-08-26 16:58:04 +00:00
|
|
|
ret = 1;
|
2008-11-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 11:45:09 +00:00
|
|
|
if (ret == 0 && log_history)
|
|
|
|
(void) zpool_log_history(g_zfs, history_str);
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
libzfs_fini(g_zfs);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The 'ZFS_ABORT' environment variable causes us to dump core on exit
|
|
|
|
* for the purposes of running ::findleaks.
|
|
|
|
*/
|
|
|
|
if (getenv("ZFS_ABORT") != NULL) {
|
|
|
|
(void) printf("dumping core by request\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|