usr/src/cmd/zpool/zpool_main.c
author perrin
Mon, 04 Aug 2008 20:36:57 -0700
changeset 7294 c9c31ef4c960
parent 7265 cc18862247da
child 7343 168aa3b38fe5
permissions -rw-r--r--
PSARC 2008/486 Intent log replay failure handling 6707530 log device failure needs some work
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
     5
 * Common Development and Distribution License (the "License").
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    21
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
5853
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <assert.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <ctype.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <dirent.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <fcntl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <libgen.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <libintl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <libuutil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <locale.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <stdio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <stdlib.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <string.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <strings.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <unistd.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <priv.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
    44
#include <pwd.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
    45
#include <zone.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    46
#include <sys/fs/zfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <libzfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include "zpool_util.h"
5913
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5904
diff changeset
    53
#include "zfs_comutil.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
static int zpool_do_create(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
static int zpool_do_destroy(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
static int zpool_do_add(int, char **);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    59
static int zpool_do_remove(int, char **);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
static int zpool_do_list(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
static int zpool_do_iostat(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
static int zpool_do_status(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
static int zpool_do_online(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
static int zpool_do_offline(int, char **);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
    67
static int zpool_do_clear(int, char **);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
static int zpool_do_attach(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
static int zpool_do_detach(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
static int zpool_do_replace(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
static int zpool_do_scrub(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
static int zpool_do_import(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
static int zpool_do_export(int, char **);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
    78
static int zpool_do_upgrade(int, char **);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
    79
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
    80
static int zpool_do_history(int, char **);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
    81
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    82
static int zpool_do_get(int, char **);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    83
static int zpool_do_set(int, char **);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    84
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
 * These libumem hooks provide a reasonable set of defaults for the allocator's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
 * debugging facilities.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
 */
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6807
diff changeset
    89
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6807
diff changeset
    90
#ifdef DEBUG
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
const char *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    92
_umem_debug_init(void)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
	return ("default,verbose"); /* $UMEM_DEBUG setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
_umem_logging_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	return ("fail,contents"); /* $UMEM_LOGGING setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
}
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6807
diff changeset
   102
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   104
typedef enum {
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   105
	HELP_ADD,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   106
	HELP_ATTACH,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   107
	HELP_CLEAR,
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   108
	HELP_CREATE,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   109
	HELP_DESTROY,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   110
	HELP_DETACH,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   111
	HELP_EXPORT,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
   112
	HELP_HISTORY,
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   113
	HELP_IMPORT,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   114
	HELP_IOSTAT,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   115
	HELP_LIST,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   116
	HELP_OFFLINE,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   117
	HELP_ONLINE,
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   118
	HELP_REPLACE,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   119
	HELP_REMOVE,
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   120
	HELP_SCRUB,
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
   121
	HELP_STATUS,
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   122
	HELP_UPGRADE,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   123
	HELP_GET,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   124
	HELP_SET
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   125
} zpool_help_t;
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   126
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   127
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
typedef struct zpool_command {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	const char	*name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	int		(*func)(int, char **);
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   131
	zpool_help_t	usage;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
} zpool_command_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
 * Master command table.  Each ZFS command has a name, associated function, and
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   136
 * usage message.  The usage messages need to be internationalized, so we have
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   137
 * to have a function to return the usage message based on a command index.
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   138
 *
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   139
 * These commands are organized according to how they are displayed in the usage
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   140
 * message.  An empty command (one with a NULL name) indicates an empty line in
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   141
 * the generic usage message.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
static zpool_command_t command_table[] = {
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   144
	{ "create",	zpool_do_create,	HELP_CREATE		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   145
	{ "destroy",	zpool_do_destroy,	HELP_DESTROY		},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
	{ NULL },
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   147
	{ "add",	zpool_do_add,		HELP_ADD		},
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   148
	{ "remove",	zpool_do_remove,	HELP_REMOVE		},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
	{ NULL },
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   150
	{ "list",	zpool_do_list,		HELP_LIST		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   151
	{ "iostat",	zpool_do_iostat,	HELP_IOSTAT		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   152
	{ "status",	zpool_do_status,	HELP_STATUS		},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
	{ NULL },
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   154
	{ "online",	zpool_do_online,	HELP_ONLINE		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   155
	{ "offline",	zpool_do_offline,	HELP_OFFLINE		},
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   156
	{ "clear",	zpool_do_clear,		HELP_CLEAR		},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
	{ NULL },
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   158
	{ "attach",	zpool_do_attach,	HELP_ATTACH		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   159
	{ "detach",	zpool_do_detach,	HELP_DETACH		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   160
	{ "replace",	zpool_do_replace,	HELP_REPLACE		},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
	{ NULL },
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   162
	{ "scrub",	zpool_do_scrub,		HELP_SCRUB		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   163
	{ NULL },
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   164
	{ "import",	zpool_do_import,	HELP_IMPORT		},
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   165
	{ "export",	zpool_do_export,	HELP_EXPORT		},
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
   166
	{ "upgrade",	zpool_do_upgrade,	HELP_UPGRADE		},
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
   167
	{ NULL },
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   168
	{ "history",	zpool_do_history,	HELP_HISTORY		},
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   169
	{ "get",	zpool_do_get,		HELP_GET		},
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   170
	{ "set",	zpool_do_set,		HELP_SET		},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
#define	NCOMMAND	(sizeof (command_table) / sizeof (command_table[0]))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
zpool_command_t *current_command;
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   176
static char history_str[HIS_MAX_RECORD_LEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   178
static const char *
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   179
get_usage(zpool_help_t idx) {
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   180
	switch (idx) {
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   181
	case HELP_ADD:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   182
		return (gettext("\tadd [-fn] <pool> <vdev> ...\n"));
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   183
	case HELP_ATTACH:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   184
		return (gettext("\tattach [-f] <pool> <device> "
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4820
diff changeset
   185
		    "<new-device>\n"));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   186
	case HELP_CLEAR:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   187
		return (gettext("\tclear <pool> [device]\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   188
	case HELP_CREATE:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   189
		return (gettext("\tcreate [-fn] [-o property=value] ... \n"
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   190
		    "\t    [-O file-system-property=value] ... \n"
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   191
		    "\t    [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   192
	case HELP_DESTROY:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   193
		return (gettext("\tdestroy [-f] <pool>\n"));
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   194
	case HELP_DETACH:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   195
		return (gettext("\tdetach <pool> <device>\n"));
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   196
	case HELP_EXPORT:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   197
		return (gettext("\texport [-f] <pool> ...\n"));
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
   198
	case HELP_HISTORY:
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
   199
		return (gettext("\thistory [-il] [<pool>] ...\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   200
	case HELP_IMPORT:
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
   201
		return (gettext("\timport [-d dir] [-D]\n"
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   202
		    "\timport [-o mntopts] [-o property=value] ... \n"
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   203
		    "\t    [-d dir | -c cachefile] [-D] [-f] [-R root] -a\n"
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   204
		    "\timport [-o mntopts] [-o property=value] ... \n"
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   205
		    "\t    [-d dir | -c cachefile] [-D] [-f] [-R root] "
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   206
		    "<pool | id> [newpool]\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   207
	case HELP_IOSTAT:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   208
		return (gettext("\tiostat [-v] [pool] ... [interval "
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   209
		    "[count]]\n"));
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   210
	case HELP_LIST:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   211
		return (gettext("\tlist [-H] [-o property[,...]] "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   212
		    "[pool] ...\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   213
	case HELP_OFFLINE:
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
   214
		return (gettext("\toffline [-t] <pool> <device> ...\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   215
	case HELP_ONLINE:
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
   216
		return (gettext("\tonline <pool> <device> ...\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   217
	case HELP_REPLACE:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   218
		return (gettext("\treplace [-f] <pool> <device> "
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4820
diff changeset
   219
		    "[new-device]\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   220
	case HELP_REMOVE:
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   221
		return (gettext("\tremove <pool> <device> ...\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   222
	case HELP_SCRUB:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   223
		return (gettext("\tscrub [-s] <pool> ...\n"));
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   224
	case HELP_STATUS:
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   225
		return (gettext("\tstatus [-vx] [pool] ...\n"));
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
   226
	case HELP_UPGRADE:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
   227
		return (gettext("\tupgrade\n"
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
   228
		    "\tupgrade -v\n"
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   229
		    "\tupgrade [-V version] <-a | pool ...>\n"));
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   230
	case HELP_GET:
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4820
diff changeset
   231
		return (gettext("\tget <\"all\" | property[,...]> "
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   232
		    "<pool> ...\n"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   233
	case HELP_SET:
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   234
		return (gettext("\tset <property=value> <pool> \n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   235
	}
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   236
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   237
	abort();
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   238
	/* NOTREACHED */
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   239
}
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   240
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
/*
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   243
 * Callback routine that will print out a pool property value.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   244
 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   245
static int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   246
print_prop_cb(int prop, void *cb)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   247
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   248
	FILE *fp = cb;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   249
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   250
	(void) fprintf(fp, "\t%-13s  ", zpool_prop_to_name(prop));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   251
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   252
	if (zpool_prop_readonly(prop))
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   253
		(void) fprintf(fp, "  NO   ");
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   254
	else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   255
		(void) fprintf(fp, " YES    ");
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   256
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   257
	if (zpool_prop_values(prop) == NULL)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   258
		(void) fprintf(fp, "-\n");
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   259
	else
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   260
		(void) fprintf(fp, "%s\n", zpool_prop_values(prop));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   261
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   262
	return (ZPROP_CONT);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   263
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   264
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   265
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
 * Display usage message.  If we're inside a command, display only the usage for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
 * that command.  Otherwise, iterate over the entire command table and display
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
 * a complete usage message.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
void
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   271
usage(boolean_t requested)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	FILE *fp = requested ? stdout : stderr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	if (current_command == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
		int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
		(void) fprintf(fp, gettext("usage: zpool command args ...\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
		(void) fprintf(fp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
		    gettext("where 'command' is one of the following:\n\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
		for (i = 0; i < NCOMMAND; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
			if (command_table[i].name == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
				(void) fprintf(fp, "\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
				(void) fprintf(fp, "%s",
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   287
				    get_usage(command_table[i].usage));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
		(void) fprintf(fp, gettext("usage:\n"));
1387
7dc47b4865df 6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents: 1354
diff changeset
   291
		(void) fprintf(fp, "%s", get_usage(current_command->usage));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   294
	if (current_command != NULL &&
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   295
	    ((strcmp(current_command->name, "set") == 0) ||
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   296
	    (strcmp(current_command->name, "get") == 0) ||
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   297
	    (strcmp(current_command->name, "list") == 0))) {
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   298
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   299
		(void) fprintf(fp,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   300
		    gettext("\nthe following properties are supported:\n"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   301
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   302
		(void) fprintf(fp, "\n\t%-13s  %s  %s\n\n",
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   303
		    "PROPERTY", "EDIT", "VALUES");
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   304
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   305
		/* Iterate over all properties */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   306
		(void) zprop_iter(print_prop_cb, fp, B_FALSE, B_TRUE,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   307
		    ZFS_TYPE_POOL);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   308
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   309
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   310
	/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   311
	 * See comments at end of main().
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   312
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   313
	if (getenv("ZFS_ABORT") != NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   314
		(void) printf("dumping core by request\n");
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   315
		abort();
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   316
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   317
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
	exit(requested ? 0 : 2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
void
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   322
print_vdev_tree(zpool_handle_t *zhp, const char *name, nvlist_t *nv, int indent,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   323
    boolean_t print_logs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	nvlist_t **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
	uint_t c, children;
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
   327
	char *vname;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
	if (name != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
		(void) printf("\t%*s%s\n", indent, "", name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
	    &child, &children) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
   336
	for (c = 0; c < children; c++) {
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   337
		uint64_t is_log = B_FALSE;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   338
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   339
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   340
		    &is_log);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   341
		if ((is_log && !print_logs) || (!is_log && print_logs))
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   342
			continue;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   343
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   344
		vname = zpool_vdev_name(g_zfs, zhp, child[c]);
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   345
		print_vdev_tree(zhp, vname, child[c], indent + 2,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   346
		    B_FALSE);
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
   347
		free(vname);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
   348
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
/*
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   352
 * Add a property pair (name, string-value) into a property nvlist.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   353
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   354
static int
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   355
add_prop_list(const char *propname, char *propval, nvlist_t **props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   356
    boolean_t poolprop)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   357
{
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   358
	zpool_prop_t prop = ZPROP_INVAL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   359
	zfs_prop_t fprop;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   360
	nvlist_t *proplist;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   361
	const char *normnm;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   362
	char *strval;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   363
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   364
	if (*props == NULL &&
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   365
	    nvlist_alloc(props, NV_UNIQUE_NAME, 0) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   366
		(void) fprintf(stderr,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   367
		    gettext("internal error: out of memory\n"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   368
		return (1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   369
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   370
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   371
	proplist = *props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   372
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   373
	if (poolprop) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   374
		if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   375
			(void) fprintf(stderr, gettext("property '%s' is "
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   376
			    "not a valid pool property\n"), propname);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   377
			return (2);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   378
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   379
		normnm = zpool_prop_to_name(prop);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   380
	} else {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   381
		if ((fprop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   382
			(void) fprintf(stderr, gettext("property '%s' is "
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   383
			    "not a valid file system property\n"), propname);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   384
			return (2);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   385
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   386
		normnm = zfs_prop_to_name(fprop);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   387
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   388
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   389
	if (nvlist_lookup_string(proplist, normnm, &strval) == 0 &&
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   390
	    prop != ZPOOL_PROP_CACHEFILE) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   391
		(void) fprintf(stderr, gettext("property '%s' "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   392
		    "specified multiple times\n"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   393
		return (2);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   394
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   395
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   396
	if (nvlist_add_string(proplist, normnm, propval) != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   397
		(void) fprintf(stderr, gettext("internal "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   398
		    "error: out of memory\n"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   399
		return (1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   400
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   401
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   402
	return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   403
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   404
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   405
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
 * zpool add [-fn] <pool> <vdev> ...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
 *	-f	Force addition of devices, even if they appear in use
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
 *	-n	Do not add the devices, but display the resulting layout if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
 *		they were to be added.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
 * Adds the given vdevs to 'pool'.  As with create, the bulk of this work is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
 * libzfs.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
zpool_do_add(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   419
	boolean_t force = B_FALSE;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   420
	boolean_t dryrun = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	char *poolname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
	zpool_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	while ((c = getopt(argc, argv, "fn")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
		case 'f':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   432
			force = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
		case 'n':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   435
			dryrun = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   440
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
	/* get pool name and check number of arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
		(void) fprintf(stderr, gettext("missing pool name argument\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   450
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
	if (argc < 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
		(void) fprintf(stderr, gettext("missing vdev specification\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   454
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	poolname = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	argc--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	argv++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   462
	if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
   465
	if ((config = zpool_get_config(zhp, NULL)) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
		(void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
		    poolname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
	/* pass off to get_vdev_spec for processing */
4276
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 4221
diff changeset
   473
	nvroot = make_root_vdev(zhp, force, !force, B_FALSE, argc, argv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
	if (nvroot == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
	if (dryrun) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
		nvlist_t *poolnvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
		verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
		    &poolnvroot) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
		(void) printf(gettext("would update '%s' to the following "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
		    "configuration:\n"), zpool_get_name(zhp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   488
		/* print original main pool and new tree */
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   489
		print_vdev_tree(zhp, poolname, poolnvroot, 0, B_FALSE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   490
		print_vdev_tree(zhp, NULL, nvroot, 0, B_FALSE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   491
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   492
		/* Do the same for the logs */
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   493
		if (num_logs(poolnvroot) > 0) {
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   494
			print_vdev_tree(zhp, "logs", poolnvroot, 0, B_TRUE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   495
			print_vdev_tree(zhp, NULL, nvroot, 0, B_TRUE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   496
		} else if (num_logs(nvroot) > 0) {
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   497
			print_vdev_tree(zhp, "logs", nvroot, 0, B_TRUE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   498
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
		ret = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
		ret = (zpool_add(zhp, nvroot) != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   505
	nvlist_free(nvroot);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   506
	zpool_close(zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   507
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   508
	return (ret);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   509
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   510
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   511
/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   512
 * zpool remove <pool> <vdev> ...
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   513
 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   514
 * Removes the given vdev from the pool.  Currently, this only supports removing
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   515
 * spares and cache devices from the pool.  Eventually, we'll want to support
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   516
 * removing leaf vdevs (as an alias for 'detach') as well as toplevel vdevs.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   517
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   518
int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   519
zpool_do_remove(int argc, char **argv)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   520
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   521
	char *poolname;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   522
	int i, ret = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   523
	zpool_handle_t *zhp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   524
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   525
	argc--;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   526
	argv++;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   527
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   528
	/* get pool name and check number of arguments */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   529
	if (argc < 1) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   530
		(void) fprintf(stderr, gettext("missing pool name argument\n"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   531
		usage(B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   532
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   533
	if (argc < 2) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   534
		(void) fprintf(stderr, gettext("missing device\n"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   535
		usage(B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   536
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   537
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   538
	poolname = argv[0];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   539
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   540
	if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   541
		return (1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   542
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   543
	for (i = 1; i < argc; i++) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   544
		if (zpool_vdev_remove(zhp, argv[i]) != 0)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   545
			ret = 1;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   546
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   547
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
/*
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   552
 * zpool create [-fn] [-o property=value] ...
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   553
 *		[-O file-system-property=value] ...
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   554
 *		[-R root] [-m mountpoint] <pool> <dev> ...
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
 *	-f	Force creation, even if devices appear in use
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
 *	-n	Do not create the pool, but display the resulting layout if it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
 *		were to be created.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
 *      -R	Create a pool under an alternate root
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
 *      -m	Set default mountpoint for the root dataset.  By default it's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
 *      	'/<pool>'
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   562
 *	-o	Set property=value.
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   563
 *	-O	Set fsproperty=value in the pool's root file system
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
 *
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   565
 * Creates the named pool according to the given vdev specification.  The
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c.  Once
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
 * we get the nvlist back from get_vdev_spec(), we either print out the contents
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
 * (if '-n' was specified), or pass it to libzfs to do the creation.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
zpool_do_create(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   573
	boolean_t force = B_FALSE;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   574
	boolean_t dryrun = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
	int c;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   576
	nvlist_t *nvroot = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
	char *poolname;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   578
	int ret = 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
	char *altroot = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
	char *mountpoint = NULL;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   581
	nvlist_t *fsprops = NULL;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   582
	nvlist_t *props = NULL;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   583
	char *propval;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
	/* check options */
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   586
	while ((c = getopt(argc, argv, ":fnR:m:o:O:")) != -1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
		case 'f':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   589
			force = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
		case 'n':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   592
			dryrun = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
		case 'R':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
			altroot = optarg;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   596
			if (add_prop_list(zpool_prop_to_name(
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   597
			    ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   598
				goto errout;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   599
			if (nvlist_lookup_string(props,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   600
			    zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   601
			    &propval) == 0)
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   602
				break;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   603
			if (add_prop_list(zpool_prop_to_name(
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   604
			    ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   605
				goto errout;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
		case 'm':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
			mountpoint = optarg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
			break;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   610
		case 'o':
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   611
			if ((propval = strchr(optarg, '=')) == NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   612
				(void) fprintf(stderr, gettext("missing "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   613
				    "'=' for -o option\n"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   614
				goto errout;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   615
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   616
			*propval = '\0';
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   617
			propval++;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   618
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   619
			if (add_prop_list(optarg, propval, &props, B_TRUE))
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   620
				goto errout;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   621
			break;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   622
		case 'O':
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   623
			if ((propval = strchr(optarg, '=')) == NULL) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   624
				(void) fprintf(stderr, gettext("missing "
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   625
				    "'=' for -O option\n"));
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   626
				goto errout;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   627
			}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   628
			*propval = '\0';
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   629
			propval++;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   630
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   631
			if (add_prop_list(optarg, propval, &fsprops, B_FALSE))
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   632
				goto errout;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   633
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
		case ':':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
			(void) fprintf(stderr, gettext("missing argument for "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
			    "'%c' option\n"), optopt);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   637
			goto badusage;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
			    optopt);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   641
			goto badusage;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
	/* get pool name and check number of arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
		(void) fprintf(stderr, gettext("missing pool name argument\n"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   651
		goto badusage;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
	if (argc < 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
		(void) fprintf(stderr, gettext("missing vdev specification\n"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   655
		goto badusage;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
	poolname = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
	 * As a special case, check for use of '/' in the name, and direct the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
	 * user to use 'zfs create' instead.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	if (strchr(poolname, '/') != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
		(void) fprintf(stderr, gettext("cannot create '%s': invalid "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
		    "character '/' in pool name\n"), poolname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
		(void) fprintf(stderr, gettext("use 'zfs create' to "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
		    "create a dataset\n"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   669
		goto errout;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
	/* pass off to get_vdev_spec for bulk processing */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   673
	nvroot = make_root_vdev(NULL, force, !force, B_FALSE, argc - 1,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   674
	    argv + 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
	if (nvroot == NULL)
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   676
		goto errout;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   678
	/* make_root_vdev() allows 0 toplevel children if there are spares */
5913
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5904
diff changeset
   679
	if (!zfs_allocatable_devs(nvroot)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   680
		(void) fprintf(stderr, gettext("invalid vdev "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   681
		    "specification: at least one toplevel vdev must be "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   682
		    "specified\n"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   683
		goto errout;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   684
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   685
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   686
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
	if (altroot != NULL && altroot[0] != '/') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
		(void) fprintf(stderr, gettext("invalid alternate root '%s': "
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   689
		    "must be an absolute path\n"), altroot);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   690
		goto errout;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	 * Check the validity of the mountpoint and direct the user to use the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
	 * '-m' mountpoint option if it looks like its in use.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
	if (mountpoint == NULL ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
	    (strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) != 0 &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
	    strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) != 0)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
		char buf[MAXPATHLEN];
5904
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   701
		DIR *dirp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
		if (mountpoint && mountpoint[0] != '/') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
			(void) fprintf(stderr, gettext("invalid mountpoint "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
			    "'%s': must be an absolute path, 'legacy', or "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
			    "'none'\n"), mountpoint);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   707
			goto errout;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
		if (mountpoint == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
			if (altroot != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
				(void) snprintf(buf, sizeof (buf), "%s/%s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
				    altroot, poolname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
				(void) snprintf(buf, sizeof (buf), "/%s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
				    poolname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
			if (altroot != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
				(void) snprintf(buf, sizeof (buf), "%s%s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
				    altroot, mountpoint);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
				(void) snprintf(buf, sizeof (buf), "%s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
				    mountpoint);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
5904
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   726
		if ((dirp = opendir(buf)) == NULL && errno != ENOENT) {
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   727
			(void) fprintf(stderr, gettext("mountpoint '%s' : "
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   728
			    "%s\n"), buf, strerror(errno));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
			(void) fprintf(stderr, gettext("use '-m' "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
			    "option to provide a different default\n"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   731
			goto errout;
5904
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   732
		} else if (dirp) {
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   733
			int count = 0;
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   734
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   735
			while (count < 3 && readdir(dirp) != NULL)
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   736
				count++;
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   737
			(void) closedir(dirp);
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   738
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   739
			if (count > 2) {
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   740
				(void) fprintf(stderr, gettext("mountpoint "
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   741
				    "'%s' exists and is not empty\n"), buf);
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   742
				(void) fprintf(stderr, gettext("use '-m' "
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   743
				    "option to provide a "
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   744
				    "different default\n"));
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   745
				goto errout;
ac17ccc8902b 6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents: 5886
diff changeset
   746
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
	if (dryrun) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
		 * For a dry run invocation, print out a basic message and run
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
		 * through all the vdevs in the list and print out in an
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
		 * appropriate hierarchy.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
		(void) printf(gettext("would create '%s' with the "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
		    "following layout:\n\n"), poolname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   759
		print_vdev_tree(NULL, poolname, nvroot, 0, B_FALSE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   760
		if (num_logs(nvroot) > 0)
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   761
			print_vdev_tree(NULL, "logs", nvroot, 0, B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
		ret = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
		 * Hand off to libzfs.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
		 */
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   768
		if (zpool_create(g_zfs, poolname,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   769
		    nvroot, props, fsprops) == 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   770
			zfs_handle_t *pool = zfs_open(g_zfs, poolname,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
			    ZFS_TYPE_FILESYSTEM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
			if (pool != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
				if (mountpoint != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
					verify(zfs_prop_set(pool,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   775
					    zfs_prop_to_name(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   776
					    ZFS_PROP_MOUNTPOINT),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
					    mountpoint) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
				if (zfs_mount(pool, NULL, 0) == 0)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5320
diff changeset
   779
					ret = zfs_shareall(pool);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
				zfs_close(pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
			}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   782
		} else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   783
			(void) fprintf(stderr, gettext("pool name may have "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   784
			    "been omitted\n"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   788
errout:
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   789
	nvlist_free(nvroot);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   790
	nvlist_free(fsprops);
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
   791
	nvlist_free(props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
	return (ret);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   793
badusage:
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   794
	nvlist_free(fsprops);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   795
	nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   796
	usage(B_FALSE);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   797
	return (2);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
 * zpool destroy <pool>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
 * 	-f	Forcefully unmount any datasets
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
 * Destroy the given pool.  Automatically unmounts any datasets in the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
zpool_do_destroy(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   810
	boolean_t force = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
	char *pool;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
	zpool_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	while ((c = getopt(argc, argv, "f")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
		case 'f':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   820
			force = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   825
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
	/* check arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
		(void) fprintf(stderr, gettext("missing pool argument\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   835
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   836
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   837
	if (argc > 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
		(void) fprintf(stderr, gettext("too many arguments\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   839
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
	pool = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   844
	if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
		 * As a special case, check for use of '/' in the name, and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
		 * direct the user to use 'zfs destroy' instead.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
		if (strchr(pool, '/') != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
			(void) fprintf(stderr, gettext("use 'zfs destroy' to "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
			    "destroy a dataset\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2926
diff changeset
   855
	if (zpool_disable_datasets(zhp, force) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
		(void) fprintf(stderr, gettext("could not destroy '%s': "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
		    "could not unmount datasets\n"), zpool_get_name(zhp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
	ret = (zpool_destroy(zhp) != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
	zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
 * zpool export [-f] <pool> ...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
 *	-f	Forcefully unmount datasets
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
 *
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   873
 * Export the given pools.  By default, the command will attempt to cleanly
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
 * unmount any active datasets within the pool.  If the '-f' flag is specified,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
 * then the datasets will be forcefully unmounted.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
zpool_do_export(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   880
	boolean_t force = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
	zpool_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
	while ((c = getopt(argc, argv, "f")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
		case 'f':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   890
			force = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   895
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
	/* check arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
		(void) fprintf(stderr, gettext("missing pool argument\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   905
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
	ret = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
	for (i = 0; i < argc; i++) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   910
		if ((zhp = zpool_open_canfail(g_zfs, argv[i])) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
			ret = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   913
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2926
diff changeset
   915
		if (zpool_disable_datasets(zhp, force) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
			ret = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
			zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
7214
04c540040a32 6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents: 7184
diff changeset
   921
		if (zpool_export(zhp, force) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
			ret = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
 * Given a vdev configuration, determine the maximum width needed for the device
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
 * name column.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
static int
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
   935
max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   937
	char *name = zpool_vdev_name(g_zfs, zhp, nv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
	nvlist_t **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
	uint_t c, children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
	if (strlen(name) + depth > max)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
		max = strlen(name) + depth;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
   945
	free(name);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
   946
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   947
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   948
	    &child, &children) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   949
		for (c = 0; c < children; c++)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   950
			if ((ret = max_width(zhp, child[c], depth + 2,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   951
			    max)) > max)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   952
				max = ret;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   953
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   954
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   955
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   956
	    &child, &children) == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   957
		for (c = 0; c < children; c++)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   958
			if ((ret = max_width(zhp, child[c], depth + 2,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   959
			    max)) > max)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   960
				max = ret;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   961
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
   962
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   964
	    &child, &children) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   965
		for (c = 0; c < children; c++)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   966
			if ((ret = max_width(zhp, child[c], depth + 2,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   967
			    max)) > max)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   968
				max = ret;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   969
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   970
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
	return (max);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
 * Print the configuration of an exported pool.  Iterate over all vdevs in the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
 * pool, printing out the name and status for each one.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
void
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   981
print_import_config(const char *name, nvlist_t *nv, int namewidth, int depth,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   982
    boolean_t print_logs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
	nvlist_t **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
	uint_t c, children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
	vdev_stat_t *vs;
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
   987
	char *type, *vname;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
	verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
	if (strcmp(type, VDEV_TYPE_MISSING) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
	verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_STATS,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
	    (uint64_t **)&vs, &c) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	(void) printf("\t%*s%-*s", depth, "", namewidth - depth, name);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   997
	(void) printf("  %s", zpool_state_to_name(vs->vs_state, vs->vs_aux));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
	if (vs->vs_aux != 0) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1000
		(void) printf("  ");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
		switch (vs->vs_aux) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
		case VDEV_AUX_OPEN_FAILED:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
			(void) printf(gettext("cannot open"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1006
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
		case VDEV_AUX_BAD_GUID_SUM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
			(void) printf(gettext("missing device"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
		case VDEV_AUX_NO_REPLICAS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
			(void) printf(gettext("insufficient replicas"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1015
		case VDEV_AUX_VERSION_NEWER:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1016
			(void) printf(gettext("newer version"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1017
			break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1018
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1019
		case VDEV_AUX_ERR_EXCEEDED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1020
			(void) printf(gettext("too many errors"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1021
			break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1022
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
			(void) printf(gettext("corrupted data"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
	    &child, &children) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1034
	for (c = 0; c < children; c++) {
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1035
		uint64_t is_log = B_FALSE;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1036
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1037
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1038
		    &is_log);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1039
		if ((is_log && !print_logs) || (!is_log && print_logs))
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1040
			continue;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1041
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1042
		vname = zpool_vdev_name(g_zfs, NULL, child[c]);
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1043
		print_import_config(vname, child[c],
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1044
		    namewidth, depth + 2, B_FALSE);
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1045
		free(vname);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1046
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1047
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1048
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1049
	    &child, &children) == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1050
		(void) printf(gettext("\tcache\n"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1051
		for (c = 0; c < children; c++) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1052
			vname = zpool_vdev_name(g_zfs, NULL, child[c]);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1053
			(void) printf("\t  %s\n", vname);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1054
			free(vname);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1055
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1056
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1057
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1058
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1059
	    &child, &children) == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1060
		(void) printf(gettext("\tspares\n"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1061
		for (c = 0; c < children; c++) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1062
			vname = zpool_vdev_name(g_zfs, NULL, child[c]);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1063
			(void) printf("\t  %s\n", vname);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1064
			free(vname);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1065
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1066
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
 * Display the status for the given pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
show_import(nvlist_t *config)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
	uint64_t pool_state;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
	vdev_stat_t *vs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
	char *name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
	uint64_t guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
	char *msgid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
	int reason;
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1082
	const char *health;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
	uint_t vsc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
	int namewidth;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
	    &name) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	    &guid) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
	    &pool_state) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
	    &nvroot) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
	    (uint64_t **)&vs, &vsc) == 0);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1097
	health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
	reason = zpool_import_status(config, &msgid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1101
	(void) printf(gettext("  pool: %s\n"), name);
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1102
	(void) printf(gettext("    id: %llu\n"), (u_longlong_t)guid);
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1103
	(void) printf(gettext(" state: %s"), health);
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1104
	if (pool_state == POOL_STATE_DESTROYED)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1105
		(void) printf(gettext(" (DESTROYED)"));
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1106
	(void) printf("\n");
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
	switch (reason) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
	case ZPOOL_STATUS_MISSING_DEV_R:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
	case ZPOOL_STATUS_MISSING_DEV_NR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
	case ZPOOL_STATUS_BAD_GUID_SUM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
		(void) printf(gettext("status: One or more devices are missing "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
		    "from the system.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
	case ZPOOL_STATUS_CORRUPT_LABEL_R:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
	case ZPOOL_STATUS_CORRUPT_LABEL_NR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
		(void) printf(gettext("status: One or more devices contains "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
		    "corrupted data.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
	case ZPOOL_STATUS_CORRUPT_DATA:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
		(void) printf(gettext("status: The pool data is corrupted.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1125
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  1126
	case ZPOOL_STATUS_OFFLINE_DEV:
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  1127
		(void) printf(gettext("status: One or more devices "
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  1128
		    "are offlined.\n"));
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  1129
		break;
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  1130
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1131
	case ZPOOL_STATUS_CORRUPT_POOL:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1132
		(void) printf(gettext("status: The pool metadata is "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1133
		    "corrupted.\n"));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1134
		break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1135
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1136
	case ZPOOL_STATUS_VERSION_OLDER:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1137
		(void) printf(gettext("status: The pool is formatted using an "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1138
		    "older on-disk version.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1139
		break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1140
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1141
	case ZPOOL_STATUS_VERSION_NEWER:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1142
		(void) printf(gettext("status: The pool is formatted using an "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1143
		    "incompatible version.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1144
		break;
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1145
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1146
	case ZPOOL_STATUS_HOSTID_MISMATCH:
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1147
		(void) printf(gettext("status: The pool was last accessed by "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1148
		    "another system.\n"));
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1149
		break;
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1150
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1151
	case ZPOOL_STATUS_FAULTED_DEV_R:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1152
	case ZPOOL_STATUS_FAULTED_DEV_NR:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1153
		(void) printf(gettext("status: One or more devices are "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1154
		    "faulted.\n"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1155
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  1156
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1157
	case ZPOOL_STATUS_BAD_LOG:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1158
		(void) printf(gettext("status: An intent log record cannot be "
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1159
		    "read.\n"));
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1160
		break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1161
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
	default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
		 * No other status can be seen when importing pools.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
		assert(reason == ZPOOL_STATUS_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
	 * Print out an action according to the overall state of the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
	 */
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1172
	if (vs->vs_state == VDEV_STATE_HEALTHY) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1173
		if (reason == ZPOOL_STATUS_VERSION_OLDER)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1174
			(void) printf(gettext("action: The pool can be "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1175
			    "imported using its name or numeric identifier, "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1176
			    "though\n\tsome features will not be available "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1177
			    "without an explicit 'zpool upgrade'.\n"));
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1178
		else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH)
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1179
			(void) printf(gettext("action: The pool can be "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1180
			    "imported using its name or numeric "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1181
			    "identifier and\n\tthe '-f' flag.\n"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
		else
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1183
			(void) printf(gettext("action: The pool can be "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1184
			    "imported using its name or numeric "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1185
			    "identifier.\n"));
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1186
	} else if (vs->vs_state == VDEV_STATE_DEGRADED) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
		(void) printf(gettext("action: The pool can be imported "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
		    "despite missing or damaged devices.  The\n\tfault "
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1189
		    "tolerance of the pool may be compromised if imported.\n"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
	} else {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1191
		switch (reason) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1192
		case ZPOOL_STATUS_VERSION_NEWER:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1193
			(void) printf(gettext("action: The pool cannot be "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1194
			    "imported.  Access the pool on a system running "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1195
			    "newer\n\tsoftware, or recreate the pool from "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1196
			    "backup.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1197
			break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1198
		case ZPOOL_STATUS_MISSING_DEV_R:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1199
		case ZPOOL_STATUS_MISSING_DEV_NR:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1200
		case ZPOOL_STATUS_BAD_GUID_SUM:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
			(void) printf(gettext("action: The pool cannot be "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
			    "imported. Attach the missing\n\tdevices and try "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
			    "again.\n"));
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1204
			break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1205
		default:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
			(void) printf(gettext("action: The pool cannot be "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
			    "imported due to damaged devices or data.\n"));
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1208
		}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1209
	}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1210
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1211
	/*
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1212
	 * If the state is "closed" or "can't open", and the aux state
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1213
	 * is "corrupt data":
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1214
	 */
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1215
	if (((vs->vs_state == VDEV_STATE_CLOSED) ||
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1216
	    (vs->vs_state == VDEV_STATE_CANT_OPEN)) &&
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1217
	    (vs->vs_aux == VDEV_AUX_CORRUPT_DATA)) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1218
		if (pool_state == POOL_STATE_DESTROYED)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1219
			(void) printf(gettext("\tThe pool was destroyed, "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1220
			    "but can be imported using the '-Df' flags.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1221
		else if (pool_state != POOL_STATE_EXPORTED)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1222
			(void) printf(gettext("\tThe pool may be active on "
5853
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  1223
			    "another system, but can be imported using\n\t"
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1224
			    "the '-f' flag.\n"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
	if (msgid != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
		(void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
		    msgid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
	(void) printf(gettext("config:\n\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  1233
	namewidth = max_width(NULL, nvroot, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
	if (namewidth < 10)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
		namewidth = 10;
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1236
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1237
	print_import_config(name, nvroot, namewidth, 0, B_FALSE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1238
	if (num_logs(nvroot) > 0) {
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1239
		(void) printf(gettext("\tlogs\n"));
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1240
		print_import_config(name, nvroot, namewidth, 0, B_TRUE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1241
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1243
	if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1244
		(void) printf(gettext("\n\tAdditional devices are known to "
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1245
		    "be part of this pool, though their\n\texact "
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  1246
		    "configuration cannot be determined.\n"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1247
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
 * Perform the import for the given configuration.  This passes the heavy
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1252
 * lifting off to zpool_import_props(), and then mounts the datasets contained
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1253
 * within the pool.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1256
do_import(nvlist_t *config, const char *newname, const char *mntopts,
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1257
    int force, nvlist_t *props, boolean_t allowfaulted)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1258
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1259
	zpool_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
	char *name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1261
	uint64_t state;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1262
	uint64_t version;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1263
	int error = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1264
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1265
	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
	    &name) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
	verify(nvlist_lookup_uint64(config,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
	    ZPOOL_CONFIG_POOL_STATE, &state) == 0);
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1270
	verify(nvlist_lookup_uint64(config,
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1271
	    ZPOOL_CONFIG_VERSION, &version) == 0);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1272
	if (version > SPA_VERSION) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1273
		(void) fprintf(stderr, gettext("cannot import '%s': pool "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1274
		    "is formatted using a newer ZFS version\n"), name);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1275
		return (1);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  1276
	} else if (state != POOL_STATE_EXPORTED && !force) {
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1277
		uint64_t hostid;
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1278
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1279
		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1280
		    &hostid) == 0) {
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1281
			if ((unsigned long)hostid != gethostid()) {
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1282
				char *hostname;
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1283
				uint64_t timestamp;
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1284
				time_t t;
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1285
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1286
				verify(nvlist_lookup_string(config,
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1287
				    ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1288
				verify(nvlist_lookup_uint64(config,
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1289
				    ZPOOL_CONFIG_TIMESTAMP, &timestamp) == 0);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1290
				t = timestamp;
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1291
				(void) fprintf(stderr, gettext("cannot import "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1292
				    "'%s': pool may be in use from other "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1293
				    "system, it was last accessed by %s "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1294
				    "(hostid: 0x%lx) on %s"), name, hostname,
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1295
				    (unsigned long)hostid,
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1296
				    asctime(localtime(&t)));
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1297
				(void) fprintf(stderr, gettext("use '-f' to "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1298
				    "import anyway\n"));
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1299
				return (1);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1300
			}
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1301
		} else {
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1302
			(void) fprintf(stderr, gettext("cannot import '%s': "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1303
			    "pool may be in use from other system\n"), name);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1304
			(void) fprintf(stderr, gettext("use '-f' to import "
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1305
			    "anyway\n"));
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1306
			return (1);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
  1307
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1310
	if (zpool_import_props(g_zfs, config, newname, props,
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1311
	    allowfaulted) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
	if (newname != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
		name = (char *)newname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1317
	verify((zhp = zpool_open_canfail(g_zfs, name)) != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2926
diff changeset
  1319
	if (zpool_enable_datasets(zhp, mntopts, 0) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1321
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
	zpool_close(zhp);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1325
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1326
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
/*
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1329
 * zpool import [-d dir] [-D]
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1330
 *       import [-o mntopts] [-o prop=value] ... [-R root] [-D]
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1331
 *              [-d dir | -c cachefile] [-f] -a
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1332
 *       import [-o mntopts] [-o prop=value] ... [-R root] [-D]
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1333
 *              [-d dir | -c cachefile] [-f] <pool | id> [newpool]
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1334
 *
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1335
 *	 -c	Read pool information from a cachefile instead of searching
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1336
 *		devices.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
 *       -d	Scan in a specific directory, other than /dev/dsk.  More than
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
 *		one directory can be specified using multiple '-d' options.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1340
 *
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1341
 *       -D     Scan for previously destroyed pools or import all or only
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1342
 *              specified destroyed pools.
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1343
 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1344
 *       -R	Temporarily import the pool, with all mountpoints relative to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
 *		the given root.  The pool will remain exported when the machine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1346
 *		is rebooted.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1347
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1348
 *       -f	Force import, even if it appears that the pool is active.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
 *
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1350
 *       -F	Import even in the presence of faulted vdevs.  This is an
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1351
 *       	intentionally undocumented option for testing purposes, and
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1352
 *       	treats the pool configuration as complete, leaving any bad
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1353
 *		vdevs in the FAULTED state.
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1354
 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
 *       -a	Import all pools found.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1356
 *
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1357
 *       -o	Set property=value and/or temporary mount options (without '=').
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1358
 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
 * The import command scans for pools to import, and import pools based on pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
 * name and GUID.  The pool can also be renamed as part of the import process.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
zpool_do_import(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1365
	char **searchdirs = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1366
	int nsearch = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1368
	int err;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1369
	nvlist_t *pools = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1370
	boolean_t do_all = B_FALSE;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1371
	boolean_t do_destroyed = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
	char *mntopts = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1373
	boolean_t do_force = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1374
	nvpair_t *elem;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
	nvlist_t *config;
6807
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1376
	uint64_t searchguid = 0;
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1377
	char *searchname = NULL;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1378
	char *propval;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1379
	nvlist_t *found_config;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1380
	nvlist_t *props = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1381
	boolean_t first;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1382
	boolean_t allow_faulted = B_FALSE;
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1383
	uint64_t pool_state;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1384
	char *cachefile = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1385
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1386
	/* check options */
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1387
	while ((c = getopt(argc, argv, ":ac:d:DfFo:p:R:")) != -1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
		case 'a':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1390
			do_all = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
			break;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1392
		case 'c':
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1393
			cachefile = optarg;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1394
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1395
		case 'd':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1396
			if (searchdirs == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
				searchdirs = safe_malloc(sizeof (char *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
			} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
				char **tmp = safe_malloc((nsearch + 1) *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1400
				    sizeof (char *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1401
				bcopy(searchdirs, tmp, nsearch *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
				    sizeof (char *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
				free(searchdirs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
				searchdirs = tmp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
			searchdirs[nsearch++] = optarg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
			break;
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1408
		case 'D':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1409
			do_destroyed = B_TRUE;
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1410
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
		case 'f':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1412
			do_force = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
			break;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1414
		case 'F':
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1415
			allow_faulted = B_TRUE;
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1416
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
		case 'o':
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1418
			if ((propval = strchr(optarg, '=')) != NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1419
				*propval = '\0';
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1420
				propval++;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1421
				if (add_prop_list(optarg, propval,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1422
				    &props, B_TRUE))
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1423
					goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1424
			} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1425
				mntopts = optarg;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1426
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
		case 'R':
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1429
			if (add_prop_list(zpool_prop_to_name(
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1430
			    ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1431
				goto error;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1432
			if (nvlist_lookup_string(props,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1433
			    zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1434
			    &propval) == 0)
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1435
				break;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1436
			if (add_prop_list(zpool_prop_to_name(
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1437
			    ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1438
				goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1439
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
		case ':':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1441
			(void) fprintf(stderr, gettext("missing argument for "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
			    "'%c' option\n"), optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1443
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1445
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1447
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1448
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1449
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1450
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1455
	if (cachefile && nsearch != 0) {
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1456
		(void) fprintf(stderr, gettext("-c is incompatible with -d\n"));
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1457
		usage(B_FALSE);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1458
	}
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1459
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1460
	if (searchdirs == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1461
		searchdirs = safe_malloc(sizeof (char *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1462
		searchdirs[0] = "/dev/dsk";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1463
		nsearch = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
	/* check argument count */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1467
	if (do_all) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1468
		if (argc != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
			(void) fprintf(stderr, gettext("too many arguments\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1470
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1471
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1473
		if (argc > 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1474
			(void) fprintf(stderr, gettext("too many arguments\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1475
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1476
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1477
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
		 * Check for the SYS_CONFIG privilege.  We do this explicitly
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1480
		 * here because otherwise any attempt to discover pools will
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1481
		 * silently fail.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1482
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
		if (argc == 0 && !priv_ineffect(PRIV_SYS_CONFIG)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
			(void) fprintf(stderr, gettext("cannot "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
			    "discover pools: permission denied\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1486
			free(searchdirs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
			return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
	 * Depending on the arguments given, we do one of the following:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
	 *	<none>	Iterate through all pools and display information about
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
	 *		each one.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
	 *	-a	Iterate through all pools and try to import each one.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
	 *	<id>	Find the pool that corresponds to the given GUID/pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
	 *		name and import that one.
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1501
	 *
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1502
	 *	-D	Above options applies only to destroyed pools.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
	if (argc != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
		char *endptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
		errno = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
		searchguid = strtoull(argv[0], &endptr, 10);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
		if (errno != 0 || *endptr != '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
			searchname = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1511
		found_config = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1512
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
6807
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1514
	if (cachefile) {
6957
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6865
diff changeset
  1515
		pools = zpool_find_import_cached(g_zfs, cachefile, searchname,
ad855bd47277 6689844 ztest fails with "zdb: can't open ztest: No such device or address"
ck153898
parents: 6865
diff changeset
  1516
		    searchguid);
6807
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1517
	} else if (searchname != NULL) {
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1518
		pools = zpool_find_import_byname(g_zfs, nsearch, searchdirs,
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1519
		    searchname);
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1520
	} else {
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1521
		/*
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1522
		 * It's OK to search by guid even if searchguid is 0.
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1523
		 */
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1524
		pools = zpool_find_import_byguid(g_zfs, nsearch, searchdirs,
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1525
		    searchguid);
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1526
	}
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1527
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1528
	if (pools == NULL) {
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1529
		if (argc != 0) {
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1530
			(void) fprintf(stderr, gettext("cannot import '%s': "
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1531
			    "no such pool available\n"), argv[0]);
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1532
		}
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1533
		free(searchdirs);
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1534
		return (1);
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1535
	}
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1536
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1537
	/*
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1538
	 * At this point we have a list of import candidate configs. Even if
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1539
	 * we were searching by pool name or guid, we still need to
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1540
	 * post-process the list to deal with pool state and possible
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1541
	 * duplicate names.
1564ba2e93f5 6689452 zfs often fails to import a zpool if several zfs import commands are running at the same time.
ck153898
parents: 6643
diff changeset
  1542
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
	err = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1544
	elem = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1545
	first = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1546
	while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
		verify(nvpair_value_nvlist(elem, &config) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
1631
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1550
		verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1551
		    &pool_state) == 0);
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1552
		if (!do_destroyed && pool_state == POOL_STATE_DESTROYED)
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1553
			continue;
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1554
		if (do_destroyed && pool_state != POOL_STATE_DESTROYED)
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1555
			continue;
39011550a5d7 PSARC/2006/082 zpool import destroyed pools
darrenm
parents: 1613
diff changeset
  1556
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1557
		if (argc == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1558
			if (first)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1559
				first = B_FALSE;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
  1560
			else if (!do_all)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1561
				(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1562
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
			if (do_all)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
				err |= do_import(config, NULL, mntopts,
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1565
				    do_force, props, allow_faulted);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
				show_import(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
		} else if (searchname != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
			char *name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
			 * We are searching for a pool based on name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
			verify(nvlist_lookup_string(config,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
			    ZPOOL_CONFIG_POOL_NAME, &name) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1576
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
			if (strcmp(name, searchname) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
				if (found_config != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
					(void) fprintf(stderr, gettext(
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
					    "cannot import '%s': more than "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
					    "one matching pool\n"), searchname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
					(void) fprintf(stderr, gettext(
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
					    "import by numeric ID instead\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1584
					err = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
				}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
				found_config = config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
			uint64_t guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
			 * Search for a pool by guid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1594
			verify(nvlist_lookup_uint64(config,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
			    ZPOOL_CONFIG_POOL_GUID, &guid) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
			if (guid == searchguid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
				found_config = config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1603
	 * If we were searching for a specific pool, verify that we found a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1604
	 * pool, and then do the import.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1605
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1606
	if (argc != 0 && err == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
		if (found_config == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1608
			(void) fprintf(stderr, gettext("cannot import '%s': "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1609
			    "no such pool available\n"), argv[0]);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1610
			err = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
			err |= do_import(found_config, argc == 1 ? NULL :
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6523
diff changeset
  1613
			    argv[1], mntopts, do_force, props, allow_faulted);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
	 * If we were just looking for pools, report an error if none were
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
	 * found.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
	if (argc == 0 && first)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
		(void) fprintf(stderr,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
		    gettext("no pools available to import\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1625
error:
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5331
diff changeset
  1626
	nvlist_free(props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
	nvlist_free(pools);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1628
	free(searchdirs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
	return (err ? 1 : 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
typedef struct iostat_cbdata {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1634
	zpool_list_t *cb_list;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1635
	int cb_verbose;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1636
	int cb_iteration;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
	int cb_namewidth;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
} iostat_cbdata_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
print_iostat_separator(iostat_cbdata_t *cb)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
	int i = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	for (i = 0; i < cb->cb_namewidth; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
		(void) printf("-");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	(void) printf("  -----  -----  -----  -----  -----  -----\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1649
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1651
print_iostat_header(iostat_cbdata_t *cb)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1653
	(void) printf("%*s     capacity     operations    bandwidth\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
	    cb->cb_namewidth, "");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1655
	(void) printf("%-*s   used  avail   read  write   read  write\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1656
	    cb->cb_namewidth, "pool");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1657
	print_iostat_separator(cb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1658
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1660
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1661
 * Display a single statistic.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1662
 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1663
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1664
print_one_stat(uint64_t value)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1665
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1666
	char buf[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1668
	zfs_nicenum(value, buf, sizeof (buf));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1669
	(void) printf("  %5s", buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1670
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1671
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1672
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1673
 * Print out all the statistics for the given vdev.  This can either be the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1674
 * toplevel configuration, or called recursively.  If 'name' is NULL, then this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1675
 * is a verbose output, and we don't want to display the toplevel pool stats.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1676
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
void
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  1678
print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  1679
    nvlist_t *newnv, iostat_cbdata_t *cb, int depth)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1680
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1681
	nvlist_t **oldchild, **newchild;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1682
	uint_t c, children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1683
	vdev_stat_t *oldvs, *newvs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1684
	vdev_stat_t zerovs = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1685
	uint64_t tdelta;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1686
	double scale;
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1687
	char *vname;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1689
	if (oldnv != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
		verify(nvlist_lookup_uint64_array(oldnv, ZPOOL_CONFIG_STATS,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
		    (uint64_t **)&oldvs, &c) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
		oldvs = &zerovs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1696
	verify(nvlist_lookup_uint64_array(newnv, ZPOOL_CONFIG_STATS,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1697
	    (uint64_t **)&newvs, &c) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1698
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1699
	if (strlen(name) + depth > cb->cb_namewidth)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1700
		(void) printf("%*s%s", depth, "", name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1701
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1702
		(void) printf("%*s%s%*s", depth, "", name,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1703
		    (int)(cb->cb_namewidth - strlen(name) - depth), "");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1705
	tdelta = newvs->vs_timestamp - oldvs->vs_timestamp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1706
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
	if (tdelta == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
		scale = 1.0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
		scale = (double)NANOSEC / tdelta;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1711
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1712
	/* only toplevel vdevs have capacity stats */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1713
	if (newvs->vs_space == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1714
		(void) printf("      -      -");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1715
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
		print_one_stat(newvs->vs_alloc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1717
		print_one_stat(newvs->vs_space - newvs->vs_alloc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1718
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
	print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_READ] -
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
	    oldvs->vs_ops[ZIO_TYPE_READ])));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
	print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_WRITE] -
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
	    oldvs->vs_ops[ZIO_TYPE_WRITE])));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
	print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_READ] -
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
	    oldvs->vs_bytes[ZIO_TYPE_READ])));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1728
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
	print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_WRITE] -
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1730
	    oldvs->vs_bytes[ZIO_TYPE_WRITE])));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1731
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1732
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1734
	if (!cb->cb_verbose)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
	if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1738
	    &newchild, &children) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1739
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1740
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
	if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
	    &oldchild, &c) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1744
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1745
	for (c = 0; c < children; c++) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1746
		vname = zpool_vdev_name(g_zfs, zhp, newchild[c]);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  1747
		print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1748
		    newchild[c], cb, depth + 2);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1749
		free(vname);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  1750
	}
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1751
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1752
	/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1753
	 * Include level 2 ARC devices in iostat output
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1754
	 */
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1755
	if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1756
	    &newchild, &children) != 0)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1757
		return;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1758
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1759
	if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1760
	    &oldchild, &c) != 0)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1761
		return;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1762
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1763
	if (children > 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1764
		(void) printf("%-*s      -      -      -      -      -      "
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1765
		    "-\n", cb->cb_namewidth, "cache");
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1766
		for (c = 0; c < children; c++) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1767
			vname = zpool_vdev_name(g_zfs, zhp, newchild[c]);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1768
			print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1769
			    newchild[c], cb, depth + 2);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1770
			free(vname);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1771
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  1772
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1773
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1774
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1775
static int
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1776
refresh_iostat(zpool_handle_t *zhp, void *data)
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1777
{
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1778
	iostat_cbdata_t *cb = data;
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1779
	boolean_t missing;
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1780
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1781
	/*
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1782
	 * If the pool has disappeared, remove it from the list and continue.
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1783
	 */
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1784
	if (zpool_refresh_stats(zhp, &missing) != 0)
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1785
		return (-1);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1786
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1787
	if (missing)
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1788
		pool_list_remove(cb->cb_list, zhp);
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1789
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1790
	return (0);
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1791
}
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1792
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1793
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1794
 * Callback to print out the iostats for the given pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1797
print_iostat(zpool_handle_t *zhp, void *data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1798
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1799
	iostat_cbdata_t *cb = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
	nvlist_t *oldconfig, *newconfig;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1801
	nvlist_t *oldnvroot, *newnvroot;
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1802
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1803
	newconfig = zpool_get_config(zhp, &oldconfig);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1804
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1805
	if (cb->cb_iteration == 1)
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1806
		oldconfig = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1807
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1808
	verify(nvlist_lookup_nvlist(newconfig, ZPOOL_CONFIG_VDEV_TREE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1809
	    &newnvroot) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1810
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1811
	if (oldconfig == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1812
		oldnvroot = NULL;
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1813
	else
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1814
		verify(nvlist_lookup_nvlist(oldconfig, ZPOOL_CONFIG_VDEV_TREE,
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1815
		    &oldnvroot) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1817
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1818
	 * Print out the statistics for the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1819
	 */
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  1820
	print_vdev_stats(zhp, zpool_get_name(zhp), oldnvroot, newnvroot, cb, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	if (cb->cb_verbose)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
		print_iostat_separator(cb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
get_namewidth(zpool_handle_t *zhp, void *data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1830
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1831
	iostat_cbdata_t *cb = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
	nvlist_t *config, *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1833
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1834
	if ((config = zpool_get_config(zhp, NULL)) != NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1835
		verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1836
		    &nvroot) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1837
		if (!cb->cb_verbose)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1838
			cb->cb_namewidth = strlen(zpool_get_name(zhp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1839
		else
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  1840
			cb->cb_namewidth = max_width(zhp, nvroot, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1843
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1844
	 * The width must fall into the range [10,38].  The upper limit is the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1845
	 * maximum we can have and still fit in 80 columns.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1846
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1847
	if (cb->cb_namewidth < 10)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1848
		cb->cb_namewidth = 10;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1849
	if (cb->cb_namewidth > 38)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
		cb->cb_namewidth = 38;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1851
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1852
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1853
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1854
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1855
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
 * zpool iostat [-v] [pool] ... [interval [count]]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1857
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
 *	-v	Display statistics for individual vdevs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1859
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1860
 * This command can be tricky because we want to be able to deal with pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
 * creation/destruction as well as vdev configuration changes.  The bulk of this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
 * processing is handled by the pool_list_* routines in zpool_iter.c.  We rely
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
 * on pool_list_update() to detect the addition of new pools.  Configuration
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1864
 * changes are all handled within libzfs.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1865
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1867
zpool_do_iostat(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1869
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1870
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1871
	int npools;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1872
	unsigned long interval = 0, count = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1873
	zpool_list_t *list;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1874
	boolean_t verbose = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1875
	iostat_cbdata_t cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1876
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1877
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1878
	while ((c = getopt(argc, argv, "v")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1879
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1880
		case 'v':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1881
			verbose = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1882
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1883
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1884
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1885
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1886
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1887
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1889
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1890
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1891
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1892
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1893
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1894
	 * Determine if the last argument is an integer or a pool name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1895
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1896
	if (argc > 0 && isdigit(argv[argc - 1][0])) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1897
		char *end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1898
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1899
		errno = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1900
		interval = strtoul(argv[argc - 1], &end, 10);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1901
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1902
		if (*end == '\0' && errno == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1903
			if (interval == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1904
				(void) fprintf(stderr, gettext("interval "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1905
				    "cannot be zero\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1906
				usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1907
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1908
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1909
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1910
			 * Ignore the last parameter
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1911
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1912
			argc--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1913
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1914
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1915
			 * If this is not a valid number, just plow on.  The
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1916
			 * user will get a more informative error message later
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1917
			 * on.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1918
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1919
			interval = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1920
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1921
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1922
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1923
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1924
	 * If the last argument is also an integer, then we have both a count
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1925
	 * and an integer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1926
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1927
	if (argc > 0 && isdigit(argv[argc - 1][0])) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1928
		char *end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1929
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1930
		errno = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1931
		count = interval;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1932
		interval = strtoul(argv[argc - 1], &end, 10);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1933
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1934
		if (*end == '\0' && errno == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1935
			if (interval == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1936
				(void) fprintf(stderr, gettext("interval "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1937
				    "cannot be zero\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1938
				usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1939
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1940
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1941
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1942
			 * Ignore the last parameter
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1943
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1944
			argc--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1945
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1946
			interval = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1947
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1948
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1949
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1950
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1951
	 * Construct the list of all interesting pools.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1952
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1953
	ret = 0;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1954
	if ((list = pool_list_get(argc, argv, NULL, &ret)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1955
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1956
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1957
	if (pool_list_count(list) == 0 && argc != 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1958
		pool_list_free(list);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1959
		return (1);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1960
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1961
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1962
	if (pool_list_count(list) == 0 && interval == 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1963
		pool_list_free(list);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1964
		(void) fprintf(stderr, gettext("no pools available\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1965
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1966
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1967
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1968
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1969
	 * Enter the main iostat loop.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1970
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1971
	cb.cb_list = list;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1972
	cb.cb_verbose = verbose;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1973
	cb.cb_iteration = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1974
	cb.cb_namewidth = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1975
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1976
	for (;;) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1977
		pool_list_update(list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1978
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1979
		if ((npools = pool_list_count(list)) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1980
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1981
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1982
		/*
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1983
		 * Refresh all statistics.  This is done as an explicit step
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1984
		 * before calculating the maximum name width, so that any
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1985
		 * configuration changes are properly accounted for.
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1986
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1987
		(void) pool_list_iter(list, B_FALSE, refresh_iostat, &cb);
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1988
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  1989
		/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1990
		 * Iterate over all pools to determine the maximum width
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1991
		 * for the pool / device name column across all pools.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1992
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
		cb.cb_namewidth = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1994
		(void) pool_list_iter(list, B_FALSE, get_namewidth, &cb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1995
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1996
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1997
		 * If it's the first time, or verbose mode, print the header.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1998
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1999
		if (++cb.cb_iteration == 1 || verbose)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2000
			print_iostat_header(&cb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2001
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2002
		(void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2003
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2004
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2005
		 * If there's more than one pool, and we're not in verbose mode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2006
		 * (which prints a separator for us), then print a separator.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2007
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2008
		if (npools > 1 && !verbose)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2009
			print_iostat_separator(&cb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2011
		if (verbose)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2012
			(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3126
diff changeset
  2014
		/*
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3126
diff changeset
  2015
		 * Flush the output so that redirection to a file isn't buffered
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3126
diff changeset
  2016
		 * indefinitely.
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3126
diff changeset
  2017
		 */
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3126
diff changeset
  2018
		(void) fflush(stdout);
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3126
diff changeset
  2019
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2020
		if (interval == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2021
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2023
		if (count != 0 && --count == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2025
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
		(void) sleep(interval);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2028
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2029
	pool_list_free(list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2030
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2031
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2033
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2034
typedef struct list_cbdata {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2035
	boolean_t	cb_scripted;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2036
	boolean_t	cb_first;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2037
	zprop_list_t	*cb_proplist;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2038
} list_cbdata_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2039
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2040
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2041
 * Given a list of columns to display, output appropriate headers for each one.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2042
 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2043
static void
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2044
print_header(zprop_list_t *pl)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2045
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2046
	const char *header;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2047
	boolean_t first = B_TRUE;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2048
	boolean_t right_justify;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2049
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2050
	for (; pl != NULL; pl = pl->pl_next) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2051
		if (pl->pl_prop == ZPROP_INVAL)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2052
			continue;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2053
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2054
		if (!first)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2055
			(void) printf("  ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2056
		else
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2057
			first = B_FALSE;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2058
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2059
		header = zpool_prop_column_name(pl->pl_prop);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2060
		right_justify = zpool_prop_align_right(pl->pl_prop);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2061
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2062
		if (pl->pl_next == NULL && !right_justify)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2063
			(void) printf("%s", header);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2064
		else if (right_justify)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2065
			(void) printf("%*s", pl->pl_width, header);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2066
		else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2067
			(void) printf("%-*s", pl->pl_width, header);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2068
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2069
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2070
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2071
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2072
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2073
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2074
 * Given a pool and a list of properties, print out all the properties according
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2075
 * to the described layout.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2076
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2077
static void
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2078
print_pool(zpool_handle_t *zhp, zprop_list_t *pl, int scripted)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2079
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2080
	boolean_t first = B_TRUE;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2081
	char property[ZPOOL_MAXPROPLEN];
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2082
	char *propstr;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2083
	boolean_t right_justify;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2084
	int width;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2085
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2086
	for (; pl != NULL; pl = pl->pl_next) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2087
		if (!first) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2088
			if (scripted)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2089
				(void) printf("\t");
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2090
			else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2091
				(void) printf("  ");
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2092
		} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2093
			first = B_FALSE;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2094
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2095
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2096
		right_justify = B_FALSE;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2097
		if (pl->pl_prop != ZPROP_INVAL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2098
			if (zpool_get_prop(zhp, pl->pl_prop, property,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2099
			    sizeof (property), NULL) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2100
				propstr = "-";
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2101
			else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2102
				propstr = property;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2103
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2104
			right_justify = zpool_prop_align_right(pl->pl_prop);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2105
		} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2106
			propstr = "-";
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2107
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2108
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2109
		width = pl->pl_width;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2110
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2111
		/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2112
		 * If this is being called in scripted mode, or if this is the
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2113
		 * last column and it is left-justified, don't include a width
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2114
		 * format specifier.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2115
		 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2116
		if (scripted || (pl->pl_next == NULL && !right_justify))
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2117
			(void) printf("%s", propstr);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2118
		else if (right_justify)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2119
			(void) printf("%*s", width, propstr);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2120
		else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2121
			(void) printf("%-*s", width, propstr);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2122
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2123
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2124
	(void) printf("\n");
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2125
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2126
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2127
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2128
 * Generic callback function to list a pool.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2129
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2130
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2131
list_callback(zpool_handle_t *zhp, void *data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2132
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2133
	list_cbdata_t *cbp = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2134
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2135
	if (cbp->cb_first) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2136
		if (!cbp->cb_scripted)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2137
			print_header(cbp->cb_proplist);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2138
		cbp->cb_first = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2139
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2141
	print_pool(zhp, cbp->cb_proplist, cbp->cb_scripted);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2146
/*
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2147
 * zpool list [-H] [-o prop[,prop]*] [pool] ...
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2148
 *
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2149
 *	-H	Scripted mode.  Don't display headers, and separate properties
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2150
 *		by a single tab.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2151
 *	-o	List of properties to display.  Defaults to
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2152
 *		"name,size,used,available,capacity,health,altroot"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2153
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2154
 * List all pools in the system, whether or not they're healthy.  Output space
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2155
 * statistics for each one, as well as health status summary.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2156
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2157
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2158
zpool_do_list(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2159
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2160
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2161
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2162
	list_cbdata_t cb = { 0 };
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2163
	static char default_props[] =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2164
	    "name,size,used,available,capacity,health,altroot";
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2165
	char *props = default_props;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2166
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2167
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2168
	while ((c = getopt(argc, argv, ":Ho:")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2169
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2170
		case 'H':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2171
			cb.cb_scripted = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2172
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2173
		case 'o':
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2174
			props = optarg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2175
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2176
		case ':':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
			(void) fprintf(stderr, gettext("missing argument for "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2178
			    "'%c' option\n"), optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2179
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2182
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2184
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2185
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2186
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2187
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2188
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2189
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2191
	if (zprop_get_list(g_zfs, props, &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2192
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2193
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2194
	cb.cb_first = B_TRUE;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2195
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2196
	ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2197
	    list_callback, &cb);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2198
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2199
	zprop_free_list(cb.cb_proplist);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2200
4221
50b4bab9766b 6540584 zfs list command should not produce "no datasets available" message in script mode
mmusante
parents: 3975
diff changeset
  2201
	if (argc == 0 && cb.cb_first && !cb.cb_scripted) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2202
		(void) printf(gettext("no pools available\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2203
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2204
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2205
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2206
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2207
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2209
static nvlist_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2210
zpool_get_vdev_by_name(nvlist_t *nv, char *name)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2212
	nvlist_t **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2213
	uint_t c, children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
	nvlist_t *match;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
	char *path;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2218
	    &child, &children) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2219
		verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2220
		if (strncmp(name, "/dev/dsk/", 9) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2221
			name += 9;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2222
		if (strncmp(path, "/dev/dsk/", 9) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2223
			path += 9;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2224
		if (strcmp(name, path) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2225
			return (nv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2226
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2227
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2229
	for (c = 0; c < children; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2230
		if ((match = zpool_get_vdev_by_name(child[c], name)) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2231
			return (match);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2232
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2233
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2234
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2237
zpool_do_attach_or_replace(int argc, char **argv, int replacing)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2239
	boolean_t force = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2240
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2241
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2242
	char *poolname, *old_disk, *new_disk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2243
	zpool_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2244
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2245
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
	while ((c = getopt(argc, argv, "f")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
		case 'f':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2250
			force = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2251
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2252
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2253
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2254
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2255
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2256
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2257
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2258
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2259
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2260
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2261
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2262
	/* get pool name and check number of arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2263
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
		(void) fprintf(stderr, gettext("missing pool name argument\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2265
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2266
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
	poolname = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2270
	if (argc < 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2271
		(void) fprintf(stderr,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2272
		    gettext("missing <device> specification\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2273
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2274
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2275
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2276
	old_disk = argv[1];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2277
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2278
	if (argc < 3) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2279
		if (!replacing) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2280
			(void) fprintf(stderr,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2281
			    gettext("missing <new_device> specification\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2282
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2283
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2284
		new_disk = old_disk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2285
		argc -= 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2286
		argv += 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2287
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2288
		new_disk = argv[2];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2289
		argc -= 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2290
		argv += 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2291
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2292
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2293
	if (argc > 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2294
		(void) fprintf(stderr, gettext("too many arguments\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2295
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2296
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2297
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2298
	if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2299
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2300
4276
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 4221
diff changeset
  2301
	if (zpool_get_config(zhp, NULL) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2302
		(void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2303
		    poolname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2304
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2305
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2306
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2307
4276
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 4221
diff changeset
  2308
	nvroot = make_root_vdev(zhp, force, B_FALSE, replacing, argc, argv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2309
	if (nvroot == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2310
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2311
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2312
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2313
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2314
	ret = zpool_vdev_attach(zhp, old_disk, new_disk, nvroot, replacing);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2315
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2316
	nvlist_free(nvroot);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2317
	zpool_close(zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2318
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2319
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2320
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2321
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2322
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2323
 * zpool replace [-f] <pool> <device> <new_device>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2324
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2325
 *	-f	Force attach, even if <new_device> appears to be in use.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2326
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2327
 * Replace <device> with <new_device>.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2330
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2331
zpool_do_replace(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2332
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2333
	return (zpool_do_attach_or_replace(argc, argv, B_TRUE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2334
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2335
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2336
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2337
 * zpool attach [-f] <pool> <device> <new_device>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2338
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2339
 *	-f	Force attach, even if <new_device> appears to be in use.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2340
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2341
 * Attach <new_device> to the mirror containing <device>.  If <device> is not
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2342
 * part of a mirror, then <device> will be transformed into a mirror of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2343
 * <device> and <new_device>.  In either case, <new_device> will begin life
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2344
 * with a DTL of [0, now], and will immediately begin to resilver itself.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2345
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2346
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2347
zpool_do_attach(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2348
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2349
	return (zpool_do_attach_or_replace(argc, argv, B_FALSE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2350
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2351
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2352
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2353
 * zpool detach [-f] <pool> <device>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2354
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2355
 *	-f	Force detach of <device>, even if DTLs argue against it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2356
 *		(not supported yet)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2357
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2358
 * Detach a device from a mirror.  The operation will be refused if <device>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2359
 * is the last device in the mirror, or if the DTLs indicate that this device
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2360
 * has the only valid copy of some data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2363
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2364
zpool_do_detach(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2365
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2366
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2367
	char *poolname, *path;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2368
	zpool_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2369
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2370
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2371
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
	while ((c = getopt(argc, argv, "f")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2374
		case 'f':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2375
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2376
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2377
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2378
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2379
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2380
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2381
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2382
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2383
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2384
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2385
	/* get pool name and check number of arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2386
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2387
		(void) fprintf(stderr, gettext("missing pool name argument\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2388
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2389
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2390
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2391
	if (argc < 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2392
		(void) fprintf(stderr,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2393
		    gettext("missing <device> specification\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2394
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2395
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2396
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2397
	poolname = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2398
	path = argv[1];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2399
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2400
	if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2401
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2402
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2403
	ret = zpool_vdev_detach(zhp, path);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2404
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2405
	zpool_close(zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2406
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2407
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2408
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2409
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2410
/*
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  2411
 * zpool online <pool> <device> ...
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2412
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2413
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2414
zpool_do_online(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2415
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2416
	int c, i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2417
	char *poolname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2418
	zpool_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2419
	int ret = 0;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2420
	vdev_state_t newstate;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2422
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2423
	while ((c = getopt(argc, argv, "t")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2424
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2425
		case 't':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2426
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2427
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2428
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2429
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2430
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2431
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2432
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2433
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2434
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2436
	/* get pool name and check number of arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2437
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2438
		(void) fprintf(stderr, gettext("missing pool name\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2439
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2440
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2441
	if (argc < 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2442
		(void) fprintf(stderr, gettext("missing device name\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2443
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2444
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2445
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2446
	poolname = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2447
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2448
	if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2449
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2450
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2451
	for (i = 1; i < argc; i++) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2452
		if (zpool_vdev_online(zhp, argv[i], 0, &newstate) == 0) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2453
			if (newstate != VDEV_STATE_HEALTHY) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2454
				(void) printf(gettext("warning: device '%s' "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2455
				    "onlined, but remains in faulted state\n"),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2456
				    argv[i]);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2457
				if (newstate == VDEV_STATE_FAULTED)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2458
					(void) printf(gettext("use 'zpool "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2459
					    "clear' to restore a faulted "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2460
					    "device\n"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2461
				else
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2462
					(void) printf(gettext("use 'zpool "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2463
					    "replace' to replace devices "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2464
					    "that are no longer present\n"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2465
			}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2466
		} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2467
			ret = 1;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2468
		}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2469
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2470
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2471
	zpool_close(zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2472
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2473
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2474
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2475
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2476
/*
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  2477
 * zpool offline [-ft] <pool> <device> ...
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2478
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2479
 *	-f	Force the device into the offline state, even if doing
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2480
 *		so would appear to compromise pool availability.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2481
 *		(not supported yet)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2482
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2483
 *	-t	Only take the device off-line temporarily.  The offline
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2484
 *		state will not be persistent across reboots.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2485
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2486
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2487
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2488
zpool_do_offline(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2489
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2490
	int c, i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2491
	char *poolname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2492
	zpool_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2493
	int ret = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2494
	boolean_t istmp = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2495
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2496
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2497
	while ((c = getopt(argc, argv, "ft")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2498
		switch (c) {
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  2499
		case 't':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2500
			istmp = B_TRUE;
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1387
diff changeset
  2501
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2502
		case 'f':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2503
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2504
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2505
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2506
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2507
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2508
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2509
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2510
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2511
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2512
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2513
	/* get pool name and check number of arguments */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2514
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2515
		(void) fprintf(stderr, gettext("missing pool name\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2516
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2517
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2518
	if (argc < 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2519
		(void) fprintf(stderr, gettext("missing device name\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2520
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2521
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2522
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2523
	poolname = argv[0];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2524
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2525
	if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2526
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2527
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2528
	for (i = 1; i < argc; i++) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2529
		if (zpool_vdev_offline(zhp, argv[i], istmp) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2530
			ret = 1;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2531
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2532
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2533
	zpool_close(zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2534
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2535
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2536
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2538
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2539
 * zpool clear <pool> [device]
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2540
 *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2541
 * Clear all errors associated with a pool or a particular device.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2542
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2543
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2544
zpool_do_clear(int argc, char **argv)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2545
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2546
	int ret = 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2547
	zpool_handle_t *zhp;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2548
	char *pool, *device;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2549
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2550
	if (argc < 2) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2551
		(void) fprintf(stderr, gettext("missing pool name\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2552
		usage(B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2553
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2554
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2555
	if (argc > 3) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2556
		(void) fprintf(stderr, gettext("too many arguments\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2557
		usage(B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2558
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2559
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2560
	pool = argv[1];
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2561
	device = argc == 3 ? argv[2] : NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2562
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2563
	if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2564
		return (1);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2565
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2566
	if (zpool_clear(zhp, device) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2567
		ret = 1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2568
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2569
	zpool_close(zhp);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2570
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2571
	return (ret);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2572
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2573
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2574
typedef struct scrub_cbdata {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2575
	int	cb_type;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2576
	int	cb_argc;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2577
	char	**cb_argv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2578
} scrub_cbdata_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2580
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2581
scrub_callback(zpool_handle_t *zhp, void *data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2582
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2583
	scrub_cbdata_t *cb = data;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2584
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2585
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2586
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2587
	 * Ignore faulted pools.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2588
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2589
	if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2590
		(void) fprintf(stderr, gettext("cannot scrub '%s': pool is "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2591
		    "currently unavailable\n"), zpool_get_name(zhp));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2592
		return (1);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2593
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2594
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2595
	err = zpool_scrub(zhp, cb->cb_type);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2596
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2597
	return (err != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2598
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2599
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2600
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2601
 * zpool scrub [-s] <pool> ...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2602
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2603
 *	-s	Stop.  Stops any in-progress scrub.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2604
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2605
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2606
zpool_do_scrub(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2607
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2608
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2609
	scrub_cbdata_t cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2611
	cb.cb_type = POOL_SCRUB_EVERYTHING;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2612
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2613
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2614
	while ((c = getopt(argc, argv, "s")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2615
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2616
		case 's':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2617
			cb.cb_type = POOL_SCRUB_NONE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2618
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2619
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2620
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2621
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2622
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2623
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2624
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2625
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2626
	cb.cb_argc = argc;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  2627
	cb.cb_argv = argv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2628
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2629
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2630
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2631
	if (argc < 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2632
		(void) fprintf(stderr, gettext("missing pool name argument\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2633
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2634
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2635
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2636
	return (for_each_pool(argc, argv, B_TRUE, NULL, scrub_callback, &cb));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2637
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2638
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2639
typedef struct status_cbdata {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2640
	int		cb_count;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  2641
	boolean_t	cb_allpools;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2642
	boolean_t	cb_verbose;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2643
	boolean_t	cb_explain;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2644
	boolean_t	cb_first;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2645
} status_cbdata_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2646
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2647
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2648
 * Print out detailed scrub status.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2649
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2650
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2651
print_scrub_status(nvlist_t *nvroot)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2652
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2653
	vdev_stat_t *vs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2654
	uint_t vsc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2655
	time_t start, end, now;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2656
	double fraction_done;
5853
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2657
	uint64_t examined, total, minutes_left, minutes_taken;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2658
	char *scrub_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2659
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2660
	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2661
	    (uint64_t **)&vs, &vsc) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2662
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2663
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2664
	 * If there's never been a scrub, there's not much to say.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2665
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2666
	if (vs->vs_scrub_end == 0 && vs->vs_scrub_type == POOL_SCRUB_NONE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2667
		(void) printf(gettext("none requested\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2668
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2669
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2670
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2671
	scrub_type = (vs->vs_scrub_type == POOL_SCRUB_RESILVER) ?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2672
	    "resilver" : "scrub";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2673
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2674
	start = vs->vs_scrub_start;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2675
	end = vs->vs_scrub_end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2676
	now = time(NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2677
	examined = vs->vs_scrub_examined;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2678
	total = vs->vs_alloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2679
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2680
	if (end != 0) {
5853
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2681
		minutes_taken = (uint64_t)((end - start) / 60);
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2682
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2683
		(void) printf(gettext("%s %s after %lluh%um with %llu errors "
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2684
		    "on %s"),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2685
		    scrub_type, vs->vs_scrub_complete ? "completed" : "stopped",
5853
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2686
		    (u_longlong_t)(minutes_taken / 60),
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2687
		    (uint_t)(minutes_taken % 60),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2688
		    (u_longlong_t)vs->vs_scrub_errors, ctime(&end));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2689
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2690
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2691
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2692
	if (examined == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2693
		examined = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2694
	if (examined > total)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2695
		total = examined;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2696
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2697
	fraction_done = (double)examined / total;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2698
	minutes_left = (uint64_t)((now - start) *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2699
	    (1 - fraction_done) / fraction_done / 60);
5853
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2700
	minutes_taken = (uint64_t)((now - start) / 60);
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2701
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2702
	(void) printf(gettext("%s in progress for %lluh%um, %.2f%% done, "
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2703
	    "%lluh%um to go\n"),
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2704
	    scrub_type, (u_longlong_t)(minutes_taken / 60),
0cbeb660905c 6346513 zpool status should display total time of completed scrub
ek110237
parents: 5450
diff changeset
  2705
	    (uint_t)(minutes_taken % 60), 100 * fraction_done,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2706
	    (u_longlong_t)(minutes_left / 60), (uint_t)(minutes_left % 60));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2707
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2708
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2709
typedef struct spare_cbdata {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2710
	uint64_t	cb_guid;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2711
	zpool_handle_t	*cb_zhp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2712
} spare_cbdata_t;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2713
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2714
static boolean_t
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2715
find_vdev(nvlist_t *nv, uint64_t search)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2716
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2717
	uint64_t guid;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2718
	nvlist_t **child;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2719
	uint_t c, children;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2720
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2721
	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) == 0 &&
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2722
	    search == guid)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2723
		return (B_TRUE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2724
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2725
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2726
	    &child, &children) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2727
		for (c = 0; c < children; c++)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2728
			if (find_vdev(child[c], search))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2729
				return (B_TRUE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2730
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2731
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2732
	return (B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2733
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2734
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2735
static int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2736
find_spare(zpool_handle_t *zhp, void *data)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2737
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2738
	spare_cbdata_t *cbp = data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2739
	nvlist_t *config, *nvroot;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2740
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2741
	config = zpool_get_config(zhp, NULL);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2742
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2743
	    &nvroot) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2744
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2745
	if (find_vdev(nvroot, cbp->cb_guid)) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2746
		cbp->cb_zhp = zhp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2747
		return (1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2748
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2749
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2750
	zpool_close(zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2751
	return (0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2752
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2753
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2754
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2755
 * Print out configuration state as requested by status_callback.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2756
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2757
void
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  2758
print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2759
    int namewidth, int depth, boolean_t isspare, boolean_t print_logs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2760
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2761
	nvlist_t **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2762
	uint_t c, children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2763
	vdev_stat_t *vs;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2764
	char rbuf[6], wbuf[6], cbuf[6], repaired[7];
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  2765
	char *vname;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2766
	uint64_t notpresent;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2767
	spare_cbdata_t cb;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2768
	char *state;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2769
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2770
	verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_STATS,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2771
	    (uint64_t **)&vs, &c) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2772
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2773
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2774
	    &child, &children) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2775
		children = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2776
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2777
	state = zpool_state_to_name(vs->vs_state, vs->vs_aux);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2778
	if (isspare) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2779
		/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2780
		 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2781
		 * online drives.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2782
		 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2783
		if (vs->vs_aux == VDEV_AUX_SPARED)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2784
			state = "INUSE";
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2785
		else if (vs->vs_state == VDEV_STATE_HEALTHY)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2786
			state = "AVAIL";
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2787
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2788
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2789
	(void) printf("\t%*s%-*s  %-8s", depth, "", namewidth - depth,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2790
	    name, state);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2791
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2792
	if (!isspare) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2793
		zfs_nicenum(vs->vs_read_errors, rbuf, sizeof (rbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2794
		zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2795
		zfs_nicenum(vs->vs_checksum_errors, cbuf, sizeof (cbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2796
		(void) printf(" %5s %5s %5s", rbuf, wbuf, cbuf);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2797
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2798
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2799
	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2800
	    &notpresent) == 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2801
		char *path;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2802
		verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
1613
aca102a242d3 6396628 zpool offline does not recognize c0d0 patten recently
eschrock
parents: 1544
diff changeset
  2803
		(void) printf("  was %s", path);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2804
	} else if (vs->vs_aux != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2805
		(void) printf("  ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2806
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2807
		switch (vs->vs_aux) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2808
		case VDEV_AUX_OPEN_FAILED:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2809
			(void) printf(gettext("cannot open"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2810
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2811
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2812
		case VDEV_AUX_BAD_GUID_SUM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2813
			(void) printf(gettext("missing device"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2814
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2815
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2816
		case VDEV_AUX_NO_REPLICAS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2817
			(void) printf(gettext("insufficient replicas"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2818
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2819
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  2820
		case VDEV_AUX_VERSION_NEWER:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  2821
			(void) printf(gettext("newer version"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  2822
			break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  2823
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2824
		case VDEV_AUX_SPARED:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2825
			verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2826
			    &cb.cb_guid) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2827
			if (zpool_iter(g_zfs, find_spare, &cb) == 1) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2828
				if (strcmp(zpool_get_name(cb.cb_zhp),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2829
				    zpool_get_name(zhp)) == 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2830
					(void) printf(gettext("currently in "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2831
					    "use"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2832
				else
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2833
					(void) printf(gettext("in use by "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2834
					    "pool '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2835
					    zpool_get_name(cb.cb_zhp));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2836
				zpool_close(cb.cb_zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2837
			} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2838
				(void) printf(gettext("currently in use"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2839
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2840
			break;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2841
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2842
		case VDEV_AUX_ERR_EXCEEDED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2843
			(void) printf(gettext("too many errors"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2844
			break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  2845
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  2846
		case VDEV_AUX_IO_FAILURE:
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  2847
			(void) printf(gettext("experienced I/O failures"));
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  2848
			break;
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  2849
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2850
		case VDEV_AUX_BAD_LOG:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2851
			(void) printf(gettext("bad intent log"));
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2852
			break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2853
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2854
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2855
			(void) printf(gettext("corrupted data"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2856
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2857
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2858
	} else if (vs->vs_scrub_repaired != 0 && children == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2859
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2860
		 * Report bytes resilvered/repaired on leaf devices.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2861
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2862
		zfs_nicenum(vs->vs_scrub_repaired, repaired, sizeof (repaired));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2863
		(void) printf(gettext("  %s %s"), repaired,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2864
		    (vs->vs_scrub_type == POOL_SCRUB_RESILVER) ?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2865
		    "resilvered" : "repaired");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2866
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2867
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2868
	(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2869
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  2870
	for (c = 0; c < children; c++) {
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2871
		uint64_t is_log = B_FALSE;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2872
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2873
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2874
		    &is_log);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2875
		if ((is_log && !print_logs) || (!is_log && print_logs))
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2876
			continue;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2877
		vname = zpool_vdev_name(g_zfs, zhp, child[c]);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  2878
		print_status_config(zhp, vname, child[c],
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2879
		    namewidth, depth + 2, isspare, B_FALSE);
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  2880
		free(vname);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 952
diff changeset
  2881
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2882
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2883
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2884
static void
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2885
print_error_log(zpool_handle_t *zhp)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2886
{
4820
acbb57436af2 6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents: 4787
diff changeset
  2887
	nvlist_t *nverrlist = NULL;
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2888
	nvpair_t *elem;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2889
	char *pathname;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2890
	size_t len = MAXPATHLEN * 2;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2891
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2892
	if (zpool_get_errlog(zhp, &nverrlist) != 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2893
		(void) printf("errors: List of errors unavailable "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2894
		    "(insufficient privileges)\n");
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2895
		return;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2896
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2897
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2898
	(void) printf("errors: Permanent errors have been "
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2899
	    "detected in the following files:\n\n");
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2900
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2901
	pathname = safe_malloc(len);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2902
	elem = NULL;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2903
	while ((elem = nvlist_next_nvpair(nverrlist, elem)) != NULL) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2904
		nvlist_t *nv;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2905
		uint64_t dsobj, obj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2906
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2907
		verify(nvpair_value_nvlist(elem, &nv) == 0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2908
		verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_DATASET,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2909
		    &dsobj) == 0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2910
		verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_OBJECT,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2911
		    &obj) == 0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2912
		zpool_obj_to_path(zhp, dsobj, obj, pathname, len);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2913
		(void) printf("%7s %s\n", "", pathname);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2914
	}
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2915
	free(pathname);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  2916
	nvlist_free(nverrlist);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2917
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2918
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2919
static void
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2920
print_spares(zpool_handle_t *zhp, nvlist_t **spares, uint_t nspares,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2921
    int namewidth)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2922
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2923
	uint_t i;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2924
	char *name;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2925
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2926
	if (nspares == 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2927
		return;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2928
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2929
	(void) printf(gettext("\tspares\n"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2930
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2931
	for (i = 0; i < nspares; i++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2932
		name = zpool_vdev_name(g_zfs, zhp, spares[i]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2933
		print_status_config(zhp, name, spares[i],
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2934
		    namewidth, 2, B_TRUE, B_FALSE);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2935
		free(name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2936
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2937
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2938
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2939
static void
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2940
print_l2cache(zpool_handle_t *zhp, nvlist_t **l2cache, uint_t nl2cache,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2941
    int namewidth)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2942
{
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2943
	uint_t i;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2944
	char *name;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2945
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2946
	if (nl2cache == 0)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2947
		return;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2948
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2949
	(void) printf(gettext("\tcache\n"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2950
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2951
	for (i = 0; i < nl2cache; i++) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2952
		name = zpool_vdev_name(g_zfs, zhp, l2cache[i]);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2953
		print_status_config(zhp, name, l2cache[i],
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2954
		    namewidth, 2, B_FALSE, B_FALSE);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2955
		free(name);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2956
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2957
}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  2958
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2959
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2960
 * Display a summary of pool status.  Displays a summary such as:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2961
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2962
 *        pool: tank
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2963
 *	status: DEGRADED
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2964
 *	reason: One or more devices ...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2965
 *         see: http://www.sun.com/msg/ZFS-xxxx-01
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2966
 *	config:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2967
 *		mirror		DEGRADED
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2968
 *                c1t0d0	OK
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2969
 *                c2t0d0	UNAVAIL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2970
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2971
 * When given the '-v' option, we print out the complete config.  If the '-e'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2972
 * option is specified, then we print out error rate information as well.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2973
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2974
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2975
status_callback(zpool_handle_t *zhp, void *data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2976
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2977
	status_cbdata_t *cbp = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2978
	nvlist_t *config, *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2979
	char *msgid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2980
	int reason;
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  2981
	const char *health;
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  2982
	uint_t c;
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  2983
	vdev_stat_t *vs;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2984
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 884
diff changeset
  2985
	config = zpool_get_config(zhp, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2986
	reason = zpool_get_status(zhp, &msgid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2987
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2988
	cbp->cb_count++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2989
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2990
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2991
	 * If we were given 'zpool status -x', only report those pools with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2992
	 * problems.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2993
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  2994
	if (reason == ZPOOL_STATUS_OK && cbp->cb_explain) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  2995
		if (!cbp->cb_allpools) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  2996
			(void) printf(gettext("pool '%s' is healthy\n"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  2997
			    zpool_get_name(zhp));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  2998
			if (cbp->cb_first)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  2999
				cbp->cb_first = B_FALSE;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3000
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3001
		return (0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3002
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3003
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3004
	if (cbp->cb_first)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3005
		cbp->cb_first = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3006
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3007
		(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3008
3741
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  3009
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  3010
	    &nvroot) == 0);
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  3011
	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
806e933bf124 6441384 zpool import action message is not correctly localized
mmusante
parents: 3444
diff changeset
  3012
	    (uint64_t **)&vs, &c) == 0);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3013
	health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3014
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3015
	(void) printf(gettext("  pool: %s\n"), zpool_get_name(zhp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3016
	(void) printf(gettext(" state: %s\n"), health);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3017
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3018
	switch (reason) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3019
	case ZPOOL_STATUS_MISSING_DEV_R:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3020
		(void) printf(gettext("status: One or more devices could not "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3021
		    "be opened.  Sufficient replicas exist for\n\tthe pool to "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3022
		    "continue functioning in a degraded state.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3023
		(void) printf(gettext("action: Attach the missing device and "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3024
		    "online it using 'zpool online'.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3025
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3026
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3027
	case ZPOOL_STATUS_MISSING_DEV_NR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3028
		(void) printf(gettext("status: One or more devices could not "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3029
		    "be opened.  There are insufficient\n\treplicas for the "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3030
		    "pool to continue functioning.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3031
		(void) printf(gettext("action: Attach the missing device and "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3032
		    "online it using 'zpool online'.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3033
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3034
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3035
	case ZPOOL_STATUS_CORRUPT_LABEL_R:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3036
		(void) printf(gettext("status: One or more devices could not "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3037
		    "be used because the label is missing or\n\tinvalid.  "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3038
		    "Sufficient replicas exist for the pool to continue\n\t"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3039
		    "functioning in a degraded state.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3040
		(void) printf(gettext("action: Replace the device using "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3041
		    "'zpool replace'.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3042
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3043
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3044
	case ZPOOL_STATUS_CORRUPT_LABEL_NR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3045
		(void) printf(gettext("status: One or more devices could not "
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3046
		    "be used because the label is missing \n\tor invalid.  "
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3047
		    "There are insufficient replicas for the pool to "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3048
		    "continue\n\tfunctioning.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3049
		(void) printf(gettext("action: Destroy and re-create the pool "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3050
		    "from a backup source.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3051
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3052
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3053
	case ZPOOL_STATUS_FAILING_DEV:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3054
		(void) printf(gettext("status: One or more devices has "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3055
		    "experienced an unrecoverable error.  An\n\tattempt was "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3056
		    "made to correct the error.  Applications are "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3057
		    "unaffected.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3058
		(void) printf(gettext("action: Determine if the device needs "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3059
		    "to be replaced, and clear the errors\n\tusing "
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3060
		    "'zpool clear' or replace the device with 'zpool "
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3061
		    "replace'.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3062
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3063
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3064
	case ZPOOL_STATUS_OFFLINE_DEV:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3065
		(void) printf(gettext("status: One or more devices has "
3413
f4cbe0204ab7 6471255 Some ZFS error messages contain spelling errors
mmusante
parents: 3377
diff changeset
  3066
		    "been taken offline by the administrator.\n\tSufficient "
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3067
		    "replicas exist for the pool to continue functioning in "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3068
		    "a\n\tdegraded state.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3069
		(void) printf(gettext("action: Online the device using "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3070
		    "'zpool online' or replace the device with\n\t'zpool "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3071
		    "replace'.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3072
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3073
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3074
	case ZPOOL_STATUS_RESILVERING:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3075
		(void) printf(gettext("status: One or more devices is "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3076
		    "currently being resilvered.  The pool will\n\tcontinue "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3077
		    "to function, possibly in a degraded state.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3078
		(void) printf(gettext("action: Wait for the resilver to "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3079
		    "complete.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3080
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3081
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3082
	case ZPOOL_STATUS_CORRUPT_DATA:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3083
		(void) printf(gettext("status: One or more devices has "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3084
		    "experienced an error resulting in data\n\tcorruption.  "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3085
		    "Applications may be affected.\n"));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3086
		(void) printf(gettext("action: Restore the file in question "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3087
		    "if possible.  Otherwise restore the\n\tentire pool from "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3088
		    "backup.\n"));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3089
		break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3090
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3091
	case ZPOOL_STATUS_CORRUPT_POOL:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3092
		(void) printf(gettext("status: The pool metadata is corrupted "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3093
		    "and the pool cannot be opened.\n"));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3094
		(void) printf(gettext("action: Destroy and re-create the pool "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3095
		    "from a backup source.\n"));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3096
		break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3097
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3098
	case ZPOOL_STATUS_VERSION_OLDER:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3099
		(void) printf(gettext("status: The pool is formatted using an "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3100
		    "older on-disk format.  The pool can\n\tstill be used, but "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3101
		    "some features are unavailable.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3102
		(void) printf(gettext("action: Upgrade the pool using 'zpool "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3103
		    "upgrade'.  Once this is done, the\n\tpool will no longer "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3104
		    "be accessible on older software versions.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3105
		break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3106
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3107
	case ZPOOL_STATUS_VERSION_NEWER:
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3108
		(void) printf(gettext("status: The pool has been upgraded to a "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3109
		    "newer, incompatible on-disk version.\n\tThe pool cannot "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3110
		    "be accessed on this system.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3111
		(void) printf(gettext("action: Access the pool from a system "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3112
		    "running more recent software, or\n\trestore the pool from "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3113
		    "backup.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3114
		break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3115
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3116
	case ZPOOL_STATUS_FAULTED_DEV_R:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3117
		(void) printf(gettext("status: One or more devices are "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3118
		    "faulted in response to persistent errors.\n\tSufficient "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3119
		    "replicas exist for the pool to continue functioning "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3120
		    "in a\n\tdegraded state.\n"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3121
		(void) printf(gettext("action: Replace the faulted device, "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3122
		    "or use 'zpool clear' to mark the device\n\trepaired.\n"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3123
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3124
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3125
	case ZPOOL_STATUS_FAULTED_DEV_NR:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3126
		(void) printf(gettext("status: One or more devices are "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3127
		    "faulted in response to persistent errors.  There are "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3128
		    "insufficient replicas for the pool to\n\tcontinue "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3129
		    "functioning.\n"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3130
		(void) printf(gettext("action: Destroy and re-create the pool "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3131
		    "from a backup source.  Manually marking the device\n"
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3132
		    "\trepaired using 'zpool clear' may allow some data "
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3133
		    "to be recovered.\n"));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3134
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4276
diff changeset
  3135
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  3136
	case ZPOOL_STATUS_IO_FAILURE_WAIT:
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  3137
	case ZPOOL_STATUS_IO_FAILURE_CONTINUE:
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  3138
		(void) printf(gettext("status: One or more devices are "
6959
f223e134ee61 6700920 vdev_clear() needs some polishing
ek110237
parents: 6957
diff changeset
  3139
		    "faulted in response to IO failures.\n"));
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  3140
		(void) printf(gettext("action: Make sure the affected devices "
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  3141
		    "are connected, then run 'zpool clear'.\n"));
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  3142
		break;
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6018
diff changeset
  3143
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3144
	case ZPOOL_STATUS_BAD_LOG:
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3145
		(void) printf(gettext("status: An intent log record "
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3146
		    "could not be read.\n"
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3147
		    "\tWaiting for adminstrator intervention to fix the "
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3148
		    "faulted pool.\n"));
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3149
		(void) printf(gettext("action: Either restore the affected "
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3150
		    "device(s) and run 'zpool online',\n"
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3151
		    "\tor ignore the intent log records by running "
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3152
		    "'zpool clear'.\n"));
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3153
		break;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3154
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3155
	default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3156
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3157
		 * The remaining errors can't actually be generated, yet.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3158
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3159
		assert(reason == ZPOOL_STATUS_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3160
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3161
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3162
	if (msgid != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3163
		(void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3164
		    msgid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3165
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3166
	if (config != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3167
		int namewidth;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3168
		uint64_t nerr;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  3169
		nvlist_t **spares, **l2cache;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  3170
		uint_t nspares, nl2cache;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3171
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3172
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3173
		(void) printf(gettext(" scrub: "));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3174
		print_scrub_status(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3175
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  3176
		namewidth = max_width(zhp, nvroot, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3177
		if (namewidth < 10)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3178
			namewidth = 10;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3180
		(void) printf(gettext("config:\n\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3181
		(void) printf(gettext("\t%-*s  %-8s %5s %5s %5s\n"), namewidth,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3182
		    "NAME", "STATE", "READ", "WRITE", "CKSUM");
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1171
diff changeset
  3183
		print_status_config(zhp, zpool_get_name(zhp), nvroot,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3184
		    namewidth, 0, B_FALSE, B_FALSE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3185
		if (num_logs(nvroot) > 0)
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3186
			print_status_config(zhp, "logs", nvroot, namewidth, 0,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3187
			    B_FALSE, B_TRUE);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3188
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  3189
		if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  3190
		    &l2cache, &nl2cache) == 0)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  3191
			print_l2cache(zhp, l2cache, nl2cache, namewidth);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  3192
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3193
		if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3194
		    &spares, &nspares) == 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3195
			print_spares(zhp, spares, nspares, namewidth);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3196
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3197
		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3198
		    &nerr) == 0) {
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3199
			nvlist_t *nverrlist = NULL;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3200
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3201
			/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3202
			 * If the approximate error count is small, get a
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3203
			 * precise count by fetching the entire log and
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3204
			 * uniquifying the results.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3205
			 */
4820
acbb57436af2 6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents: 4787
diff changeset
  3206
			if (nerr > 0 && nerr < 100 && !cbp->cb_verbose &&
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3207
			    zpool_get_errlog(zhp, &nverrlist) == 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3208
				nvpair_t *elem;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3209
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3210
				elem = NULL;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3211
				nerr = 0;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3212
				while ((elem = nvlist_next_nvpair(nverrlist,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3213
				    elem)) != NULL) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3214
					nerr++;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3215
				}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3216
			}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3413
diff changeset
  3217
			nvlist_free(nverrlist);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3218
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3219
			(void) printf("\n");
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3220
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3221
			if (nerr == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3222
				(void) printf(gettext("errors: No known data "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3223
				    "errors\n"));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3224
			else if (!cbp->cb_verbose)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3225
				(void) printf(gettext("errors: %llu data "
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2731
diff changeset
  3226
				    "errors, use '-v' for a list\n"),
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2731
diff changeset
  3227
				    (u_longlong_t)nerr);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3228
			else
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3229
				print_error_log(zhp);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3230
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3231
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3232
		(void) printf(gettext("config: The configuration cannot be "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3233
		    "determined.\n"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3234
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3236
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3237
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3238
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3239
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3240
 * zpool status [-vx] [pool] ...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3241
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3242
 *	-v	Display complete error logs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3243
 *	-x	Display only pools with potential problems
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3244
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3245
 * Describes the health status of all pools or some subset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3246
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3247
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3248
zpool_do_status(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3249
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3250
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3251
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3252
	status_cbdata_t cb = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3254
	/* check options */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3255
	while ((c = getopt(argc, argv, "vx")) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3256
		switch (c) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3257
		case 'v':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3258
			cb.cb_verbose = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3259
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3260
		case 'x':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3261
			cb.cb_explain = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3262
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3263
		case '?':
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3264
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3265
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3266
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3267
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3268
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3270
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3271
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3272
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3273
	cb.cb_first = B_TRUE;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3274
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3275
	if (argc == 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3276
		cb.cb_allpools = B_TRUE;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3277
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3278
	ret = for_each_pool(argc, argv, B_TRUE, NULL, status_callback, &cb);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3279
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3280
	if (argc == 0 && cb.cb_count == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3281
		(void) printf(gettext("no pools available\n"));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3282
	else if (cb.cb_explain && cb.cb_first && cb.cb_allpools)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  3283
		(void) printf(gettext("all pools are healthy\n"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3284
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3285
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3286
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3287
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3288
typedef struct upgrade_cbdata {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3289
	int	cb_all;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3290
	int	cb_first;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3291
	int	cb_newer;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3292
	int	cb_argc;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3293
	uint64_t cb_version;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3294
	char	**cb_argv;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3295
} upgrade_cbdata_t;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3296
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3297
static int
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3298
upgrade_cb(zpool_handle_t *zhp, void *arg)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3299
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3300
	upgrade_cbdata_t *cbp = arg;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3301
	nvlist_t *config;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3302
	uint64_t version;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3303
	int ret = 0;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3304
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3305
	config = zpool_get_config(zhp, NULL);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3306
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3307
	    &version) == 0);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3308
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  3309
	if (!cbp->cb_newer && version < SPA_VERSION) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3310
		if (!cbp->cb_all) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3311
			if (cbp->cb_first) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3312
				(void) printf(gettext("The following pools are "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3313
				    "out of date, and can be upgraded.  After "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3314
				    "being\nupgraded, these pools will no "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3315
				    "longer be accessible by older software "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3316
				    "versions.\n\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3317
				(void) printf(gettext("VER  POOL\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3318
				(void) printf(gettext("---  ------------\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3319
				cbp->cb_first = B_FALSE;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3320
			}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3321
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2731
diff changeset
  3322
			(void) printf("%2llu   %s\n", (u_longlong_t)version,
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3323
			    zpool_get_name(zhp));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3324
		} else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3325
			cbp->cb_first = B_FALSE;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3326
			ret = zpool_upgrade(zhp, cbp->cb_version);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3327
			if (!ret) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3328
				(void) printf(gettext("Successfully upgraded "
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3329
				    "'%s'\n\n"), zpool_get_name(zhp));
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3330
			}
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3331
		}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  3332
	} else if (cbp->cb_newer && version > SPA_VERSION) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3333
		assert(!cbp->cb_all);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3334
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3335
		if (cbp->cb_first) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3336
			(void) printf(gettext("The following pools are "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3337
			    "formatted using a newer software version and\n"
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3338
			    "cannot be accessed on the current system.\n\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3339
			(void) printf(gettext("VER  POOL\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3340
			(void) printf(gettext("---  ------------\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3341
			cbp->cb_first = B_FALSE;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3342
		}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3343
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2731
diff changeset
  3344
		(void) printf("%2llu   %s\n", (u_longlong_t)version,
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3345
		    zpool_get_name(zhp));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3346
	}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3347
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3348
	zpool_close(zhp);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3349
	return (ret);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3350
}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3351
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3352
/* ARGSUSED */
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3353
static int
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3354
upgrade_one(zpool_handle_t *zhp, void *data)
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3355
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3356
	upgrade_cbdata_t *cbp = data;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3357
	uint64_t cur_version;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3358
	int ret;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3359
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3360
	if (strcmp("log", zpool_get_name(zhp)) == 0) {
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3361
		(void) printf(gettext("'log' is now a reserved word\n"
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3362
		    "Pool 'log' must be renamed using export and import"
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3363
		    " to upgrade.\n"));
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3364
		return (1);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3365
	}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3366
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3367
	cur_version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL);
6018
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3368
	if (cur_version > cbp->cb_version) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3369
		(void) printf(gettext("Pool '%s' is already formatted "
6018
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3370
		    "using more current version '%llu'.\n"),
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3371
		    zpool_get_name(zhp), cur_version);
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3372
		return (0);
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3373
	}
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3374
	if (cur_version == cbp->cb_version) {
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3375
		(void) printf(gettext("Pool '%s' is already formatted "
109fdf2d7ad7 6628084 Incorrect error message when trying to upgrade a v10 pool
brendan
parents: 5994
diff changeset
  3376
		    "using the current version.\n"), zpool_get_name(zhp));
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3377
		return (0);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3378
	}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3379
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3380
	ret = zpool_upgrade(zhp, cbp->cb_version);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3381
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3382
	if (!ret) {
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1760
diff changeset
  3383
		(void) printf(gettext("Successfully upgraded '%s' "
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3384
		    "from version %llu to version %llu\n\n"),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3385
		    zpool_get_name(zhp), (u_longlong_t)cur_version,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3386
		    (u_longlong_t)cbp->cb_version);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3387
	}
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3388
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3389
	return (ret != 0);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3390
}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3391
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3392
/*
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3393
 * zpool upgrade
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3394
 * zpool upgrade -v
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3395
 * zpool upgrade [-V version] <-a | pool ...>
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3396
 *
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3397
 * With no arguments, display downrev'd ZFS pool available for upgrade.
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3398
 * Individual pools can be upgraded by specifying the pool, and '-a' will
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3399
 * upgrade all pools.
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3400
 */
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3401
int
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3402
zpool_do_upgrade(int argc, char **argv)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3403
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3404
	int c;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3405
	upgrade_cbdata_t cb = { 0 };
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3406
	int ret = 0;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3407
	boolean_t showversions = B_FALSE;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3408
	char *end;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3409
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3410
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3411
	/* check options */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3412
	while ((c = getopt(argc, argv, "avV:")) != -1) {
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3413
		switch (c) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3414
		case 'a':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3415
			cb.cb_all = B_TRUE;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3416
			break;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3417
		case 'v':
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3418
			showversions = B_TRUE;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3419
			break;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3420
		case 'V':
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3421
			cb.cb_version = strtoll(optarg, &end, 10);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3422
			if (*end != '\0' || cb.cb_version > SPA_VERSION ||
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3423
			    cb.cb_version < SPA_VERSION_1) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3424
				(void) fprintf(stderr,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3425
				    gettext("invalid version '%s'\n"), optarg);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3426
				usage(B_FALSE);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3427
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3428
			break;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3429
		case '?':
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3430
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3431
			    optopt);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3432
			usage(B_FALSE);
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3433
		}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3434
	}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3435
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3436
	cb.cb_argc = argc;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3437
	cb.cb_argv = argv;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3438
	argc -= optind;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3439
	argv += optind;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3440
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3441
	if (cb.cb_version == 0) {
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3442
		cb.cb_version = SPA_VERSION;
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3443
	} else if (!cb.cb_all && argc == 0) {
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3444
		(void) fprintf(stderr, gettext("-V option is "
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3445
		    "incompatible with other arguments\n"));
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3446
		usage(B_FALSE);
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3447
	}
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3448
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3449
	if (showversions) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3450
		if (cb.cb_all || argc != 0) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3451
			(void) fprintf(stderr, gettext("-v option is "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3452
			    "incompatible with other arguments\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3453
			usage(B_FALSE);
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3454
		}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3455
	} else if (cb.cb_all) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3456
		if (argc != 0) {
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3457
			(void) fprintf(stderr, gettext("-a option should not "
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  3458
			    "be used along with a pool name\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3459
			usage(B_FALSE);
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3460
		}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3461
	}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3462
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  3463
	(void) printf(gettext("This system is currently running "
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  3464
	    "ZFS pool version %llu.\n\n"), SPA_VERSION);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3465
	cb.cb_first = B_TRUE;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3466
	if (showversions) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3467
		(void) printf(gettext("The following versions are "
3413
f4cbe0204ab7 6471255 Some ZFS error messages contain spelling errors
mmusante
parents: 3377
diff changeset
  3468
		    "supported:\n\n"));
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3469
		(void) printf(gettext("VER  DESCRIPTION\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3470
		(void) printf("---  -----------------------------------------"
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3471
		    "---------------\n");
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3472
		(void) printf(gettext(" 1   Initial ZFS version\n"));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1760
diff changeset
  3473
		(void) printf(gettext(" 2   Ditto blocks "
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1760
diff changeset
  3474
		    "(replicated metadata)\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3475
		(void) printf(gettext(" 3   Hot spares and double parity "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3476
		    "RAID-Z\n"));
3863
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  3477
		(void) printf(gettext(" 4   zpool history\n"));
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  3478
		(void) printf(gettext(" 5   Compression using the gzip "
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  3479
		    "algorithm\n"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3480
		(void) printf(gettext(" 6   bootfs pool property\n"));
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3481
		(void) printf(gettext(" 7   Separate intent log devices\n"));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3482
		(void) printf(gettext(" 8   Delegated administration\n"));
5390
d93266868417 6624710 zpool upgrade message is not correctly aligned which results in test failure
ck153898
parents: 5378
diff changeset
  3483
		(void) printf(gettext(" 9   refquota and refreservation "
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5363
diff changeset
  3484
		    "properties\n"));
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5390
diff changeset
  3485
		(void) printf(gettext(" 10  Cache devices\n"));
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6959
diff changeset
  3486
		(void) printf(gettext(" 11  Improved scrub performance\n"));
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  3487
		(void) printf(gettext(" 12  Snapshot properties\n"));
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3488
		(void) printf(gettext("For more information on a particular "
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3489
		    "version, including supported releases, see:\n\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3490
		(void) printf("http://www.opensolaris.org/os/community/zfs/"
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3491
		    "version/N\n\n");
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3492
		(void) printf(gettext("Where 'N' is the version number.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3493
	} else if (argc == 0) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3494
		int notfound;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3495
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3496
		ret = zpool_iter(g_zfs, upgrade_cb, &cb);
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3497
		notfound = cb.cb_first;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3498
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3499
		if (!cb.cb_all && ret == 0) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3500
			if (!cb.cb_first)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3501
				(void) printf("\n");
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3502
			cb.cb_first = B_TRUE;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3503
			cb.cb_newer = B_TRUE;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3504
			ret = zpool_iter(g_zfs, upgrade_cb, &cb);
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3505
			if (!cb.cb_first) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3506
				notfound = B_FALSE;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3507
				(void) printf("\n");
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3508
			}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3509
		}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3510
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3511
		if (ret == 0) {
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3512
			if (notfound)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3513
				(void) printf(gettext("All pools are formatted "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3514
				    "using this version.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3515
			else if (!cb.cb_all)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3516
				(void) printf(gettext("Use 'zpool upgrade -v' "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3517
				    "for a list of available versions and "
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3518
				    "their associated\nfeatures.\n"));
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3519
		}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3520
	} else {
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3521
		ret = for_each_pool(argc, argv, B_FALSE, NULL,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3522
		    upgrade_one, &cb);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3523
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3524
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3525
	return (ret);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3526
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3527
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3528
typedef struct hist_cbdata {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3529
	boolean_t first;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3530
	int longfmt;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3531
	int internal;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3532
} hist_cbdata_t;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3533
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3534
char *hist_event_table[LOG_END] = {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3535
	"invalid event",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3536
	"pool create",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3537
	"vdev add",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3538
	"pool remove",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3539
	"pool destroy",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3540
	"pool export",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3541
	"pool import",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3542
	"vdev attach",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3543
	"vdev replace",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3544
	"vdev detach",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3545
	"vdev online",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3546
	"vdev offline",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3547
	"vdev upgrade",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3548
	"pool clear",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3549
	"pool scrub",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3550
	"pool property set",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3551
	"create",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3552
	"clone",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3553
	"destroy",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3554
	"destroy_begin_sync",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3555
	"inherit",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3556
	"property set",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3557
	"quota set",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3558
	"permission update",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3559
	"permission remove",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3560
	"permission who remove",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3561
	"promote",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3562
	"receive",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3563
	"rename",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3564
	"reservation set",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3565
	"replay_inc_sync",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3566
	"replay_full_sync",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3567
	"rollback",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3568
	"snapshot",
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  3569
	"filesystem version upgrade",
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5363
diff changeset
  3570
	"refquota set",
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5363
diff changeset
  3571
	"refreservation set",
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6959
diff changeset
  3572
	"pool scrub done",
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3573
};
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3574
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3575
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3576
 * Print out the command history for a specific pool.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3577
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3578
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3579
get_history_one(zpool_handle_t *zhp, void *data)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3580
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3581
	nvlist_t *nvhis;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3582
	nvlist_t **records;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3583
	uint_t numrecords;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3584
	char *cmdstr;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3585
	char *pathstr;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3586
	uint64_t dst_time;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3587
	time_t tsec;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3588
	struct tm t;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3589
	char tbuf[30];
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3590
	int ret, i;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3591
	uint64_t who;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3592
	struct passwd *pwd;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3593
	char *hostname;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3594
	char *zonename;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3595
	char internalstr[MAXPATHLEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3596
	hist_cbdata_t *cb = (hist_cbdata_t *)data;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3597
	uint64_t txg;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3598
	uint64_t ievent;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3599
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3600
	cb->first = B_FALSE;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3601
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3602
	(void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3603
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3604
	if ((ret = zpool_get_history(zhp, &nvhis)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3605
		return (ret);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3606
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3607
	verify(nvlist_lookup_nvlist_array(nvhis, ZPOOL_HIST_RECORD,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3608
	    &records, &numrecords) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3609
	for (i = 0; i < numrecords; i++) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3610
		if (nvlist_lookup_uint64(records[i], ZPOOL_HIST_TIME,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3611
		    &dst_time) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3612
			continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3613
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3614
		/* is it an internal event or a standard event? */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3615
		if (nvlist_lookup_string(records[i], ZPOOL_HIST_CMD,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3616
		    &cmdstr) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3617
			if (cb->internal == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3618
				continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3619
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3620
			if (nvlist_lookup_uint64(records[i],
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3621
			    ZPOOL_HIST_INT_EVENT, &ievent) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3622
				continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3623
			verify(nvlist_lookup_uint64(records[i],
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3624
			    ZPOOL_HIST_TXG, &txg) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3625
			verify(nvlist_lookup_string(records[i],
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3626
			    ZPOOL_HIST_INT_STR, &pathstr) == 0);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6959
diff changeset
  3627
			if (ievent >= LOG_END)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3628
				continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3629
			(void) snprintf(internalstr,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3630
			    sizeof (internalstr),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3631
			    "[internal %s txg:%lld] %s",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3632
			    hist_event_table[ievent], txg,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3633
			    pathstr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3634
			cmdstr = internalstr;
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3635
		}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3636
		tsec = dst_time;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3637
		(void) localtime_r(&tsec, &t);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3638
		(void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3639
		(void) printf("%s %s", tbuf, cmdstr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3640
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3641
		if (!cb->longfmt) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3642
			(void) printf("\n");
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3643
			continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3644
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3645
		(void) printf(" [");
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3646
		if (nvlist_lookup_uint64(records[i],
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3647
		    ZPOOL_HIST_WHO, &who) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3648
			pwd = getpwuid((uid_t)who);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3649
			if (pwd)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3650
				(void) printf("user %s on",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3651
				    pwd->pw_name);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3652
			else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3653
				(void) printf("user %d on",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3654
				    (int)who);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3655
		} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3656
			(void) printf(gettext("no info]\n"));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3657
			continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3658
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3659
		if (nvlist_lookup_string(records[i],
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3660
		    ZPOOL_HIST_HOST, &hostname) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3661
			(void) printf(" %s", hostname);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3662
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3663
		if (nvlist_lookup_string(records[i],
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3664
		    ZPOOL_HIST_ZONE, &zonename) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3665
			(void) printf(":%s", zonename);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3666
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3667
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3668
		(void) printf("]");
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3669
		(void) printf("\n");
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3670
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3671
	(void) printf("\n");
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3672
	nvlist_free(nvhis);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3673
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3674
	return (ret);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3675
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3676
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3677
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3678
 * zpool history <pool>
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3679
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3680
 * Displays the history of commands that modified pools.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3681
 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3682
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3683
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3684
int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3685
zpool_do_history(int argc, char **argv)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3686
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3687
	hist_cbdata_t cbdata = { 0 };
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3688
	int ret;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3689
	int c;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3690
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3691
	cbdata.first = B_TRUE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3692
	/* check options */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3693
	while ((c = getopt(argc, argv, "li")) != -1) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3694
		switch (c) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3695
		case 'l':
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3696
			cbdata.longfmt = 1;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3697
			break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3698
		case 'i':
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3699
			cbdata.internal = 1;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3700
			break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3701
		case '?':
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3702
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3703
			    optopt);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3704
			usage(B_FALSE);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3705
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3706
	}
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3707
	argc -= optind;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3708
	argv += optind;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3709
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3710
	ret = for_each_pool(argc, argv, B_FALSE,  NULL, get_history_one,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3711
	    &cbdata);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3712
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3713
	if (argc == 0 && cbdata.first == B_TRUE) {
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3714
		(void) printf(gettext("no pools available\n"));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3715
		return (0);
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3716
	}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3717
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3718
	return (ret);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3719
}
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1631
diff changeset
  3720
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3721
static int
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3722
get_callback(zpool_handle_t *zhp, void *data)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3723
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3724
	zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3725
	char value[MAXNAMELEN];
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3726
	zprop_source_t srctype;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3727
	zprop_list_t *pl;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3728
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3729
	for (pl = cbp->cb_proplist; pl != NULL; pl = pl->pl_next) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3730
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3731
		/*
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3732
		 * Skip the special fake placeholder. This will also skip
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3733
		 * over the name property when 'all' is specified.
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3734
		 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3735
		if (pl->pl_prop == ZPOOL_PROP_NAME &&
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3736
		    pl == cbp->cb_proplist)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3737
			continue;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3738
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3739
		if (zpool_get_prop(zhp, pl->pl_prop,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3740
		    value, sizeof (value), &srctype) != 0)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3741
			continue;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3742
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3743
		zprop_print_one_property(zpool_get_name(zhp), cbp,
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3744
		    zpool_prop_to_name(pl->pl_prop), value, srctype, NULL);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3745
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3746
	return (0);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3747
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3748
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3749
int
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3750
zpool_do_get(int argc, char **argv)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3751
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3752
	zprop_get_cbdata_t cb = { 0 };
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3753
	zprop_list_t fake_name = { 0 };
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3754
	int ret;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3755
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3756
	if (argc < 3)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3757
		usage(B_FALSE);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3758
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3759
	cb.cb_first = B_TRUE;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3760
	cb.cb_sources = ZPROP_SRC_ALL;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3761
	cb.cb_columns[0] = GET_COL_NAME;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3762
	cb.cb_columns[1] = GET_COL_PROPERTY;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3763
	cb.cb_columns[2] = GET_COL_VALUE;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3764
	cb.cb_columns[3] = GET_COL_SOURCE;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3765
	cb.cb_type = ZFS_TYPE_POOL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3766
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3767
	if (zprop_get_list(g_zfs, argv[1],  &cb.cb_proplist,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3768
	    ZFS_TYPE_POOL) != 0)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3769
		usage(B_FALSE);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3770
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3771
	if (cb.cb_proplist != NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3772
		fake_name.pl_prop = ZPOOL_PROP_NAME;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3773
		fake_name.pl_width = strlen(gettext("NAME"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3774
		fake_name.pl_next = cb.cb_proplist;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3775
		cb.cb_proplist = &fake_name;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3776
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3777
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3778
	ret = for_each_pool(argc - 2, argv + 2, B_TRUE, &cb.cb_proplist,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3779
	    get_callback, &cb);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3780
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3781
	if (cb.cb_proplist == &fake_name)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3782
		zprop_free_list(fake_name.pl_next);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3783
	else
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3784
		zprop_free_list(cb.cb_proplist);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3785
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3786
	return (ret);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3787
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3788
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3789
typedef struct set_cbdata {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3790
	char *cb_propname;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3791
	char *cb_value;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3792
	boolean_t cb_any_successful;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3793
} set_cbdata_t;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3794
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3795
int
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3796
set_callback(zpool_handle_t *zhp, void *data)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3797
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3798
	int error;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3799
	set_cbdata_t *cb = (set_cbdata_t *)data;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3800
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3801
	error = zpool_set_prop(zhp, cb->cb_propname, cb->cb_value);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3802
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3803
	if (!error)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3804
		cb->cb_any_successful = B_TRUE;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3805
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3806
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3807
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3808
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3809
int
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3810
zpool_do_set(int argc, char **argv)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3811
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3812
	set_cbdata_t cb = { 0 };
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3813
	int error;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3814
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3815
	if (argc > 1 && argv[1][0] == '-') {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3816
		(void) fprintf(stderr, gettext("invalid option '%c'\n"),
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3817
		    argv[1][1]);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3818
		usage(B_FALSE);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3819
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3820
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3821
	if (argc < 2) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3822
		(void) fprintf(stderr, gettext("missing property=value "
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3823
		    "argument\n"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3824
		usage(B_FALSE);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3825
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3826
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3827
	if (argc < 3) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3828
		(void) fprintf(stderr, gettext("missing pool name\n"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3829
		usage(B_FALSE);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3830
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3831
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3832
	if (argc > 3) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3833
		(void) fprintf(stderr, gettext("too many pool names\n"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3834
		usage(B_FALSE);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3835
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3836
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3837
	cb.cb_propname = argv[1];
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3838
	cb.cb_value = strchr(cb.cb_propname, '=');
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3839
	if (cb.cb_value == NULL) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3840
		(void) fprintf(stderr, gettext("missing value in "
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3841
		    "property=value argument\n"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3842
		usage(B_FALSE);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3843
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3844
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3845
	*(cb.cb_value) = '\0';
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3846
	cb.cb_value++;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3847
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3848
	error = for_each_pool(argc - 2, argv + 2, B_TRUE, NULL,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3849
	    set_callback, &cb);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3850
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3851
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3852
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3853
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3854
static int
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3855
find_command_idx(char *command, int *idx)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3856
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3857
	int i;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3858
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3859
	for (i = 0; i < NCOMMAND; i++) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3860
		if (command_table[i].name == NULL)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3861
			continue;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3862
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3863
		if (strcmp(command, command_table[i].name) == 0) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3864
			*idx = i;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3865
			return (0);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3866
		}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3867
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3868
	return (1);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3869
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3870
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3871
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3872
main(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3873
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3874
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3875
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3876
	char *cmdname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3877
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3878
	(void) setlocale(LC_ALL, "");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3879
	(void) textdomain(TEXT_DOMAIN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3880
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3881
	if ((g_zfs = libzfs_init()) == NULL) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3882
		(void) fprintf(stderr, gettext("internal error: failed to "
2731
2dd6e16860b6 6463349 error message from zpool(1M) is missing a newline
nd150628
parents: 2676
diff changeset
  3883
		    "initialize ZFS library\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3884
		return (1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3885
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3886
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3887
	libzfs_print_on_error(g_zfs, B_TRUE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3888
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3889
	opterr = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3890
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3891
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3892
	 * Make sure the user has specified some command.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3893
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3894
	if (argc < 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3895
		(void) fprintf(stderr, gettext("missing command\n"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3896
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3897
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3898
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3899
	cmdname = argv[1];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3900
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3901
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3902
	 * Special case '-?'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3903
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3904
	if (strcmp(cmdname, "-?") == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3905
		usage(B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3906
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  3907
	zpool_set_history_str("zpool", argc, argv, history_str);
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  3908
	verify(zpool_stage_history(g_zfs, history_str) == 0);
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  3909
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3910
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3911
	 * Run the appropriate command.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3912
	 */
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3913
	if (find_command_idx(cmdname, &i) == 0) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3914
		current_command = &command_table[i];
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3915
		ret = command_table[i].func(argc - 1, argv + 1);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3916
	} else if (strchr(cmdname, '=')) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3917
		verify(find_command_idx("set", &i) == 0);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3918
		current_command = &command_table[i];
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3919
		ret = command_table[i].func(argc, argv);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3920
	} else if (strcmp(cmdname, "freeze") == 0 && argc == 3) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3921
		/*
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3922
		 * 'freeze' is a vile debugging abomination, so we treat
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3923
		 * it as such.
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3924
		 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3925
		char buf[16384];
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3926
		int fd = open(ZFS_DEV, O_RDWR);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3927
		(void) strcpy((void *)buf, argv[2]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3928
		return (!!ioctl(fd, ZFS_IOC_POOL_FREEZE, buf));
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4715
diff changeset
  3929
	} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3930
		(void) fprintf(stderr, gettext("unrecognized "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3931
		    "command '%s'\n"), cmdname);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3932
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3933
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3934
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3935
	libzfs_fini(g_zfs);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3936
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3937
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3938
	 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3939
	 * for the purposes of running ::findleaks.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3940
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3941
	if (getenv("ZFS_ABORT") != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3942
		(void) printf("dumping core by request\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3943
		abort();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3944
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3945
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3946
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3947
}