usr/src/lib/libzfs/common/libzfs_pool.c
author Lin Ling <Lin.Ling@Sun.COM>
Mon, 03 May 2010 14:54:08 -0700
changeset 12296 7cf402a7f374
parent 11814 09d130965476
child 12383 c8a3959209ef
permissions -rw-r--r--
6675946 'zpool status' should show the progress of resilvering for individual disk. 6683750 scrub -s have to wait until resilver completed? 6841252 Resilvering not restartable - causing an excess reboot delay 6855073 spa scrub stats (eg %done) are reset on reboot 6891824 7410 NAS head "continually resilvering" following HDD replacement 6899970 scrub/resilver percent complete reporting in zpool status can be overly optimistic 6940889 add interval (count) args to zpool list 6944623 dbuf_read_done() locking performance improvement 6946760 mutex problem in bplist_enqueue() 6391915 RFE: provide interval arg to zpool status to monitor resilvering 6946512 want zfs_send() to pass back debug info 6943992 'zpool scrub' should not restart the existing scrub silently 6878281 zpool should store the time of last scrub/resilver and other zpool status info in pool properties. 6935158 Assertion failed: used <= spa_get_dspace(dd->dd_pool->dp_spa) 6944388 dsl_dataset_snapshot_reserve_space() causes dp_write_limit=max
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.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <ctype.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <devid.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <fcntl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <libintl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <stdio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <stdlib.h>
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2926
diff changeset
    33
#include <strings.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <unistd.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
    35
#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
    36
#include <sys/vtoc.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/zfs_ioctl.h>
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    38
#include <dlfcn.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include "zfs_namecheck.h"
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
    41
#include "zfs_prop.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include "libzfs_impl.h"
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
    43
#include "zfs_comutil.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
    45
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
    46
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
    47
#if defined(__i386) || defined(__amd64)
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
    48
#define	BOOTCMD	"installgrub(1M)"
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
    49
#else
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
    50
#define	BOOTCMD	"installboot(1M)"
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
    51
