usr/src/lib/libzfs/common/libzfs_status.c
author Christopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 12:11:39 -0700
changeset 13700 2889e2596bd6
parent 12296 7cf402a7f374
child 13753 2aba784c276b
permissions -rw-r--r--
2619 asynchronous destruction of ZFS file systems 2747 SPA versioning with zfs feature flags Reviewed by: Matt Ahrens <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Dan Kruchinin <[email protected]> Approved by: Eric Schrock <[email protected]>
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
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
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
 */
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
    21
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
    23
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
    24
 * Copyright (c) 2012 by Delphix. All rights reserved.
789
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
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
 * This file contains the functions which analyze the status of a pool.  This
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
 * include both the status of an active pool, as well as the status exported
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
 * pools.  Returns one of the ZPOOL_STATUS_* defines describing the status of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
 * the pool.  This status is independent (to a certain degree) from the state of
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    32
 * the pool.  A pool's state describes only whether or not it is capable of
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
 * providing the necessary fault tolerance for data.  The status describes the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
 * overall status of devices.  A pool that is online can still have a device
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
 * that is experiencing errors.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 * Only a subset of the possible faults can be detected using 'zpool status',
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 * and not all possible errors correspond to a FMA message ID.  The explanation
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
 * is left up to the caller, depending on whether it is a live pool or an
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 * import.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <libzfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <string.h>
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
    45
#include <unistd.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include "libzfs_impl.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    49
 * Message ID table.  This must be kept in sync with the ZPOOL_STATUS_* defines
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
 * in libzfs.h.  Note that there are some status results which go past the end
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 * of this table, and hence have no associated message ID.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 */
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
    53
