usr/src/lib/libzfs/common/libzfs_pool.c
author Joshua M. Clulow <jmc@joyent.com>
Mon, 04 Mar 2013 23:52:56 +0000
changeset 14188 afe390b9f1e0
parent 14162 dc75c925d8aa
permissions -rw-r--r--
4020 Make ldi_ev_remove_callbacks safe to use in LDI callbacks Reviewed by: Robert Mustacchi <[email protected]> Approved by: Dan McDonald <[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
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1354
diff changeset
     5
 * Common Development and Distribution License (the "License").
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1354
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: 1773
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: 11814
diff changeset
    23
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
    24
 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
    25
 * Copyright (c) 2012 by Delphix. All rights reserved.
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
    26
 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <ctype.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <devid.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <fcntl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <libintl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <stdio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <stdlib.h>
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2926
diff changeset
    36
#include <strings.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <unistd.h>
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
    38
#include <libgen.h>
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: 3912
diff changeset
    39
#include <sys/efi_partition.h>
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
    40
#include <sys/vtoc.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/zfs_ioctl.h>
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    42
#include <dlfcn.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include "zfs_namecheck.h"
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
    45
#include "zfs_prop.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include "libzfs_impl.h"
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
    47
#include "zfs_comutil.h"
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
    48
#include "zfeature_common.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
    50
static int read_efi_label(nvlist_t *config, diskaddr_t *sb);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    51
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    52
#define	DISK_ROOT	"/dev/dsk"
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    53
#define	RDISK_ROOT	"/dev/rdsk"
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    54
#define	BACKUP_SLICE	"s2"
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    55
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
    56
typedef struct prop_flags {
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
    57
	int create:1;	/* Validate property on creation */
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
    58
	int import:1;	/* Validate property on import */
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
    59
} prop_flags_t;
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
    60
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    61
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    62
 * ====================================================================
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    63
 *   zpool property functions
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    64
 * ====================================================================
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    65
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    66
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    67
static int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    68
zpool_get_all_props(zpool_handle_t *zhp)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    69
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    70
	zfs_cmd_t zc = { 0 };
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    71
	libzfs_handle_t *hdl = zhp->zpool_hdl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    72
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    73
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    74
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    75
	if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    76
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    77
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    78
	while (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_GET_PROPS, &zc) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    79
		if (errno == ENOMEM) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    80
			if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    81
				zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    82
				return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    83
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    84
		} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    85
			zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    86
			return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    87
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    88
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    89
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    90
	if (zcmd_read_dst_nvlist(hdl, &zc, &zhp->zpool_props) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    91
		zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    92
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    93
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    94
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    95
	zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    96
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    97
	return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    98
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    99
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   100
static int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   101
zpool_props_refresh(zpool_handle_t *zhp)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   102
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   103
	nvlist_t *old_props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   104
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   105
	old_props = zhp->zpool_props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   106
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   107
	if (zpool_get_all_props(zhp) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   108
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   109
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   110
	nvlist_free(old_props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   111
	return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   112
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   113
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   114
static char *
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   115
zpool_get_prop_string(zpool_handle_t *zhp, zpool_prop_t prop,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   116
    zprop_source_t *src)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   117
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   118
	nvlist_t *nv, *nvl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   119
	uint64_t ival;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   120
	char *value;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   121
	zprop_source_t source;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   122
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   123
	nvl = zhp->zpool_props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   124
	if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   125
		verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &ival) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   126
		source = ival;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   127
		verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   128
	} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   129
		source = ZPROP_SRC_DEFAULT;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   130
		if ((value = (char *)zpool_prop_default_string(prop)) == NULL)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   131
			value = "-";
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   132
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   133
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   134
	if (src)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   135
		*src = source;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   136
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   137
	return (value);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   138
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   139
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   140
uint64_t
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   141
zpool_get_prop_int(zpool_handle_t *zhp, zpool_prop_t prop, zprop_source_t *src)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   142
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   143
	nvlist_t *nv, *nvl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   144
	uint64_t value;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   145
	zprop_source_t source;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   146
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   147
	if (zhp->zpool_props == NULL && zpool_get_all_props(zhp)) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   148
		/*
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   149
		 * zpool_get_all_props() has most likely failed because
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   150
		 * the pool is faulted, but if all we need is the top level
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   151
		 * vdev's guid then get it from the zhp config nvlist.
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   152
		 */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   153
		if ((prop == ZPOOL_PROP_GUID) &&
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   154
		    (nvlist_lookup_nvlist(zhp->zpool_config,
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   155
		    ZPOOL_CONFIG_VDEV_TREE, &nv) == 0) &&
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   156
		    (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &value)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   157
		    == 0)) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   158
			return (value);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   159
		}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   160
		return (zpool_prop_default_numeric(prop));
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   161
	}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   162
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   163
	nvl = zhp->zpool_props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   164
	if (nvlist_lookup_nvlist(nvl, zpool_prop_to_name(prop), &nv) == 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   165
		verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   166
		source = value;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   167
		verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   168
	} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   169
		source = ZPROP_SRC_DEFAULT;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   170
		value = zpool_prop_default_numeric(prop);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   171
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   172
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   173
	if (src)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   174
		*src = source;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   175
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   176
	return (value);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   177
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   178
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   179
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   180
 * Map VDEV STATE to printed strings.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   181
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   182
char *
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   183
zpool_state_to_name(vdev_state_t state, vdev_aux_t aux)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   184
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   185
	switch (state) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   186
	case VDEV_STATE_CLOSED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   187
	case VDEV_STATE_OFFLINE:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   188
		return (gettext("OFFLINE"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   189
	case VDEV_STATE_REMOVED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   190
		return (gettext("REMOVED"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   191
	case VDEV_STATE_CANT_OPEN:
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   192
		if (aux == VDEV_AUX_CORRUPT_DATA || aux == VDEV_AUX_BAD_LOG)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   193
			return (gettext("FAULTED"));
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
   194
		else if (aux == VDEV_AUX_SPLIT_POOL)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
   195
			return (gettext("SPLIT"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   196
		else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   197
			return (gettext("UNAVAIL"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   198
	case VDEV_STATE_FAULTED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   199
		return (gettext("FAULTED"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   200
	case VDEV_STATE_DEGRADED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   201
		return (gettext("DEGRADED"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   202
	case VDEV_STATE_HEALTHY:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   203
		return (gettext("ONLINE"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   204
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   205
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   206
	return (gettext("UNKNOWN"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   207
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   208
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   209
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   210
 * Get a zpool property value for 'prop' and return the value in
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   211
 * a pre-allocated buffer.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   212
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   213
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   214
zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   215
    zprop_source_t *srctype)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   216
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   217
	uint64_t intval;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   218
	const char *strval;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   219
	zprop_source_t src = ZPROP_SRC_NONE;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   220
	nvlist_t *nvroot;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   221
	vdev_stat_t *vs;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   222
	uint_t vsc;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   223
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   224
	if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   225
		switch (prop) {
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   226
		case ZPOOL_PROP_NAME:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   227
			(void) strlcpy(buf, zpool_get_name(zhp), len);
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   228
			break;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   229
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   230
		case ZPOOL_PROP_HEALTH:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   231
			(void) strlcpy(buf, "FAULTED", len);
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   232
			break;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   233
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   234
		case ZPOOL_PROP_GUID:
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   235
			intval = zpool_get_prop_int(zhp, prop, &src);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   236
			(void) snprintf(buf, len, "%llu", intval);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   237
			break;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   238
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   239
		case ZPOOL_PROP_ALTROOT:
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   240
		case ZPOOL_PROP_CACHEFILE:
13525
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   241
		case ZPOOL_PROP_COMMENT:
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   242
			if (zhp->zpool_props != NULL ||
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   243
			    zpool_get_all_props(zhp) == 0) {
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   244
				(void) strlcpy(buf,
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   245
				    zpool_get_prop_string(zhp, prop, &src),
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   246
				    len);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   247
				if (srctype != NULL)
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   248
					*srctype = src;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   249
				return (0);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   250
			}
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   251
			/* FALLTHROUGH */
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   252
		default:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   253
			(void) strlcpy(buf, "-", len);
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   254
			break;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   255
		}
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   256
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   257
		if (srctype != NULL)
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   258
			*srctype = src;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   259
		return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   260
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   261
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   262
	if (zhp->zpool_props == NULL && zpool_get_all_props(zhp) &&
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   263
	    prop != ZPOOL_PROP_NAME)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   264
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   265
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   266
	switch (zpool_prop_get_type(prop)) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   267
	case PROP_TYPE_STRING:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   268
		(void) strlcpy(buf, zpool_get_prop_string(zhp, prop, &src),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   269
		    len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   270
		break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   271
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   272
	case PROP_TYPE_NUMBER:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   273
		intval = zpool_get_prop_int(zhp, prop, &src);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   274
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   275
		switch (prop) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   276
		case ZPOOL_PROP_SIZE:
10956
0c81acaaf614 6897693 deduplication can only go so far
George Wilson <George.Wilson@Sun.COM>
parents: 10922
diff changeset
   277
		case ZPOOL_PROP_ALLOCATED:
0c81acaaf614 6897693 deduplication can only go so far
George Wilson <George.Wilson@Sun.COM>
parents: 10922
diff changeset
   278
		case ZPOOL_PROP_FREE:
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   279
		case ZPOOL_PROP_FREEING:
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
   280
		case ZPOOL_PROP_EXPANDSZ:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   281
			(void) zfs_nicenum(intval, buf, len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   282
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   283
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   284
		case ZPOOL_PROP_CAPACITY:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   285
			(void) snprintf(buf, len, "%llu%%",
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   286
			    (u_longlong_t)intval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   287
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   288
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   289
		case ZPOOL_PROP_DEDUPRATIO:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   290
			(void) snprintf(buf, len, "%llu.%02llux",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   291
			    (u_longlong_t)(intval / 100),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   292
			    (u_longlong_t)(intval % 100));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   293
			break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   294
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   295
		case ZPOOL_PROP_HEALTH:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   296
			verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   297
			    ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   298
			verify(nvlist_lookup_uint64_array(nvroot,
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
   299
			    ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &vsc)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
   300
			    == 0);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   301
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   302
			(void) strlcpy(buf, zpool_state_to_name(intval,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   303
			    vs->vs_aux), len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   304
			break;
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   305
		case ZPOOL_PROP_VERSION:
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   306
			if (intval >= SPA_VERSION_FEATURES) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   307
				(void) snprintf(buf, len, "-");
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   308
				break;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   309
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   310
			/* FALLTHROUGH */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   311
		default:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   312
			(void) snprintf(buf, len, "%llu", intval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   313
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   314
		break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   315
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   316
	case PROP_TYPE_INDEX:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   317
		intval = zpool_get_prop_int(zhp, prop, &src);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   318
		if (zpool_prop_index_to_string(prop, intval, &strval)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   319
		    != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   320
			return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   321
		(void) strlcpy(buf, strval, len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   322
		break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   323
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   324
	default:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   325
		abort();
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   326
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   327
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   328
	if (srctype)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   329
		*srctype = src;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   330
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   331
	return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   332
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   333
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   334
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   335
 * Check if the bootfs name has the same pool name as it is set to.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   336
 * Assuming bootfs is a valid dataset name.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   337
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   338
static boolean_t
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   339
bootfs_name_valid(const char *pool, char *bootfs)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   340
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   341
	int len = strlen(pool);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   342
7300
3f0c3af330d3 6667976 support booting up a snapshot root dataset
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   343
	if (!zfs_name_valid(bootfs, ZFS_TYPE_FILESYSTEM|ZFS_TYPE_SNAPSHOT))
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   344
		return (B_FALSE);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   345
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   346
	if (strncmp(pool, bootfs, len) == 0 &&
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   347
	    (bootfs[len] == '/' || bootfs[len] == '\0'))
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   348
		return (B_TRUE);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   349
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   350
	return (B_FALSE);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   351
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   352
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   353
/*
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   354
 * Inspect the configuration to determine if any of the devices contain
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   355
 * an EFI label.
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   356
 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   357
static boolean_t
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   358
pool_uses_efi(nvlist_t *config)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   359
{
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   360
	nvlist_t **child;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   361
	uint_t c, children;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   362
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   363
	if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   364
	    &child, &children) != 0)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   365
		return (read_efi_label(config, NULL) >= 0);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   366
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   367
	for (c = 0; c < children; c++) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   368
		if (pool_uses_efi(child[c]))
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   369
			return (B_TRUE);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   370
	}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   371
	return (B_FALSE);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   372
}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   373
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
   374
boolean_t
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
   375
zpool_is_bootable(zpool_handle_t *zhp)
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   376
{
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   377
	char bootfs[ZPOOL_MAXNAMELEN];
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   378
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   379
	return (zpool_get_prop(zhp, ZPOOL_PROP_BOOTFS, bootfs,
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   380
	    sizeof (bootfs), NULL) == 0 && strncmp(bootfs, "-",
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   381
	    sizeof (bootfs)) != 0);
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   382
}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   383
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   384
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   385
/*
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   386
 * Given an nvlist of zpool properties to be set, validate that they are
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   387
 * correct, and parse any numeric properties (index, boolean, etc) if they are
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   388
 * specified as strings.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   389
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   390
static nvlist_t *
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   391
zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   392
    nvlist_t *props, uint64_t version, prop_flags_t flags, char *errbuf)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   393
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   394
	nvpair_t *elem;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   395
	nvlist_t *retprops;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   396
	zpool_prop_t prop;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   397
	char *strval;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   398
	uint64_t intval;
13525
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   399
	char *slash, *check;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   400
	struct stat64 statbuf;
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   401
	zpool_handle_t *zhp;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   402
	nvlist_t *nvroot;
5094
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
	if (nvlist_alloc(&retprops, NV_UNIQUE_NAME, 0) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   405
		(void) no_memory(hdl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   406
		return (NULL);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   407
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   408
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   409
	elem = NULL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   410
	while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   411
		const char *propname = nvpair_name(elem);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   412
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   413
		prop = zpool_name_to_prop(propname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   414
		if (prop == ZPROP_INVAL && zpool_prop_feature(propname)) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   415
			int err;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   416
			zfeature_info_t *feature;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   417
			char *fname = strchr(propname, '@') + 1;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   418
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   419
			err = zfeature_lookup_name(fname, &feature);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   420
			if (err != 0) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   421
				ASSERT3U(err, ==, ENOENT);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   422
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   423
				    "invalid feature '%s'"), fname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   424
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   425
				goto error;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   426
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   427
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   428
			if (nvpair_type(elem) != DATA_TYPE_STRING) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   429
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   430
				    "'%s' must be a string"), propname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   431
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   432
				goto error;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   433
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   434
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   435
			(void) nvpair_value_string(elem, &strval);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   436
			if (strcmp(strval, ZFS_FEATURE_ENABLED) != 0) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   437
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   438
				    "property '%s' can only be set to "
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   439
				    "'enabled'"), propname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   440
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   441
				goto error;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   442
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   443
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   444
			if (nvlist_add_uint64(retprops, propname, 0) != 0) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   445
				(void) no_memory(hdl);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   446
				goto error;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   447
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   448
			continue;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   449
		}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   450
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   451
		/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   452
		 * Make sure this property is valid and applies to this type.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   453
		 */
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   454
		if (prop == ZPROP_INVAL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   455
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   456
			    "invalid property '%s'"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   457
			(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   458
			goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   459
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   460
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   461
		if (zpool_prop_readonly(prop)) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   462
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   463
			    "is readonly"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   464
			(void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   465
			goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   466
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   467
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   468
		if (zprop_parse_value(hdl, elem, prop, ZFS_TYPE_POOL, retprops,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   469
		    &strval, &intval, errbuf) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   470
			goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   471
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   472
		/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   473
		 * Perform additional checking for specific properties.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   474
		 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   475
		switch (prop) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   476
		case ZPOOL_PROP_VERSION:
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   477
			if (intval < version ||
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   478
			    !SPA_VERSION_IS_SUPPORTED(intval)) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   479
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   480
				    "property '%s' number %d is invalid."),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   481
				    propname, intval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   482
				(void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   483
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   484
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   485
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   486
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   487
		case ZPOOL_PROP_BOOTFS:
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   488
			if (flags.create || flags.import) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   489
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   490
				    "property '%s' cannot be set at creation "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   491
				    "or import time"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   492
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   493
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   494
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   495
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   496
			if (version < SPA_VERSION_BOOTFS) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   497
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   498
				    "pool must be upgraded to support "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   499
				    "'%s' property"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   500
				(void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   501
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   502
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   503
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   504
			/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   505
			 * bootfs property value has to be a dataset name and
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   506
			 * the dataset has to be in the same pool as it sets to.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   507
			 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   508
			if (strval[0] != '\0' && !bootfs_name_valid(poolname,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   509
			    strval)) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   510
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   511
				    "is an invalid name"), strval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   512
				(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   513
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   514
			}
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   515
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   516
			if ((zhp = zpool_open_canfail(hdl, poolname)) == NULL) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   517
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   518
				    "could not open pool '%s'"), poolname);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   519
				(void) zfs_error(hdl, EZFS_OPENFAILED, errbuf);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   520
				goto error;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   521
			}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   522
			verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   523
			    ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   524
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   525
			/*
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   526
			 * bootfs property cannot be set on a disk which has
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   527
			 * been EFI labeled.
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   528
			 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   529
			if (pool_uses_efi(nvroot)) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   530
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   531
				    "property '%s' not supported on "
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   532
				    "EFI labeled devices"), propname);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   533
				(void) zfs_error(hdl, EZFS_POOL_NOTSUP, errbuf);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   534
				zpool_close(zhp);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   535
				goto error;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   536
			}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   537
			zpool_close(zhp);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   538
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   539
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   540
		case ZPOOL_PROP_ALTROOT:
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   541
			if (!flags.create && !flags.import) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   542
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   543
				    "property '%s' can only be set during pool "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   544
				    "creation or import"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   545
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   546
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   547
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   548
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   549
			if (strval[0] != '/') {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   550
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   551
				    "bad alternate root '%s'"), strval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   552
				(void) zfs_error(hdl, EZFS_BADPATH, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   553
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   554
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   555
			break;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   556
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   557
		case ZPOOL_PROP_CACHEFILE:
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   558
			if (strval[0] == '\0')
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   559
				break;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   560
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   561
			if (strcmp(strval, "none") == 0)
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   562
				break;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   563
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   564
			if (strval[0] != '/') {
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   565
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   566
				    "property '%s' must be empty, an "
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   567
				    "absolute path, or 'none'"), propname);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   568
				(void) zfs_error(hdl, EZFS_BADPATH, errbuf);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   569
				goto error;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   570
			}
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   571
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   572
			slash = strrchr(strval, '/');
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   573
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   574
			if (slash[1] == '\0' || strcmp(slash, "/.") == 0 ||
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   575
			    strcmp(slash, "/..") == 0) {
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   576
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   577
				    "'%s' is not a valid file"), strval);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   578
				(void) zfs_error(hdl, EZFS_BADPATH, errbuf);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   579
				goto error;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   580
			}
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   581
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   582
			*slash = '\0';
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   583
5621
cd0984d5b1c1 6627006 setting cachefile to default value confuses ZFS
eschrock
parents: 5450
diff changeset
   584
			if (strval[0] != '\0' &&
cd0984d5b1c1 6627006 setting cachefile to default value confuses ZFS
eschrock
parents: 5450
diff changeset
   585
			    (stat64(strval, &statbuf) != 0 ||
cd0984d5b1c1 6627006 setting cachefile to default value confuses ZFS
eschrock
parents: 5450
diff changeset
   586
			    !S_ISDIR(statbuf.st_mode))) {
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   587
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   588
				    "'%s' is not a valid directory"),
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   589
				    strval);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   590
				(void) zfs_error(hdl, EZFS_BADPATH, errbuf);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   591
				goto error;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   592
			}
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   593
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   594
			*slash = '/';
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   595
			break;
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   596
13525
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   597
		case ZPOOL_PROP_COMMENT:
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   598
			for (check = strval; *check != '\0'; check++) {
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   599
				if (!isprint(*check)) {
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   600
					zfs_error_aux(hdl,
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   601
					    dgettext(TEXT_DOMAIN,
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   602
					    "comment may only have printable "
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   603
					    "characters"));
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   604
					(void) zfs_error(hdl, EZFS_BADPROP,
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   605
					    errbuf);
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   606
					goto error;
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   607
				}
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   608
			}
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   609
			if (strlen(strval) > ZPROP_MAX_COMMENT) {
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   610
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   611
				    "comment must not exceed %d characters"),
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   612
				    ZPROP_MAX_COMMENT);
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   613
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   614
				goto error;
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   615
			}
7059b67f1bc2 1693 persistent 'comment' field for a zpool
Dan McDonald <danmcd@nexenta.com>
parents: 13514
diff changeset
   616
			break;
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   617
		case ZPOOL_PROP_READONLY:
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   618
			if (!flags.import) {
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   619
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   620
				    "property '%s' can only be set at "
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   621
				    "import time"), propname);
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   622
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   623
				goto error;
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   624
			}
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   625
			break;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   626
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   627
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   628
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   629
	return (retprops);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   630
error:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   631
	nvlist_free(retprops);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   632
	return (NULL);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   633
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   634
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   635
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   636
 * Set zpool property : propname=propval.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   637
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   638
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   639
zpool_set_prop(zpool_handle_t *zhp, const char *propname, const char *propval)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   640
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   641
	zfs_cmd_t zc = { 0 };
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   642
	int ret = -1;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   643
	char errbuf[1024];
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   644
	nvlist_t *nvl = NULL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   645
	nvlist_t *realprops;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   646
	uint64_t version;
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   647
	prop_flags_t flags = { 0 };
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   648
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   649
	(void) snprintf(errbuf, sizeof (errbuf),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   650
	    dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   651
	    zhp->zpool_name);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   652
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   653
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   654
		return (no_memory(zhp->zpool_hdl));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   655
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   656
	if (nvlist_add_string(nvl, propname, propval) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   657
		nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   658
		return (no_memory(zhp->zpool_hdl));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   659
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   660
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   661
	version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   662
	if ((realprops = zpool_valid_proplist(zhp->zpool_hdl,
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
   663
	    zhp->zpool_name, nvl, version, flags, errbuf)) == NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   664
		nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   665
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   666
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   667
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   668
	nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   669
	nvl = realprops;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   670
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   671
	/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   672
	 * Execute the corresponding ioctl() to set this property.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   673
	 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   674
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   675
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   676
	if (zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, nvl) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   677
		nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   678
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   679
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   680
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   681
	ret = zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_SET_PROPS, &zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   682
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   683
	zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   684
	nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   685
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   686
	if (ret)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   687
		(void) zpool_standard_error(zhp->zpool_hdl, errno, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   688
	else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   689
		(void) zpool_props_refresh(zhp);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   690
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   691
	return (ret);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   692
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   693
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   694
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   695
zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   696
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   697
	libzfs_handle_t *hdl = zhp->zpool_hdl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   698
	zprop_list_t *entry;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   699
	char buf[ZFS_MAXPROPLEN];
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   700
	nvlist_t *features = NULL;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   701
	zprop_list_t **last;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   702
	boolean_t firstexpand = (NULL == *plp);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   703
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   704
	if (zprop_expand_list(hdl, plp, ZFS_TYPE_POOL) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   705
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   706
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   707
	last = plp;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   708
	while (*last != NULL)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   709
		last = &(*last)->pl_next;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   710
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   711
	if ((*plp)->pl_all)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   712
		features = zpool_get_features(zhp);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   713
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   714
	if ((*plp)->pl_all && firstexpand) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   715
		for (int i = 0; i < SPA_FEATURES; i++) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   716
			zprop_list_t *entry = zfs_alloc(hdl,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   717
			    sizeof (zprop_list_t));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   718
			entry->pl_prop = ZPROP_INVAL;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   719
			entry->pl_user_prop = zfs_asprintf(hdl, "feature@%s",
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   720
			    spa_feature_table[i].fi_uname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   721
			entry->pl_width = strlen(entry->pl_user_prop);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   722
			entry->pl_all = B_TRUE;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   723
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   724
			*last = entry;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   725
			last = &entry->pl_next;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   726
		}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   727
	}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   728
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   729
	/* add any unsupported features */
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   730
	for (nvpair_t *nvp = nvlist_next_nvpair(features, NULL);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   731
	    nvp != NULL; nvp = nvlist_next_nvpair(features, nvp)) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   732
		char *propname;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   733
		boolean_t found;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   734
		zprop_list_t *entry;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   735
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   736
		if (zfeature_is_supported(nvpair_name(nvp)))
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   737
			continue;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   738
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   739
		propname = zfs_asprintf(hdl, "unsupported@%s",
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   740
		    nvpair_name(nvp));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   741
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   742
		/*
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   743
		 * Before adding the property to the list make sure that no
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   744
		 * other pool already added the same property.
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   745
		 */
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   746
		found = B_FALSE;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   747
		entry = *plp;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   748
		while (entry != NULL) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   749
			if (entry->pl_user_prop != NULL &&
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   750
			    strcmp(propname, entry->pl_user_prop) == 0) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   751
				found = B_TRUE;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   752
				break;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   753
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   754
			entry = entry->pl_next;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   755
		}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   756
		if (found) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   757
			free(propname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   758
			continue;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   759
		}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   760
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   761
		entry = zfs_alloc(hdl, sizeof (zprop_list_t));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   762
		entry->pl_prop = ZPROP_INVAL;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   763
		entry->pl_user_prop = propname;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   764
		entry->pl_width = strlen(entry->pl_user_prop);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   765
		entry->pl_all = B_TRUE;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   766
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   767
		*last = entry;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   768
		last = &entry->pl_next;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   769
	}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   770
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   771
	for (entry = *plp; entry != NULL; entry = entry->pl_next) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   772
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   773
		if (entry->pl_fixed)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   774
			continue;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   775
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   776
		if (entry->pl_prop != ZPROP_INVAL &&
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   777
		    zpool_get_prop(zhp, entry->pl_prop, buf, sizeof (buf),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   778
		    NULL) == 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   779
			if (strlen(buf) > entry->pl_width)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   780
				entry->pl_width = strlen(buf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   781
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   782
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   783
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   784
	return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   785
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   786
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   787
/*
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   788
 * Get the state for the given feature on the given ZFS pool.
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   789
 */
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   790
int
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   791
zpool_prop_get_feature(zpool_handle_t *zhp, const char *propname, char *buf,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   792
    size_t len)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   793
{
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   794
	uint64_t refcount;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   795
	boolean_t found = B_FALSE;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   796
	nvlist_t *features = zpool_get_features(zhp);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   797
	boolean_t supported;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   798
	const char *feature = strchr(propname, '@') + 1;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   799
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   800
	supported = zpool_prop_feature(propname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   801
	ASSERT(supported || zfs_prop_unsupported(propname));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   802
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   803
	/*
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   804
	 * Convert from feature name to feature guid. This conversion is
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   805
	 * unecessary for unsupported@... properties because they already
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   806
	 * use guids.
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   807
	 */
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   808
	if (supported) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   809
		int ret;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   810
		zfeature_info_t *fi;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   811
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   812
		ret = zfeature_lookup_name(feature, &fi);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   813
		if (ret != 0) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   814
			(void) strlcpy(buf, "-", len);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   815
			return (ENOTSUP);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   816
		}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   817
		feature = fi->fi_guid;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   818
	}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   819
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   820
	if (nvlist_lookup_uint64(features, feature, &refcount) == 0)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   821
		found = B_TRUE;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   822
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   823
	if (supported) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   824
		if (!found) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   825
			(void) strlcpy(buf, ZFS_FEATURE_DISABLED, len);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   826
		} else  {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   827
			if (refcount == 0)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   828
				(void) strlcpy(buf, ZFS_FEATURE_ENABLED, len);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   829
			else
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   830
				(void) strlcpy(buf, ZFS_FEATURE_ACTIVE, len);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   831
		}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   832
	} else {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   833
		if (found) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   834
			if (refcount == 0) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   835
				(void) strcpy(buf, ZFS_UNSUPPORTED_INACTIVE);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   836
			} else {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   837
				(void) strcpy(buf, ZFS_UNSUPPORTED_READONLY);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   838
			}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   839
		} else {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   840
			(void) strlcpy(buf, "-", len);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   841
			return (ENOTSUP);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   842
		}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   843
	}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   844
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   845
	return (0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
   846
}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   847
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   849
 * Don't start the slice at the default block of 34; many storage
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   850
 * devices will use a stripe width of 128k, so start there instead.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   851
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   852
#define	NEW_START_BLOCK	256
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   853
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   854
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
 * Validate the given pool name, optionally putting an extended error message in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
 * 'buf'.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
 */
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   858
boolean_t
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   859
zpool_name_valid(libzfs_handle_t *hdl, boolean_t isopen, const char *pool)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
	namecheck_err_t why;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
	char what;
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   863
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   865
	ret = pool_namecheck(pool, &why, &what);
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   866
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   867
	/*
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   868
	 * The rules for reserved pool names were extended at a later point.
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   869
	 * But we need to support users with existing pools that may now be
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   870
	 * invalid.  So we only check for this expanded set of names during a
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   871
	 * create (or import), and only in userland.
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   872
	 */
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   873
	if (ret == 0 && !isopen &&
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   874
	    (strncmp(pool, "mirror", 6) == 0 ||
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   875
	    strncmp(pool, "raidz", 5) == 0 ||
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   876
	    strncmp(pool, "spare", 5) == 0 ||
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   877
	    strcmp(pool, "log") == 0)) {
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   878
		if (hdl != NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   879
			zfs_error_aux(hdl,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   880
			    dgettext(TEXT_DOMAIN, "name is reserved"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   881
		return (B_FALSE);
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   882
	}
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   883
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   884
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   885
	if (ret != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   886
		if (hdl != NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
			switch (why) {
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   888
			case NAME_ERR_TOOLONG:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   889
				zfs_error_aux(hdl,
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   890
				    dgettext(TEXT_DOMAIN, "name is too long"));
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   891
				break;
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   892
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
			case NAME_ERR_INVALCHAR:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   894
				zfs_error_aux(hdl,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
				    dgettext(TEXT_DOMAIN, "invalid character "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
				    "'%c' in pool name"), what);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
			case NAME_ERR_NOLETTER:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   900
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   901
				    "name must begin with a letter"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
			case NAME_ERR_RESERVED:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   905
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   906
				    "name is reserved"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
			case NAME_ERR_DISKLIKE:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   910
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   911
				    "pool name is reserved"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
				break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   913
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   914
			case NAME_ERR_LEADING_SLASH:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   915
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   916
				    "leading slash in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   917
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   918
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   919
			case NAME_ERR_EMPTY_COMPONENT:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   920
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   921
				    "empty component in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   922
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   923
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   924
			case NAME_ERR_TRAILING_SLASH:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   925
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   926
				    "trailing slash in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   927
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   928
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   929
			case NAME_ERR_MULTIPLE_AT:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   930
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   931
				    "multiple '@' delimiters in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   932
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   933
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   936
		return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   939
	return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
 * Open a handle to the given pool, even if the pool is currently in the FAULTED
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
 * state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
zpool_handle_t *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   947
zpool_open_canfail(libzfs_handle_t *hdl, const char *pool)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
	zpool_handle_t *zhp;
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   950
	boolean_t missing;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
	 * Make sure the pool name is valid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   955
	if (!zpool_name_valid(hdl, B_TRUE, pool)) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
   956
		(void) zfs_error_fmt(hdl, EZFS_INVALIDNAME,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   957
		    dgettext(TEXT_DOMAIN, "cannot open '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   958
		    pool);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   962
	if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   963
		return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   965
	zhp->zpool_hdl = hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
	(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   968
	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
   969
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   970
		return (NULL);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   971
	}
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   972
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   973
	if (missing) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   974
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "no such pool"));
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
   975
		(void) zfs_error_fmt(hdl, EZFS_NOENT,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   976
		    dgettext(TEXT_DOMAIN, "cannot open '%s'"), pool);
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   977
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   978
		return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
 * Like the above, but silent on error.  Used when iterating over pools (because
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
 * the configuration cache may be out of date).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
 */
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   988
int
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   989
zpool_open_silent(libzfs_handle_t *hdl, const char *pool, zpool_handle_t **ret)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
	zpool_handle_t *zhp;
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   992
	boolean_t missing;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   994
	if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   995
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   997
	zhp->zpool_hdl = hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
	(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1000
	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
  1001
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1002
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1005
	if (missing) {
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1006
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1007
		*ret = NULL;
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1008
		return (0);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1009
	}
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1010
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1011
	*ret = zhp;
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1012
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
 * Similar to zpool_open_canfail(), but refuses to open pools in the faulted
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
 * state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
zpool_handle_t *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1020
zpool_open(libzfs_handle_t *hdl, const char *pool)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
	zpool_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1024
	if ((zhp = zpool_open_canfail(hdl, pool)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	if (zhp->zpool_state == POOL_STATE_UNAVAIL) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  1028
		(void) zfs_error_fmt(hdl, EZFS_POOLUNAVAIL,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1029
		    dgettext(TEXT_DOMAIN, "cannot open '%s'"), zhp->zpool_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
 * Close the handle.  Simply frees the memory associated with the handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
zpool_close(zpool_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
	if (zhp->zpool_config)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
		nvlist_free(zhp->zpool_config);
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1045
	if (zhp->zpool_old_config)
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
  1046
		nvlist_free(zhp->zpool_old_config);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1047
	if (zhp->zpool_props)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1048
		nvlist_free(zhp->zpool_props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
	free(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
 * Return the name of the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
zpool_get_name(zpool_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
	return (zhp->zpool_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1060
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
 * Return the state of the pool (ACTIVE or UNAVAILABLE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
zpool_get_state(zpool_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
	return (zhp->zpool_state);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
 * Create the named pool, using the provided vdev list.  It is assumed
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
 * that the consumer has already validated the contents of the nvlist, so we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
 * don't have to worry about error semantics.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1077
zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot,
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1078
    nvlist_t *props, nvlist_t *fsprops)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	zfs_cmd_t zc = { 0 };
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1081
	nvlist_t *zc_fsprops = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1082
	nvlist_t *zc_props = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1083
	char msg[1024];
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1084
	int ret = -1;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1085
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1086
	(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1087
	    "cannot create '%s'"), pool);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1089
	if (!zpool_name_valid(hdl, B_FALSE, pool))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1090
		return (zfs_error(hdl, EZFS_INVALIDNAME, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1091
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1092
	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1093
		return (-1);
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1094
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1095
	if (props) {
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
  1096
		prop_flags_t flags = { .create = B_TRUE, .import = B_FALSE };
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
  1097
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1098
		if ((zc_props = zpool_valid_proplist(hdl, pool, props,
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
  1099
		    SPA_VERSION_1, flags, msg)) == NULL) {
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1100
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1101
		}
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1102
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1104
	if (fsprops) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1105
		uint64_t zoned;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1106
		char *zonestr;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1107
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1108
		zoned = ((nvlist_lookup_string(fsprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1109
		    zfs_prop_to_name(ZFS_PROP_ZONED), &zonestr) == 0) &&
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1110
		    strcmp(zonestr, "on") == 0);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1111
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1112
		if ((zc_fsprops = zfs_valid_proplist(hdl,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1113
		    ZFS_TYPE_FILESYSTEM, fsprops, zoned, NULL, msg)) == NULL) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1114
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1115
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1116
		if (!zc_props &&
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1117
		    (nvlist_alloc(&zc_props, NV_UNIQUE_NAME, 0) != 0)) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1118
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1119
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1120
		if (nvlist_add_nvlist(zc_props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1121
		    ZPOOL_ROOTFS_PROPS, zc_fsprops) != 0) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1122
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1123
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1124
	}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1125
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1126
	if (zc_props && zcmd_write_src_nvlist(hdl, &zc, zc_props) != 0)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1127
		goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1128
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1129
	(void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1131
	if ((ret = zfs_ioctl(hdl, ZFS_IOC_POOL_CREATE, &zc)) != 0) {
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1132
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1133
		zcmd_free_nvlists(&zc);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1134
		nvlist_free(zc_props);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1135
		nvlist_free(zc_fsprops);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1136
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
		case EBUSY:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
			 * This can happen if the user has specified the same
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
			 * device multiple times.  We can't reliably detect this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
			 * until we try to add it and see we already have a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
			 * label.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1145
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1146
			    "one or more vdevs refer to the same device"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1147
			return (zfs_error(hdl, EZFS_BADDEV, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
		case EOVERFLOW:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
			/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1151
			 * This occurs when one of the devices is below
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
			 * SPA_MINDEVSIZE.  Unfortunately, we can't detect which
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
			 * device was the problem device since there's no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
			 * reliable way to determine device size from userland.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
				char buf[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
				zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1161
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1162
				    "one or more devices is less than the "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1163
				    "minimum size (%s)"), buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
			}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1165
			return (zfs_error(hdl, EZFS_BADDEV, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
		case ENOSPC:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1168
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1169
			    "one or more devices is out of space"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1170
			return (zfs_error(hdl, EZFS_BADDEV, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1172
		case ENOTBLK:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1173
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1174
			    "cache device must be a disk or disk slice"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1175
			return (zfs_error(hdl, EZFS_BADDEV, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1176
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1178
			return (zpool_standard_error(hdl, errno, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1182
create_failed:
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1183
	zcmd_free_nvlists(&zc);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1184
	nvlist_free(zc_props);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1185
	nvlist_free(zc_fsprops);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1186
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
 * Destroy the given pool.  It is up to the caller to ensure that there are no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
 * datasets left in the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
int
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1194
zpool_destroy(zpool_handle_t *zhp, const char *log_str)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
	zfs_handle_t *zfp = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1198
	libzfs_handle_t *hdl = zhp->zpool_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1199
	char msg[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
	if (zhp->zpool_state == POOL_STATE_ACTIVE &&
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1202
	    (zfp = zfs_open(hdl, zhp->zpool_name, ZFS_TYPE_FILESYSTEM)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1206
	zc.zc_history = (uint64_t)(uintptr_t)log_str;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1208
	if (zfs_ioctl(hdl, ZFS_IOC_POOL_DESTROY, &zc) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1209
		(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1210
		    "cannot destroy '%s'"), zhp->zpool_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1212
		if (errno == EROFS) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1213
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1214
			    "one or more devices is read only"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1215
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1216
		} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1217
			(void) zpool_standard_error(hdl, errno, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
		if (zfp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1221
			zfs_close(zfp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
	if (zfp) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
		remove_mountpoint(zfp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
		zfs_close(zfp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
 * Add the given vdevs to the pool.  The caller must have already performed the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
 * necessary verification to ensure that the vdev specification is well-formed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
zpool_add(zpool_handle_t *zhp, nvlist_t *nvroot)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1240
	zfs_cmd_t zc = { 0 };
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1241
	int ret;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1242
	libzfs_handle_t *hdl = zhp->zpool_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1243
	char msg[1024];
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1244
	nvlist_t **spares, **l2cache;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1245
	uint_t nspares, nl2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1246
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1247
	(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1248
	    "cannot add to '%s'"), zhp->zpool_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1249
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1250
	if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) <
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1251
	    SPA_VERSION_SPARES &&
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1252
	    nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1253
	    &spares, &nspares) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1254
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1255
		    "upgraded to add hot spares"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1256
		return (zfs_error(hdl, EZFS_BADVERSION, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1257
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1258
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  1259
	if (zpool_is_bootable(zhp) && nvlist_lookup_nvlist_array(nvroot,
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1260
	    ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1261
		uint64_t s;
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1262
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1263
		for (s = 0; s < nspares; s++) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1264
			char *path;
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1265
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1266
			if (nvlist_lookup_string(spares[s], ZPOOL_CONFIG_PATH,
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1267
			    &path) == 0 && pool_uses_efi(spares[s])) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1268
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1269
				    "device '%s' contains an EFI label and "
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1270
				    "cannot be used on root pools."),
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1271
				    zpool_vdev_name(hdl, NULL, spares[s],
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1272
				    B_FALSE));
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1273
				return (zfs_error(hdl, EZFS_POOL_NOTSUP, msg));
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1274
			}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1275
		}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1276
	}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1277
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1278
	if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) <
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1279
	    SPA_VERSION_L2CACHE &&
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1280
	    nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1281
	    &l2cache, &nl2cache) == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1282
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be "
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1283
		    "upgraded to add cache devices"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1284
		return (zfs_error(hdl, EZFS_BADVERSION, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1285
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1286
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1287
	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1288
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1289
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1290
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1291
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_ADD, &zc) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1293
		case EBUSY:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1294
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1295
			 * This can happen if the user has specified the same
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1296
			 * device multiple times.  We can't reliably detect this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1297
			 * until we try to add it and see we already have a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1298
			 * label.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1299
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1300
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1301
			    "one or more vdevs refer to the same device"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1302
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1303
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1304
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1305
		case EOVERFLOW:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1307
			 * This occurrs when one of the devices is below
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
			 * SPA_MINDEVSIZE.  Unfortunately, we can't detect which
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
			 * device was the problem device since there's no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
			 * reliable way to determine device size from userland.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
				char buf[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
				zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1317
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1318
				    "device is less than the minimum "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1319
				    "size (%s)"), buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
			}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1321
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1322
			break;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1323
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1324
		case ENOTSUP:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1325
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1326
			    "pool must be upgraded to add these vdevs"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1327
			(void) zfs_error(hdl, EZFS_BADVERSION, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1330
		case EDOM:
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1331
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1332
			    "root pool can not have multiple vdevs"
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1333
			    " or separate logs"));
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1334
			(void) zfs_error(hdl, EZFS_POOL_NOTSUP, msg);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1335
			break;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1336
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1337
		case ENOTBLK:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1338
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1339
			    "cache device must be a disk or disk slice"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1340
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1341
			break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1342
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1344
			(void) zpool_standard_error(hdl, errno, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1346
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1347
		ret = -1;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1348
	} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1349
		ret = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1350
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1351
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1352
	zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1353
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1354
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1356
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1357
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1358
 * Exports the pool from the system.  The caller must ensure that there are no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
 * mounted datasets in the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
 */
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1361
static int
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1362
zpool_export_common(zpool_handle_t *zhp, boolean_t force, boolean_t hardforce,
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1363
    const char *log_str)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1365
	zfs_cmd_t zc = { 0 };
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
  1366
	char msg[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
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
  1368
	(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
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
  1369
	    "cannot export '%s'"), zhp->zpool_name);
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
  1370
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1371
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
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
  1372
	zc.zc_cookie = force;
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1373
	zc.zc_guid = hardforce;
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1374
	zc.zc_history = (uint64_t)(uintptr_t)log_str;
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
  1375
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
  1376
	if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_EXPORT, &zc) != 0) {
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
  1377
		switch (errno) {
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
  1378
		case EXDEV:
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
  1379
			zfs_error_aux(zhp->zpool_hdl, dgettext(TEXT_DOMAIN,
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
  1380
			    "use '-f' to override the following errors:\n"
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
  1381
			    "'%s' has an active shared spare which could be"
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
  1382
			    " used by other pools once '%s' is exported."),
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
  1383
			    zhp->zpool_name, zhp->zpool_name);
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
  1384
			return (zfs_error(zhp->zpool_hdl, EZFS_ACTIVE_SPARE,
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
  1385
			    msg));
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
  1386
		default:
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
  1387
			return (zpool_standard_error_fmt(zhp->zpool_hdl, errno,
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
  1388
			    msg));
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
  1389
		}
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
  1390
	}
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
  1391
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1395
int
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1396
zpool_export(zpool_handle_t *zhp, boolean_t force, const char *log_str)
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1397
{
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1398
	return (zpool_export_common(zhp, force, B_FALSE, log_str));
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1399
}
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1400
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1401
int
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1402
zpool_export_force(zpool_handle_t *zhp, const char *log_str)
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1403
{
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  1404
	return (zpool_export_common(zhp, B_TRUE, B_TRUE, log_str));
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1405
}
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1406
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1407
static void
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1408
zpool_rewind_exclaim(libzfs_handle_t *hdl, const char *name, boolean_t dryrun,
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1409
    nvlist_t *config)
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1410
{
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1411
	nvlist_t *nv = NULL;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1412
	uint64_t rewindto;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1413
	int64_t loss = -1;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1414
	struct tm t;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1415
	char timestr[128];
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1416
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1417
	if (!hdl->libzfs_printerr || config == NULL)
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1418
		return;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1419
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1420
	if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nv) != 0 ||
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1421
	    nvlist_lookup_nvlist(nv, ZPOOL_CONFIG_REWIND_INFO, &nv) != 0) {
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1422
		return;
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1423
	}
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1424
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1425
	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1426
		return;
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1427
	(void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1428
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1429
	if (localtime_r((time_t *)&rewindto, &t) != NULL &&
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1430
	    strftime(timestr, 128, 0, &t) != 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1431
		if (dryrun) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1432
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1433
			    "Would be able to return %s "
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1434
			    "to its state as of %s.\n"),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1435
			    name, timestr);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1436
		} else {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1437
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1438
			    "Pool %s returned to its state as of %s.\n"),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1439
			    name, timestr);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1440
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1441
		if (loss > 120) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1442
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1443
			    "%s approximately %lld "),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1444
			    dryrun ? "Would discard" : "Discarded",
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1445
			    (loss + 30) / 60);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1446
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1447
			    "minutes of transactions.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1448
		} else if (loss > 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1449
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1450
			    "%s approximately %lld "),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1451
			    dryrun ? "Would discard" : "Discarded", loss);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1452
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1453
			    "seconds of transactions.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1454
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1455
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1456
}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1457
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1458
void
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1459
zpool_explain_recover(libzfs_handle_t *hdl, const char *name, int reason,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1460
    nvlist_t *config)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1461
{
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1462
	nvlist_t *nv = NULL;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1463
	int64_t loss = -1;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1464
	uint64_t edata = UINT64_MAX;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1465
	uint64_t rewindto;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1466
	struct tm t;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1467
	char timestr[128];
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1468
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1469
	if (!hdl->libzfs_printerr)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1470
		return;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1471
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1472
	if (reason >= 0)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1473
		(void) printf(dgettext(TEXT_DOMAIN, "action: "));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1474
	else
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1475
		(void) printf(dgettext(TEXT_DOMAIN, "\t"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1476
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1477
	/* All attempted rewinds failed if ZPOOL_CONFIG_LOAD_TIME missing */
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1478
	if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nv) != 0 ||
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1479
	    nvlist_lookup_nvlist(nv, ZPOOL_CONFIG_REWIND_INFO, &nv) != 0 ||
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1480
	    nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1481
		goto no_info;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1482
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1483
	(void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1484
	(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_DATA_ERRORS,
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1485
	    &edata);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1486
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1487
	(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1488
	    "Recovery is possible, but will result in some data loss.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1489
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1490
	if (localtime_r((time_t *)&rewindto, &t) != NULL &&
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1491
	    strftime(timestr, 128, 0, &t) != 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1492
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1493
		    "\tReturning the pool to its state as of %s\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1494
		    "\tshould correct the problem.  "),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1495
		    timestr);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1496
	} else {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1497
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1498
		    "\tReverting the pool to an earlier state "
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1499
		    "should correct the problem.\n\t"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1500
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1501
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1502
	if (loss > 120) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1503
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1504
		    "Approximately %lld minutes of data\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1505
		    "\tmust be discarded, irreversibly.  "), (loss + 30) / 60);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1506
	} else if (loss > 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1507
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1508
		    "Approximately %lld seconds of data\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1509
		    "\tmust be discarded, irreversibly.  "), loss);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1510
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1511
	if (edata != 0 && edata != UINT64_MAX) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1512
		if (edata == 1) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1513
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1514
			    "After rewind, at least\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1515
			    "\tone persistent user-data error will remain.  "));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1516
		} else {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1517
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1518
			    "After rewind, several\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1519
			    "\tpersistent user-data errors will remain.  "));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1520
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1521
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1522
	(void) printf(dgettext(TEXT_DOMAIN,
11026
e8e10df16a8f 6899159 injection isn't trashing pools
Tim Haley <Tim.Haley@Sun.COM>
parents: 10956
diff changeset
  1523
	    "Recovery can be attempted\n\tby executing 'zpool %s -F %s'.  "),
e8e10df16a8f 6899159 injection isn't trashing pools
Tim Haley <Tim.Haley@Sun.COM>
parents: 10956
diff changeset
  1524
	    reason >= 0 ? "clear" : "import", name);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1525
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1526
	(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1527
	    "A scrub of the pool\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1528
	    "\tis strongly recommended after recovery.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1529
	return;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1530
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1531
no_info:
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1532
	(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1533
	    "Destroy and re-create the pool from\n\ta backup source.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1534
}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1535
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
/*
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1537
 * zpool_import() is a contracted interface. Should be kept the same
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1538
 * if possible.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1539
 *
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1540
 * Applications should use zpool_import_props() to import a pool with
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1541
 * new properties value to be set.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1542
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1544
zpool_import(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1545
    char *altroot)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1546
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1547
	nvlist_t *props = NULL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1548
	int ret;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1549
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1550
	if (altroot != NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1551
		if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1552
			return (zfs_error_fmt(hdl, EZFS_NOMEM,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1553
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1554
			    newname));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1555
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1556
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1557
		if (nvlist_add_string(props,
8084
b811cc60d650 6769612 zpool_import() will continue to write to cachefile even if altroot is set
George Wilson <George.Wilson@Sun.COM>
parents: 7965
diff changeset
  1558
		    zpool_prop_to_name(ZPOOL_PROP_ALTROOT), altroot) != 0 ||
b811cc60d650 6769612 zpool_import() will continue to write to cachefile even if altroot is set
George Wilson <George.Wilson@Sun.COM>
parents: 7965
diff changeset
  1559
		    nvlist_add_string(props,
b811cc60d650 6769612 zpool_import() will continue to write to cachefile even if altroot is set
George Wilson <George.Wilson@Sun.COM>
parents: 7965
diff changeset
  1560
		    zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), "none") != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1561
			nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1562
			return (zfs_error_fmt(hdl, EZFS_NOMEM,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1563
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1564
			    newname));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1565
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1566
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1567
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1568
	ret = zpool_import_props(hdl, config, newname, props,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1569
	    ZFS_IMPORT_NORMAL);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1570
	if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1571
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1572
	return (ret);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1573
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1574
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1575
static void
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1576
print_vdev_tree(libzfs_handle_t *hdl, const char *name, nvlist_t *nv,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1577
    int indent)
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1578
{
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1579
	nvlist_t **child;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1580
	uint_t c, children;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1581
	char *vname;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1582
	uint64_t is_log = 0;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1583
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1584
	(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1585
	    &is_log);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1586
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1587
	if (name != NULL)
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1588
		(void) printf("\t%*s%s%s\n", indent, "", name,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1589
		    is_log ? " [log]" : "");
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1590
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1591
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1592
	    &child, &children) != 0)
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1593
		return;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1594
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1595
	for (c = 0; c < children; c++) {
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1596
		vname = zpool_vdev_name(hdl, NULL, child[c], B_TRUE);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1597
		print_vdev_tree(hdl, vname, child[c], indent + 2);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1598
		free(vname);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1599
	}
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1600
}
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1601
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1602
void
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1603
zpool_print_unsup_feat(nvlist_t *config)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1604
{
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1605
	nvlist_t *nvinfo, *unsup_feat;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1606
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1607
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nvinfo) ==
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1608
	    0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1609
	verify(nvlist_lookup_nvlist(nvinfo, ZPOOL_CONFIG_UNSUP_FEAT,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1610
	    &unsup_feat) == 0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1611
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1612
	for (nvpair_t *nvp = nvlist_next_nvpair(unsup_feat, NULL); nvp != NULL;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1613
	    nvp = nvlist_next_nvpair(unsup_feat, nvp)) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1614
		char *desc;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1615
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1616
		verify(nvpair_type(nvp) == DATA_TYPE_STRING);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1617
		verify(nvpair_value_string(nvp, &desc) == 0);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1618
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1619
		if (strlen(desc) > 0)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1620
			(void) printf("\t%s (%s)\n", nvpair_name(nvp), desc);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1621
		else
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1622
			(void) printf("\t%s\n", nvpair_name(nvp));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1623
	}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1624
}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1625
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1626
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1627
 * Import the given pool using the known configuration and a list of
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1628
 * properties to be set. The configuration should have come from
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1629
 * zpool_find_import(). The 'newname' parameters control whether the pool
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1630
 * is imported with a different name.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1631
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1632
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1633
zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1634
    nvlist_t *props, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1635
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1636
	zfs_cmd_t zc = { 0 };
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1637
	zpool_rewind_policy_t policy;
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1638
	nvlist_t *nv = NULL;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1639
	nvlist_t *nvinfo = NULL;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1640
	nvlist_t *missing = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
	char *thename;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
	char *origname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
	int ret;
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1644
	int error = 0;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1645
	char errbuf[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
	    &origname) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1649
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1650
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1651
	    "cannot import pool '%s'"), origname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1652
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1653
	if (newname != NULL) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1654
		if (!zpool_name_valid(hdl, B_FALSE, newname))
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  1655
			return (zfs_error_fmt(hdl, EZFS_INVALIDNAME,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1656
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1657
			    newname));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1658
		thename = (char *)newname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1660
		thename = origname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1661
	}
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
	if (props) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1664
		uint64_t version;
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
  1665
		prop_flags_t flags = { .create = B_FALSE, .import = B_TRUE };
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1666
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1667
		verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1668
		    &version) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1669
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1670
		if ((props = zpool_valid_proplist(hdl, origname,
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
  1671
		    props, version, flags, errbuf)) == NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1672
			return (-1);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1673
		} else if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1674
			nvlist_free(props);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1675
			return (-1);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1676
		}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1677
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1678
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
	(void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1680
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1681
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1682
	    &zc.zc_guid) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1683
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1684
	if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) {
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1685
		nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1686
		return (-1);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1687
	}
12986
caf415d9aa53 6973547 zpool import succeeds but prints error message
George Wilson <George.Wilson@Sun.COM>
parents: 12961
diff changeset
  1688
	if (zcmd_alloc_dst_nvlist(hdl, &zc, zc.zc_nvlist_conf_size * 2) != 0) {
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1689
		nvlist_free(props);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1690
		return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1691
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1693
	zc.zc_cookie = flags;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1694
	while ((ret = zfs_ioctl(hdl, ZFS_IOC_POOL_IMPORT, &zc)) != 0 &&
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1695
	    errno == ENOMEM) {
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1696
		if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1697
			zcmd_free_nvlists(&zc);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1698
			return (-1);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1699
		}
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1700
	}
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1701
	if (ret != 0)
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1702
		error = errno;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1703
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1704
	(void) zcmd_read_dst_nvlist(hdl, &zc, &nv);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1705
	zpool_get_rewind_policy(config, &policy);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1706
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1707
	if (error) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
		char desc[1024];
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1709
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1710
		/*
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1711
		 * Dry-run failed, but we print out what success
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1712
		 * looks like if we found a best txg
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1713
		 */
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1714
		if (policy.zrp_request & ZPOOL_TRY_REWIND) {
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1715
			zpool_rewind_exclaim(hdl, newname ? origname : thename,
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1716
			    B_TRUE, nv);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1717
			nvlist_free(nv);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1718
			return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1719
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1720
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
		if (newname == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
			(void) snprintf(desc, sizeof (desc),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
			    thename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
			(void) snprintf(desc, sizeof (desc),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
			    dgettext(TEXT_DOMAIN, "cannot import '%s' as '%s'"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1728
			    origname, thename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1730
		switch (error) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1731
		case ENOTSUP:
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1732
			if (nv != NULL && nvlist_lookup_nvlist(nv,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1733
			    ZPOOL_CONFIG_LOAD_INFO, &nvinfo) == 0 &&
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1734
			    nvlist_exists(nvinfo, ZPOOL_CONFIG_UNSUP_FEAT)) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1735
				(void) printf(dgettext(TEXT_DOMAIN, "This "
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1736
				    "pool uses the following feature(s) not "
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1737
				    "supported by this system:\n"));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1738
				zpool_print_unsup_feat(nv);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1739
				if (nvlist_exists(nvinfo,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1740
				    ZPOOL_CONFIG_CAN_RDONLY)) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1741
					(void) printf(dgettext(TEXT_DOMAIN,
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1742
					    "All unsupported features are only "
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1743
					    "required for writing to the pool."
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1744
					    "\nThe pool can be imported using "
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1745
					    "'-o readonly=on'.\n"));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1746
				}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13570
diff changeset
  1747
			}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1748
			/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1749
			 * Unsupported version.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1750
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1751
			(void) zfs_error(hdl, EZFS_BADVERSION, desc);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1752
			break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1753
2174
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1754
		case EINVAL:
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1755
			(void) zfs_error(hdl, EZFS_INVALCONFIG, desc);
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1756
			break;
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1757
11814
09d130965476 6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents: 11422
diff changeset
  1758
		case EROFS:
09d130965476 6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents: 11422
diff changeset
  1759
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
09d130965476 6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents: 11422
diff changeset
  1760
			    "one or more devices is read only"));
09d130965476 6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents: 11422
diff changeset
  1761
			(void) zfs_error(hdl, EZFS_BADDEV, desc);
09d130965476 6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents: 11422
diff changeset
  1762
			break;
09d130965476 6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents: 11422
diff changeset
  1763
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1764
		case ENXIO:
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1765
			if (nv && nvlist_lookup_nvlist(nv,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1766
			    ZPOOL_CONFIG_LOAD_INFO, &nvinfo) == 0 &&
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1767
			    nvlist_lookup_nvlist(nvinfo,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1768
			    ZPOOL_CONFIG_MISSING_DEVICES, &missing) == 0) {
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1769
				(void) printf(dgettext(TEXT_DOMAIN,
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1770
				    "The devices below are missing, use "
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1771
				    "'-m' to import the pool anyway:\n"));
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1772
				print_vdev_tree(hdl, NULL, missing, 2);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1773
				(void) printf("\n");
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1774
			}
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1775
			(void) zpool_standard_error(hdl, error, desc);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1776
			break;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1777
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1778
		case EEXIST:
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1779
			(void) zpool_standard_error(hdl, error, desc);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1780
			break;
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1781
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
		default:
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1783
			(void) zpool_standard_error(hdl, error, desc);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1784
			zpool_explain_recover(hdl,
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1785
			    newname ? origname : thename, -error, nv);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1786
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1787
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1788
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1789
		nvlist_free(nv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1790
		ret = -1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1792
		zpool_handle_t *zhp;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1793
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1794
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
		 * This should never fail, but play it safe anyway.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
		 */
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9816
diff changeset
  1797
		if (zpool_open_silent(hdl, thename, &zhp) != 0)
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
  1798
			ret = -1;
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9816
diff changeset
  1799
		else if (zhp != NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
			zpool_close(zhp);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1801
		if (policy.zrp_request &
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1802
		    (ZPOOL_DO_REWIND | ZPOOL_TRY_REWIND)) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1803
			zpool_rewind_exclaim(hdl, newname ? origname : thename,
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1804
			    ((policy.zrp_request & ZPOOL_TRY_REWIND) != 0), nv);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1805
		}
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  1806
		nvlist_free(nv);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1807
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1808
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1809
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1810
	zcmd_free_nvlists(&zc);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1811
	nvlist_free(props);
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1812
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1813
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1814
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1816
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1817
 * Scan the pool.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1818
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1819
int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1820
zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1824
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1827
	zc.zc_cookie = func;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1828
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1829
	if (zfs_ioctl(hdl, ZFS_IOC_POOL_SCAN, &zc) == 0 ||
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1830
	    (errno == ENOENT && func != POOL_SCAN_NONE))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1831
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1833
	if (func == POOL_SCAN_SCRUB) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1834
		(void) snprintf(msg, sizeof (msg),
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1835
		    dgettext(TEXT_DOMAIN, "cannot scrub %s"), zc.zc_name);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1836
	} else if (func == POOL_SCAN_NONE) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1837
		(void) snprintf(msg, sizeof (msg),
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1838
		    dgettext(TEXT_DOMAIN, "cannot cancel scrubbing %s"),
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1839
		    zc.zc_name);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1840
	} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1841
		assert(!"unexpected result");
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1842
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1843
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1844
	if (errno == EBUSY) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1845
		nvlist_t *nvroot;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1846
		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: 11814
diff changeset
  1847
		uint_t psc;
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1848
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1849
		verify(nvlist_lookup_nvlist(zhp->zpool_config,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1850
		    ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1851
		(void) nvlist_lookup_uint64_array(nvroot,
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1852
		    ZPOOL_CONFIG_SCAN_STATS, (uint64_t **)&ps, &psc);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1853
		if (ps && ps->pss_func == POOL_SCAN_SCRUB)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1854
			return (zfs_error(hdl, EZFS_SCRUBBING, msg));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1855
		else
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1856
			return (zfs_error(hdl, EZFS_RESILVERING, msg));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1857
	} else if (errno == ENOENT) {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1858
		return (zfs_error(hdl, EZFS_NO_SCRUB, msg));
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1859
	} else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1860
		return (zpool_standard_error(hdl, errno, msg));
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1861
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1864
/*
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1865
 * This provides a very minimal check whether a given string is likely a
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1866
 * c#t#d# style string.  Users of this are expected to do their own
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1867
 * verification of the s# part.
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1868
 */
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1869
#define	CTD_CHECK(str)  (str && str[0] == 'c' && isdigit(str[1]))
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1870
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1871
/*
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1872
 * More elaborate version for ones which may start with "/dev/dsk/"
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1873
 * and the like.
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1874
 */
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1875
static int
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1876
ctd_check_path(char *str) {
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1877
	/*
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1878
	 * If it starts with a slash, check the last component.
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1879
	 */
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1880
	if (str && str[0] == '/') {
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1881
		char *tmp = strrchr(str, '/');
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1882
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1883
		/*
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1884
		 * If it ends in "/old", check the second-to-last
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1885
		 * component of the string instead.
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1886
		 */
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1887
		if (tmp != str && strcmp(tmp, "/old") == 0) {
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1888
			for (tmp--; *tmp != '/'; tmp--)
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1889
				;
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1890
		}
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1891
		str = tmp + 1;
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1892
	}
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1893
	return (CTD_CHECK(str));
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1894
}
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1895
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1896
/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1897
 * Find a vdev that matches the search criteria specified. We use the
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1898
 * the nvpair name to determine how we should look for the device.
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1899
 * 'avail_spare' is set to TRUE if the provided guid refers to an AVAIL
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1900
 * spare; but FALSE if its an INUSE spare.
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1901
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1902
static nvlist_t *
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1903
vdev_to_nvlist_iter(nvlist_t *nv, nvlist_t *search, boolean_t *avail_spare,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1904
    boolean_t *l2cache, boolean_t *log)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1905
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1906
	uint_t c, children;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1907
	nvlist_t **child;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1908
	nvlist_t *ret;
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  1909
	uint64_t is_log;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1910
	char *srchkey;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1911
	nvpair_t *pair = nvlist_next_nvpair(search, NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1912
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1913
	/* Nothing to look for */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1914
	if (search == NULL || pair == NULL)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1915
		return (NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1916
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1917
	/* Obtain the key we will use to search */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1918
	srchkey = nvpair_name(pair);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1919
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1920
	switch (nvpair_type(pair)) {
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1921
	case DATA_TYPE_UINT64:
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1922
		if (strcmp(srchkey, ZPOOL_CONFIG_GUID) == 0) {
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1923
			uint64_t srchval, theguid;
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1924
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1925
			verify(nvpair_value_uint64(pair, &srchval) == 0);
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1926
			verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1927
			    &theguid) == 0);
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1928
			if (theguid == srchval)
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  1929
				return (nv);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1930
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1931
		break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1932
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1933
	case DATA_TYPE_STRING: {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1934
		char *srchval, *val;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1935
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1936
		verify(nvpair_value_string(pair, &srchval) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1937
		if (nvlist_lookup_string(nv, srchkey, &val) != 0)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1938
			break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1939
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1940
		/*
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1941
		 * Search for the requested value. Special cases:
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1942
		 *
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1943
		 * - ZPOOL_CONFIG_PATH for whole disk entries.  These end in
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1944
		 *   "s0" or "s0/old".  The "s0" part is hidden from the user,
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1945
		 *   but included in the string, so this matches around it.
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1946
		 * - looking for a top-level vdev name (i.e. ZPOOL_CONFIG_TYPE).
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1947
		 *
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1948
		 * Otherwise, all other searches are simple string compares.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1949
		 */
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1950
		if (strcmp(srchkey, ZPOOL_CONFIG_PATH) == 0 &&
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1951
		    ctd_check_path(val)) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1952
			uint64_t wholedisk = 0;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1953
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1954
			(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1955
			    &wholedisk);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1956
			if (wholedisk) {
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1957
				int slen = strlen(srchval);
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1958
				int vlen = strlen(val);
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1959
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1960
				if (slen != vlen - 2)
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1961
					break;
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1962
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1963
				/*
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1964
				 * make_leaf_vdev() should only set
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1965
				 * wholedisk for ZPOOL_CONFIG_PATHs which
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1966
				 * will include "/dev/dsk/", giving plenty of
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1967
				 * room for the indices used next.
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1968
				 */
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1969
				ASSERT(vlen >= 6);
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1970
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1971
				/*
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1972
				 * strings identical except trailing "s0"
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1973
				 */
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1974
				if (strcmp(&val[vlen - 2], "s0") == 0 &&
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1975
				    strncmp(srchval, val, slen) == 0)
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1976
					return (nv);
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1977
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1978
				/*
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1979
				 * strings identical except trailing "s0/old"
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1980
				 */
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1981
				if (strcmp(&val[vlen - 6], "s0/old") == 0 &&
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1982
				    strcmp(&srchval[slen - 4], "/old") == 0 &&
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1983
				    strncmp(srchval, val, slen - 4) == 0)
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1984
					return (nv);
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  1985
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1986
				break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1987
			}
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1988
		} else if (strcmp(srchkey, ZPOOL_CONFIG_TYPE) == 0 && val) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1989
			char *type, *idx, *end, *p;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1990
			uint64_t id, vdev_id;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1991
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1992
			/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1993
			 * Determine our vdev type, keeping in mind
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1994
			 * that the srchval is composed of a type and
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1995
			 * vdev id pair (i.e. mirror-4).
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1996
			 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1997
			if ((type = strdup(srchval)) == NULL)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1998
				return (NULL);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1999
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2000
			if ((p = strrchr(type, '-')) == NULL) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2001
				free(type);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2002
				break;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2003
			}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2004
			idx = p + 1;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2005
			*p = '\0';
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2006
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2007
			/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2008
			 * If the types don't match then keep looking.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2009
			 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2010
			if (strncmp(val, type, strlen(val)) != 0) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2011
				free(type);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2012
				break;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2013
			}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2014
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2015
			verify(strncmp(type, VDEV_TYPE_RAIDZ,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2016
			    strlen(VDEV_TYPE_RAIDZ)) == 0 ||
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2017
			    strncmp(type, VDEV_TYPE_MIRROR,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2018
			    strlen(VDEV_TYPE_MIRROR)) == 0);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2019
			verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2020
			    &id) == 0);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2021
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2022
			errno = 0;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2023
			vdev_id = strtoull(idx, &end, 10);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2024
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2025
			free(type);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2026
			if (errno != 0)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2027
				return (NULL);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2028
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2029
			/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2030
			 * Now verify that we have the correct vdev id.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2031
			 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2032
			if (vdev_id == id)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2033
				return (nv);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2034
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2035
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2036
		/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2037
		 * Common case
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2038
		 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2039
		if (strcmp(srchval, val) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2040
			return (nv);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2041
		break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2042
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2043
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2044
	default:
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2045
		break;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2046
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2047
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2048
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2049
	    &child, &children) != 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2050
		return (NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2051
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2052
	for (c = 0; c < children; c++) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2053
		if ((ret = vdev_to_nvlist_iter(child[c], search,
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2054
		    avail_spare, l2cache, NULL)) != NULL) {
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2055
			/*
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2056
			 * The 'is_log' value is only set for the toplevel
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2057
			 * vdev, not the leaf vdevs.  So we always lookup the
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2058
			 * log device from the root of the vdev tree (where
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2059
			 * 'log' is non-NULL).
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2060
			 */
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2061
			if (log != NULL &&
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2062
			    nvlist_lookup_uint64(child[c],
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2063
			    ZPOOL_CONFIG_IS_LOG, &is_log) == 0 &&
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2064
			    is_log) {
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2065
				*log = B_TRUE;
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2066
			}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2067
			return (ret);
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2068
		}
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2069
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2070
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2071
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2072
	    &child, &children) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2073
		for (c = 0; c < children; c++) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2074
			if ((ret = vdev_to_nvlist_iter(child[c], search,
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2075
			    avail_spare, l2cache, NULL)) != NULL) {
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2076
				*avail_spare = B_TRUE;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2077
				return (ret);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2078
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2079
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2080
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2081
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2082
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2083
	    &child, &children) == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2084
		for (c = 0; c < children; c++) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2085
			if ((ret = vdev_to_nvlist_iter(child[c], search,
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2086
			    avail_spare, l2cache, NULL)) != NULL) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2087
				*l2cache = B_TRUE;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2088
				return (ret);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2089
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2090
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2091
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2092
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2093
	return (NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2094
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2095
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2096
/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2097
 * Given a physical path (minus the "/devices" prefix), find the
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2098
 * associated vdev.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2099
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2100
nvlist_t *
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2101
zpool_find_vdev_by_physpath(zpool_handle_t *zhp, const char *ppath,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2102
    boolean_t *avail_spare, boolean_t *l2cache, boolean_t *log)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2103
{
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2104
	nvlist_t *search, *nvroot, *ret;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2105
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2106
	verify(nvlist_alloc(&search, NV_UNIQUE_NAME, KM_SLEEP) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2107
	verify(nvlist_add_string(search, ZPOOL_CONFIG_PHYS_PATH, ppath) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2108
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2109
	verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2110
	    &nvroot) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2111
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2112
	*avail_spare = B_FALSE;
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2113
	*l2cache = B_FALSE;
13056
233e20cbda69 6975471 syseventd dumps core in zfsdle_vdev_online
Mark J Musante <Mark.Musante@Sun.COM>
parents: 13049
diff changeset
  2114
	if (log != NULL)
233e20cbda69 6975471 syseventd dumps core in zfsdle_vdev_online
Mark J Musante <Mark.Musante@Sun.COM>
parents: 13049
diff changeset
  2115
		*log = B_FALSE;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2116
	ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2117
	nvlist_free(search);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2118
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2119
	return (ret);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2120
}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2121
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2122
/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2123
 * Determine if we have an "interior" top-level vdev (i.e mirror/raidz).
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2124
 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2125
boolean_t
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2126
zpool_vdev_is_interior(const char *name)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2127
{
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2128
	if (strncmp(name, VDEV_TYPE_RAIDZ, strlen(VDEV_TYPE_RAIDZ)) == 0 ||
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2129
	    strncmp(name, VDEV_TYPE_MIRROR, strlen(VDEV_TYPE_MIRROR)) == 0)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2130
		return (B_TRUE);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2131
	return (B_FALSE);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2132
}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2133
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2134
nvlist_t *
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2135
zpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare,
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2136
    boolean_t *l2cache, boolean_t *log)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2137
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2138
	char buf[MAXPATHLEN];
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2139
	char *end;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2140
	nvlist_t *nvroot, *search, *ret;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2141
	uint64_t guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2142
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2143
	verify(nvlist_alloc(&search, NV_UNIQUE_NAME, KM_SLEEP) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2144
1613
aca102a242d3 6396628 zpool offline does not recognize c0d0 patten recently
eschrock
parents: 1544
diff changeset
  2145
	guid = strtoull(path, &end, 10);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2146
	if (guid != 0 && *end == '\0') {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2147
		verify(nvlist_add_uint64(search, ZPOOL_CONFIG_GUID, guid) == 0);
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2148
	} else if (zpool_vdev_is_interior(path)) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2149
		verify(nvlist_add_string(search, ZPOOL_CONFIG_TYPE, path) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2150
	} else if (path[0] != '/') {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2151
		(void) snprintf(buf, sizeof (buf), "%s%s", "/dev/dsk/", path);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2152
		verify(nvlist_add_string(search, ZPOOL_CONFIG_PATH, buf) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2153
	} else {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2154
		verify(nvlist_add_string(search, ZPOOL_CONFIG_PATH, path) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2155
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2156
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2157
	verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2158
	    &nvroot) == 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2159
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2160
	*avail_spare = B_FALSE;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2161
	*l2cache = B_FALSE;
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2162
	if (log != NULL)
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2163
		*log = B_FALSE;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2164
	ret = vdev_to_nvlist_iter(nvroot, search, avail_spare, l2cache, log);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2165
	nvlist_free(search);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2166
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2167
	return (ret);
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2168
}
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2169
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2170
static int
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2171
vdev_online(nvlist_t *nv)
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2172
{
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2173
	uint64_t ival;
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2174
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2175
	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE, &ival) == 0 ||
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2176
	    nvlist_lookup_uint64(nv, ZPOOL_CONFIG_FAULTED, &ival) == 0 ||
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2177
	    nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVED, &ival) == 0)
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2178
		return (0);
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2179
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2180
	return (1);
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2181
}
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2182
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2183
/*
9790
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2184
 * Helper function for zpool_get_physpaths().
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2185
 */
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2186
static int
9790
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2187
vdev_get_one_physpath(nvlist_t *config, char *physpath, size_t physpath_size,
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2188
    size_t *bytes_written)
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2189
{
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2190
	size_t bytes_left, pos, rsz;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2191
	char *tmppath;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2192
	const char *format;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2193
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2194
	if (nvlist_lookup_string(config, ZPOOL_CONFIG_PHYS_PATH,
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2195
	    &tmppath) != 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2196
		return (EZFS_NODEVICE);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2197
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2198
	pos = *bytes_written;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2199
	bytes_left = physpath_size - pos;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2200
	format = (pos == 0) ? "%s" : " %s";
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2201
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2202
	rsz = snprintf(physpath + pos, bytes_left, format, tmppath);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2203
	*bytes_written += rsz;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2204
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2205
	if (rsz >= bytes_left) {
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2206
		/* if physpath was not copied properly, clear it */
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2207
		if (bytes_left != 0) {
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2208
			physpath[pos] = 0;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2209
		}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2210
		return (EZFS_NOSPC);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2211
	}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2212
	return (0);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2213
}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2214
9790
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2215
static int
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2216
vdev_get_physpaths(nvlist_t *nv, char *physpath, size_t phypath_size,
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2217
    size_t *rsz, boolean_t is_spare)
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2218
{
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2219
	char *type;
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2220
	int ret;
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2221
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2222
	if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0)
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2223
		return (EZFS_INVALCONFIG);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2224
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2225
	if (strcmp(type, VDEV_TYPE_DISK) == 0) {
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2226
		/*
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2227
		 * An active spare device has ZPOOL_CONFIG_IS_SPARE set.
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2228
		 * For a spare vdev, we only want to boot from the active
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2229
		 * spare device.
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2230
		 */
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2231
		if (is_spare) {
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2232
			uint64_t spare = 0;
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2233
			(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPARE,
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2234
			    &spare);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2235
			if (!spare)
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2236
				return (EZFS_INVALCONFIG);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2237
		}
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2238
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2239
		if (vdev_online(nv)) {
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2240
			if ((ret = vdev_get_one_physpath(nv, physpath,
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2241
			    phypath_size, rsz)) != 0)
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2242
				return (ret);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2243
		}
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2244
	} else if (strcmp(type, VDEV_TYPE_MIRROR) == 0 ||
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2245
	    strcmp(type, VDEV_TYPE_REPLACING) == 0 ||
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2246
	    (is_spare = (strcmp(type, VDEV_TYPE_SPARE) == 0))) {
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2247
		nvlist_t **child;
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2248
		uint_t count;
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2249
		int i, ret;
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2250
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2251
		if (nvlist_lookup_nvlist_array(nv,
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2252
		    ZPOOL_CONFIG_CHILDREN, &child, &count) != 0)
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2253
			return (EZFS_INVALCONFIG);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2254
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2255
		for (i = 0; i < count; i++) {
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2256
			ret = vdev_get_physpaths(child[i], physpath,
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2257
			    phypath_size, rsz, is_spare);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2258
			if (ret == EZFS_NOSPC)
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2259
				return (ret);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2260
		}
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2261
	}
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2262
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2263
	return (EZFS_POOL_INVALARG);
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2264
}
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2265
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2266
/*
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2267
 * Get phys_path for a root pool config.
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2268
 * Return 0 on success; non-zero on failure.
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2269
 */
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2270
static int
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2271
zpool_get_config_physpath(nvlist_t *config, char *physpath, size_t phypath_size)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2272
{
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2273
	size_t rsz;
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2274
	nvlist_t *vdev_root;
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2275
	nvlist_t **child;
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2276
	uint_t count;
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2277
	char *type;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2278
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2279
	rsz = 0;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2280
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2281
	if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2282
	    &vdev_root) != 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2283
		return (EZFS_INVALCONFIG);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2284
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2285
	if (nvlist_lookup_string(vdev_root, ZPOOL_CONFIG_TYPE, &type) != 0 ||
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2286
	    nvlist_lookup_nvlist_array(vdev_root, ZPOOL_CONFIG_CHILDREN,
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2287
	    &child, &count) != 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2288
		return (EZFS_INVALCONFIG);
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2289
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2290
	/*
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2291
	 * root pool can not have EFI labeled disks and can only have
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2292
	 * a single top-level vdev.
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2293
	 */
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2294
	if (strcmp(type, VDEV_TYPE_ROOT) != 0 || count != 1 ||
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2295
	    pool_uses_efi(vdev_root))
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2296
		return (EZFS_POOL_INVALARG);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2297
9790
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2298
	(void) vdev_get_physpaths(child[0], physpath, phypath_size, &rsz,
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2299
	    B_FALSE);
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2300
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2301
	/* No online devices */
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2302
	if (rsz == 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2303
		return (EZFS_NODEVICE);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2304
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2305
	return (0);
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2306
}
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  2307
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2308
/*
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2309
 * Get phys_path for a root pool
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2310
 * Return 0 on success; non-zero on failure.
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2311
 */
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2312
int
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2313
zpool_get_physpath(zpool_handle_t *zhp, char *physpath, size_t phypath_size)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2314
{
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2315
	return (zpool_get_config_physpath(zhp->zpool_config, physpath,
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2316
	    phypath_size));
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2317
}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2318
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  2319
/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2320
 * If the device has being dynamically expanded then we need to relabel
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2321
 * the disk to use the new unallocated space.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2322
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2323
static int
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2324
zpool_relabel_disk(libzfs_handle_t *hdl, const char *name)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2325
{
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2326
	char path[MAXPATHLEN];
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2327
	char errbuf[1024];
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2328
	int fd, error;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2329
	int (*_efi_use_whole_disk)(int);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2330
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2331
	if ((_efi_use_whole_disk = (int (*)(int))dlsym(RTLD_DEFAULT,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2332
	    "efi_use_whole_disk")) == NULL)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2333
		return (-1);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2334
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2335
	(void) snprintf(path, sizeof (path), "%s/%s", RDISK_ROOT, name);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2336
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2337
	if ((fd = open(path, O_RDWR | O_NDELAY)) < 0) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2338
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot "
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2339
		    "relabel '%s': unable to open device"), name);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2340
		return (zfs_error(hdl, EZFS_OPENFAILED, errbuf));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2341
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2342
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2343
	/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2344
	 * It's possible that we might encounter an error if the device
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2345
	 * does not have any unallocated space left. If so, we simply
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2346
	 * ignore that error and continue on.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2347
	 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2348
	error = _efi_use_whole_disk(fd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2349
	(void) close(fd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2350
	if (error && error != VT_ENOSPC) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2351
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot "
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2352
		    "relabel '%s': unable to read disk capacity"), name);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2353
		return (zfs_error(hdl, EZFS_NOCAP, errbuf));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2354
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2355
	return (0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2356
}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2357
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2358
/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2359
 * Bring the specified vdev online.   The 'flags' parameter is a set of the
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2360
 * ZFS_ONLINE_* flags.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2363
zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags,
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2364
    vdev_state_t *newstate)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2365
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2366
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2367
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2368
	nvlist_t *tgt;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2369
	boolean_t avail_spare, l2cache, islog;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2370
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2371
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2372
	if (flags & ZFS_ONLINE_EXPAND) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2373
		(void) snprintf(msg, sizeof (msg),
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2374
		    dgettext(TEXT_DOMAIN, "cannot expand %s"), path);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2375
	} else {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2376
		(void) snprintf(msg, sizeof (msg),
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2377
		    dgettext(TEXT_DOMAIN, "cannot online %s"), path);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2378
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2379
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2380
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2381
	if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache,
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2382
	    &islog)) == NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2383
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2384
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2385
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2386
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2387
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2388
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2389
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2390
	if (flags & ZFS_ONLINE_EXPAND ||
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2391
	    zpool_get_prop_int(zhp, ZPOOL_PROP_AUTOEXPAND, NULL)) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2392
		char *pathname = NULL;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2393
		uint64_t wholedisk = 0;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2394
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2395
		(void) nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_WHOLE_DISK,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2396
		    &wholedisk);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2397
		verify(nvlist_lookup_string(tgt, ZPOOL_CONFIG_PATH,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2398
		    &pathname) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2399
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2400
		/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2401
		 * XXX - L2ARC 1.0 devices can't support expansion.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2402
		 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2403
		if (l2cache) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2404
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2405
			    "cannot expand cache devices"));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2406
			return (zfs_error(hdl, EZFS_VDEVNOTSUP, msg));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2407
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2408
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2409
		if (wholedisk) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2410
			pathname += strlen(DISK_ROOT) + 1;
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2411
			(void) zpool_relabel_disk(hdl, pathname);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2412
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2413
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2414
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2415
	zc.zc_cookie = VDEV_STATE_ONLINE;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2416
	zc.zc_obj = flags;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2417
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2418
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_SET_STATE, &zc) != 0) {
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2419
		if (errno == EINVAL) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2420
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "was split "
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2421
			    "from this pool into a new one.  Use '%s' "
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2422
			    "instead"), "zpool detach");
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2423
			return (zfs_error(hdl, EZFS_POSTSPLIT_ONLINE, msg));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2424
		}
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2425
		return (zpool_standard_error(hdl, errno, msg));
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2426
	}
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2427
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2428
	*newstate = zc.zc_cookie;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2429
	return (0);
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
 * Take the specified vdev offline
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2434
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2435
int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2436
zpool_vdev_offline(zpool_handle_t *zhp, const char *path, boolean_t istmp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2437
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2438
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2439
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2440
	nvlist_t *tgt;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2441
	boolean_t avail_spare, l2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2442
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2443
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2444
	(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2445
	    dgettext(TEXT_DOMAIN, "cannot offline %s"), path);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2446
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2447
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2448
	if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache,
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2449
	    NULL)) == NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2450
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2451
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2452
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2453
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2454
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2455
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2456
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2457
	zc.zc_cookie = VDEV_STATE_OFFLINE;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2458
	zc.zc_obj = istmp ? ZFS_OFFLINE_TEMPORARY : 0;
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1354
diff changeset
  2459
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2460
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_SET_STATE, &zc) == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2461
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2462
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2463
	switch (errno) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2464
	case EBUSY:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2466
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2467
		 * There are no other replicas of this device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2468
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2469
		return (zfs_error(hdl, EZFS_NOREPLICAS, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2470
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2471
	case EEXIST:
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2472
		/*
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2473
		 * The log device has unplayed logs
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2474
		 */
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2475
		return (zfs_error(hdl, EZFS_UNPLAYED_LOGS, msg));
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2476
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2477
	default:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2478
		return (zpool_standard_error(hdl, errno, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2479
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2480
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2481
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2482
/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2483
 * Mark the given vdev faulted.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2484
 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2485
int
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2486
zpool_vdev_fault(zpool_handle_t *zhp, uint64_t guid, vdev_aux_t aux)
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2487
{
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2488
	zfs_cmd_t zc = { 0 };
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2489
	char msg[1024];
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2490
	libzfs_handle_t *hdl = zhp->zpool_hdl;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2491
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2492
	(void) snprintf(msg, sizeof (msg),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2493
	    dgettext(TEXT_DOMAIN, "cannot fault %llu"), guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2494
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2495
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2496
	zc.zc_guid = guid;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2497
	zc.zc_cookie = VDEV_STATE_FAULTED;
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2498
	zc.zc_obj = aux;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2499
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2500
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_VDEV_SET_STATE, &zc) == 0)
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2501
		return (0);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2502
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2503
	switch (errno) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2504
	case EBUSY:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2505
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2506
		/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2507
		 * There are no other replicas of this device.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2508
		 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2509
		return (zfs_error(hdl, EZFS_NOREPLICAS, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2510
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2511
	default:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2512
		return (zpool_standard_error(hdl, errno, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2513
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2514
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2515
}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2516
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2517
/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2518
 * Mark the given vdev degraded.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2519
 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2520
int
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2521
zpool_vdev_degrade(zpool_handle_t *zhp, uint64_t guid, vdev_aux_t aux)
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2522
{
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2523
	zfs_cmd_t zc = { 0 };
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2524
	char msg[1024];
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2525
	libzfs_handle_t *hdl = zhp->zpool_hdl;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2526
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2527
	(void) snprintf(msg, sizeof (msg),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2528
	    dgettext(TEXT_DOMAIN, "cannot degrade %llu"), guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2529
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2530
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2531
	zc.zc_guid = guid;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2532
	zc.zc_cookie = VDEV_STATE_DEGRADED;
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2533
	zc.zc_obj = aux;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2534
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2535
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_VDEV_SET_STATE, &zc) == 0)
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2536
		return (0);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2537
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2538
	return (zpool_standard_error(hdl, errno, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2539
}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2540
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2541
/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2542
 * Returns TRUE if the given nvlist is a vdev that was originally swapped in as
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2543
 * a hot spare.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2544
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2545
static boolean_t
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2546
is_replacing_spare(nvlist_t *search, nvlist_t *tgt, int which)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2547
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2548
	nvlist_t **child;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2549
	uint_t c, children;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2550
	char *type;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2551
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2552
	if (nvlist_lookup_nvlist_array(search, ZPOOL_CONFIG_CHILDREN, &child,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2553
	    &children) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2554
		verify(nvlist_lookup_string(search, ZPOOL_CONFIG_TYPE,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2555
		    &type) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2556
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2557
		if (strcmp(type, VDEV_TYPE_SPARE) == 0 &&
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2558
		    children == 2 && child[which] == tgt)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2559
			return (B_TRUE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2560
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2561
		for (c = 0; c < children; c++)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2562
			if (is_replacing_spare(child[c], tgt, which))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2563
				return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2564
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2565
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2566
	return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2567
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2569
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2570
 * Attach new_disk (fully described by nvroot) to old_disk.
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2571
 * If 'replacing' is specified, the new disk will replace the old one.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2573
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2574
zpool_vdev_attach(zpool_handle_t *zhp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2575
    const char *old_disk, const char *new_disk, nvlist_t *nvroot, int replacing)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2576
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2577
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2578
	char msg[1024];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2579
	int ret;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2580
	nvlist_t *tgt;
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2581
	boolean_t avail_spare, l2cache, islog;
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2582
	uint64_t val;
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2583
	char *newname;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2584
	nvlist_t **child;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2585
	uint_t children;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2586
	nvlist_t *config_root;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2587
	libzfs_handle_t *hdl = zhp->zpool_hdl;
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  2588
	boolean_t rootpool = zpool_is_bootable(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2590
	if (replacing)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2591
		(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2592
		    "cannot replace %s with %s"), old_disk, new_disk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2593
	else
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2594
		(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2595
		    "cannot attach %s to %s"), new_disk, old_disk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2596
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2597
	/*
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2598
	 * If this is a root pool, make sure that we're not attaching an
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2599
	 * EFI labeled device.
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2600
	 */
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2601
	if (rootpool && pool_uses_efi(nvroot)) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2602
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2603
		    "EFI labeled devices are not supported on root pools."));
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2604
		return (zfs_error(hdl, EZFS_POOL_NOTSUP, msg));
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2605
	}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2606
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2607
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2608
	if ((tgt = zpool_find_vdev(zhp, old_disk, &avail_spare, &l2cache,
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2609
	    &islog)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2610
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2611
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2612
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2613
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2614
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2615
	if (l2cache)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2616
		return (zfs_error(hdl, EZFS_ISL2CACHE, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2617
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2618
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2619
	zc.zc_cookie = replacing;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2620
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2621
	if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2622
	    &child, &children) != 0 || children != 1) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2623
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2624
		    "new device must be a single disk"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2625
		return (zfs_error(hdl, EZFS_INVALCONFIG, msg));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2626
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2627
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2628
	verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2629
	    ZPOOL_CONFIG_VDEV_TREE, &config_root) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2630
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2631
	if ((newname = zpool_vdev_name(NULL, NULL, child[0], B_FALSE)) == NULL)
7041
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2632
		return (-1);
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2633
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2634
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2635
	 * If the target is a hot spare that has been swapped in, we can only
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2636
	 * replace it with another hot spare.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2637
	 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2638
	if (replacing &&
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2639
	    nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_IS_SPARE, &val) == 0 &&
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2640
	    (zpool_find_vdev(zhp, newname, &avail_spare, &l2cache,
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2641
	    NULL) == NULL || !avail_spare) &&
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2642
	    is_replacing_spare(config_root, tgt, 1)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2643
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2644
		    "can only be replaced by another hot spare"));
7041
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2645
		free(newname);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2646
		return (zfs_error(hdl, EZFS_BADTARGET, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2647
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2648
7041
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2649
	free(newname);
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2650
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2651
	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2652
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2653
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2654
	ret = zfs_ioctl(hdl, ZFS_IOC_VDEV_ATTACH, &zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2655
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  2656
	zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2657
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2658
	if (ret == 0) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2659
		if (rootpool) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2660
			/*
9790
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2661
			 * XXX need a better way to prevent user from
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2662
			 * booting up a half-baked vdev.
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2663
			 */
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2664
			(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Make "
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2665
			    "sure to wait until resilver is done "
e276ee006ff6 6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents: 9701
diff changeset
  2666
			    "before rebooting.\n"));
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2667
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2668
		return (0);
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2669
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2670
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2671
	switch (errno) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2672
	case ENOTSUP:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2673
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2674
		 * Can't attach to or replace this type of vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2675
		 */
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2676
		if (replacing) {
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2677
			uint64_t version = zpool_get_prop_int(zhp,
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2678
			    ZPOOL_PROP_VERSION, NULL);
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2679
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2680
			if (islog)
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2681
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2682
				    "cannot replace a log with a spare"));
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2683
			else if (version >= SPA_VERSION_MULTI_REPLACE)
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2684
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2685
				    "already in replacing/spare config; wait "
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2686
				    "for completion or use 'zpool detach'"));
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2687
			else
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2688
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2689
				    "cannot replace a replacing device"));
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2690
		} else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2691
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2692
			    "can only attach to mirrors and top-level "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2693
			    "disks"));
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2694
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2695
		(void) zfs_error(hdl, EZFS_BADTARGET, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2696
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2697
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2698
	case EINVAL:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2699
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2700
		 * The new device must be a single disk.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2701
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2702
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2703
		    "new device must be a single disk"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2704
		(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2705
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2706
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2707
	case EBUSY:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2708
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "%s is busy"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2709
		    new_disk);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2710
		(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2711
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2712
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2713
	case EOVERFLOW:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2714
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2715
		 * The new device is too small.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2716
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2717
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2718
		    "device is too small"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2719
		(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2720
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2722
	case EDOM:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2723
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
		 * The new device has a different alignment requirement.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2725
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2726
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2727
		    "devices have different sector alignment"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2728
		(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2730
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2731
	case ENAMETOOLONG:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2732
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2733
		 * The resulting top-level vdev spec won't fit in the label.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2734
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2735
		(void) zfs_error(hdl, EZFS_DEVOVERFLOW, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2736
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2737
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2738
	default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2739
		(void) zpool_standard_error(hdl, errno, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2740
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2741
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2742
	return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2743
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2744
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2745
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2746
 * Detach the specified device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2747
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2748
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2749
zpool_vdev_detach(zpool_handle_t *zhp, const char *path)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2750
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2751
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2752
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2753
	nvlist_t *tgt;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2754
	boolean_t avail_spare, l2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2755
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2756
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2757
	(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2758
	    dgettext(TEXT_DOMAIN, "cannot detach %s"), path);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2759
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2760
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2761
	if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache,
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2762
	    NULL)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2763
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2764
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2765
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2766
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2767
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2768
	if (l2cache)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2769
		return (zfs_error(hdl, EZFS_ISL2CACHE, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2770
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2771
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2772
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  2773
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_DETACH, &zc) == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2774
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2775
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2776
	switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2777
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2778
	case ENOTSUP:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2779
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2780
		 * Can't detach from this type of vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2781
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2782
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "only "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2783
		    "applicable to mirror and replacing vdevs"));
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  2784
		(void) zfs_error(hdl, EZFS_BADTARGET, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2785
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2786
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2787
	case EBUSY:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2788
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2789
		 * There are no other replicas of this device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2790
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2791
		(void) zfs_error(hdl, EZFS_NOREPLICAS, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2792
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2793
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2794
	default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2795
		(void) zpool_standard_error(hdl, errno, msg);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2796
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2797
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2798
	return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2799
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2800
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2801
/*
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2802
 * Find a mirror vdev in the source nvlist.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2803
 *
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2804
 * The mchild array contains a list of disks in one of the top-level mirrors
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2805
 * of the source pool.  The schild array contains a list of disks that the
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2806
 * user specified on the command line.  We loop over the mchild array to
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2807
 * see if any entry in the schild array matches.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2808
 *
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2809
 * If a disk in the mchild array is found in the schild array, we return
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2810
 * the index of that entry.  Otherwise we return -1.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2811
 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2812
static int
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2813
find_vdev_entry(zpool_handle_t *zhp, nvlist_t **mchild, uint_t mchildren,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2814
    nvlist_t **schild, uint_t schildren)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2815
{
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2816
	uint_t mc;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2817
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2818
	for (mc = 0; mc < mchildren; mc++) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2819
		uint_t sc;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2820
		char *mpath = zpool_vdev_name(zhp->zpool_hdl, zhp,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2821
		    mchild[mc], B_FALSE);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2822
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2823
		for (sc = 0; sc < schildren; sc++) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2824
			char *spath = zpool_vdev_name(zhp->zpool_hdl, zhp,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2825
			    schild[sc], B_FALSE);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2826
			boolean_t result = (strcmp(mpath, spath) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2827
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2828
			free(spath);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2829
			if (result) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2830
				free(mpath);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2831
				return (mc);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2832
			}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2833
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2834
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2835
		free(mpath);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2836
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2837
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2838
	return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2839
}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2840
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2841
/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2842
 * Split a mirror pool.  If newroot points to null, then a new nvlist
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2843
 * is generated and it is the responsibility of the caller to free it.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2844
 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2845
int
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2846
zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2847
    nvlist_t *props, splitflags_t flags)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2848
{
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2849
	zfs_cmd_t zc = { 0 };
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2850
	char msg[1024];
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2851
	nvlist_t *tree, *config, **child, **newchild, *newconfig = NULL;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2852
	nvlist_t **varray = NULL, *zc_props = NULL;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2853
	uint_t c, children, newchildren, lastlog = 0, vcount, found = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2854
	libzfs_handle_t *hdl = zhp->zpool_hdl;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2855
	uint64_t vers;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2856
	boolean_t freelist = B_FALSE, memory_err = B_TRUE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2857
	int retval = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2858
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2859
	(void) snprintf(msg, sizeof (msg),
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2860
	    dgettext(TEXT_DOMAIN, "Unable to split %s"), zhp->zpool_name);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2861
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2862
	if (!zpool_name_valid(hdl, B_FALSE, newname))
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2863
		return (zfs_error(hdl, EZFS_INVALIDNAME, msg));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2864
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2865
	if ((config = zpool_get_config(zhp, NULL)) == NULL) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2866
		(void) fprintf(stderr, gettext("Internal error: unable to "
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2867
		    "retrieve pool configuration\n"));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2868
		return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2869
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2870
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2871
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &tree)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2872
	    == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2873
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, &vers) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2874
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2875
	if (props) {
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
  2876
		prop_flags_t flags = { .create = B_FALSE, .import = B_TRUE };
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2877
		if ((zc_props = zpool_valid_proplist(hdl, zhp->zpool_name,
13061
bda0decf867b PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents: 13056
diff changeset
  2878
		    props, vers, flags, msg)) == NULL)
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2879
			return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2880
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2881
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2882
	if (nvlist_lookup_nvlist_array(tree, ZPOOL_CONFIG_CHILDREN, &child,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2883
	    &children) != 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2884
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2885
		    "Source pool is missing vdev tree"));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2886
		if (zc_props)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2887
			nvlist_free(zc_props);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2888
		return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2889
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2890
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2891
	varray = zfs_alloc(hdl, children * sizeof (nvlist_t *));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2892
	vcount = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2893
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2894
	if (*newroot == NULL ||
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2895
	    nvlist_lookup_nvlist_array(*newroot, ZPOOL_CONFIG_CHILDREN,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2896
	    &newchild, &newchildren) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2897
		newchildren = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2898
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2899
	for (c = 0; c < children; c++) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2900
		uint64_t is_log = B_FALSE, is_hole = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2901
		char *type;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2902
		nvlist_t **mchild, *vdev;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2903
		uint_t mchildren;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2904
		int entry;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2905
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2906
		/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2907
		 * Unlike cache & spares, slogs are stored in the
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2908
		 * ZPOOL_CONFIG_CHILDREN array.  We filter them out here.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2909
		 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2910
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2911
		    &is_log);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2912
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2913
		    &is_hole);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2914
		if (is_log || is_hole) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2915
			/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2916
			 * Create a hole vdev and put it in the config.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2917
			 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2918
			if (nvlist_alloc(&vdev, NV_UNIQUE_NAME, 0) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2919
				goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2920
			if (nvlist_add_string(vdev, ZPOOL_CONFIG_TYPE,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2921
			    VDEV_TYPE_HOLE) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2922
				goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2923
			if (nvlist_add_uint64(vdev, ZPOOL_CONFIG_IS_HOLE,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2924
			    1) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2925
				goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2926
			if (lastlog == 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2927
				lastlog = vcount;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2928
			varray[vcount++] = vdev;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2929
			continue;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2930
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2931
		lastlog = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2932
		verify(nvlist_lookup_string(child[c], ZPOOL_CONFIG_TYPE, &type)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2933
		    == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2934
		if (strcmp(type, VDEV_TYPE_MIRROR) != 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2935
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2936
			    "Source pool must be composed only of mirrors\n"));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2937
			retval = zfs_error(hdl, EZFS_INVALCONFIG, msg);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2938
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2939
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2940
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2941
		verify(nvlist_lookup_nvlist_array(child[c],
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2942
		    ZPOOL_CONFIG_CHILDREN, &mchild, &mchildren) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2943
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2944
		/* find or add an entry for this top-level vdev */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2945
		if (newchildren > 0 &&
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2946
		    (entry = find_vdev_entry(zhp, mchild, mchildren,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2947
		    newchild, newchildren)) >= 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2948
			/* We found a disk that the user specified. */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2949
			vdev = mchild[entry];
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2950
			++found;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2951
		} else {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2952
			/* User didn't specify a disk for this vdev. */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2953
			vdev = mchild[mchildren - 1];
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2954
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2955
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2956
		if (nvlist_dup(vdev, &varray[vcount++], 0) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2957
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2958
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2959
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2960
	/* did we find every disk the user specified? */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2961
	if (found != newchildren) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2962
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "Device list must "
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2963
		    "include at most one disk from each mirror"));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2964
		retval = zfs_error(hdl, EZFS_INVALCONFIG, msg);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2965
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2966
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2967
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2968
	/* Prepare the nvlist for populating. */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2969
	if (*newroot == NULL) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2970
		if (nvlist_alloc(newroot, NV_UNIQUE_NAME, 0) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2971
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2972
		freelist = B_TRUE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2973
		if (nvlist_add_string(*newroot, ZPOOL_CONFIG_TYPE,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2974
		    VDEV_TYPE_ROOT) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2975
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2976
	} else {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2977
		verify(nvlist_remove_all(*newroot, ZPOOL_CONFIG_CHILDREN) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2978
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2979
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2980
	/* Add all the children we found */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2981
	if (nvlist_add_nvlist_array(*newroot, ZPOOL_CONFIG_CHILDREN, varray,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2982
	    lastlog == 0 ? vcount : lastlog) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2983
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2984
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2985
	/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2986
	 * If we're just doing a dry run, exit now with success.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2987
	 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2988
	if (flags.dryrun) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2989
		memory_err = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2990
		freelist = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2991
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2992
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2993
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2994
	/* now build up the config list & call the ioctl */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2995
	if (nvlist_alloc(&newconfig, NV_UNIQUE_NAME, 0) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2996
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2997
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2998
	if (nvlist_add_nvlist(newconfig,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2999
	    ZPOOL_CONFIG_VDEV_TREE, *newroot) != 0 ||
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3000
	    nvlist_add_string(newconfig,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3001
	    ZPOOL_CONFIG_POOL_NAME, newname) != 0 ||
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3002
	    nvlist_add_uint64(newconfig, ZPOOL_CONFIG_VERSION, vers) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3003
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3004
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3005
	/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3006
	 * The new pool is automatically part of the namespace unless we
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3007
	 * explicitly export it.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3008
	 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3009
	if (!flags.import)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3010
		zc.zc_cookie = ZPOOL_EXPORT_AFTER_SPLIT;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3011
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3012
	(void) strlcpy(zc.zc_string, newname, sizeof (zc.zc_string));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3013
	if (zcmd_write_conf_nvlist(hdl, &zc, newconfig) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3014
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3015
	if (zc_props != NULL && zcmd_write_src_nvlist(hdl, &zc, zc_props) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3016
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3017
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3018
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_SPLIT, &zc) != 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3019
		retval = zpool_standard_error(hdl, errno, msg);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3020
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3021
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3022
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3023
	freelist = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3024
	memory_err = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3025
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3026
out:
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3027
	if (varray != NULL) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3028
		int v;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3029
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3030
		for (v = 0; v < vcount; v++)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3031
			nvlist_free(varray[v]);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3032
		free(varray);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3033
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3034
	zcmd_free_nvlists(&zc);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3035
	if (zc_props)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3036
		nvlist_free(zc_props);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3037
	if (newconfig)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3038
		nvlist_free(newconfig);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3039
	if (freelist) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3040
		nvlist_free(*newroot);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3041
		*newroot = NULL;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3042
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3043
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3044
	if (retval != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3045
		return (retval);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3046
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3047
	if (memory_err)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3048
		return (no_memory(hdl));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3049
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3050
	return (0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3051
}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3052
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  3053
/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3054
 * Remove the given device.  Currently, this is supported only for hot spares
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3055
 * and level 2 cache devices.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3056
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3057
int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3058
zpool_vdev_remove(zpool_handle_t *zhp, const char *path)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3059
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3060
	zfs_cmd_t zc = { 0 };
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3061
	char msg[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3062
	nvlist_t *tgt;
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3063
	boolean_t avail_spare, l2cache, islog;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3064
	libzfs_handle_t *hdl = zhp->zpool_hdl;
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3065
	uint64_t version;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3066
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3067
	(void) snprintf(msg, sizeof (msg),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3068
	    dgettext(TEXT_DOMAIN, "cannot remove %s"), path);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3069
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3070
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  3071
	if ((tgt = zpool_find_vdev(zhp, path, &avail_spare, &l2cache,
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3072
	    &islog)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3073
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3074
	/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3075
	 * XXX - this should just go away.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3076
	 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3077
	if (!avail_spare && !l2cache && !islog) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3078
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3079
		    "only inactive hot spares, cache, top-level, "
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3080
		    "or log devices can be removed"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3081
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3082
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3083
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3084
	version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3085
	if (islog && version < SPA_VERSION_HOLES) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3086
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3087
		    "pool must be upgrade to support log removal"));
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3088
		return (zfs_error(hdl, EZFS_BADVERSION, msg));
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3089
	}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3090
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3091
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3092
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3093
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_REMOVE, &zc) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3094
		return (0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3095
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3096
	return (zpool_standard_error(hdl, errno, msg));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3097
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3098
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3099
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3100
 * Clear the errors for the pool, or the particular device if specified.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3101
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3102
int
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3103
zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3104
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3105
	zfs_cmd_t zc = { 0 };
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3106
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3107
	nvlist_t *tgt;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3108
	zpool_rewind_policy_t policy;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3109
	boolean_t avail_spare, l2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3110
	libzfs_handle_t *hdl = zhp->zpool_hdl;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3111
	nvlist_t *nvi = NULL;
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3112
	int error;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3113
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3114
	if (path)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3115
		(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3116
		    dgettext(TEXT_DOMAIN, "cannot clear errors for %s"),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3117
		    path);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3118
	else
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3119
		(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3120
		    dgettext(TEXT_DOMAIN, "cannot clear errors for %s"),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3121
		    zhp->zpool_name);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3122
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3123
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3124
	if (path) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3125
		if ((tgt = zpool_find_vdev(zhp, path, &avail_spare,
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  3126
		    &l2cache, NULL)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3127
			return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3128
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3129
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3130
		 * Don't allow error clearing for hot spares.  Do allow
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3131
		 * error clearing for l2cache devices.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  3132
		 */
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  3133
		if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3134
			return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3135
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3136
		verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3137
		    &zc.zc_guid) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3138
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3139
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3140
	zpool_get_rewind_policy(rewindnvl, &policy);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3141
	zc.zc_cookie = policy.zrp_request;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3142
12986
caf415d9aa53 6973547 zpool import succeeds but prints error message
George Wilson <George.Wilson@Sun.COM>
parents: 12961
diff changeset
  3143
	if (zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size * 2) != 0)
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3144
		return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3145
13049
2511753a6599 6782540 zpool cannot replace a replacing device
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12986
diff changeset
  3146
	if (zcmd_write_src_nvlist(hdl, &zc, rewindnvl) != 0)
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3147
		return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3148
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3149
	while ((error = zfs_ioctl(hdl, ZFS_IOC_CLEAR, &zc)) != 0 &&
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3150
	    errno == ENOMEM) {
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3151
		if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3152
			zcmd_free_nvlists(&zc);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3153
			return (-1);
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3154
		}
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3155
	}
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3156
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12877
diff changeset
  3157
	if (!error || ((policy.zrp_request & ZPOOL_TRY_REWIND) &&
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3158
	    errno != EPERM && errno != EACCES)) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3159
		if (policy.zrp_request &
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3160
		    (ZPOOL_DO_REWIND | ZPOOL_TRY_REWIND)) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3161
			(void) zcmd_read_dst_nvlist(hdl, &zc, &nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3162
			zpool_rewind_exclaim(hdl, zc.zc_name,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3163
			    ((policy.zrp_request & ZPOOL_TRY_REWIND) != 0),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3164
			    nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3165
			nvlist_free(nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3166
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3167
		zcmd_free_nvlists(&zc);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3168
		return (0);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3169
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3170
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  3171
	zcmd_free_nvlists(&zc);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3172
	return (zpool_standard_error(hdl, errno, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3173
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3174
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2926
diff changeset
  3175
/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3176
 * Similar to zpool_clear(), but takes a GUID (used by fmd).
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3177
 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3178
int
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3179
zpool_vdev_clear(zpool_handle_t *zhp, uint64_t guid)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3180
{
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3181
	zfs_cmd_t zc = { 0 };
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3182
	char msg[1024];
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3183
	libzfs_handle_t *hdl = zhp->zpool_hdl;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3184
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3185
	(void) snprintf(msg, sizeof (msg),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3186
	    dgettext(TEXT_DOMAIN, "cannot clear errors for %llx"),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3187
	    guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3188
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3189
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3190
	zc.zc_guid = guid;
12441
9aaceacbbfb2 6952889 zpool_vdev_clear is broken
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 12383
diff changeset
  3191
	zc.zc_cookie = ZPOOL_NO_REWIND;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3192
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3193
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_CLEAR, &zc) == 0)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3194
		return (0);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3195
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3196
	return (zpool_standard_error(hdl, errno, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3197
}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3198
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3199
/*
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3200
 * Change the GUID for a pool.
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3201
 */
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3202
int
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3203
zpool_reguid(zpool_handle_t *zhp)
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3204
{
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3205
	char msg[1024];
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3206
	libzfs_handle_t *hdl = zhp->zpool_hdl;
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3207
	zfs_cmd_t zc = { 0 };
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3208
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3209
	(void) snprintf(msg, sizeof (msg),
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3210
	    dgettext(TEXT_DOMAIN, "cannot reguid '%s'"), zhp->zpool_name);
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3211
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3212
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3213
	if (zfs_ioctl(hdl, ZFS_IOC_POOL_REGUID, &zc) == 0)
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3214
		return (0);
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3215
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3216
	return (zpool_standard_error(hdl, errno, msg));
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3217
}
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3218
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13061
diff changeset
  3219
/*
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3220
 * Reopen the pool.
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3221
 */
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3222
int
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3223
zpool_reopen(zpool_handle_t *zhp)
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3224
{
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3225
	zfs_cmd_t zc = { 0 };
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3226
	char msg[1024];
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3227
	libzfs_handle_t *hdl = zhp->zpool_hdl;
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3228
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3229
	(void) snprintf(msg, sizeof (msg),
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3230
	    dgettext(TEXT_DOMAIN, "cannot reopen '%s'"),
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3231
	    zhp->zpool_name);
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3232
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3233
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3234
	if (zfs_ioctl(hdl, ZFS_IOC_POOL_REOPEN, &zc) == 0)
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3235
		return (0);
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3236
	return (zpool_standard_error(hdl, errno, msg));
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3237
}
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3238
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3239
/*
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3240
 * Convert from a devid string to a path.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3241
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3242
static char *
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3243
devid_to_path(char *devid_str)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3244
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3245
	ddi_devid_t devid;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3246
	char *minor;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3247
	char *path;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3248
	devid_nmlist_t *list = NULL;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3249
	int ret;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3250
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3251
	if (devid_str_decode(devid_str, &devid, &minor) != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3252
		return (NULL);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3253
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3254
	ret = devid_deviceid_to_nmlist("/dev", devid, minor, &list);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3255
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3256
	devid_str_free(minor);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3257
	devid_free(devid);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3258
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3259
	if (ret != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3260
		return (NULL);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3261
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3262
	if ((path = strdup(list[0].devname)) == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3263
		return (NULL);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3264
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3265
	devid_free_nmlist(list);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3266
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3267
	return (path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3268
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3269
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3270
/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3271
 * Convert from a path to a devid string.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3272
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3273
static char *
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3274
path_to_devid(const char *path)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3275
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3276
	int fd;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3277
	ddi_devid_t devid;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3278
	char *minor, *ret;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3279
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3280
	if ((fd = open(path, O_RDONLY)) < 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3281
		return (NULL);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3282
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3283
	minor = NULL;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3284
	ret = NULL;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3285
	if (devid_get(fd, &devid) == 0) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3286
		if (devid_get_minor_name(fd, &minor) == 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3287
			ret = devid_str_encode(devid, minor);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3288
		if (minor != NULL)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3289
			devid_str_free(minor);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3290
		devid_free(devid);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3291
	}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3292
	(void) close(fd);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3293
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3294
	return (ret);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3295
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3296
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3297
/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3298
 * Issue the necessary ioctl() to update the stored path value for the vdev.  We
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3299
 * ignore any failure here, since a common case is for an unprivileged user to
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3300
 * type 'zpool status', and we'll display the correct information anyway.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3301
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3302
static void
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3303
set_path(zpool_handle_t *zhp, nvlist_t *nv, const char *path)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3304
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3305
	zfs_cmd_t zc = { 0 };
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3306
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3307
	(void) strncpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3308
	(void) strncpy(zc.zc_value, path, sizeof (zc.zc_value));
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3309
	verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3310
	    &zc.zc_guid) == 0);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3311
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3312
	(void) ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SETPATH, &zc);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3313
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3314
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3315
/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3316
 * Given a vdev, return the name to display in iostat.  If the vdev has a path,
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3317
 * we use that, stripping off any leading "/dev/dsk/"; if not, we use the type.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3318
 * We also check if this is a whole disk, in which case we strip off the
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3319
 * trailing 's0' slice name.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3320
 *
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3321
 * This routine is also responsible for identifying when disks have been
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3322
 * reconfigured in a new location.  The kernel will have opened the device by
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3323
 * devid, but the path will still refer to the old location.  To catch this, we
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3324
 * first do a path -> devid translation (which is fast for the common case).  If
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3325
 * the devid matches, we're done.  If not, we do a reverse devid -> path
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3326
 * translation and issue the appropriate ioctl() to update the path of the vdev.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3327
 * If 'zhp' is NULL, then this is an exported pool, and we don't need to do any
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3328
 * of these checks.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3329
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3330
char *
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3331
zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3332
    boolean_t verbose)
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3333
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3334
	char *path, *devid;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3335
	uint64_t value;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3336
	char buf[64];
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3337
	vdev_stat_t *vs;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3338
	uint_t vsc;
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3339
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3340
	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3341
	    &value) == 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3342
		verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3343
		    &value) == 0);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
  3344
		(void) snprintf(buf, sizeof (buf), "%llu",
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
  3345
		    (u_longlong_t)value);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3346
		path = buf;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3347
	} else if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3348
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3349
		/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3350
		 * If the device is dead (faulted, offline, etc) then don't
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3351
		 * bother opening it.  Otherwise we may be forcing the user to
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3352
		 * open a misbehaving device, which can have undesirable
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3353
		 * effects.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3354
		 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  3355
		if ((nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3356
		    (uint64_t **)&vs, &vsc) != 0 ||
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3357
		    vs->vs_state >= VDEV_STATE_DEGRADED) &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  3358
		    zhp != NULL &&
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3359
		    nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &devid) == 0) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3360
			/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3361
			 * Determine if the current path is correct.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3362
			 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3363
			char *newdevid = path_to_devid(path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3364
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3365
			if (newdevid == NULL ||
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3366
			    strcmp(devid, newdevid) != 0) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3367
				char *newpath;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3368
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3369
				if ((newpath = devid_to_path(devid)) != NULL) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3370
					/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3371
					 * Update the path appropriately.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3372
					 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3373
					set_path(zhp, nv, newpath);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3374
					if (nvlist_add_string(nv,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3375
					    ZPOOL_CONFIG_PATH, newpath) == 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3376
						verify(nvlist_lookup_string(nv,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3377
						    ZPOOL_CONFIG_PATH,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3378
						    &path) == 0);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3379
					free(newpath);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3380
				}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3381
			}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3382
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3383
			if (newdevid)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3384
				devid_str_free(newdevid);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3385
		}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3386
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3387
		if (strncmp(path, "/dev/dsk/", 9) == 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3388
			path += 9;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3389
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3390
		if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3391
		    &value) == 0 && value) {
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3392
			int pathlen = strlen(path);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3393
			char *tmp = zfs_strdup(hdl, path);
12383
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3394
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3395
			/*
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3396
			 * If it starts with c#, and ends with "s0", chop
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3397
			 * the "s0" off, or if it ends with "s0/old", remove
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3398
			 * the "s0" from the middle.
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3399
			 */
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3400
			if (CTD_CHECK(tmp)) {
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3401
				if (strcmp(&tmp[pathlen - 2], "s0") == 0) {
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3402
					tmp[pathlen - 2] = '\0';
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3403
				} else if (pathlen > 6 &&
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3404
				    strcmp(&tmp[pathlen - 6], "s0/old") == 0) {
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3405
					(void) strcpy(&tmp[pathlen - 6],
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3406
					    "/old");
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3407
				}
c8a3959209ef 6881631 zpool_vdev_name(): "c0t0d0s0/old" becomes "c0t0d0s0/o" on whole disks that were replaced
John Harres <John.Harres@Sun.COM>
parents: 12296
diff changeset
  3408
			}
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3409
			return (tmp);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3410
		}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3411
	} else {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3412
		verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &path) == 0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3413
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3414
		/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3415
		 * If it's a raidz device, we need to stick in the parity level.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3416
		 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3417
		if (strcmp(path, VDEV_TYPE_RAIDZ) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3418
			verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3419
			    &value) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3420
			(void) snprintf(buf, sizeof (buf), "%s%llu", path,
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
  3421
			    (u_longlong_t)value);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3422
			path = buf;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3423
		}
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3424
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3425
		/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3426
		 * We identify each top-level vdev by using a <type-id>
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3427
		 * naming convention.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3428
		 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3429
		if (verbose) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3430
			uint64_t id;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3431
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3432
			verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3433
			    &id) == 0);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3434
			(void) snprintf(buf, sizeof (buf), "%s-%llu", path,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3435
			    (u_longlong_t)id);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3436
			path = buf;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3437
		}
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3438
	}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3439
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3440
	return (zfs_strdup(hdl, path));
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3441
}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3442
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3443
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3444
zbookmark_compare(const void *a, const void *b)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3445
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3446
	return (memcmp(a, b, sizeof (zbookmark_t)));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3447
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3448
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3449
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3450
 * Retrieve the persistent error log, uniquify the members, and return to the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3451
 * caller.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3452
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3453
int
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3454
zpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3455
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3456
	zfs_cmd_t zc = { 0 };
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3457
	uint64_t count;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3458
	zbookmark_t *zb = NULL;
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3459
	int i;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3460
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3461
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3462
	 * Retrieve the raw error list from the kernel.  If the number of errors
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3463
	 * has increased, allocate more space and continue until we get the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3464
	 * entire list.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3465
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3466
	verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_ERRCOUNT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3467
	    &count) == 0);
4820
acbb57436af2 6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents: 4715
diff changeset
  3468
	if (count == 0)
acbb57436af2 6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents: 4715
diff changeset
  3469
		return (0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3470
	if ((zc.zc_nvlist_dst = (uintptr_t)zfs_alloc(zhp->zpool_hdl,
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
  3471
	    count * sizeof (zbookmark_t))) == (uintptr_t)NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3472
		return (-1);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3473
	zc.zc_nvlist_dst_size = count;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3474
	(void) strcpy(zc.zc_name, zhp->zpool_name);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3475
	for (;;) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3476
		if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_ERROR_LOG,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3477
		    &zc) != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3478
			free((void *)(uintptr_t)zc.zc_nvlist_dst);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3479
			if (errno == ENOMEM) {
3823
2cbdd0a48584 6494119 zpool status command exits with abort
vb160487
parents: 3741
diff changeset
  3480
				count = zc.zc_nvlist_dst_size;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3481
				if ((zc.zc_nvlist_dst = (uintptr_t)
3823
2cbdd0a48584 6494119 zpool status command exits with abort
vb160487
parents: 3741
diff changeset
  3482
				    zfs_alloc(zhp->zpool_hdl, count *
2cbdd0a48584 6494119 zpool status command exits with abort
vb160487
parents: 3741
diff changeset
  3483
				    sizeof (zbookmark_t))) == (uintptr_t)NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3484
					return (-1);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3485
			} else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3486
				return (-1);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3487
			}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3488
		} else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3489
			break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3490
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3491
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3492
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3493
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3494
	 * Sort the resulting bookmarks.  This is a little confusing due to the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3495
	 * implementation of ZFS_IOC_ERROR_LOG.  The bookmarks are copied last
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3496
	 * to first, and 'zc_nvlist_dst_size' indicates the number of boomarks
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3497
	 * _not_ copied as part of the process.  So we point the start of our
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3498
	 * array appropriate and decrement the total number of elements.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3499
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3500
	zb = ((zbookmark_t *)(uintptr_t)zc.zc_nvlist_dst) +
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3501
	    zc.zc_nvlist_dst_size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3502
	count -= zc.zc_nvlist_dst_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3503
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3504
	qsort(zb, count, sizeof (zbookmark_t), zbookmark_compare);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3505
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3506
	verify(nvlist_alloc(nverrlistp, 0, KM_SLEEP) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3507
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3508
	/*
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3509
	 * Fill in the nverrlistp with nvlist's of dataset and object numbers.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3510
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3511
	for (i = 0; i < count; i++) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3512
		nvlist_t *nv;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3513
3700
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3444
diff changeset
  3514
		/* ignoring zb_blkid and zb_level for now */
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3444
diff changeset
  3515
		if (i > 0 && zb[i-1].zb_objset == zb[i].zb_objset &&
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3444
diff changeset
  3516
		    zb[i-1].zb_object == zb[i].zb_object)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3517
			continue;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3518
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3519
		if (nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3520
			goto nomem;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3521
		if (nvlist_add_uint64(nv, ZPOOL_ERR_DATASET,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3522
		    zb[i].zb_objset) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3523
			nvlist_free(nv);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3524
			goto nomem;
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3525
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3526
		if (nvlist_add_uint64(nv, ZPOOL_ERR_OBJECT,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3527
		    zb[i].zb_object) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3528
			nvlist_free(nv);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3529
			goto nomem;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3530
		}
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3531
		if (nvlist_add_nvlist(*nverrlistp, "ejk", nv) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3532
			nvlist_free(nv);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3533
			goto nomem;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3534
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3535
		nvlist_free(nv);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3536
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3537
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3538
	free((void *)(uintptr_t)zc.zc_nvlist_dst);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3539
	return (0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3540
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3541
nomem:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3542
	free((void *)(uintptr_t)zc.zc_nvlist_dst);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3543
	return (no_memory(zhp->zpool_hdl));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3544
}
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3545
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3546
/*
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3547
 * Upgrade a ZFS pool to the latest on-disk version.
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3548
 */
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3549
int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3550
zpool_upgrade(zpool_handle_t *zhp, uint64_t new_version)
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3551
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3552
	zfs_cmd_t zc = { 0 };
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3553
	libzfs_handle_t *hdl = zhp->zpool_hdl;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3554
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3555
	(void) strcpy(zc.zc_name, zhp->zpool_name);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3556
	zc.zc_cookie = new_version;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3557
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3558
	if (zfs_ioctl(hdl, ZFS_IOC_POOL_UPGRADE, &zc) != 0)
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3559
		return (zpool_standard_error_fmt(hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3560
		    dgettext(TEXT_DOMAIN, "cannot upgrade '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3561
		    zhp->zpool_name));
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3562
	return (0);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3563
}
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3564
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3565
void
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3566
zfs_save_arguments(int argc, char **argv, char *string, int len)
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3567
{
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3568
	(void) strlcpy(string, basename(argv[0]), len);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3569
	for (int i = 1; i < argc; i++) {
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3570
		(void) strlcat(string, " ", len);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3571
		(void) strlcat(string, argv[i], len);
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3572
	}
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3573
}
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3574
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3575
int
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3576
zpool_log_history(libzfs_handle_t *hdl, const char *message)
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3577
{
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3578
	zfs_cmd_t zc = { 0 };
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3579
	nvlist_t *args;
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3580
	int err;
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3581
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3582
	args = fnvlist_alloc();
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3583
	fnvlist_add_string(args, "message", message);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3584
	err = zcmd_write_src_nvlist(hdl, &zc, args);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3585
	if (err == 0)
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3586
		err = ioctl(hdl->libzfs_fd, ZFS_IOC_LOG_HISTORY, &zc);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3587
	nvlist_free(args);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3588
	zcmd_free_nvlists(&zc);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
  3589
	return (err);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3590
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3591
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3592
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3593
 * Perform ioctl to get some command history of a pool.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3594
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3595
 * 'buf' is the buffer to fill up to 'len' bytes.  'off' is the
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3596
 * logical offset of the history buffer to start reading from.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3597
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3598
 * Upon return, 'off' is the next logical offset to read from and
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3599
 * 'len' is the actual amount of bytes read into 'buf'.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3600
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3601
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3602
get_history(zpool_handle_t *zhp, char *buf, uint64_t *off, uint64_t *len)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3603
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3604
	zfs_cmd_t zc = { 0 };
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3605
	libzfs_handle_t *hdl = zhp->zpool_hdl;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3606
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3607
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3608
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3609
	zc.zc_history = (uint64_t)(uintptr_t)buf;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3610
	zc.zc_history_len = *len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3611
	zc.zc_history_offset = *off;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3612
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3613
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_GET_HISTORY, &zc) != 0) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3614
		switch (errno) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3615
		case EPERM:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3616
			return (zfs_error_fmt(hdl, EZFS_PERM,
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3617
			    dgettext(TEXT_DOMAIN,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3618
			    "cannot show history for pool '%s'"),
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3619
			    zhp->zpool_name));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3620
		case ENOENT:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3621
			return (zfs_error_fmt(hdl, EZFS_NOHISTORY,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3622
			    dgettext(TEXT_DOMAIN, "cannot get history for pool "
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3623
			    "'%s'"), zhp->zpool_name));
3863
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3624
		case ENOTSUP:
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3625
			return (zfs_error_fmt(hdl, EZFS_BADVERSION,
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3626
			    dgettext(TEXT_DOMAIN, "cannot get history for pool "
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3627
			    "'%s', pool must be upgraded"), zhp->zpool_name));
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3628
		default:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3629
			return (zpool_standard_error_fmt(hdl, errno,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3630
			    dgettext(TEXT_DOMAIN,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3631
			    "cannot get history for '%s'"), zhp->zpool_name));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3632
		}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3633
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3634
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3635
	*len = zc.zc_history_len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3636
	*off = zc.zc_history_offset;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3637
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3638
	return (0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3639
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3640
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3641
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3642
 * Process the buffer of nvlists, unpacking and storing each nvlist record
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3643
 * into 'records'.  'leftover' is set to the number of bytes that weren't
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3644
 * processed as there wasn't a complete record.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3645
 */
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3646
int
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3647
zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3648
    nvlist_t ***records, uint_t *numrecords)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3649
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3650
	uint64_t reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3651
	nvlist_t *nv;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3652
	int i;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3653
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3654
	while (bytes_read > sizeof (reclen)) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3655
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3656
		/* get length of packed record (stored as little endian) */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3657
		for (i = 0, reclen = 0; i < sizeof (reclen); i++)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3658
			reclen += (uint64_t)(((uchar_t *)buf)[i]) << (8*i);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3659
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3660
		if (bytes_read < sizeof (reclen) + reclen)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3661
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3662
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3663
		/* unpack record */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3664
		if (nvlist_unpack(buf + sizeof (reclen), reclen, &nv, 0) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3665
			return (ENOMEM);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3666
		bytes_read -= sizeof (reclen) + reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3667
		buf += sizeof (reclen) + reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3668
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3669
		/* add record to nvlist array */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3670
		(*numrecords)++;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3671
		if (ISP2(*numrecords + 1)) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3672
			*records = realloc(*records,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3673
			    *numrecords * 2 * sizeof (nvlist_t *));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3674
		}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3675
		(*records)[*numrecords - 1] = nv;
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
	*leftover = bytes_read;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3679
	return (0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3680
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3681
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3682
#define	HIS_BUF_LEN	(128*1024)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3683
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3684
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3685
 * Retrieve the command history of a pool.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3686
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3687
int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3688
zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3689
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3690
	char buf[HIS_BUF_LEN];
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3691
	uint64_t off = 0;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3692
	nvlist_t **records = NULL;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3693
	uint_t numrecords = 0;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3694
	int err, i;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3695
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3696
	do {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3697
		uint64_t bytes_read = sizeof (buf);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3698
		uint64_t leftover;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3699
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3700
		if ((err = get_history(zhp, buf, &off, &bytes_read)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3701
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3702
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3703
		/* if nothing else was read in, we're at EOF, just return */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3704
		if (!bytes_read)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3705
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3706
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3707
		if ((err = zpool_history_unpack(buf, bytes_read,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3708
		    &leftover, &records, &numrecords)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3709
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3710
		off -= leftover;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3711
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3712
		/* CONSTCOND */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3713
	} while (1);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3714
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3715
	if (!err) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3716
		verify(nvlist_alloc(nvhisp, NV_UNIQUE_NAME, 0) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3717
		verify(nvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3718
		    records, numrecords) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3719
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3720
	for (i = 0; i < numrecords; i++)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3721
		nvlist_free(records[i]);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3722
	free(records);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3723
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3724
	return (err);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3725
}
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3726
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3727
void
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3728
zpool_obj_to_path(zpool_handle_t *zhp, uint64_t dsobj, uint64_t obj,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3729
    char *pathname, size_t len)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3730
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3731
	zfs_cmd_t zc = { 0 };
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3732
	boolean_t mounted = B_FALSE;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3733
	char *mntpnt = NULL;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3734
	char dsname[MAXNAMELEN];
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3735
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3736
	if (dsobj == 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3737
		/* special case for the MOS */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3738
		(void) snprintf(pathname, len, "<metadata>:<0x%llx>", obj);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3739
		return;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3740
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3741
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3742
	/* get the dataset's name */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3743
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3744
	zc.zc_obj = dsobj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3745
	if (ioctl(zhp->zpool_hdl->libzfs_fd,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3746
	    ZFS_IOC_DSOBJ_TO_DSNAME, &zc) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3747
		/* just write out a path of two object numbers */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3748
		(void) snprintf(pathname, len, "<0x%llx>:<0x%llx>",
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3749
		    dsobj, obj);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3750
		return;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3751
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3752
	(void) strlcpy(dsname, zc.zc_value, sizeof (dsname));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3753
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3754
	/* find out if the dataset is mounted */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3755
	mounted = is_mounted(zhp->zpool_hdl, dsname, &mntpnt);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3756
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3757
	/* get the corrupted object's path */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3758
	(void) strlcpy(zc.zc_name, dsname, sizeof (zc.zc_name));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3759
	zc.zc_obj = obj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3760
	if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_OBJ_TO_PATH,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3761
	    &zc) == 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3762
		if (mounted) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3763
			(void) snprintf(pathname, len, "%s%s", mntpnt,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3764
			    zc.zc_value);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3765
		} else {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3766
			(void) snprintf(pathname, len, "%s:%s",
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3767
			    dsname, zc.zc_value);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3768
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3769
	} else {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3770
		(void) snprintf(pathname, len, "%s:<0x%llx>", dsname, obj);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3771
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3772
	free(mntpnt);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3773
}
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  3774
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: 3912
diff changeset
  3775
/*
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3776
 * Read the EFI label from the config, if a label does not exist then
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3777
 * pass back the error to the caller. If the caller has passed a non-NULL
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3778
 * diskaddr argument then we set it to the starting address of the EFI
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3779
 * partition.
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3780
 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3781
static int
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3782
read_efi_label(nvlist_t *config, diskaddr_t *sb)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3783
{
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3784
	char *path;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3785
	int fd;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3786
	char diskname[MAXPATHLEN];
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3787
	int err = -1;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3788
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3789
	if (nvlist_lookup_string(config, ZPOOL_CONFIG_PATH, &path) != 0)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3790
		return (err);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3791
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3792
	(void) snprintf(diskname, sizeof (diskname), "%s%s", RDISK_ROOT,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3793
	    strrchr(path, '/'));
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3794
	if ((fd = open(diskname, O_RDONLY|O_NDELAY)) >= 0) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3795
		struct dk_gpt *vtoc;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3796
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3797
		if ((err = efi_alloc_and_read(fd, &vtoc)) >= 0) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3798
			if (sb != NULL)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3799
				*sb = vtoc->efi_parts[0].p_start;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3800
			efi_free(vtoc);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3801
		}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3802
		(void) close(fd);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3803
	}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3804
	return (err);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3805
}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3806
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3807
/*
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: 3912
diff changeset
  3808
 * determine where a partition starts on a disk in the current
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3809
 * configuration
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3810
 */
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3811
static diskaddr_t
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3812
find_start_block(nvlist_t *config)
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3813
{
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3814
	nvlist_t **child;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3815
	uint_t c, children;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3816
	diskaddr_t sb = MAXOFFSET_T;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3817
	uint64_t wholedisk;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3818
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3819
	if (nvlist_lookup_nvlist_array(config,
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3820
	    ZPOOL_CONFIG_CHILDREN, &child, &children) != 0) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3821
		if (nvlist_lookup_uint64(config,
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3822
		    ZPOOL_CONFIG_WHOLE_DISK,
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3823
		    &wholedisk) != 0 || !wholedisk) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3824
			return (MAXOFFSET_T);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3825
		}
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3826
		if (read_efi_label(config, &sb) < 0)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3827
			sb = MAXOFFSET_T;
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: 3912
diff changeset
  3828
		return (sb);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3829
	}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3830
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3831
	for (c = 0; c < children; c++) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3832
		sb = find_start_block(child[c]);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3833
		if (sb != MAXOFFSET_T) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3834
			return (sb);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3835
		}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3836
	}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3837
	return (MAXOFFSET_T);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3838
}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3839
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3840
/*
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3841
 * Label an individual disk.  The name provided is the short name,
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3842
 * stripped of any leading /dev path.
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3843
 */
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3844
int
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3845
zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, char *name)
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3846
{
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3847
	char path[MAXPATHLEN];
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3848
	struct dk_gpt *vtoc;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3849
	int fd;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3850
	size_t resv = EFI_MIN_RESV_SIZE;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3851
	uint64_t slice_size;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3852
	diskaddr_t start_block;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3853
	char errbuf[1024];
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3854
6289
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3855
	/* prepare an error message just in case */
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3856
	(void) snprintf(errbuf, sizeof (errbuf),
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3857
	    dgettext(TEXT_DOMAIN, "cannot label '%s'"), name);
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3858
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: 3912
diff changeset
  3859
	if (zhp) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3860
		nvlist_t *nvroot;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3861
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 13525
diff changeset
  3862
		if (zpool_is_bootable(zhp)) {
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3863
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3864
			    "EFI labeled devices are not supported on root "
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3865
			    "pools."));
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3866
			return (zfs_error(hdl, EZFS_POOL_NOTSUP, errbuf));
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3867
		}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3868
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: 3912
diff changeset
  3869
		verify(nvlist_lookup_nvlist(zhp->zpool_config,
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3870
		    ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3871
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3872
		if (zhp->zpool_start_block == 0)
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3873
			start_block = find_start_block(nvroot);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3874
		else
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3875
			start_block = zhp->zpool_start_block;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3876
		zhp->zpool_start_block = start_block;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3877
	} else {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3878
		/* new pool */
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3879
		start_block = NEW_START_BLOCK;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3880
	}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3881
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3882
	(void) snprintf(path, sizeof (path), "%s/%s%s", RDISK_ROOT, name,
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3883
	    BACKUP_SLICE);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3884
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3885
	if ((fd = open(path, O_RDWR | O_NDELAY)) < 0) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3886
		/*
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3887
		 * This shouldn't happen.  We've long since verified that this
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3888
		 * is a valid device.
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3889
		 */
6289
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3890
		zfs_error_aux(hdl,
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3891
		    dgettext(TEXT_DOMAIN, "unable to open device"));
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: 3912
diff changeset
  3892
		return (zfs_error(hdl, EZFS_OPENFAILED, errbuf));
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3893
	}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3894
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3895
	if (efi_alloc_and_init(fd, EFI_NUMPAR, &vtoc) != 0) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3896
		/*
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3897
		 * The only way this can fail is if we run out of memory, or we
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3898
		 * were unable to read the disk's capacity
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3899
		 */
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3900
		if (errno == ENOMEM)
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3901
			(void) no_memory(hdl);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3902
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3903
		(void) close(fd);
6289
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3904
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3905
		    "unable to read disk capacity"), name);
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: 3912
diff changeset
  3906
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3907
		return (zfs_error(hdl, EZFS_NOCAP, errbuf));
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3908
	}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3909
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3910
	slice_size = vtoc->efi_last_u_lba + 1;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3911
	slice_size -= EFI_MIN_RESV_SIZE;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3912
	if (start_block == MAXOFFSET_T)
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3913
		start_block = NEW_START_BLOCK;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3914
	slice_size -= start_block;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3915
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3916
	vtoc->efi_parts[0].p_start = start_block;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3917
	vtoc->efi_parts[0].p_size = slice_size;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3918
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3919
	/*
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3920
	 * Why we use V_USR: V_BACKUP confuses users, and is considered
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3921
	 * disposable by some EFI utilities (since EFI doesn't have a backup
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3922
	 * slice).  V_UNASSIGNED is supposed to be used only for zero size
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3923
	 * partitions, and efi_write() will fail if we use it.  V_ROOT, V_BOOT,
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3924
	 * etc. were all pretty specific.  V_USR is as close to reality as we
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3925
	 * can get, in the absence of V_OTHER.
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3926
	 */
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3927
	vtoc->efi_parts[0].p_tag = V_USR;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3928
	(void) strcpy(vtoc->efi_parts[0].p_name, "zfs");
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3929
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3930
	vtoc->efi_parts[8].p_start = slice_size + start_block;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3931
	vtoc->efi_parts[8].p_size = resv;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3932
	vtoc->efi_parts[8].p_tag = V_RESERVED;
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3933
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3934
	if (efi_write(fd, vtoc) != 0) {
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3935
		/*
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3936
		 * Some block drivers (like pcata) may not support EFI
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3937
		 * GPT labels.  Print out a helpful error message dir-
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3938
		 * ecting the user to manually label the disk and give
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3939
		 * a specific slice.
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3940
		 */
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3941
		(void) close(fd);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3942
		efi_free(vtoc);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3943
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3944
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6289
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3945
		    "try using fdisk(1M) and then provide a specific slice"));
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: 3912
diff changeset
  3946
		return (zfs_error(hdl, EZFS_LABELFAILED, errbuf));
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3947
	}
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3948
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3949
	(void) close(fd);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3950
	efi_free(vtoc);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3951
	return (0);
c42d49ffb16f 6385547 zpool create of a mirror using a device and a slice of a device (of same size) reports an error
taylor
parents: 3912
diff changeset
  3952
}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3953
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3954
static boolean_t
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3955
supported_dump_vdev_type(libzfs_handle_t *hdl, nvlist_t *config, char *errbuf)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3956
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3957
	char *type;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3958
	nvlist_t **child;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3959
	uint_t children, c;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3960
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3961
	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_TYPE, &type) == 0);
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
  3962
	if (strcmp(type, VDEV_TYPE_FILE) == 0 ||
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3963
	    strcmp(type, VDEV_TYPE_HOLE) == 0 ||
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3964
	    strcmp(type, VDEV_TYPE_MISSING) == 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3965
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3966
		    "vdev type '%s' is not supported"), type);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3967
		(void) zfs_error(hdl, EZFS_VDEVNOTSUP, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3968
		return (B_FALSE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3969
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3970
	if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3971
	    &child, &children) == 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3972
		for (c = 0; c < children; c++) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3973
			if (!supported_dump_vdev_type(hdl, child[c], errbuf))
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3974
				return (B_FALSE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3975
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3976
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3977
	return (B_TRUE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3978
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3979
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3980
/*
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
  3981
 * Check if this zvol is allowable for use as a dump device; zero if
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
  3982
 * it is, > 0 if it isn't, < 0 if it isn't a zvol.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
  3983
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
  3984
 * Allowable storage configurations include mirrors, all raidz variants, and
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
  3985
 * pools with log, cache, and spare devices.  Pools which are backed by files or
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14049
diff changeset
  3986
 * have missing/hole vdevs are not suitable.
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3987
 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3988
int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3989
zvol_check_dump_config(char *arg)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3990
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3991
	zpool_handle_t *zhp = NULL;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3992
	nvlist_t *config, *nvroot;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3993
	char *p, *volname;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3994
	nvlist_t **top;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3995
	uint_t toplevels;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3996
	libzfs_handle_t *hdl;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3997
	char errbuf[1024];
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3998
	char poolname[ZPOOL_MAXNAMELEN];
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3999
	int pathlen = strlen(ZVOL_FULL_DEV_DIR);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4000
	int ret = 1;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4001
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4002
	if (strncmp(arg, ZVOL_FULL_DEV_DIR, pathlen)) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4003
		return (-1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4004
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4005
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4006
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4007
	    "dump is not supported on device '%s'"), arg);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4008
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4009
	if ((hdl = libzfs_init()) == NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4010
		return (1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4011
	libzfs_print_on_error(hdl, B_TRUE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4012
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4013
	volname = arg + pathlen;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4014
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4015
	/* check the configuration of the pool */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4016
	if ((p = strchr(volname, '/')) == NULL) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4017
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4018
		    "malformed dataset name"));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4019
		(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4020
		return (1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4021
	} else if (p - volname >= ZFS_MAXNAMELEN) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4022
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4023
		    "dataset name is too long"));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4024
		(void) zfs_error(hdl, EZFS_NAMETOOLONG, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4025
		return (1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4026
	} else {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4027
		(void) strncpy(poolname, volname, p - volname);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4028
		poolname[p - volname] = '\0';
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4029
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4030
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4031
	if ((zhp = zpool_open(hdl, poolname)) == NULL) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4032
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4033
		    "could not open pool '%s'"), poolname);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4034
		(void) zfs_error(hdl, EZFS_OPENFAILED, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4035
		goto out;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4036
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4037
	config = zpool_get_config(zhp, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4038
	if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4039
	    &nvroot) != 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4040
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4041
		    "could not obtain vdev configuration for  '%s'"), poolname);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4042
		(void) zfs_error(hdl, EZFS_INVALCONFIG, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4043
		goto out;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4044
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4045
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4046
	verify(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4047
	    &top, &toplevels) == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4048
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4049
	if (!supported_dump_vdev_type(hdl, top[0], errbuf)) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4050
		goto out;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4051
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4052
	ret = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4053
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4054
out:
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4055
	if (zhp)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4056
		zpool_close(zhp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4057
	libzfs_fini(hdl);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4058
	return (ret);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  4059
}