#endif
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
    52
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    53
#define	DISK_ROOT	"/dev/dsk"
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    54
#define	RDISK_ROOT	"/dev/rdsk"
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    55
#define	BACKUP_SLICE	"s2"
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
    56
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    57
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    58
 * ====================================================================
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    59
 *   zpool property functions
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    60
 * ====================================================================
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
static int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    64
zpool_get_all_props(zpool_handle_t *zhp)
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
	zfs_cmd_t zc = { 0 };
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    67
	libzfs_handle_t *hdl = zhp->zpool_hdl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    68
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    69
	(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
    70
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    71
	if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    72
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    73
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    74
	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
    75
		if (errno == ENOMEM) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    76
			if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    77
				zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    78
				return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    79
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    80
		} else {
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
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    85
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    86
	if (zcmd_read_dst_nvlist(hdl, &zc, &zhp->zpool_props) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    87
		zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    88
		return (-1);
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
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
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    93
	return (0);
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
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    96
static int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
    97
zpool_props_refresh(zpool_handle_t *zhp)
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
	nvlist_t *old_props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   100
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   101
	old_props = zhp->zpool_props;
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
	if (zpool_get_all_props(zhp) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   104
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   105
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   106
	nvlist_free(old_props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   107
	return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   108
}
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
static char *
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   111
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
   112
    zprop_source_t *src)
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
	nvlist_t *nv, *nvl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   115
	uint64_t ival;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   116
	char *value;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   117
	zprop_source_t source;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   118
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   119
	nvl = zhp->zpool_props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   120
	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
   121
		verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &ival) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   122
		source = ival;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   123
		verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   124
	} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   125
		source = ZPROP_SRC_DEFAULT;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   126
		if ((value = (char *)zpool_prop_default_string(prop)) == NULL)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   127
			value = "-";
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   128
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   129
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   130
	if (src)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   131
		*src = source;
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
	return (value);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   134
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   135
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   136
uint64_t
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   137
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
   138
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   139
	nvlist_t *nv, *nvl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   140
	uint64_t value;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   141
	zprop_source_t source;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   142
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   143
	if (zhp->zpool_props == NULL && zpool_get_all_props(zhp)) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   144
		/*
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   145
		 * zpool_get_all_props() has most likely failed because
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   146
		 * 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
   147
		 * 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
   148
		 */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   149
		if ((prop == ZPOOL_PROP_GUID) &&
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   150
		    (nvlist_lookup_nvlist(zhp->zpool_config,
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   151
		    ZPOOL_CONFIG_VDEV_TREE, &nv) == 0) &&
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   152
		    (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &value)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   153
		    == 0)) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   154
			return (value);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   155
		}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   156
		return (zpool_prop_default_numeric(prop));
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   157
	}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   158
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   159
	nvl = zhp->zpool_props;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   160
	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
   161
		verify(nvlist_lookup_uint64(nv, ZPROP_SOURCE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   162
		source = value;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   163
		verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   164
	} else {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   165
		source = ZPROP_SRC_DEFAULT;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   166
		value = zpool_prop_default_numeric(prop);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   167
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   168
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   169
	if (src)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   170
		*src = source;
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
	return (value);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   173
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   174
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
 * Map VDEV STATE to printed strings.
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
char *
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   179
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
   180
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   181
	switch (state) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   182
	case VDEV_STATE_CLOSED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   183
	case VDEV_STATE_OFFLINE:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   184
		return (gettext("OFFLINE"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   185
	case VDEV_STATE_REMOVED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   186
		return (gettext("REMOVED"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   187
	case VDEV_STATE_CANT_OPEN:
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7214
diff changeset
   188
		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
   189
			return (gettext("FAULTED"));
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
   190
		else if (aux == VDEV_AUX_SPLIT_POOL)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
   191
			return (gettext("SPLIT"));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   192
		else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   193
			return (gettext("UNAVAIL"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   194
	case VDEV_STATE_FAULTED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   195
		return (gettext("FAULTED"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   196
	case VDEV_STATE_DEGRADED:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   197
		return (gettext("DEGRADED"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   198
	case VDEV_STATE_HEALTHY:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   199
		return (gettext("ONLINE"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   200
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   201
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   202
	return (gettext("UNKNOWN"));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   203
}
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
 * 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
   207
 * a pre-allocated buffer.
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
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   210
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
   211
    zprop_source_t *srctype)
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
	uint64_t intval;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   214
	const char *strval;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   215
	zprop_source_t src = ZPROP_SRC_NONE;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   216
	nvlist_t *nvroot;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   217
	vdev_stat_t *vs;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   218
	uint_t vsc;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   219
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   220
	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
   221
		switch (prop) {
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   222
		case ZPOOL_PROP_NAME:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   223
			(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
   224
			break;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   225
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   226
		case ZPOOL_PROP_HEALTH:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   227
			(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
   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_GUID:
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   231
			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
   232
			(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
   233
			break;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   234
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   235
		case ZPOOL_PROP_ALTROOT:
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   236
		case ZPOOL_PROP_CACHEFILE:
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   237
			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
   238
			    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
   239
				(void) strlcpy(buf,
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   240
				    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
   241
				    len);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   242
				if (srctype != NULL)
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   243
					*srctype = src;
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   244
				return (0);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   245
			}
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   246
			/* FALLTHROUGH */
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   247
		default:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   248
			(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
   249
			break;
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
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   252
		if (srctype != NULL)
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8211
diff changeset
   253
			*srctype = src;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   254
		return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   255
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   256
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   257
	if (zhp->zpool_props == NULL && zpool_get_all_props(zhp) &&
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   258
	    prop != ZPOOL_PROP_NAME)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   259
		return (-1);
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
	switch (zpool_prop_get_type(prop)) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   262
	case PROP_TYPE_STRING:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   263
		(void) strlcpy(buf, zpool_get_prop_string(zhp, prop, &src),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   264
		    len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   265
		break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   266
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   267
	case PROP_TYPE_NUMBER:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   268
		intval = zpool_get_prop_int(zhp, prop, &src);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   269
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   270
		switch (prop) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   271
		case ZPOOL_PROP_SIZE:
10956
0c81acaaf614 6897693 deduplication can only go so far
George Wilson <George.Wilson@Sun.COM>
parents: 10922
diff changeset
   272
		case ZPOOL_PROP_ALLOCATED:
0c81acaaf614 6897693 deduplication can only go so far
George Wilson <George.Wilson@Sun.COM>
parents: 10922
diff changeset
   273
		case ZPOOL_PROP_FREE:
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   274
			(void) zfs_nicenum(intval, buf, len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   275
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   276
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   277
		case ZPOOL_PROP_CAPACITY:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   278
			(void) snprintf(buf, len, "%llu%%",
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   279
			    (u_longlong_t)intval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   280
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   281
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   282
		case ZPOOL_PROP_DEDUPRATIO:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   283
			(void) snprintf(buf, len, "%llu.%02llux",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   284
			    (u_longlong_t)(intval / 100),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   285
			    (u_longlong_t)(intval % 100));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   286
			break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   287
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   288
		case ZPOOL_PROP_HEALTH:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   289
			verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   290
			    ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   291
			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
   292
			    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
   293
			    == 0);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   294
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   295
			(void) strlcpy(buf, zpool_state_to_name(intval,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   296
			    vs->vs_aux), len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   297
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   298
		default:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   299
			(void) snprintf(buf, len, "%llu", intval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   300
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   301
		break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   302
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   303
	case PROP_TYPE_INDEX:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   304
		intval = zpool_get_prop_int(zhp, prop, &src);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   305
		if (zpool_prop_index_to_string(prop, intval, &strval)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   306
		    != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   307
			return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   308
		(void) strlcpy(buf, strval, len);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   309
		break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   310
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
		abort();
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
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   315
	if (srctype)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   316
		*srctype = src;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   317
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   318
	return (0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   319
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   320
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   321
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   322
 * 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
   323
 * Assuming bootfs is a valid dataset name.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   324
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   325
static boolean_t
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   326
bootfs_name_valid(const char *pool, char *bootfs)
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
	int len = strlen(pool);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   329
7300
3f0c3af330d3 6667976 support booting up a snapshot root dataset
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   330
	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
   331
		return (B_FALSE);
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
	if (strncmp(pool, bootfs, len) == 0 &&
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   334
	    (bootfs[len] == '/' || bootfs[len] == '\0'))
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   335
		return (B_TRUE);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   336
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   337
	return (B_FALSE);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   338
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   339
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   340
/*
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   341
 * 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
   342
 * an EFI label.
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   343
 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   344
static boolean_t
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   345
pool_uses_efi(nvlist_t *config)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   346
{
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   347
	nvlist_t **child;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   348
	uint_t c, children;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   349
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   350
	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
   351
	    &child, &children) != 0)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   352
		return (read_efi_label(config, NULL) >= 0);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   353
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   354
	for (c = 0; c < children; c++) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   355
		if (pool_uses_efi(child[c]))
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   356
			return (B_TRUE);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   357
	}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   358
	return (B_FALSE);
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
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   361
static boolean_t
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   362
pool_is_bootable(zpool_handle_t *zhp)
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   363
{
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   364
	char bootfs[ZPOOL_MAXNAMELEN];
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   365
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   366
	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
   367
	    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
   368
	    sizeof (bootfs)) != 0);
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   369
}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   370
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
   371
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   372
/*
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   373
 * 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
   374
 * 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
   375
 * specified as strings.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   376
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   377
static nvlist_t *
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   378
zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   379
    nvlist_t *props, uint64_t version, boolean_t create_or_import, char *errbuf)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   380
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   381
	nvpair_t *elem;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   382
	nvlist_t *retprops;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   383
	zpool_prop_t prop;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   384
	char *strval;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   385
	uint64_t intval;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   386
	char *slash;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   387
	struct stat64 statbuf;
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   388
	zpool_handle_t *zhp;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   389
	nvlist_t *nvroot;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   390
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   391
	if (nvlist_alloc(&retprops, NV_UNIQUE_NAME, 0) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   392
		(void) no_memory(hdl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   393
		return (NULL);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   394
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   395
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   396
	elem = NULL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   397
	while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   398
		const char *propname = nvpair_name(elem);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   399
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   400
		/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   401
		 * Make sure this property is valid and applies to this type.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   402
		 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   403
		if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   404
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   405
			    "invalid property '%s'"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   406
			(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   407
			goto error;
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
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   410
		if (zpool_prop_readonly(prop)) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   411
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   412
			    "is readonly"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   413
			(void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   414
			goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   415
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   416
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   417
		if (zprop_parse_value(hdl, elem, prop, ZFS_TYPE_POOL, retprops,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   418
		    &strval, &intval, errbuf) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   419
			goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   420
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   421
		/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   422
		 * Perform additional checking for specific properties.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   423
		 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   424
		switch (prop) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   425
		case ZPOOL_PROP_VERSION:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   426
			if (intval < version || intval > SPA_VERSION) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   427
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   428
				    "property '%s' number %d is invalid."),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   429
				    propname, intval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   430
				(void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   431
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   432
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   433
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   434
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   435
		case ZPOOL_PROP_BOOTFS:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   436
			if (create_or_import) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   437
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   438
				    "property '%s' cannot be set at creation "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   439
				    "or import time"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   440
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   441
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   442
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   443
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   444
			if (version < SPA_VERSION_BOOTFS) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   445
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   446
				    "pool must be upgraded to support "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   447
				    "'%s' property"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   448
				(void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   449
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   450
			}
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
			/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   453
			 * bootfs property value has to be a dataset name and
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   454
			 * 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
   455
			 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   456
			if (strval[0] != '\0' && !bootfs_name_valid(poolname,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   457
			    strval)) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   458
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   459
				    "is an invalid name"), strval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   460
				(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   461
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   462
			}
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   463
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   464
			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
   465
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   466
				    "could not open pool '%s'"), poolname);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   467
				(void) zfs_error(hdl, EZFS_OPENFAILED, errbuf);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   468
				goto error;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   469
			}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   470
			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
   471
			    ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   472
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   473
			/*
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   474
			 * 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
   475
			 * been EFI labeled.
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   476
			 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   477
			if (pool_uses_efi(nvroot)) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   478
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   479
				    "property '%s' not supported on "
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   480
				    "EFI labeled devices"), propname);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   481
				(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
   482
				zpool_close(zhp);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   483
				goto error;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   484
			}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
   485
			zpool_close(zhp);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   486
			break;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   487
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   488
		case ZPOOL_PROP_ALTROOT:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   489
			if (!create_or_import) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   490
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   491
				    "property '%s' can only be set during pool "
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   492
				    "creation or import"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   493
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   494
				goto error;
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
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   497
			if (strval[0] != '/') {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   498
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   499
				    "bad alternate root '%s'"), strval);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   500
				(void) zfs_error(hdl, EZFS_BADPATH, 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
			break;
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   504
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   505
		case ZPOOL_PROP_CACHEFILE:
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   506
			if (strval[0] == '\0')
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   507
				break;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   508
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   509
			if (strcmp(strval, "none") == 0)
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   510
				break;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   511
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   512
			if (strval[0] != '/') {
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   513
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   514
				    "property '%s' must be empty, an "
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   515
				    "absolute path, or 'none'"), propname);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   516
				(void) zfs_error(hdl, EZFS_BADPATH, errbuf);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   517
				goto error;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   518
			}
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   519
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   520
			slash = strrchr(strval, '/');
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   521
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   522
			if (slash[1] == '\0' || strcmp(slash, "/.") == 0 ||
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   523
			    strcmp(slash, "/..") == 0) {
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   524
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   525
				    "'%s' is not a valid file"), strval);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   526
				(void) zfs_error(hdl, EZFS_BADPATH, errbuf);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   527
				goto error;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   528
			}
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   529
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   530
			*slash = '\0';
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   531
5621
cd0984d5b1c1 6627006 setting cachefile to default value confuses ZFS
eschrock
parents: 5450
diff changeset
   532
			if (strval[0] != '\0' &&
cd0984d5b1c1 6627006 setting cachefile to default value confuses ZFS
eschrock
parents: 5450
diff changeset
   533
			    (stat64(strval, &statbuf) != 0 ||
cd0984d5b1c1 6627006 setting cachefile to default value confuses ZFS
eschrock
parents: 5450
diff changeset
   534
			    !S_ISDIR(statbuf.st_mode))) {
5363
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   535
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   536
				    "'%s' is not a valid directory"),
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   537
				    strval);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   538
				(void) zfs_error(hdl, EZFS_BADPATH, errbuf);
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   539
				goto error;
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   540
			}
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   541
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   542
			*slash = '/';
36eeffc5336d PSARC 2007/607 ZFS cachefile property
eschrock
parents: 5320
diff changeset
   543
			break;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   544
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   545
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   546
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   547
	return (retprops);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   548
error:
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   549
	nvlist_free(retprops);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   550
	return (NULL);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   551
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   552
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   553
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   554
 * Set zpool property : propname=propval.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   555
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   556
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   557
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
   558
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   559
	zfs_cmd_t zc = { 0 };
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   560
	int ret = -1;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   561
	char errbuf[1024];
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   562
	nvlist_t *nvl = NULL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   563
	nvlist_t *realprops;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   564
	uint64_t version;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   565
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   566
	(void) snprintf(errbuf, sizeof (errbuf),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   567
	    dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   568
	    zhp->zpool_name);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   569
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   570
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   571
		return (no_memory(zhp->zpool_hdl));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   572
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   573
	if (nvlist_add_string(nvl, propname, propval) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   574
		nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   575
		return (no_memory(zhp->zpool_hdl));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   576
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   577
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   578
	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
   579
	if ((realprops = zpool_valid_proplist(zhp->zpool_hdl,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   580
	    zhp->zpool_name, nvl, version, B_FALSE, errbuf)) == NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   581
		nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   582
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   583
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   584
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   585
	nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   586
	nvl = realprops;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   587
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   588
	/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   589
	 * Execute the corresponding ioctl() to set this property.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   590
	 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   591
	(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
   592
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   593
	if (zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, nvl) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   594
		nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   595
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   596
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   597
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   598
	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
   599
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   600
	zcmd_free_nvlists(&zc);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   601
	nvlist_free(nvl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   602
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   603
	if (ret)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   604
		(void) zpool_standard_error(zhp->zpool_hdl, errno, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   605
	else
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   606
		(void) zpool_props_refresh(zhp);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   607
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   608
	return (ret);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   609
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   610
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   611
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   612
zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   613
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   614
	libzfs_handle_t *hdl = zhp->zpool_hdl;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   615
	zprop_list_t *entry;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   616
	char buf[ZFS_MAXPROPLEN];
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   617
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   618
	if (zprop_expand_list(hdl, plp, ZFS_TYPE_POOL) != 0)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   619
		return (-1);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   620
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   621
	for (entry = *plp; entry != NULL; entry = entry->pl_next) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   622
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   623
		if (entry->pl_fixed)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   624
			continue;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   625
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   626
		if (entry->pl_prop != ZPROP_INVAL &&
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   627
		    zpool_get_prop(zhp, entry->pl_prop, buf, sizeof (buf),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   628
		    NULL) == 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   629
			if (strlen(buf) > entry->pl_width)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   630
				entry->pl_width = strlen(buf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   631
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   632
	}
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
	return (0);
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
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   637
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   639
 * 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
   640
 * 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
   641
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   642
#define	NEW_START_BLOCK	256
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   643
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
   644
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
 * Validate the given pool name, optionally putting an extended error message in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
 * 'buf'.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
 */
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   648
boolean_t
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   649
zpool_name_valid(libzfs_handle_t *hdl, boolean_t isopen, const char *pool)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
	namecheck_err_t why;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
	char what;
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   653
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   655
	ret = pool_namecheck(pool, &why, &what);
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   656
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   657
	/*
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   658
	 * 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
   659
	 * 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
   660
	 * 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
   661
	 * 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
   662
	 */
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   663
	if (ret == 0 && !isopen &&
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   664
	    (strncmp(pool, "mirror", 6) == 0 ||
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   665
	    strncmp(pool, "raidz", 5) == 0 ||
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   666
	    strncmp(pool, "spare", 5) == 0 ||
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   667
	    strcmp(pool, "log") == 0)) {
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   668
		if (hdl != NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   669
			zfs_error_aux(hdl,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
   670
			    dgettext(TEXT_DOMAIN, "name is reserved"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   671
		return (B_FALSE);
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   672
	}
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   673
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   674
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1760
diff changeset
   675
	if (ret != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   676
		if (hdl != NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
			switch (why) {
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   678
			case NAME_ERR_TOOLONG:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   679
				zfs_error_aux(hdl,
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   680
				    dgettext(TEXT_DOMAIN, "name is too long"));
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   681
				break;
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 952
diff changeset
   682
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
			case NAME_ERR_INVALCHAR:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   684
				zfs_error_aux(hdl,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
				    dgettext(TEXT_DOMAIN, "invalid character "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
				    "'%c' in pool name"), what);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
			case NAME_ERR_NOLETTER:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   690
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   691
				    "name must begin with a letter"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
			case NAME_ERR_RESERVED:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   695
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   696
				    "name is reserved"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
			case NAME_ERR_DISKLIKE:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   700
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   701
				    "pool name is reserved"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
				break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   703
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   704
			case NAME_ERR_LEADING_SLASH:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   705
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   706
				    "leading slash in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   707
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   708
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   709
			case NAME_ERR_EMPTY_COMPONENT:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   710
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   711
				    "empty component in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   712
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   713
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   714
			case NAME_ERR_TRAILING_SLASH:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   715
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   716
				    "trailing slash in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   717
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   718
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   719
			case NAME_ERR_MULTIPLE_AT:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   720
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   721
				    "multiple '@' delimiters in name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   722
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
   723
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   726
		return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   729
	return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
 * 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
   734
 * state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
zpool_handle_t *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   737
zpool_open_canfail(libzfs_handle_t *hdl, const char *pool)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
	zpool_handle_t *zhp;
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   740
	boolean_t missing;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
	 * Make sure the pool name is valid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   745
	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
   746
		(void) zfs_error_fmt(hdl, EZFS_INVALIDNAME,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   747
		    dgettext(TEXT_DOMAIN, "cannot open '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   748
		    pool);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   752
	if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   753
		return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   755
	zhp->zpool_hdl = hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   758
	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
   759
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   760
		return (NULL);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   761
	}
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   762
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   763
	if (missing) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   764
		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
   765
		(void) zfs_error_fmt(hdl, EZFS_NOENT,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   766
		    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
   767
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   768
		return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
 * Like the above, but silent on error.  Used when iterating over pools (because
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
 * the configuration cache may be out of date).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
 */
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   778
int
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   779
zpool_open_silent(libzfs_handle_t *hdl, const char *pool, zpool_handle_t **ret)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
	zpool_handle_t *zhp;
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   782
	boolean_t missing;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   784
	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
   785
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   787
	zhp->zpool_hdl = hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
	(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   790
	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
   791
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   792
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   795
	if (missing) {
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   796
		zpool_close(zhp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   797
		*ret = NULL;
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   798
		return (0);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   799
	}
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   800
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   801
	*ret = zhp;
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   802
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
 * Similar to zpool_open_canfail(), but refuses to open pools in the faulted
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
 * state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
zpool_handle_t *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   810
zpool_open(libzfs_handle_t *hdl, const char *pool)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
	zpool_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   814
	if ((zhp = zpool_open_canfail(hdl, pool)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	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
   818
		(void) zfs_error_fmt(hdl, EZFS_POOLUNAVAIL,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   819
		    dgettext(TEXT_DOMAIN, "cannot open '%s'"), zhp->zpool_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
		zpool_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
 * Close the handle.  Simply frees the memory associated with the handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
zpool_close(zpool_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
	if (zhp->zpool_config)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
		nvlist_free(zhp->zpool_config);
952
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
   835
	if (zhp->zpool_old_config)
12ec54aa046e 6344502 placeholder bug for the remaining Makefile cleanup work for ZFS
eschrock
parents: 789
diff changeset
   836
		nvlist_free(zhp->zpool_old_config);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
   837
	if (zhp->zpool_props)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
   838
		nvlist_free(zhp->zpool_props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
	free(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
 * Return the name of the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
zpool_get_name(zpool_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
	return (zhp->zpool_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
 * Return the state of the pool (ACTIVE or UNAVAILABLE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
zpool_get_state(zpool_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
	return (zhp->zpool_state);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
 * Create the named pool, using the provided vdev list.  It is assumed
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
 * that the consumer has already validated the contents of the nvlist, so we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
 * don't have to worry about error semantics.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   867
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
   868
    nvlist_t *props, nvlist_t *fsprops)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	zfs_cmd_t zc = { 0 };
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   871
	nvlist_t *zc_fsprops = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   872
	nvlist_t *zc_props = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   873
	char msg[1024];
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   874
	char *altroot;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   875
	int ret = -1;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   876
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   877
	(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   878
	    "cannot create '%s'"), pool);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   880
	if (!zpool_name_valid(hdl, B_FALSE, pool))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   881
		return (zfs_error(hdl, EZFS_INVALIDNAME, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   882
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
   883
	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
   884
		return (-1);
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
   885
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   886
	if (props) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   887
		if ((zc_props = zpool_valid_proplist(hdl, pool, props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   888
		    SPA_VERSION_1, B_TRUE, msg)) == NULL) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   889
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   890
		}
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
   891
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   893
	if (fsprops) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   894
		uint64_t zoned;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   895
		char *zonestr;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   896
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   897
		zoned = ((nvlist_lookup_string(fsprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   898
		    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
   899
		    strcmp(zonestr, "on") == 0);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   900
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   901
		if ((zc_fsprops = zfs_valid_proplist(hdl,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   902
		    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
   903
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   904
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   905
		if (!zc_props &&
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   906
		    (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
   907
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   908
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   909
		if (nvlist_add_nvlist(zc_props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   910
		    ZPOOL_ROOTFS_PROPS, zc_fsprops) != 0) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   911
			goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   912
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   913
	}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   914
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   915
	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
   916
		goto create_failed;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   917
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
	(void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   920
	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
   921
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
   922
		zcmd_free_nvlists(&zc);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   923
		nvlist_free(zc_props);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   924
		nvlist_free(zc_fsprops);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   925
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
		case EBUSY:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
			 * This can happen if the user has specified the same
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
			 * device multiple times.  We can't reliably detect this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
			 * until we try to add it and see we already have a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
			 * label.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   934
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   935
			    "one or more vdevs refer to the same device"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   936
			return (zfs_error(hdl, EZFS_BADDEV, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
		case EOVERFLOW:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
			/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   940
			 * This occurs when one of the devices is below
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
			 * SPA_MINDEVSIZE.  Unfortunately, we can't detect which
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
			 * device was the problem device since there's no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
			 * reliable way to determine device size from userland.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
				char buf[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
				zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   950
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   951
				    "one or more devices is less than the "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   952
				    "minimum size (%s)"), buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
			}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   954
			return (zfs_error(hdl, EZFS_BADDEV, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
		case ENOSPC:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   957
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   958
			    "one or more devices is out of space"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   959
			return (zfs_error(hdl, EZFS_BADDEV, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   961
		case ENOTBLK:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   962
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   963
			    "cache device must be a disk or disk slice"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   964
			return (zfs_error(hdl, EZFS_BADDEV, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
   965
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
   967
			return (zpool_standard_error(hdl, errno, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
	 * If this is an alternate root pool, then we automatically set the
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
   973
	 * mountpoint of the root dataset to be '/'.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
	 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   975
	if (nvlist_lookup_string(props, zpool_prop_to_name(ZPOOL_PROP_ALTROOT),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   976
	    &altroot) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
		zfs_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   979
		verify((zhp = zfs_open(hdl, pool, ZFS_TYPE_DATASET)) != NULL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
   980
		verify(zfs_prop_set(zhp, zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
   981
		    "/") == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
		zfs_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   986
create_failed:
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
   987
	zcmd_free_nvlists(&zc);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   988
	nvlist_free(zc_props);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   989
	nvlist_free(zc_fsprops);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   990
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
 * 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
   995
 * datasets left in the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
zpool_destroy(zpool_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
	zfs_handle_t *zfp = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1002
	libzfs_handle_t *hdl = zhp->zpool_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1003
	char msg[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
	if (zhp->zpool_state == POOL_STATE_ACTIVE &&
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1006
	    (zfp = zfs_open(zhp->zpool_hdl, zhp->zpool_name,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1007
	    ZFS_TYPE_FILESYSTEM)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1012
	if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_DESTROY, &zc) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1013
		(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1014
		    "cannot destroy '%s'"), zhp->zpool_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1016
		if (errno == EROFS) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1017
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1018
			    "one or more devices is read only"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1019
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1020
		} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1021
			(void) zpool_standard_error(hdl, errno, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
		if (zfp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
			zfs_close(zfp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
	if (zfp) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
		remove_mountpoint(zfp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
		zfs_close(zfp);
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 (0);
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
 * Add the given vdevs to the pool.  The caller must have already performed the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
 * necessary verification to ensure that the vdev specification is well-formed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
zpool_add(zpool_handle_t *zhp, nvlist_t *nvroot)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1044
	zfs_cmd_t zc = { 0 };
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1045
	int ret;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1046
	libzfs_handle_t *hdl = zhp->zpool_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1047
	char msg[1024];
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1048
	nvlist_t **spares, **l2cache;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1049
	uint_t nspares, nl2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1050
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1051
	(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1052
	    "cannot add to '%s'"), zhp->zpool_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1053
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1054
	if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) <
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1055
	    SPA_VERSION_SPARES &&
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1056
	    nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1057
	    &spares, &nspares) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1058
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1059
		    "upgraded to add hot spares"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1060
		return (zfs_error(hdl, EZFS_BADVERSION, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1061
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1063
	if (pool_is_bootable(zhp) && nvlist_lookup_nvlist_array(nvroot,
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1064
	    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
  1065
		uint64_t s;
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1066
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1067
		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
  1068
			char *path;
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1069
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1070
			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
  1071
			    &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
  1072
				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
  1073
				    "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
  1074
				    "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
  1075
				    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
  1076
				    B_FALSE));
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1077
				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
  1078
			}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1079
		}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1080
	}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  1081
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1082
	if (zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL) <
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1083
	    SPA_VERSION_L2CACHE &&
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1084
	    nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1085
	    &l2cache, &nl2cache) == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1086
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be "
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1087
		    "upgraded to add cache devices"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1088
		return (zfs_error(hdl, EZFS_BADVERSION, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1089
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1090
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1091
	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1092
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1095
	if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_ADD, &zc) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
		case EBUSY:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
			 * This can happen if the user has specified the same
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
			 * device multiple times.  We can't reliably detect this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
			 * until we try to add it and see we already have a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
			 * label.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1104
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1105
			    "one or more vdevs refer to the same device"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1106
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
		case EOVERFLOW:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
			 * This occurrs when one of the devices is below
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
			 * SPA_MINDEVSIZE.  Unfortunately, we can't detect which
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
			 * device was the problem device since there's no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
			 * reliable way to determine device size from userland.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
			{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
				char buf[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
				zfs_nicenum(SPA_MINDEVSIZE, buf, sizeof (buf));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1121
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1122
				    "device is less than the minimum "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1123
				    "size (%s)"), buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
			}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1125
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1126
			break;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1127
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1128
		case ENOTSUP:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1129
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1130
			    "pool must be upgraded to add these vdevs"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1131
			(void) zfs_error(hdl, EZFS_BADVERSION, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1134
		case EDOM:
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1135
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1136
			    "root pool can not have multiple vdevs"
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  1137
			    " or separate logs"));
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1138
			(void) zfs_error(hdl, EZFS_POOL_NOTSUP, msg);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1139
			break;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  1140
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1141
		case ENOTBLK:
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1142
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1143
			    "cache device must be a disk or disk slice"));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1144
			(void) zfs_error(hdl, EZFS_BADDEV, msg);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1145
			break;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1146
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1148
			(void) zpool_standard_error(hdl, errno, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1151
		ret = -1;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1152
	} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1153
		ret = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1156
	zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1158
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
 * Exports the pool from the system.  The caller must ensure that there are no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
 * mounted datasets in the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
int
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
  1166
zpool_export_common(zpool_handle_t *zhp, boolean_t force, boolean_t hardforce)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
	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
  1169
	char msg[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
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
  1171
	(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
  1172
	    "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
  1173
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
	(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
  1175
	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
  1176
	zc.zc_guid = hardforce;
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
  1177
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
  1178
	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
  1179
		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
  1180
		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
  1181
			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
  1182
			    "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
  1183
			    "'%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
  1184
			    " 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
  1185
			    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
  1186
			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
  1187
			    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
  1188
		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
  1189
			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
  1190
			    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
  1191
		}
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
  1192
	}
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
  1193
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
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
  1197
int
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1198
zpool_export(zpool_handle_t *zhp, boolean_t force)
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1199
{
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1200
	return (zpool_export_common(zhp, force, B_FALSE));
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1201
}
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1202
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1203
int
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1204
zpool_export_force(zpool_handle_t *zhp)
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1205
{
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1206
	return (zpool_export_common(zhp, B_TRUE, B_TRUE));
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1207
}
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8084
diff changeset
  1208
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1209
static void
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1210
zpool_rewind_exclaim(libzfs_handle_t *hdl, const char *name, boolean_t dryrun,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1211
    nvlist_t *rbi)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1212
{
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1213
	uint64_t rewindto;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1214
	int64_t loss = -1;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1215
	struct tm t;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1216
	char timestr[128];
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1217
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1218
	if (!hdl->libzfs_printerr || rbi == NULL)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1219
		return;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1220
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1221
	if (nvlist_lookup_uint64(rbi, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1222
		return;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1223
	(void) nvlist_lookup_int64(rbi, ZPOOL_CONFIG_REWIND_TIME, &loss);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1224
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1225
	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
  1226
	    strftime(timestr, 128, 0, &t) != 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1227
		if (dryrun) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1228
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1229
			    "Would be able to return %s "
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1230
			    "to its state as of %s.\n"),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1231
			    name, timestr);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1232
		} else {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1233
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1234
			    "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
  1235
			    name, timestr);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1236
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1237
		if (loss > 120) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1238
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1239
			    "%s approximately %lld "),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1240
			    dryrun ? "Would discard" : "Discarded",
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1241
			    (loss + 30) / 60);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1242
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1243
			    "minutes of transactions.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1244
		} else if (loss > 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1245
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1246
			    "%s approximately %lld "),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1247
			    dryrun ? "Would discard" : "Discarded", loss);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1248
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1249
			    "seconds of transactions.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1250
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1251
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1252
}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1253
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1254
void
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1255
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
  1256
    nvlist_t *config)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1257
{
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1258
	int64_t loss = -1;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1259
	uint64_t edata = UINT64_MAX;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1260
	uint64_t rewindto;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1261
	struct tm t;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1262
	char timestr[128];
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1263
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1264
	if (!hdl->libzfs_printerr)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1265
		return;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1266
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1267
	if (reason >= 0)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1268
		(void) printf(dgettext(TEXT_DOMAIN, "action: "));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1269
	else
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1270
		(void) printf(dgettext(TEXT_DOMAIN, "\t"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1271
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1272
	/* All attempted rewinds failed if ZPOOL_CONFIG_LOAD_TIME missing */
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1273
	if (nvlist_lookup_uint64(config,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1274
	    ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1275
		goto no_info;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1276
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1277
	(void) nvlist_lookup_int64(config, ZPOOL_CONFIG_REWIND_TIME, &loss);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1278
	(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_LOAD_DATA_ERRORS,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1279
	    &edata);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1280
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1281
	(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1282
	    "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
  1283
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1284
	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
  1285
	    strftime(timestr, 128, 0, &t) != 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1286
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1287
		    "\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
  1288
		    "\tshould correct the problem.  "),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1289
		    timestr);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1290
	} else {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1291
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1292
		    "\tReverting the pool to an earlier state "
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1293
		    "should correct the problem.\n\t"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1294
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1295
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1296
	if (loss > 120) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1297
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1298
		    "Approximately %lld minutes of data\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1299
		    "\tmust be discarded, irreversibly.  "), (loss + 30) / 60);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1300
	} else if (loss > 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1301
		(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1302
		    "Approximately %lld seconds of data\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1303
		    "\tmust be discarded, irreversibly.  "), loss);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1304
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1305
	if (edata != 0 && edata != UINT64_MAX) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1306
		if (edata == 1) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1307
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1308
			    "After rewind, at least\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1309
			    "\tone persistent user-data error will remain.  "));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1310
		} else {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1311
			(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1312
			    "After rewind, several\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1313
			    "\tpersistent user-data errors will remain.  "));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1314
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1315
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1316
	(void) printf(dgettext(TEXT_DOMAIN,
11026
e8e10df16a8f 6899159 injection isn't trashing pools
Tim Haley <Tim.Haley@Sun.COM>
parents: 10956
diff changeset
  1317
	    "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
  1318
	    reason >= 0 ? "clear" : "import", name);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1319
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1320
	(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1321
	    "A scrub of the pool\n"
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1322
	    "\tis strongly recommended after recovery.\n"));
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1323
	return;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1324
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1325
no_info:
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1326
	(void) printf(dgettext(TEXT_DOMAIN,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1327
	    "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
  1328
}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1329
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
/*
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1331
 * zpool_import() is a contracted interface. Should be kept the same
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1332
 * if possible.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1333
 *
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1334
 * Applications should use zpool_import_props() to import a pool with
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1335
 * new properties value to be set.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1338
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
  1339
    char *altroot)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1340
{
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1341
	nvlist_t *props = NULL;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1342
	int ret;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1343
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1344
	if (altroot != NULL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1345
		if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1346
			return (zfs_error_fmt(hdl, EZFS_NOMEM,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1347
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1348
			    newname));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1349
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1350
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1351
		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
  1352
		    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
  1353
		    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
  1354
		    zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), "none") != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1355
			nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1356
			return (zfs_error_fmt(hdl, EZFS_NOMEM,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1357
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1358
			    newname));
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1359
		}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1360
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1361
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1362
	ret = zpool_import_props(hdl, config, newname, props, B_FALSE);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1363
	if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1364
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1365
	return (ret);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1366
}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1367
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1368
/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1369
 * 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
  1370
 * properties to be set. The configuration should have come from
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1371
 * zpool_find_import(). The 'newname' parameters control whether the pool
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1372
 * is imported with a different name.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1373
 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1374
int
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1375
zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1376
    nvlist_t *props, boolean_t importfaulted)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1377
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1378
	zfs_cmd_t zc = { 0 };
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1379
	zpool_rewind_policy_t policy;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1380
	nvlist_t *nvi = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1381
	char *thename;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1382
	char *origname;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1383
	uint64_t returned_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
	int ret;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1385
	char errbuf[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1386
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
	    &origname) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1390
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1391
	    "cannot import pool '%s'"), origname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1392
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
	if (newname != NULL) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1394
		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
  1395
			return (zfs_error_fmt(hdl, EZFS_INVALIDNAME,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1396
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1397
			    newname));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
		thename = (char *)newname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1400
		thename = origname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1401
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1403
	if (props) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1404
		uint64_t version;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1405
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1406
		verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1407
		    &version) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1408
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1409
		if ((props = zpool_valid_proplist(hdl, origname,
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1410
		    props, version, B_TRUE, errbuf)) == NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1411
			return (-1);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1412
		} 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
  1413
			nvlist_free(props);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1414
			return (-1);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1415
		}
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1416
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
	(void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1419
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1421
	    &zc.zc_guid) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1423
	if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) {
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1424
		nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1425
		return (-1);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1426
	}
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1427
	returned_size =  zc.zc_nvlist_conf_size + 512;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1428
	if (zcmd_alloc_dst_nvlist(hdl, &zc, returned_size) != 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1429
		nvlist_free(props);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1430
		return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1431
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6423
diff changeset
  1433
	zc.zc_cookie = (uint64_t)importfaulted;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
	ret = 0;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1435
	if (zfs_ioctl(hdl, ZFS_IOC_POOL_IMPORT, &zc) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
		char desc[1024];
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1437
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1438
		(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
  1439
		zpool_get_rewind_policy(config, &policy);
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
		 * 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
  1442
		 * 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
  1443
		 */
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1444
		if ((policy.zrp_request & ZPOOL_TRY_REWIND) && nvi) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1445
			zpool_rewind_exclaim(hdl, newname ? origname : thename,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1446
			    B_TRUE, nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1447
			nvlist_free(nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1448
			return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1449
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1450
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
		if (newname == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
			(void) snprintf(desc, sizeof (desc),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
			    dgettext(TEXT_DOMAIN, "cannot import '%s'"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
			    thename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
			(void) snprintf(desc, sizeof (desc),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1457
			    dgettext(TEXT_DOMAIN, "cannot import '%s' as '%s'"),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1458
			    origname, thename);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1459
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1460
		switch (errno) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1461
		case ENOTSUP:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1462
			/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1463
			 * Unsupported version.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1464
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1465
			(void) zfs_error(hdl, EZFS_BADVERSION, desc);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1466
			break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1467
2174
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1468
		case EINVAL:
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1469
			(void) zfs_error(hdl, EZFS_INVALCONFIG, desc);
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1470
			break;
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2142
diff changeset
  1471
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
  1472
		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
  1473
			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
  1474
			    "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
  1475
			(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
  1476
			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
  1477
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
		default:
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1479
			(void) zcmd_read_dst_nvlist(hdl, &zc, &nvi);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1480
			(void) zpool_standard_error(hdl, errno, desc);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1481
			zpool_explain_recover(hdl,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1482
			    newname ? origname : thename, -errno, nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1483
			nvlist_free(nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1484
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
		ret = -1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
		zpool_handle_t *zhp;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1490
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
		 * This should never fail, but play it safe anyway.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
		 */
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
  1494
		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
  1495
			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
  1496
		else if (zhp != NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
			zpool_close(zhp);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1498
		(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
  1499
		zpool_get_rewind_policy(config, &policy);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1500
		if (policy.zrp_request &
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1501
		    (ZPOOL_DO_REWIND | ZPOOL_TRY_REWIND)) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1502
			zpool_rewind_exclaim(hdl, newname ? origname : thename,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1503
			    ((policy.zrp_request & ZPOOL_TRY_REWIND) != 0),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1504
			    nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1505
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1506
		nvlist_free(nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  1507
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  1510
	zcmd_free_nvlists(&zc);
5320
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1511
	nvlist_free(props);
43bde2b01a59 6614232 results of zpool_validate_properties() are consistently leaked
lling
parents: 5094
diff changeset
  1512
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1517
 * Scan the pool.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
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
  1520
zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1521
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1522
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1523
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1524
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1525
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1526
	(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
  1527
	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
  1528
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1529
	if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_SCAN, &zc) == 0 ||
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1530
	    (errno == ENOENT && func != POOL_SCAN_NONE))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1531
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1532
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1533
	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
  1534
		(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
  1535
		    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
  1536
	} 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
  1537
		(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
  1538
		    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
  1539
		    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
  1540
	} else {
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1541
		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
  1542
	}
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1543
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1544
	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
  1545
		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
  1546
		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
  1547
		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
  1548
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1549
		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
  1550
		    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
  1551
		(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
  1552
		    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
  1553
		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
  1554
			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
  1555
		else
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  1556
			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
  1557
	} 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
  1558
		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
  1559
	} else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1560
		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
  1561
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1562
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1564
/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1565
 * 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
  1566
 * 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
  1567
 * '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
  1568
 * spare; but FALSE if its an INUSE spare.
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1569
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1570
static nvlist_t *
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1571
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
  1572
    boolean_t *l2cache, boolean_t *log)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1573
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1574
	uint_t c, children;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1575
	nvlist_t **child;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1576
	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
  1577
	uint64_t is_log;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1578
	char *srchkey;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1579
	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
  1580
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1581
	/* Nothing to look for */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1582
	if (search == NULL || pair == NULL)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1583
		return (NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1584
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1585
	/* 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
  1586
	srchkey = nvpair_name(pair);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1587
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1588
	switch (nvpair_type(pair)) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1589
	case DATA_TYPE_UINT64: {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1590
		uint64_t srchval, theguid, present;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1591
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1592
		verify(nvpair_value_uint64(pair, &srchval) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1593
		if (strcmp(srchkey, ZPOOL_CONFIG_GUID) == 0) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1594
			if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1595
			    &present) == 0) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1596
				/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1597
				 * If the device has never been present since
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1598
				 * import, the only reliable way to match the
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1599
				 * vdev is by GUID.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1600
				 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1601
				verify(nvlist_lookup_uint64(nv,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1602
				    ZPOOL_CONFIG_GUID, &theguid) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1603
				if (theguid == srchval)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1604
					return (nv);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1605
			}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1606
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1607
		break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1608
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1609
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1610
	case DATA_TYPE_STRING: {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1611
		char *srchval, *val;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1612
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1613
		verify(nvpair_value_string(pair, &srchval) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1614
		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
  1615
			break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1616
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1617
		/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1618
		 * Search for the requested value. We special case the search
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1619
		 * for ZPOOL_CONFIG_PATH when it's a wholedisk and when
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1620
		 * Looking for a top-level vdev name (i.e. ZPOOL_CONFIG_TYPE).
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1621
		 * Otherwise, all other searches are simple string compares.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1622
		 */
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1623
		if (strcmp(srchkey, ZPOOL_CONFIG_PATH) == 0 && val) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1624
			uint64_t wholedisk = 0;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1625
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1626
			(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
  1627
			    &wholedisk);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1628
			if (wholedisk) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1629
				/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1630
				 * For whole disks, the internal path has 's0',
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1631
				 * but the path passed in by the user doesn't.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1632
				 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1633
				if (strlen(srchval) == strlen(val) - 2 &&
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1634
				    strncmp(srchval, val, strlen(srchval)) == 0)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1635
					return (nv);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1636
				break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1637
			}
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1638
		} 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
  1639
			char *type, *idx, *end, *p;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1640
			uint64_t id, vdev_id;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1641
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1642
			/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1643
			 * 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
  1644
			 * 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
  1645
			 * 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
  1646
			 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1647
			if ((type = strdup(srchval)) == NULL)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1648
				return (NULL);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1649
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1650
			if ((p = strrchr(type, '-')) == NULL) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1651
				free(type);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1652
				break;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1653
			}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1654
			idx = p + 1;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1655
			*p = '\0';
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1656
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1657
			/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1658
			 * 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
  1659
			 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1660
			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
  1661
				free(type);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1662
				break;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1663
			}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1664
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1665
			verify(strncmp(type, VDEV_TYPE_RAIDZ,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1666
			    strlen(VDEV_TYPE_RAIDZ)) == 0 ||
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1667
			    strncmp(type, VDEV_TYPE_MIRROR,
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1668
			    strlen(VDEV_TYPE_MIRROR)) == 0);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1669
			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
  1670
			    &id) == 0);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1671
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1672
			errno = 0;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1673
			vdev_id = strtoull(idx, &end, 10);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1674
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1675
			free(type);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1676
			if (errno != 0)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1677
				return (NULL);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1678
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1679
			/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1680
			 * 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
  1681
			 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1682
			if (vdev_id == id)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1683
				return (nv);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1684
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1685
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1686
		/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1687
		 * Common case
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1688
		 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1689
		if (strcmp(srchval, val) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1690
			return (nv);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1691
		break;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1692
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1693
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1694
	default:
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1695
		break;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1696
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1697
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1698
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1699
	    &child, &children) != 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1700
		return (NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1701
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  1702
	for (c = 0; c < children; c++) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1703
		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
  1704
		    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
  1705
			/*
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  1706
			 * 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
  1707
			 * 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
  1708
			 * 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
  1709
			 * '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
  1710
			 */
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  1711
			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
  1712
			    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
  1713
			    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
  1714
			    is_log) {
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  1715
				*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
  1716
			}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1717
			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
  1718
		}
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  1719
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1720
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1721
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1722
	    &child, &children) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1723
		for (c = 0; c < children; c++) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1724
			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
  1725
			    avail_spare, l2cache, NULL)) != NULL) {
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1726
				*avail_spare = B_TRUE;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1727
				return (ret);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1728
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1729
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1730
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1731
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1732
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1733
	    &child, &children) == 0) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1734
		for (c = 0; c < children; c++) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1735
			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
  1736
			    avail_spare, l2cache, NULL)) != NULL) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1737
				*l2cache = B_TRUE;
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1738
				return (ret);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1739
			}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1740
		}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1741
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1742
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1743
	return (NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1744
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1745
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1746
/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1747
 * 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
  1748
 * associated vdev.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1749
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1750
nvlist_t *
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1751
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
  1752
    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
  1753
{
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1754
	nvlist_t *search, *nvroot, *ret;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1755
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1756
	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
  1757
	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
  1758
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1759
	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
  1760
	    &nvroot) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1761
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1762
	*avail_spare = B_FALSE;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1763
	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
  1764
	nvlist_free(search);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1765
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1766
	return (ret);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1767
}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1768
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1769
/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1770
 * 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
  1771
 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1772
boolean_t
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1773
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
  1774
{
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1775
	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
  1776
	    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
  1777
		return (B_TRUE);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1778
	return (B_FALSE);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1779
}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  1780
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  1781
nvlist_t *
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1782
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
  1783
    boolean_t *l2cache, boolean_t *log)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1784
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1785
	char buf[MAXPATHLEN];
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1786
	char *end;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1787
	nvlist_t *nvroot, *search, *ret;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1788
	uint64_t guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1789
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1790
	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
  1791
1613
aca102a242d3 6396628 zpool offline does not recognize c0d0 patten recently
eschrock
parents: 1544
diff changeset
  1792
	guid = strtoull(path, &end, 10);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1793
	if (guid != 0 && *end == '\0') {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1794
		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
  1795
	} 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
  1796
		verify(nvlist_add_string(search, ZPOOL_CONFIG_TYPE, path) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1797
	} else if (path[0] != '/') {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1798
		(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
  1799
		verify(nvlist_add_string(search, ZPOOL_CONFIG_PATH, buf) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1800
	} else {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1801
		verify(nvlist_add_string(search, ZPOOL_CONFIG_PATH, path) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1802
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1803
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1804
	verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1805
	    &nvroot) == 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1806
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1807
	*avail_spare = B_FALSE;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  1808
	*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
  1809
	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
  1810
		*log = B_FALSE;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1811
	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
  1812
	nvlist_free(search);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1813
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1814
	return (ret);
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1815
}
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1816
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1817
static int
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1818
vdev_online(nvlist_t *nv)
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1819
{
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1820
	uint64_t ival;
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1821
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1822
	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
  1823
	    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
  1824
	    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
  1825
		return (0);
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1826
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1827
	return (1);
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1828
}
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1829
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1830
/*
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
  1831
 * Helper function for zpool_get_physpaths().
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1832
 */
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1833
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
  1834
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
  1835
    size_t *bytes_written)
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1836
{
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1837
	size_t bytes_left, pos, rsz;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1838
	char *tmppath;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1839
	const char *format;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1840
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1841
	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
  1842
	    &tmppath) != 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1843
		return (EZFS_NODEVICE);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1844
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1845
	pos = *bytes_written;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1846
	bytes_left = physpath_size - pos;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1847
	format = (pos == 0) ? "%s" : " %s";
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1848
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1849
	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
  1850
	*bytes_written += rsz;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1851
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1852
	if (rsz >= bytes_left) {
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1853
		/* 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
  1854
		if (bytes_left != 0) {
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1855
			physpath[pos] = 0;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1856
		}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1857
		return (EZFS_NOSPC);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1858
	}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1859
	return (0);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1860
}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1861
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
  1862
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
  1863
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
  1864
    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
  1865
{
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
  1866
	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
  1867
	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
  1868
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
  1869
	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
  1870
		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
  1871
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
  1872
	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
  1873
		/*
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
  1874
		 * 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
  1875
		 * 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
  1876
		 * 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
  1877
		 */
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
  1878
		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
  1879
			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
  1880
			(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
  1881
			    &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
  1882
			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
  1883
				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
  1884
		}
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
  1885
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
  1886
		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
  1887
			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
  1888
			    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
  1889
				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
  1890
		}
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
  1891
	} 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
  1892
	    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
  1893
	    (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
  1894
		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
  1895
		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
  1896
		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
  1897
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
  1898
		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
  1899
		    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
  1900
			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
  1901
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
  1902
		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
  1903
			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
  1904
			    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
  1905
			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
  1906
				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
  1907
		}
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
  1908
	}
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
  1909
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
  1910
	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
  1911
}
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
  1912
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1913
/*
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1914
 * 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
  1915
 * 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
  1916
 */
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1917
static int
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1918
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
  1919
{
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1920
	size_t rsz;
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1921
	nvlist_t *vdev_root;
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1922
	nvlist_t **child;
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1923
	uint_t count;
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1924
	char *type;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1925
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1926
	rsz = 0;
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1927
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1928
	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
  1929
	    &vdev_root) != 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1930
		return (EZFS_INVALCONFIG);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1931
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1932
	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
  1933
	    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
  1934
	    &child, &count) != 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1935
		return (EZFS_INVALCONFIG);
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1936
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1937
	/*
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1938
	 * 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
  1939
	 * a single top-level vdev.
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1940
	 */
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1941
	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
  1942
	    pool_uses_efi(vdev_root))
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1943
		return (EZFS_POOL_INVALARG);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1944
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
  1945
	(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
  1946
	    B_FALSE);
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1947
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1948
	/* No online devices */
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1949
	if (rsz == 0)
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1950
		return (EZFS_NODEVICE);
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1951
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1952
	return (0);
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1953
}
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7326
diff changeset
  1954
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  1955
/*
9160
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1956
 * Get phys_path for a root pool
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1957
 * 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
  1958
 */
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1959
int
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1960
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
  1961
{
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1962
	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
  1963
	    phypath_size));
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1964
}
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1965
1517e6edbc6f PSARC/2008/760 Boot configuration Service
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 8525
diff changeset
  1966
/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1967
 * 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
  1968
 * 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
  1969
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1970
static int
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1971
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
  1972
{
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1973
	char path[MAXPATHLEN];
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1974
	char errbuf[1024];
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1975
	int fd, error;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1976
	int (*_efi_use_whole_disk)(int);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1977
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1978
	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
  1979
	    "efi_use_whole_disk")) == NULL)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1980
		return (-1);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1981
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1982
	(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
  1983
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1984
	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
  1985
		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
  1986
		    "relabel '%s': unable to open device"), name);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1987
		return (zfs_error(hdl, EZFS_OPENFAILED, errbuf));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1988
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1989
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1990
	/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1991
	 * 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
  1992
	 * 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
  1993
	 * ignore that error and continue on.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1994
	 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1995
	error = _efi_use_whole_disk(fd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1996
	(void) close(fd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1997
	if (error && error != VT_ENOSPC) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  1998
		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
  1999
		    "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
  2000
		return (zfs_error(hdl, EZFS_NOCAP, errbuf));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2001
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2002
	return (0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2003
}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2004
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2005
/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2006
 * Bring the specified vdev online.   The 'flags' parameter is a set of the
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2007
 * ZFS_ONLINE_* flags.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2008
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2009
int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2010
zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags,
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2011
    vdev_state_t *newstate)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2012
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2014
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2015
	nvlist_t *tgt;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2016
	boolean_t avail_spare, l2cache, islog;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2017
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2018
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2019
	if (flags & ZFS_ONLINE_EXPAND) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2020
		(void) snprintf(msg, sizeof (msg),
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2021
		    dgettext(TEXT_DOMAIN, "cannot expand %s"), path);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2022
	} else {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2023
		(void) snprintf(msg, sizeof (msg),
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2024
		    dgettext(TEXT_DOMAIN, "cannot online %s"), path);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2025
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2027
	(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
  2028
	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
  2029
	    &islog)) == NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2030
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2031
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2032
	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
  2033
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2034
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2035
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2036
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2037
	if (flags & ZFS_ONLINE_EXPAND ||
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2038
	    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
  2039
		char *pathname = NULL;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2040
		uint64_t wholedisk = 0;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2041
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2042
		(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
  2043
		    &wholedisk);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2044
		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
  2045
		    &pathname) == 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2046
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2047
		/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2048
		 * 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
  2049
		 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2050
		if (l2cache) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2051
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2052
			    "cannot expand cache devices"));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2053
			return (zfs_error(hdl, EZFS_VDEVNOTSUP, msg));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2054
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2055
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2056
		if (wholedisk) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2057
			pathname += strlen(DISK_ROOT) + 1;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2058
			(void) zpool_relabel_disk(zhp->zpool_hdl, pathname);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2059
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2060
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9790
diff changeset
  2061
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2062
	zc.zc_cookie = VDEV_STATE_ONLINE;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2063
	zc.zc_obj = flags;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2064
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2065
	if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_SET_STATE, &zc) != 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2066
		if (errno == EINVAL) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2067
			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
  2068
			    "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
  2069
			    "instead"), "zpool detach");
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2070
			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
  2071
		}
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2072
		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
  2073
	}
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2074
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2075
	*newstate = zc.zc_cookie;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2076
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2077
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2078
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2079
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2080
 * Take the specified vdev offline
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2081
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2082
int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2083
zpool_vdev_offline(zpool_handle_t *zhp, const char *path, boolean_t istmp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2084
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2085
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2086
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2087
	nvlist_t *tgt;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2088
	boolean_t avail_spare, l2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2089
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2090
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2091
	(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2092
	    dgettext(TEXT_DOMAIN, "cannot offline %s"), path);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2093
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2094
	(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
  2095
	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
  2096
	    NULL)) == NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2097
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2098
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2099
	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
  2100
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2101
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2102
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2103
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2104
	zc.zc_cookie = VDEV_STATE_OFFLINE;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2105
	zc.zc_obj = istmp ? ZFS_OFFLINE_TEMPORARY : 0;
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1354
diff changeset
  2106
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  2107
	if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_SET_STATE, &zc) == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2108
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2109
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2110
	switch (errno) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2111
	case EBUSY:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2112
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2113
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2114
		 * There are no other replicas of this device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2115
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2116
		return (zfs_error(hdl, EZFS_NOREPLICAS, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2117
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2118
	case EEXIST:
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2119
		/*
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2120
		 * 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
  2121
		 */
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9160
diff changeset
  2122
		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
  2123
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2124
	default:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2125
		return (zpool_standard_error(hdl, errno, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2126
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2127
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2128
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2129
/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2130
 * Mark the given vdev faulted.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2131
 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2132
int
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2133
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
  2134
{
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2135
	zfs_cmd_t zc = { 0 };
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2136
	char msg[1024];
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2137
	libzfs_handle_t *hdl = zhp->zpool_hdl;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2138
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2139
	(void) snprintf(msg, sizeof (msg),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2140
	    dgettext(TEXT_DOMAIN, "cannot fault %llu"), guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2141
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2142
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2143
	zc.zc_guid = guid;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2144
	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
  2145
	zc.zc_obj = aux;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2146
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2147
	if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SET_STATE, &zc) == 0)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2148
		return (0);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2149
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2150
	switch (errno) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2151
	case EBUSY:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2152
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2153
		/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2154
		 * There are no other replicas of this device.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2155
		 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2156
		return (zfs_error(hdl, EZFS_NOREPLICAS, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2157
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2158
	default:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2159
		return (zpool_standard_error(hdl, errno, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2160
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2161
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2162
}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2163
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2164
/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2165
 * Mark the given vdev degraded.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2166
 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2167
int
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10685
diff changeset
  2168
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
  2169
{
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2170
	zfs_cmd_t zc = { 0 };
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2171
	char msg[1024];
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2172
	libzfs_handle_t *hdl = zhp->zpool_hdl;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2173
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2174
	(void) snprintf(msg, sizeof (msg),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2175
	    dgettext(TEXT_DOMAIN, "cannot degrade %llu"), guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2176
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2177
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2178
	zc.zc_guid = guid;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2179
	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
  2180
	zc.zc_obj = aux;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2181
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2182
	if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SET_STATE, &zc) == 0)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2183
		return (0);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2184
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2185
	return (zpool_standard_error(hdl, errno, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2186
}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2187
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2188
/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2189
 * 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
  2190
 * a hot spare.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2191
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2192
static boolean_t
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2193
is_replacing_spare(nvlist_t *search, nvlist_t *tgt, int which)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2194
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2195
	nvlist_t **child;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2196
	uint_t c, children;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2197
	char *type;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2198
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2199
	if (nvlist_lookup_nvlist_array(search, ZPOOL_CONFIG_CHILDREN, &child,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2200
	    &children) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2201
		verify(nvlist_lookup_string(search, ZPOOL_CONFIG_TYPE,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2202
		    &type) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2203
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2204
		if (strcmp(type, VDEV_TYPE_SPARE) == 0 &&
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2205
		    children == 2 && child[which] == tgt)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2206
			return (B_TRUE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2207
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2208
		for (c = 0; c < children; c++)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2209
			if (is_replacing_spare(child[c], tgt, which))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2210
				return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2212
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2213
	return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
 * Attach new_disk (fully described by nvroot) to old_disk.
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2218
 * If 'replacing' is specified, the new disk will replace the old one.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2219
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2220
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2221
zpool_vdev_attach(zpool_handle_t *zhp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2222
    const char *old_disk, const char *new_disk, nvlist_t *nvroot, int replacing)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2223
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2224
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2225
	char msg[1024];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2226
	int ret;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2227
	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
  2228
	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
  2229
	uint64_t val;
7041
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2230
	char *path, *newname;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2231
	nvlist_t **child;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2232
	uint_t children;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2233
	nvlist_t *config_root;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2234
	libzfs_handle_t *hdl = zhp->zpool_hdl;
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2235
	boolean_t rootpool = pool_is_bootable(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2237
	if (replacing)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2238
		(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2239
		    "cannot replace %s with %s"), old_disk, new_disk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2240
	else
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2241
		(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2242
		    "cannot attach %s to %s"), new_disk, old_disk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2243
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2244
	/*
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2245
	 * 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
  2246
	 * EFI labeled device.
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2247
	 */
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2248
	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
  2249
		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
  2250
		    "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
  2251
		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
  2252
	}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2253
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2254
	(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
  2255
	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
  2256
	    &islog)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2257
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2258
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2259
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2260
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2261
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2262
	if (l2cache)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2263
		return (zfs_error(hdl, EZFS_ISL2CACHE, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2264
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2265
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2266
	zc.zc_cookie = replacing;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2267
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2268
	if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2269
	    &child, &children) != 0 || children != 1) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2270
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2271
		    "new device must be a single disk"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2272
		return (zfs_error(hdl, EZFS_INVALCONFIG, msg));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2273
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2274
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2275
	verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2276
	    ZPOOL_CONFIG_VDEV_TREE, &config_root) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2277
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2278
	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
  2279
		return (-1);
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2280
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2281
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2282
	 * 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
  2283
	 * replace it with another hot spare.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2284
	 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2285
	if (replacing &&
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2286
	    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
  2287
	    (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
  2288
	    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
  2289
	    is_replacing_spare(config_root, tgt, 1)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2290
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2291
		    "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
  2292
		free(newname);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2293
		return (zfs_error(hdl, EZFS_BADTARGET, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2294
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2295
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2296
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2297
	 * If we are attempting to replace a spare, it canot be applied to an
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2298
	 * already spared device.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2299
	 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2300
	if (replacing &&
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2301
	    nvlist_lookup_string(child[0], ZPOOL_CONFIG_PATH, &path) == 0 &&
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2302
	    zpool_find_vdev(zhp, newname, &avail_spare,
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2303
	    &l2cache, 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
  2304
	    is_replacing_spare(config_root, tgt, 0)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2305
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2306
		    "device has already been replaced with a spare"));
7041
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2307
		free(newname);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2308
		return (zfs_error(hdl, EZFS_BADTARGET, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2309
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2310
7041
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2311
	free(newname);
b4c5fe87fad8 6721901 uninitialized variable in zfs_fm_recv() can confuse diagnosis
eschrock
parents: 6643
diff changeset
  2312
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2313
	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2314
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2315
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  2316
	ret = zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_VDEV_ATTACH, &zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2317
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  2318
	zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2319
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2320
	if (ret == 0) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2321
		if (rootpool) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2322
			/*
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2323
			 * XXX - This should be removed once we can
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2324
			 * automatically install the bootblocks on the
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2325
			 * newly attached disk.
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2326
			 */
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2327
			(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Please "
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2328
			    "be sure to invoke %s to make '%s' bootable.\n"),
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2329
			    BOOTCMD, new_disk);
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
  2330
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
  2331
			/*
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
  2332
			 * 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
  2333
			 * 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
  2334
			 */
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
  2335
			(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
  2336
			    "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
  2337
			    "before rebooting.\n"));
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2338
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2339
		return (0);
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  2340
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2341
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2342
	switch (errno) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2343
	case ENOTSUP:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2344
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2345
		 * Can't attach to or replace this type of vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2346
		 */
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2347
		if (replacing) {
7326
a3c803100a09 6713886 hot spares of mirrored log devices should not be allowed
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 7300
diff changeset
  2348
			if (islog)
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2349
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2350
				    "cannot replace a log with a spare"));
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2351
			else
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2352
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2353
				    "cannot replace a replacing device"));
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2354
		} else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2355
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2356
			    "can only attach to mirrors and top-level "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2357
			    "disks"));
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2358
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2359
		(void) zfs_error(hdl, EZFS_BADTARGET, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2360
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2362
	case EINVAL:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2363
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2364
		 * The new device must be a single disk.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2365
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2366
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2367
		    "new device must be a single disk"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2368
		(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2369
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2370
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2371
	case EBUSY:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2372
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "%s is busy"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2373
		    new_disk);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2374
		(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2375
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2376
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2377
	case EOVERFLOW:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2378
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2379
		 * The new device is too small.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2380
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2381
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2382
		    "device is too small"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2383
		(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2384
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2385
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2386
	case EDOM:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2387
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2388
		 * The new device has a different alignment requirement.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2389
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2390
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2391
		    "devices have different sector alignment"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2392
		(void) zfs_error(hdl, EZFS_BADDEV, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2393
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2394
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2395
	case ENAMETOOLONG:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2396
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2397
		 * The resulting top-level vdev spec won't fit in the label.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2398
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2399
		(void) zfs_error(hdl, EZFS_DEVOVERFLOW, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2400
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2401
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2402
	default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2403
		(void) zpool_standard_error(hdl, errno, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2404
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2405
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2406
	return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2407
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2408
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2409
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2410
 * Detach the specified device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2411
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2412
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2413
zpool_vdev_detach(zpool_handle_t *zhp, const char *path)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2414
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2415
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2416
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2417
	nvlist_t *tgt;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2418
	boolean_t avail_spare, l2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2419
	libzfs_handle_t *hdl = zhp->zpool_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2420
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2421
	(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2422
	    dgettext(TEXT_DOMAIN, "cannot detach %s"), path);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2423
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2424
	(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
  2425
	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
  2426
	    NULL)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2427
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2428
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2429
	if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2430
		return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2431
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2432
	if (l2cache)
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2433
		return (zfs_error(hdl, EZFS_ISL2CACHE, msg));
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2434
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2435
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2436
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  2437
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_DETACH, &zc) == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2438
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2439
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2440
	switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2441
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2442
	case ENOTSUP:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2443
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2444
		 * Can't detach from this type of vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2445
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2446
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "only "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2447
		    "applicable to mirror and replacing vdevs"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2448
		(void) zfs_error(zhp->zpool_hdl, EZFS_BADTARGET, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2449
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2450
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2451
	case EBUSY:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2452
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2453
		 * There are no other replicas of this device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2454
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2455
		(void) zfs_error(hdl, EZFS_NOREPLICAS, msg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2456
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2457
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2458
	default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2459
		(void) zpool_standard_error(hdl, errno, msg);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2460
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2461
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2462
	return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2463
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2464
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2465
/*
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2466
 * 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
  2467
 *
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2468
 * 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
  2469
 * 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
  2470
 * 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
  2471
 * 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
  2472
 *
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2473
 * 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
  2474
 * 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
  2475
 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2476
static int
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2477
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
  2478
    nvlist_t **schild, uint_t schildren)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2479
{
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2480
	uint_t mc;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2481
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2482
	for (mc = 0; mc < mchildren; mc++) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2483
		uint_t sc;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2484
		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
  2485
		    mchild[mc], B_FALSE);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2486
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2487
		for (sc = 0; sc < schildren; sc++) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2488
			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
  2489
			    schild[sc], B_FALSE);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2490
			boolean_t result = (strcmp(mpath, spath) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2491
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2492
			free(spath);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2493
			if (result) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2494
				free(mpath);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2495
				return (mc);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2496
			}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2497
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2498
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2499
		free(mpath);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2500
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2501
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2502
	return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2503
}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2504
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2505
/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2506
 * 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
  2507
 * 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
  2508
 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2509
int
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2510
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
  2511
    nvlist_t *props, splitflags_t flags)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2512
{
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2513
	zfs_cmd_t zc = { 0 };
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2514
	char msg[1024];
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2515
	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
  2516
	nvlist_t **varray = NULL, *zc_props = NULL;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2517
	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
  2518
	libzfs_handle_t *hdl = zhp->zpool_hdl;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2519
	uint64_t vers;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2520
	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
  2521
	int retval = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2522
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2523
	(void) snprintf(msg, sizeof (msg),
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2524
	    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
  2525
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2526
	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
  2527
		return (zfs_error(hdl, EZFS_INVALIDNAME, msg));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2528
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2529
	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
  2530
		(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
  2531
		    "retrieve pool configuration\n"));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2532
		return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2533
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2534
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2535
	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
  2536
	    == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2537
	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
  2538
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2539
	if (props) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2540
		if ((zc_props = zpool_valid_proplist(hdl, zhp->zpool_name,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2541
		    props, vers, B_TRUE, msg)) == NULL)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2542
			return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2543
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2544
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2545
	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
  2546
	    &children) != 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2547
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2548
		    "Source pool is missing vdev tree"));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2549
		if (zc_props)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2550
			nvlist_free(zc_props);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2551
		return (-1);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2552
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2553
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2554
	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
  2555
	vcount = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2556
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2557
	if (*newroot == NULL ||
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2558
	    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
  2559
	    &newchild, &newchildren) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2560
		newchildren = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2561
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2562
	for (c = 0; c < children; c++) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2563
		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
  2564
		char *type;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2565
		nvlist_t **mchild, *vdev;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2566
		uint_t mchildren;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2567
		int entry;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2568
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2569
		/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2570
		 * 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
  2571
		 * 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
  2572
		 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2573
		(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
  2574
		    &is_log);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2575
		(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
  2576
		    &is_hole);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2577
		if (is_log || is_hole) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2578
			/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2579
			 * 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
  2580
			 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2581
			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
  2582
				goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2583
			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
  2584
			    VDEV_TYPE_HOLE) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2585
				goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2586
			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
  2587
			    1) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2588
				goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2589
			if (lastlog == 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2590
				lastlog = vcount;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2591
			varray[vcount++] = vdev;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2592
			continue;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2593
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2594
		lastlog = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2595
		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
  2596
		    == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2597
		if (strcmp(type, VDEV_TYPE_MIRROR) != 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2598
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2599
			    "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
  2600
			retval = zfs_error(hdl, EZFS_INVALCONFIG, msg);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2601
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2602
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2603
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2604
		verify(nvlist_lookup_nvlist_array(child[c],
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2605
		    ZPOOL_CONFIG_CHILDREN, &mchild, &mchildren) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2606
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2607
		/* 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
  2608
		if (newchildren > 0 &&
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2609
		    (entry = find_vdev_entry(zhp, mchild, mchildren,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2610
		    newchild, newchildren)) >= 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2611
			/* 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
  2612
			vdev = mchild[entry];
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2613
			++found;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2614
		} else {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2615
			/* 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
  2616
			vdev = mchild[mchildren - 1];
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2617
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2618
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2619
		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
  2620
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2621
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2622
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2623
	/* 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
  2624
	if (found != newchildren) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2625
		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
  2626
		    "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
  2627
		retval = zfs_error(hdl, EZFS_INVALCONFIG, msg);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2628
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2629
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2630
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2631
	/* Prepare the nvlist for populating. */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2632
	if (*newroot == NULL) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2633
		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
  2634
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2635
		freelist = B_TRUE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2636
		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
  2637
		    VDEV_TYPE_ROOT) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2638
			goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2639
	} else {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2640
		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
  2641
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2642
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2643
	/* Add all the children we found */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2644
	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
  2645
	    lastlog == 0 ? vcount : lastlog) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2646
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2647
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2648
	/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2649
	 * 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
  2650
	 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2651
	if (flags.dryrun) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2652
		memory_err = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2653
		freelist = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2654
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2655
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2656
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2657
	/* 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
  2658
	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
  2659
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2660
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2661
	if (nvlist_add_nvlist(newconfig,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2662
	    ZPOOL_CONFIG_VDEV_TREE, *newroot) != 0 ||
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2663
	    nvlist_add_string(newconfig,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2664
	    ZPOOL_CONFIG_POOL_NAME, newname) != 0 ||
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2665
	    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
  2666
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2667
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2668
	/*
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2669
	 * 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
  2670
	 * explicitly export it.
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2671
	 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2672
	if (!flags.import)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2673
		zc.zc_cookie = ZPOOL_EXPORT_AFTER_SPLIT;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2674
	(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
  2675
	(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
  2676
	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
  2677
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2678
	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
  2679
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2680
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2681
	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
  2682
		retval = zpool_standard_error(hdl, errno, msg);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2683
		goto out;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2684
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2685
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2686
	freelist = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2687
	memory_err = B_FALSE;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2688
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2689
out:
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2690
	if (varray != NULL) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2691
		int v;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2692
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2693
		for (v = 0; v < vcount; v++)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2694
			nvlist_free(varray[v]);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2695
		free(varray);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2696
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2697
	zcmd_free_nvlists(&zc);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2698
	if (zc_props)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2699
		nvlist_free(zc_props);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2700
	if (newconfig)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2701
		nvlist_free(newconfig);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2702
	if (freelist) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2703
		nvlist_free(*newroot);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2704
		*newroot = NULL;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2705
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2706
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2707
	if (retval != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2708
		return (retval);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2709
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2710
	if (memory_err)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2711
		return (no_memory(hdl));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2712
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2713
	return (0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2714
}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2715
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11026
diff changeset
  2716
/*
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2717
 * Remove the given device.  Currently, this is supported only for hot spares
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2718
 * and level 2 cache devices.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2719
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2720
int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2721
zpool_vdev_remove(zpool_handle_t *zhp, const char *path)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2722
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2723
	zfs_cmd_t zc = { 0 };
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2724
	char msg[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2725
	nvlist_t *tgt;
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2726
	boolean_t avail_spare, l2cache, islog;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2727
	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
  2728
	uint64_t version;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2729
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2730
	(void) snprintf(msg, sizeof (msg),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2731
	    dgettext(TEXT_DOMAIN, "cannot remove %s"), path);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2732
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2733
	(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
  2734
	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
  2735
	    &islog)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2736
		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
  2737
	/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2738
	 * XXX - this should just go away.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2739
	 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2740
	if (!avail_spare && !l2cache && !islog) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2741
		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
  2742
		    "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
  2743
		    "or log devices can be removed"));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2744
		return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2745
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2746
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2747
	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
  2748
	if (islog && version < SPA_VERSION_HOLES) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2749
		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
  2750
		    "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
  2751
		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
  2752
	}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2753
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2754
	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2755
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  2756
	if (zfs_ioctl(hdl, ZFS_IOC_VDEV_REMOVE, &zc) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2757
		return (0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2758
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2759
	return (zpool_standard_error(hdl, errno, msg));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2760
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2761
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2762
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2763
 * Clear the errors for the pool, or the particular device if specified.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2764
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2765
int
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2766
zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2767
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2768
	zfs_cmd_t zc = { 0 };
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2769
	char msg[1024];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2770
	nvlist_t *tgt;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2771
	zpool_rewind_policy_t policy;
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2772
	boolean_t avail_spare, l2cache;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2773
	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
  2774
	nvlist_t *nvi = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2775
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2776
	if (path)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2777
		(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2778
		    dgettext(TEXT_DOMAIN, "cannot clear errors for %s"),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  2779
		    path);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2780
	else
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2781
		(void) snprintf(msg, sizeof (msg),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2782
		    dgettext(TEXT_DOMAIN, "cannot clear errors for %s"),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2783
		    zhp->zpool_name);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2784
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2785
	(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
  2786
	if (path) {
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2787
		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
  2788
		    &l2cache, NULL)) == 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2789
			return (zfs_error(hdl, EZFS_NODEVICE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2790
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2791
		/*
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2792
		 * Don't allow error clearing for hot spares.  Do allow
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2793
		 * error clearing for l2cache devices.
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5363
diff changeset
  2794
		 */
2468
b5038d012f66 6433208 should not be able to offline/online a spare
ek110237
parents: 2174
diff changeset
  2795
		if (avail_spare)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2796
			return (zfs_error(hdl, EZFS_ISSPARE, msg));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2797
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2798
		verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2799
		    &zc.zc_guid) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2800
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2801
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2802
	zpool_get_rewind_policy(rewindnvl, &policy);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2803
	zc.zc_cookie = policy.zrp_request;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2804
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2805
	if (zcmd_alloc_dst_nvlist(hdl, &zc, 8192) != 0)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2806
		return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2807
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2808
	if (zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, rewindnvl) != 0)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2809
		return (-1);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2810
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2811
	if (zfs_ioctl(hdl, ZFS_IOC_CLEAR, &zc) == 0 ||
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2812
	    ((policy.zrp_request & ZPOOL_TRY_REWIND) &&
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2813
	    errno != EPERM && errno != EACCES)) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2814
		if (policy.zrp_request &
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2815
		    (ZPOOL_DO_REWIND | ZPOOL_TRY_REWIND)) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2816
			(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
  2817
			zpool_rewind_exclaim(hdl, zc.zc_name,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2818
			    ((policy.zrp_request & ZPOOL_TRY_REWIND) != 0),
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2819
			    nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2820
			nvlist_free(nvi);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2821
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2822
		zcmd_free_nvlists(&zc);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2823
		return (0);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2824
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2825
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10817
diff changeset
  2826
	zcmd_free_nvlists(&zc);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2827
	return (zpool_standard_error(hdl, errno, msg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2828
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2829
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2926
diff changeset
  2830
/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2831
 * Similar to zpool_clear(), but takes a GUID (used by fmd).
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2832
 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2833
int
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2834
zpool_vdev_clear(zpool_handle_t *zhp, uint64_t guid)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2835
{
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2836
	zfs_cmd_t zc = { 0 };
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2837
	char msg[1024];
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2838
	libzfs_handle_t *hdl = zhp->zpool_hdl;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2839
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2840
	(void) snprintf(msg, sizeof (msg),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2841
	    dgettext(TEXT_DOMAIN, "cannot clear errors for %llx"),
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2842
	    guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2843
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2844
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2845
	zc.zc_guid = guid;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2846
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2847
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_CLEAR, &zc) == 0)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2848
		return (0);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2849
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2850
	return (zpool_standard_error(hdl, errno, msg));
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2851
}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2852
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2853
/*
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2854
 * Convert from a devid string to a path.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2855
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2856
static char *
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2857
devid_to_path(char *devid_str)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2858
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2859
	ddi_devid_t devid;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2860
	char *minor;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2861
	char *path;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2862
	devid_nmlist_t *list = NULL;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2863
	int ret;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2864
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2865
	if (devid_str_decode(devid_str, &devid, &minor) != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2866
		return (NULL);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2867
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2868
	ret = devid_deviceid_to_nmlist("/dev", devid, minor, &list);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2869
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2870
	devid_str_free(minor);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2871
	devid_free(devid);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2872
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2873
	if (ret != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2874
		return (NULL);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2875
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2876
	if ((path = strdup(list[0].devname)) == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2877
		return (NULL);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2878
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2879
	devid_free_nmlist(list);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2880
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2881
	return (path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2882
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2883
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2884
/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2885
 * Convert from a path to a devid string.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2886
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2887
static char *
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2888
path_to_devid(const char *path)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2889
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2890
	int fd;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2891
	ddi_devid_t devid;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2892
	char *minor, *ret;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2893
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2894
	if ((fd = open(path, O_RDONLY)) < 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2895
		return (NULL);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2896
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2897
	minor = NULL;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2898
	ret = NULL;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2899
	if (devid_get(fd, &devid) == 0) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2900
		if (devid_get_minor_name(fd, &minor) == 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2901
			ret = devid_str_encode(devid, minor);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2902
		if (minor != NULL)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2903
			devid_str_free(minor);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2904
		devid_free(devid);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2905
	}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2906
	(void) close(fd);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2907
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2908
	return (ret);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2909
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2910
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2911
/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2912
 * 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
  2913
 * 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
  2914
 * type 'zpool status', and we'll display the correct information anyway.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2915
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2916
static void
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2917
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
  2918
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2919
	zfs_cmd_t zc = { 0 };
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2920
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2921
	(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
  2922
	(void) strncpy(zc.zc_value, path, sizeof (zc.zc_value));
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2923
	verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2924
	    &zc.zc_guid) == 0);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2925
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2926
	(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
  2927
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2928
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2929
/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2930
 * 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
  2931
 * 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
  2932
 * 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
  2933
 * trailing 's0' slice name.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2934
 *
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2935
 * This routine is also responsible for identifying when disks have been
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2936
 * 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
  2937
 * 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
  2938
 * 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
  2939
 * 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
  2940
 * 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
  2941
 * 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
  2942
 * of these checks.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2943
 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2944
char *
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2945
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
  2946
    boolean_t verbose)
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2947
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2948
	char *path, *devid;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2949
	uint64_t value;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2950
	char buf[64];
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2951
	vdev_stat_t *vs;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2952
	uint_t vsc;
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2953
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2954
	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2955
	    &value) == 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2956
		verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2957
		    &value) == 0);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
  2958
		(void) snprintf(buf, sizeof (buf), "%llu",
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
  2959
		    (u_longlong_t)value);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2960
		path = buf;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2961
	} 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
  2962
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2963
		/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2964
		 * If the device is dead (faulted, offline, etc) then don't
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2965
		 * bother opening it.  Otherwise we may be forcing the user to
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2966
		 * open a misbehaving device, which can have undesirable
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2967
		 * effects.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2968
		 */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11814
diff changeset
  2969
		if ((nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2970
		    (uint64_t **)&vs, &vsc) != 0 ||
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2971
		    vs->vs_state >= VDEV_STATE_DEGRADED) &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4295
diff changeset
  2972
		    zhp != NULL &&
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2973
		    nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &devid) == 0) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2974
			/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2975
			 * Determine if the current path is correct.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2976
			 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2977
			char *newdevid = path_to_devid(path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2978
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2979
			if (newdevid == NULL ||
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2980
			    strcmp(devid, newdevid) != 0) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2981
				char *newpath;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2982
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2983
				if ((newpath = devid_to_path(devid)) != NULL) {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2984
					/*
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2985
					 * Update the path appropriately.
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2986
					 */
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2987
					set_path(zhp, nv, newpath);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2988
					if (nvlist_add_string(nv,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2989
					    ZPOOL_CONFIG_PATH, newpath) == 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2990
						verify(nvlist_lookup_string(nv,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2991
						    ZPOOL_CONFIG_PATH,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2992
						    &path) == 0);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2993
					free(newpath);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2994
				}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2995
			}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2996
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2997
			if (newdevid)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  2998
				devid_str_free(newdevid);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  2999
		}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3000
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3001
		if (strncmp(path, "/dev/dsk/", 9) == 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3002
			path += 9;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3003
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3004
		if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3005
		    &value) == 0 && value) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3006
			char *tmp = zfs_strdup(hdl, path);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3007
			if (tmp == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3008
				return (NULL);
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3009
			tmp[strlen(path) - 2] = '\0';
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3010
			return (tmp);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3011
		}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3012
	} else {
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3013
		verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &path) == 0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3014
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3015
		/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3016
		 * 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
  3017
		 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3018
		if (strcmp(path, VDEV_TYPE_RAIDZ) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3019
			verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3020
			    &value) == 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3021
			(void) snprintf(buf, sizeof (buf), "%s%llu", path,
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2676
diff changeset
  3022
			    (u_longlong_t)value);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3023
			path = buf;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3024
		}
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3025
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3026
		/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3027
		 * 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
  3028
		 * naming convention.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3029
		 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3030
		if (verbose) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3031
			uint64_t id;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3032
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3033
			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
  3034
			    &id) == 0);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3035
			(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
  3036
			    (u_longlong_t)id);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3037
			path = buf;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3038
		}
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3039
	}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3040
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3041
	return (zfs_strdup(hdl, path));
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1003
diff changeset
  3042
}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3043
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3044
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3045
zbookmark_compare(const void *a, const void *b)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3046
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3047
	return (memcmp(a, b, sizeof (zbookmark_t)));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3048
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3049
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3050
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3051
 * Retrieve the persistent error log, uniquify the members, and return to the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3052
 * caller.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3053
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3054
int
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3055
zpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3056
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3057
	zfs_cmd_t zc = { 0 };
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3058
	uint64_t count;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3059
	zbookmark_t *zb = NULL;
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3060
	int i;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3061
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3062
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3063
	 * Retrieve the raw error list from the kernel.  If the number of errors
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3064
	 * has increased, allocate more space and continue until we get the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3065
	 * entire list.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3066
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3067
	verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_ERRCOUNT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3068
	    &count) == 0);
4820
acbb57436af2 6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents: 4715
diff changeset
  3069
	if (count == 0)
acbb57436af2 6588264 zpool_get_errlog() can attempt to calloc size 0
ek110237
parents: 4715
diff changeset
  3070
		return (0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3071
	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
  3072
	    count * sizeof (zbookmark_t))) == (uintptr_t)NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3073
		return (-1);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3074
	zc.zc_nvlist_dst_size = count;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3075
	(void) strcpy(zc.zc_name, zhp->zpool_name);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3076
	for (;;) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3077
		if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_ERROR_LOG,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3078
		    &zc) != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3079
			free((void *)(uintptr_t)zc.zc_nvlist_dst);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3080
			if (errno == ENOMEM) {
3823
2cbdd0a48584 6494119 zpool status command exits with abort
vb160487
parents: 3741
diff changeset
  3081
				count = zc.zc_nvlist_dst_size;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3082
				if ((zc.zc_nvlist_dst = (uintptr_t)
3823
2cbdd0a48584 6494119 zpool status command exits with abort
vb160487
parents: 3741
diff changeset
  3083
				    zfs_alloc(zhp->zpool_hdl, count *
2cbdd0a48584 6494119 zpool status command exits with abort
vb160487
parents: 3741
diff changeset
  3084
				    sizeof (zbookmark_t))) == (uintptr_t)NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3085
					return (-1);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3086
			} else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3087
				return (-1);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3088
			}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3089
		} else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3090
			break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3091
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3092
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3093
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3094
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3095
	 * Sort the resulting bookmarks.  This is a little confusing due to the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3096
	 * implementation of ZFS_IOC_ERROR_LOG.  The bookmarks are copied last
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3097
	 * to first, and 'zc_nvlist_dst_size' indicates the number of boomarks
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3098
	 * _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
  3099
	 * array appropriate and decrement the total number of elements.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3100
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3101
	zb = ((zbookmark_t *)(uintptr_t)zc.zc_nvlist_dst) +
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3102
	    zc.zc_nvlist_dst_size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3103
	count -= zc.zc_nvlist_dst_size;
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
	qsort(zb, count, sizeof (zbookmark_t), zbookmark_compare);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3106
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3107
	verify(nvlist_alloc(nverrlistp, 0, KM_SLEEP) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3108
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3109
	/*
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3110
	 * Fill in the nverrlistp with nvlist's of dataset and object numbers.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3111
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3112
	for (i = 0; i < count; i++) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3113
		nvlist_t *nv;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3114
3700
3a7e0afcf1b4 6523936 BAD TRAP: type=8 (#df Double fault) rp=fec266f8 addr=0
ek110237
parents: 3444
diff changeset
  3115
		/* 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
  3116
		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
  3117
		    zb[i-1].zb_object == zb[i].zb_object)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3118
			continue;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3119
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3120
		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
  3121
			goto nomem;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3122
		if (nvlist_add_uint64(nv, ZPOOL_ERR_DATASET,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3123
		    zb[i].zb_objset) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3124
			nvlist_free(nv);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3125
			goto nomem;
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3126
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3127
		if (nvlist_add_uint64(nv, ZPOOL_ERR_OBJECT,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3128
		    zb[i].zb_object) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3129
			nvlist_free(nv);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3130
			goto nomem;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3131
		}
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3132
		if (nvlist_add_nvlist(*nverrlistp, "ejk", nv) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3133
			nvlist_free(nv);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3134
			goto nomem;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3135
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3136
		nvlist_free(nv);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3137
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3138
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3139
	free((void *)(uintptr_t)zc.zc_nvlist_dst);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3140
	return (0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3141
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3142
nomem:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2468
diff changeset
  3143
	free((void *)(uintptr_t)zc.zc_nvlist_dst);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3144
	return (no_memory(zhp->zpool_hdl));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3145
}
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3146
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3147
/*
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3148
 * Upgrade a ZFS pool to the latest on-disk version.
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3149
 */
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3150
int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3151
zpool_upgrade(zpool_handle_t *zhp, uint64_t new_version)
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3152
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3153
	zfs_cmd_t zc = { 0 };
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3154
	libzfs_handle_t *hdl = zhp->zpool_hdl;
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3155
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3156
	(void) strcpy(zc.zc_name, zhp->zpool_name);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3157
	zc.zc_cookie = new_version;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  3158
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3159
	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
  3160
		return (zpool_standard_error_fmt(hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3161
		    dgettext(TEXT_DOMAIN, "cannot upgrade '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1773
diff changeset
  3162
		    zhp->zpool_name));
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3163
	return (0);
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1635
diff changeset
  3164
}
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3165
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3166
void
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3167
zpool_set_history_str(const char *subcommand, int argc, char **argv,
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3168
    char *history_str)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3169
{
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3170
	int i;
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3171
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3172
	(void) strlcpy(history_str, subcommand, HIS_MAX_RECORD_LEN);
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3173
	for (i = 1; i < argc; i++) {
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3174
		if (strlen(history_str) + 1 + strlen(argv[i]) >
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3175
		    HIS_MAX_RECORD_LEN)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3176
			break;
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3177
		(void) strlcat(history_str, " ", HIS_MAX_RECORD_LEN);
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3178
		(void) strlcat(history_str, argv[i], HIS_MAX_RECORD_LEN);
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3179
	}
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3180
}
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3181
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3182
/*
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3183
 * Stage command history for logging.
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3184
 */
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3185
int
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3186
zpool_stage_history(libzfs_handle_t *hdl, const char *history_str)
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3187
{
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3188
	if (history_str == NULL)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3189
		return (EINVAL);
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3190
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3191
	if (strlen(history_str) > HIS_MAX_RECORD_LEN)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3192
		return (EINVAL);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3193
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4657
diff changeset
  3194
	if (hdl->libzfs_log_str != NULL)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3195
		free(hdl->libzfs_log_str);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3196
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3197
	if ((hdl->libzfs_log_str = strdup(history_str)) == NULL)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3198
		return (no_memory(hdl));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  3199
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4820
diff changeset
  3200
	return (0);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3201
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3202
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3203
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3204
 * Perform ioctl to get some command history of a pool.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3205
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3206
 * 'buf' is the buffer to fill up to 'len' bytes.  'off' is the
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3207
 * logical offset of the history buffer to start reading from.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3208
 *
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3209
 * Upon return, 'off' is the next logical offset to read from and
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3210
 * 'len' is the actual amount of bytes read into 'buf'.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3211
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3212
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3213
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
  3214
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3215
	zfs_cmd_t zc = { 0 };
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3216
	libzfs_handle_t *hdl = zhp->zpool_hdl;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3217
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3218
	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3219
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3220
	zc.zc_history = (uint64_t)(uintptr_t)buf;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3221
	zc.zc_history_len = *len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3222
	zc.zc_history_offset = *off;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3223
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3224
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_GET_HISTORY, &zc) != 0) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3225
		switch (errno) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3226
		case EPERM:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3227
			return (zfs_error_fmt(hdl, EZFS_PERM,
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3228
			    dgettext(TEXT_DOMAIN,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3229
			    "cannot show history for pool '%s'"),
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3230
			    zhp->zpool_name));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3231
		case ENOENT:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3232
			return (zfs_error_fmt(hdl, EZFS_NOHISTORY,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3233
			    dgettext(TEXT_DOMAIN, "cannot get history for pool "
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3234
			    "'%s'"), zhp->zpool_name));
3863
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3235
		case ENOTSUP:
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3236
			return (zfs_error_fmt(hdl, EZFS_BADVERSION,
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3237
			    dgettext(TEXT_DOMAIN, "cannot get history for pool "
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3823
diff changeset
  3238
			    "'%s', pool must be upgraded"), zhp->zpool_name));
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3239
		default:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3126
diff changeset
  3240
			return (zpool_standard_error_fmt(hdl, errno,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3241
			    dgettext(TEXT_DOMAIN,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3242
			    "cannot get history for '%s'"), zhp->zpool_name));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3243
		}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3244
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3245
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3246
	*len = zc.zc_history_len;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3247
	*off = zc.zc_history_offset;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3248
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3249
	return (0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3250
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3251
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3252
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3253
 * Process the buffer of nvlists, unpacking and storing each nvlist record
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3254
 * into 'records'.  'leftover' is set to the number of bytes that weren't
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3255
 * processed as there wasn't a complete record.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3256
 */
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10594
diff changeset
  3257
int
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3258
zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3259
    nvlist_t ***records, uint_t *numrecords)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3260
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3261
	uint64_t reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3262
	nvlist_t *nv;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3263
	int i;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3264
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3265
	while (bytes_read > sizeof (reclen)) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3266
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3267
		/* get length of packed record (stored as little endian) */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3268
		for (i = 0, reclen = 0; i < sizeof (reclen); i++)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3269
			reclen += (uint64_t)(((uchar_t *)buf)[i]) << (8*i);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3270
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3271
		if (bytes_read < sizeof (reclen) + reclen)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3272
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3273
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3274
		/* unpack record */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3275
		if (nvlist_unpack(buf + sizeof (reclen), reclen, &nv, 0) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3276
			return (ENOMEM);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3277
		bytes_read -= sizeof (reclen) + reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3278
		buf += sizeof (reclen) + reclen;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3279
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3280
		/* add record to nvlist array */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3281
		(*numrecords)++;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3282
		if (ISP2(*numrecords + 1)) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3283
			*records = realloc(*records,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3284
			    *numrecords * 2 * sizeof (nvlist_t *));
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3285
		}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3286
		(*records)[*numrecords - 1] = nv;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3287
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3288
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3289
	*leftover = bytes_read;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3290
	return (0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3291
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3292
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3293
#define	HIS_BUF_LEN	(128*1024)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3294
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3295
/*
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3296
 * Retrieve the command history of a pool.
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3297
 */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3298
int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3299
zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3300
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3301
	char buf[HIS_BUF_LEN];
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3302
	uint64_t off = 0;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3303
	nvlist_t **records = NULL;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3304
	uint_t numrecords = 0;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3305
	int err, i;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3306
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3307
	do {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3308
		uint64_t bytes_read = sizeof (buf);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3309
		uint64_t leftover;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3310
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3311
		if ((err = get_history(zhp, buf, &off, &bytes_read)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3312
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3313
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3314
		/* if nothing else was read in, we're at EOF, just return */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3315
		if (!bytes_read)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3316
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3317
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3318
		if ((err = zpool_history_unpack(buf, bytes_read,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3319
		    &leftover, &records, &numrecords)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3320
			break;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3321
		off -= leftover;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3322
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3323
		/* CONSTCOND */
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3324
	} while (1);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3325
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3326
	if (!err) {
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3327
		verify(nvlist_alloc(nvhisp, NV_UNIQUE_NAME, 0) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3328
		verify(nvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3329
		    records, numrecords) == 0);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3330
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3331
	for (i = 0; i < numrecords; i++)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3332
		nvlist_free(records[i]);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3333
	free(records);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3334
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3335
	return (err);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2856
diff changeset
  3336
}
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3337
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3338
void
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3339
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
  3340
    char *pathname, size_t len)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3341
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3342
	zfs_cmd_t zc = { 0 };
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3343
	boolean_t mounted = B_FALSE;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3344
	char *mntpnt = NULL;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3345
	char dsname[MAXNAMELEN];
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3346
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3347
	if (dsobj == 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3348
		/* special case for the MOS */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3349
		(void) snprintf(pathname, len, "<metadata>:<0x%llx>", obj);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3350
		return;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3351
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3352
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3353
	/* get the dataset's name */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3354
	(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
  3355
	zc.zc_obj = dsobj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3356
	if (ioctl(zhp->zpool_hdl->libzfs_fd,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3357
	    ZFS_IOC_DSOBJ_TO_DSNAME, &zc) != 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3358
		/* 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
  3359
		(void) snprintf(pathname, len, "<0x%llx>:<0x%llx>",
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3360
		    dsobj, obj);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3361
		return;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3362
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3363
	(void) strlcpy(dsname, zc.zc_value, sizeof (dsname));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3364
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3365
	/* find out if the dataset is mounted */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3366
	mounted = is_mounted(zhp->zpool_hdl, dsname, &mntpnt);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3367
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3368
	/* get the corrupted object's path */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3369
	(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
  3370
	zc.zc_obj = obj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3371
	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
  3372
	    &zc) == 0) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3373
		if (mounted) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3374
			(void) snprintf(pathname, len, "%s%s", mntpnt,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3375
			    zc.zc_value);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3376
		} else {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3377
			(void) snprintf(pathname, len, "%s:%s",
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3378
			    dsname, zc.zc_value);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3379
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3380
	} else {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3381
		(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
  3382
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3383
	free(mntpnt);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3377
diff changeset
  3384
}
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3863
diff changeset
  3385
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
  3386
/*
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3387
 * 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
  3388
 * 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
  3389
 * 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
  3390
 * partition.
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3391
 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3392
static int
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3393
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
  3394
{
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3395
	char *path;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3396
	int fd;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3397
	char diskname[MAXPATHLEN];
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3398
	int err = -1;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3399
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3400
	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
  3401
		return (err);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3402
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3403
	(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
  3404
	    strrchr(path, '/'));
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3405
	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
  3406
		struct dk_gpt *vtoc;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3407
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3408
		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
  3409
			if (sb != NULL)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3410
				*sb = vtoc->efi_parts[0].p_start;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3411
			efi_free(vtoc);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3412
		}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3413
		(void) close(fd);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3414
	}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3415
	return (err);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3416
}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3417
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3418
/*
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
  3419
 * 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
  3420
 * 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
  3421
 */
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
  3422
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
  3423
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
  3424
{
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
  3425
	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
  3426
	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
  3427
	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
  3428
	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
  3429
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
  3430
	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
  3431
	    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
  3432
		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
  3433
		    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
  3434
		    &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
  3435
			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
  3436
		}
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3437
		if (read_efi_label(config, &sb) < 0)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 7041
diff changeset
  3438
			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
  3439
		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
  3440
	}
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
  3441
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
  3442
	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
  3443
		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
  3444
		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
  3445
			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
  3446
		}
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
  3447
	}
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
  3448
	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
  3449
}
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
  3450
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
  3451
/*
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
  3452
 * 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
  3453
 * 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
  3454
 */
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
  3455
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
  3456
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
  3457
{
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
  3458
	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
  3459
	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
  3460
	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
  3461
	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
  3462
	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
  3463
	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
  3464
	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
  3465
6289
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3466
	/* 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
  3467
	(void) snprintf(errbuf, sizeof (errbuf),
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3468
	    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
  3469
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
  3470
	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
  3471
		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
  3472
7965
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3473
		if (pool_is_bootable(zhp)) {
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3474
			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
  3475
			    "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
  3476
			    "pools."));
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3477
			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
  3478
		}
b795da521357 6740164 zpool attach can create an illegal root pool
George Wilson <George.Wilson@Sun.COM>
parents: 7656
diff changeset
  3479
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
  3480
		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
  3481
		    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
  3482
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
  3483
		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
  3484
			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
  3485
		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
  3486
			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
  3487
		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
  3488
	} 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
  3489
		/* 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
  3490
		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
  3491
	}
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
  3492
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
  3493
	(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
  3494
	    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
  3495
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
  3496
	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
  3497
		/*
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
  3498
		 * 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
  3499
		 * 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
  3500
		 */
6289
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3501
		zfs_error_aux(hdl,
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3502
		    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
  3503
		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
  3504
	}
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
  3505
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
  3506
	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
  3507
		/*
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
  3508
		 * 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
  3509
		 * 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
  3510
		 */
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
  3511
		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
  3512
			(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
  3513
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
  3514
		(void) close(fd);
6289
9a83171c70d6 6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents: 5621
diff changeset
  3515
		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
  3516
		    "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
  3517
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
  3518
		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
  3519
	}
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
  3520
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
  3521
	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
  3522
	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
  3523
	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
  3524
		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
  3525
	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
  3526
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
  3527
	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
  3528
	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
  3529
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
  3530
	/*
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
  3531
	 * 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
  3532
	 * 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
  3533
	 * 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
  3534
	 * 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
  3535
	 * 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
  3536
	 * 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
  3537
	 */
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
  3538
	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
  3539
	(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
  3540
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
  3541
	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
  3542
	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
  3543
	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
  3544
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
  3545
	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
  3546
		/*
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
  3547
		 * 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
  3548
		 * 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
  3549
		 * 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
  3550
		 * 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
  3551
		 */
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
  3552
		(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
  3553
		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
  3554
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
  3555
		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
  3556
		    "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
  3557
		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
  3558
	}
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
  3559
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
  3560
	(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
  3561
	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
  3562
	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
  3563
}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3564
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3565
static boolean_t
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3566
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
  3567
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3568
	char *type;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3569
	nvlist_t **child;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3570
	uint_t children, c;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3571
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3572
	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_TYPE, &type) == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3573
	if (strcmp(type, VDEV_TYPE_RAIDZ) == 0 ||
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3574
	    strcmp(type, VDEV_TYPE_FILE) == 0 ||
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3575
	    strcmp(type, VDEV_TYPE_LOG) == 0 ||
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  3576
	    strcmp(type, VDEV_TYPE_HOLE) == 0 ||
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3577
	    strcmp(type, VDEV_TYPE_MISSING) == 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3578
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3579
		    "vdev type '%s' is not supported"), type);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3580
		(void) zfs_error(hdl, EZFS_VDEVNOTSUP, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3581
		return (B_FALSE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3582
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3583
	if (nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_CHILDREN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3584
	    &child, &children) == 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3585
		for (c = 0; c < children; c++) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3586
			if (!supported_dump_vdev_type(hdl, child[c], errbuf))
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3587
				return (B_FALSE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3588
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3589
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3590
	return (B_TRUE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3591
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3592
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3593
/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3594
 * check if this zvol is allowable for use as a dump device; zero if
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3595
 * it is, > 0 if it isn't, < 0 if it isn't a zvol
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3596
 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3597
int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3598
zvol_check_dump_config(char *arg)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3599
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3600
	zpool_handle_t *zhp = NULL;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3601
	nvlist_t *config, *nvroot;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3602
	char *p, *volname;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3603
	nvlist_t **top;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3604
	uint_t toplevels;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3605
	libzfs_handle_t *hdl;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3606
	char errbuf[1024];
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3607
	char poolname[ZPOOL_MAXNAMELEN];
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3608
	int pathlen = strlen(ZVOL_FULL_DEV_DIR);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3609
	int ret = 1;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3610
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3611
	if (strncmp(arg, ZVOL_FULL_DEV_DIR, pathlen)) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3612
		return (-1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3613
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3614
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3615
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3616
	    "dump is not supported on device '%s'"), arg);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3617
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3618
	if ((hdl = libzfs_init()) == NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3619
		return (1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3620
	libzfs_print_on_error(hdl, B_TRUE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3621
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3622
	volname = arg + pathlen;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3623
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3624
	/* check the configuration of the pool */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3625
	if ((p = strchr(volname, '/')) == NULL) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3626
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3627
		    "malformed dataset name"));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3628
		(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3629
		return (1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3630
	} else if (p - volname >= ZFS_MAXNAMELEN) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3631
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3632
		    "dataset name is too long"));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3633
		(void) zfs_error(hdl, EZFS_NAMETOOLONG, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3634
		return (1);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3635
	} else {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3636
		(void) strncpy(poolname, volname, p - volname);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3637
		poolname[p - volname] = '\0';
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3638
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3639
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3640
	if ((zhp = zpool_open(hdl, poolname)) == NULL) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3641
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3642
		    "could not open pool '%s'"), poolname);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3643
		(void) zfs_error(hdl, EZFS_OPENFAILED, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3644
		goto out;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3645
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3646
	config = zpool_get_config(zhp, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3647
	if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3648
	    &nvroot) != 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3649
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3650
		    "could not obtain vdev configuration for  '%s'"), poolname);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3651
		(void) zfs_error(hdl, EZFS_INVALCONFIG, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3652
		goto out;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3653
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3654
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3655
	verify(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3656
	    &top, &toplevels) == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3657
	if (toplevels != 1) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3658
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3659
		    "'%s' has multiple top level vdevs"), poolname);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3660
		(void) zfs_error(hdl, EZFS_DEVOVERFLOW, errbuf);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3661
		goto out;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3662
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3663
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3664
	if (!supported_dump_vdev_type(hdl, top[0], errbuf)) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3665
		goto out;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3666
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3667
	ret = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3668
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3669
out:
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3670
	if (zhp)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3671
		zpool_close(zhp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3672
	libzfs_fini(hdl);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3673
	return (ret);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6289
diff changeset
  3674
}