static char *zfs_msgid_table[] = {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
	"ZFS-8000-14",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
	"ZFS-8000-2Q",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
	"ZFS-8000-3C",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
	"ZFS-8000-4J",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
	"ZFS-8000-5E",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
	"ZFS-8000-6X",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
	"ZFS-8000-72",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
	"ZFS-8000-8A",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	"ZFS-8000-9P",
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
    63
	"ZFS-8000-A5",
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 4577
diff changeset
    64
	"ZFS-8000-EY",
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 4577
diff changeset
    65
	"ZFS-8000-HC",
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
    66
	"ZFS-8000-JQ",
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
    67
	"ZFS-8000-K4",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
    70
#define	NMSGID	(sizeof (zfs_msgid_table) / sizeof (zfs_msgid_table[0]))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
vdev_missing(uint64_t state, uint64_t aux, uint64_t errs)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	return (state == VDEV_STATE_CANT_OPEN &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	    aux == VDEV_AUX_OPEN_FAILED);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
static int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    82
vdev_faulted(uint64_t state, uint64_t aux, uint64_t errs)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    83
{
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    84
	return (state == VDEV_STATE_FAULTED);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    85
}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    86
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    87
/* ARGSUSED */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    88
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
vdev_errors(uint64_t state, uint64_t aux, uint64_t errs)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
{
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
    91
	return (state == VDEV_STATE_DEGRADED || errs != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
vdev_broken(uint64_t state, uint64_t aux, uint64_t errs)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	return (state == VDEV_STATE_CANT_OPEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
vdev_offlined(uint64_t state, uint64_t aux, uint64_t errs)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	return (state == VDEV_STATE_OFFLINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
10151
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   108
/* ARGSUSED */
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   109
static int
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   110
vdev_removed(uint64_t state, uint64_t aux, uint64_t errs)
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   111
{
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   112
	return (state == VDEV_STATE_REMOVED);
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   113
}
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   114
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
 * Detect if any leaf devices that have seen errors or could not be opened.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1760
diff changeset
   118
static boolean_t
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
find_vdev_problem(nvlist_t *vdev, int (*func)(uint64_t, uint64_t, uint64_t))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	nvlist_t **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	vdev_stat_t *vs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	uint_t c, children;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	char *type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	 * Ignore problems within a 'replacing' vdev, since we're presumably in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	 * the process of repairing any such errors, and don't want to call them
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	 * out again.  We'll pick up the fact that a resilver is happening
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	 * later.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	verify(nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE, &type) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1760
diff changeset
   134
		return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN, &child,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
	    &children) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
		for (c = 0; c < children; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
			if (find_vdev_problem(child[c], func))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1760
diff changeset
   140
				return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	} else {
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   142
		verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
		    (uint64_t **)&vs, &c) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
		if (func(vs->vs_state, vs->vs_aux,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
		    vs->vs_read_errors +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
		    vs->vs_write_errors +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
		    vs->vs_checksum_errors))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1760
diff changeset
   149
			return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1760
diff changeset
   152
	return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
 * Active pool health status.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
 * To determine the status for a pool, we make several passes over the config,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
 * picking the most egregious error we find.  In order of importance, we do the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
 * following:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
 *	- Check for a complete and valid configuration
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   163
 *	- Look for any faulted or missing devices in a non-replicated config
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   164
 *	- Check for any data errors
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   165
 *	- Check for any faulted or missing devices in a replicated config
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
 *	- Look for any devices showing errors
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
 *	- Check for any resilvering devices
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
 * There can obviously be multiple errors within a single pool, so this routine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
 * only picks the most damaging of all the current errors to report.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
static zpool_status_t
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   173
check_status(nvlist_t *config, boolean_t isimport)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
	vdev_stat_t *vs;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   177
	pool_scan_stat_t *ps = NULL;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   178
	uint_t vsc, psc;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   179
	uint64_t nerr;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   180
	uint64_t version;
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   181
	uint64_t stateval;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   182
	uint64_t suspended;
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   183
	uint64_t hostid = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   185
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   186
	    &version) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	    &nvroot) == 0);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   189
	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	    (uint64_t **)&vs, &vsc) == 0);
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   191
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   192
	    &stateval) == 0);
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   193
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   194
	/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   195
	 * Currently resilvering a vdev
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   196
	 */
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   197
	(void) nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   198
	    (uint64_t **)&ps, &psc);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   199
	if (ps && ps->pss_func == POOL_SCAN_RESILVER &&
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   200
	    ps->pss_state == DSS_SCANNING)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   201
		return (ZPOOL_STATUS_RESILVERING);
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   202
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   203
	/*
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   204
	 * Pool last accessed by another system.
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   205
	 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11149
diff changeset
   206
	(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   207
	if (hostid != 0 && (unsigned long)hostid != gethostid() &&
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   208
	    stateval == POOL_STATE_ACTIVE)
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   209
		return (ZPOOL_STATUS_HOSTID_MISMATCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
	/*
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   212
	 * Newer on-disk version.
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   213
	 */
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   214
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   215
	    vs->vs_aux == VDEV_AUX_VERSION_NEWER)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   216
		return (ZPOOL_STATUS_VERSION_NEWER);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   217
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   218
	/*
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   219
	 * Unsupported feature(s).
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   220
	 */
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   221
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   222
	    vs->vs_aux == VDEV_AUX_UNSUP_FEAT) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   223
		nvlist_t *nvinfo;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   224
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   225
		verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   226
		    &nvinfo) == 0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   227
		if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY))
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   228
			return (ZPOOL_STATUS_UNSUP_FEAT_WRITE);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   229
		return (ZPOOL_STATUS_UNSUP_FEAT_READ);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   230
	}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   231
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   232
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	 * Check that the config is complete.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   236
	    vs->vs_aux == VDEV_AUX_BAD_GUID_SUM)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
		return (ZPOOL_STATUS_BAD_GUID_SUM);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   238
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   239
	/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   240
	 * Check whether the pool has suspended due to failed I/O.
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 4577
diff changeset
   241
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   242
	if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   243
	    &suspended) == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   244
		if (suspended == ZIO_FAILURE_MODE_CONTINUE)
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 4577
diff changeset
   245
			return (ZPOOL_STATUS_IO_FAILURE_CONTINUE);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   246
		return (ZPOOL_STATUS_IO_FAILURE_WAIT);
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 4577
diff changeset
   247
	}
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 4577
diff changeset
   248
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 4577
diff changeset
   249
	/*
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   250
	 * Could not read a log.
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   251
	 */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   252
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   253
	    vs->vs_aux == VDEV_AUX_BAD_LOG) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   254
		return (ZPOOL_STATUS_BAD_LOG);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   255
	}
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   256
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6523
diff changeset
   257
	/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   258
	 * Bad devices in non-replicated config.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   259
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   260
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   261
	    find_vdev_problem(nvroot, vdev_faulted))
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   262
		return (ZPOOL_STATUS_FAULTED_DEV_NR);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   263
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   264
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   265
	    find_vdev_problem(nvroot, vdev_missing))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   266
		return (ZPOOL_STATUS_MISSING_DEV_NR);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   267
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   268
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   269
	    find_vdev_problem(nvroot, vdev_broken))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   270
		return (ZPOOL_STATUS_CORRUPT_LABEL_NR);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   271
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   272
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   273
	 * Corrupted pool metadata
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   274
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   275
	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   276
	    vs->vs_aux == VDEV_AUX_CORRUPT_DATA)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   277
		return (ZPOOL_STATUS_CORRUPT_POOL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   278
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   279
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   280
	 * Persistent data errors.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   281
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   282
	if (!isimport) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   283
		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   284
		    &nerr) == 0 && nerr != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   285
			return (ZPOOL_STATUS_CORRUPT_DATA);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   289
	 * Missing devices in a replicated config.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
	 */
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   291
	if (find_vdev_problem(nvroot, vdev_faulted))
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   292
		return (ZPOOL_STATUS_FAULTED_DEV_R);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   293
	if (find_vdev_problem(nvroot, vdev_missing))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   294
		return (ZPOOL_STATUS_MISSING_DEV_R);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   295
	if (find_vdev_problem(nvroot, vdev_broken))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   296
		return (ZPOOL_STATUS_CORRUPT_LABEL_R);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
	 * Devices with errors
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	if (!isimport && find_vdev_problem(nvroot, vdev_errors))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
		return (ZPOOL_STATUS_FAILING_DEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
	 * Offlined devices
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	if (find_vdev_problem(nvroot, vdev_offlined))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
		return (ZPOOL_STATUS_OFFLINE_DEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	/*
10151
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   311
	 * Removed device
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   312
	 */
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   313
	if (find_vdev_problem(nvroot, vdev_removed))
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   314
		return (ZPOOL_STATUS_REMOVED_DEV);
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   315
3e86bccfd4da 6793967 zpool status -x sometimes incorrect.
George Wilson <George.Wilson@Sun.COM>
parents: 7754
diff changeset
   316
	/*
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   317
	 * Outdated, but usable, version
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
	 */
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 12296
diff changeset
   319
	if (SPA_VERSION_IS_SUPPORTED(version) && version != SPA_VERSION)
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   320
		return (ZPOOL_STATUS_VERSION_OLDER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
	return (ZPOOL_STATUS_OK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
zpool_status_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
zpool_get_status(zpool_handle_t *zhp, char **msgid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   328
	zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
	if (ret >= NMSGID)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
		*msgid = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
	else
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 3975
diff changeset
   333
		*msgid = zfs_msgid_table[ret];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
zpool_status_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
zpool_import_status(nvlist_t *config, char **msgid)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7294
diff changeset
   341
	zpool_status_t ret = check_status(config, B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
	if (ret >= NMSGID)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
		*msgid = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
	else
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 2082
diff changeset
   346
		*msgid = zfs_msgid_table[ret];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
}
11149
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   350
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   351
static void
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   352
dump_ddt_stat(const ddt_stat_t *dds, int h)
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   353
{
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   354
	char refcnt[6];
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   355
	char blocks[6], lsize[6], psize[6], dsize[6];
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   356
	char ref_blocks[6], ref_lsize[6], ref_psize[6], ref_dsize[6];
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   357
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   358
	if (dds == NULL || dds->dds_blocks == 0)
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   359
		return;
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   360
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   361
	if (h == -1)
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   362
		(void) strcpy(refcnt, "Total");
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   363
	else
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   364
		zfs_nicenum(1ULL << h, refcnt, sizeof (refcnt));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   365
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   366
	zfs_nicenum(dds->dds_blocks, blocks, sizeof (blocks));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   367
	zfs_nicenum(dds->dds_lsize, lsize, sizeof (lsize));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   368
	zfs_nicenum(dds->dds_psize, psize, sizeof (psize));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   369
	zfs_nicenum(dds->dds_dsize, dsize, sizeof (dsize));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   370
	zfs_nicenum(dds->dds_ref_blocks, ref_blocks, sizeof (ref_blocks));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   371
	zfs_nicenum(dds->dds_ref_lsize, ref_lsize, sizeof (ref_lsize));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   372
	zfs_nicenum(dds->dds_ref_psize, ref_psize, sizeof (ref_psize));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   373
	zfs_nicenum(dds->dds_ref_dsize, ref_dsize, sizeof (ref_dsize));
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   374
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   375
	(void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   376
	    refcnt,
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   377
	    blocks, lsize, psize, dsize,
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   378
	    ref_blocks, ref_lsize, ref_psize, ref_dsize);
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   379
}
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   380
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   381
/*
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   382
 * Print the DDT histogram and the column totals.
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   383
 */
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   384
void
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   385
zpool_dump_ddt(const ddt_stat_t *dds_total, const ddt_histogram_t *ddh)
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   386
{
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   387
	int h;
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   388
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   389
	(void) printf("\n");
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   390
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   391
	(void) printf("bucket   "
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   392
	    "           allocated             "
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   393
	    "          referenced          \n");
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   394
	(void) printf("______   "
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   395
	    "______________________________   "
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   396
	    "______________________________\n");
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   397
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   398
	(void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   399
	    "refcnt",
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   400
	    "blocks", "LSIZE", "PSIZE", "DSIZE",
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   401
	    "blocks", "LSIZE", "PSIZE", "DSIZE");
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   402
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   403
	(void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   404
	    "------",
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   405
	    "------", "-----", "-----", "-----",
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   406
	    "------", "-----", "-----", "-----");
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   407
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   408
	for (h = 0; h < 64; h++)
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   409
		dump_ddt_stat(&ddh->ddh_stat[h], h);
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   410
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   411
	dump_ddt_stat(dds_total, -1);
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   412
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   413
	(void) printf("\n");
8bad7424e2c2 6903731 need userland dedup stats
George Wilson <George.Wilson@Sun.COM>
parents: 10151
diff changeset
   414
}