usr/src/uts/common/fs/zfs/vdev_disk.c
author Lin Ling <Lin.Ling@Sun.COM>
Wed, 24 Sep 2008 20:56:23 -0700
changeset 7687 1132fbaf0c27
parent 7553 05e51cba6833
child 7754 b80e4842ad54
permissions -rw-r--r--
6750475 can't boot off a mirrored root with a failed disk
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
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
     5
 * Common Development and Distribution License (the "License").
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
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
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
    22
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
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 <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/spa.h>
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
    28
#include <sys/refcount.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/vdev_disk.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/zio.h>
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
    33
#include <sys/sunldi.h>
6976
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
    34
#include <sys/fm/fs/zfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 * Virtual device vector for disks.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
extern ldi_ident_t zfs_li;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
typedef struct vdev_disk_buf {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
	buf_t	vdb_buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
	zio_t	*vdb_io;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
} vdev_disk_buf_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
static int
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
    48
vdev_disk_open_common(vdev_t *vd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
	vdev_disk_t *dvd;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
    51
	dev_t dev;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
	 * We must have a pathname, and it must be absolute.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
	if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	dvd = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_disk_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
	 * When opening a disk device, we want to preserve the user's original
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
	 * intent.  We always want to open the device by the path the user gave
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
	 * us, even if it is one of multiple paths to the save device.  But we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
	 * also want to be able to survive disks being removed/recabled.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	 * Therefore the sequence of opening devices is:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
	 *
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
    71
	 * 1. Try opening the device by path.  For legacy pools without the
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
    72
	 *    'whole_disk' property, attempt to fix the path by appending 's0'.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	 * 2. If the devid of the device matches the stored value, return
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	 *    success.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	 * 3. Otherwise, the device may have moved.  Try opening the device
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	 *    by the devid instead.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
	 *
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
    80
	 * If the vdev is part of the root pool, we avoid opening it by path.
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
    81
	 * We do this because there is no /dev path available early in boot,
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
    82
	 * and if we try to open the device by path at a later point, we can
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
    83
	 * deadlock when devfsadm attempts to open the underlying backing store
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
    84
	 * file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
	if (vd->vdev_devid != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
		if (ddi_devid_str_decode(vd->vdev_devid, &dvd->vd_devid,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
		    &dvd->vd_minor) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
			vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
			return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
	error = EINVAL;		/* presume failure */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
    96
	if (vd->vdev_path != NULL && !spa_is_root(vd->vdev_spa)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
		ddi_devid_t devid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
    99
		if (vd->vdev_wholedisk == -1ULL) {
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   100
			size_t len = strlen(vd->vdev_path) + 3;
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   101
			char *buf = kmem_alloc(len, KM_SLEEP);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   102
			ldi_handle_t lh;
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   103
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   104
			(void) snprintf(buf, len, "%ss0", vd->vdev_path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   106
			if (ldi_open_by_name(buf, spa_mode, kcred,
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   107
			    &lh, zfs_li) == 0) {
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   108
				spa_strfree(vd->vdev_path);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   109
				vd->vdev_path = buf;
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   110
				vd->vdev_wholedisk = 1ULL;
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   111
				(void) ldi_close(lh, spa_mode, kcred);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   112
			} else {
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   113
				kmem_free(buf, len);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   114
			}
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   115
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   117
		error = ldi_open_by_name(vd->vdev_path, spa_mode, kcred,
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   118
		    &dvd->vd_lh, zfs_li);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
		 * Compare the devid to the stored value.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
		if (error == 0 && vd->vdev_devid != NULL &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
		    ldi_get_devid(dvd->vd_lh, &devid) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
			if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
				(void) ldi_close(dvd->vd_lh, spa_mode, kcred);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
				dvd->vd_lh = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
			ddi_devid_free(devid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
		}
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   132
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   133
		/*
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   134
		 * If we succeeded in opening the device, but 'vdev_wholedisk'
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   135
		 * is not yet set, then this must be a slice.
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   136
		 */
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   137
		if (error == 0 && vd->vdev_wholedisk == -1ULL)
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   138
			vd->vdev_wholedisk = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
	 * If we were unable to open by path, or the devid check fails, open by
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	 * devid instead.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	if (error != 0 && vd->vdev_devid != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
		error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
		    spa_mode, kcred, &dvd->vd_lh, zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   149
	/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   150
	 * If all else fails, then try opening by physical path (if available)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   151
	 * or the logical path (if we failed due to the devid check).  While not
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   152
	 * as reliable as the devid, this will give us something, and the higher
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   153
	 * level vdev validation will prevent us from opening the wrong device.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   154
	 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   155
	if (error) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   156
		if (vd->vdev_physpath != NULL &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   157
		    (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != ENODEV)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   158
			error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode,
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   159
			    kcred, &dvd->vd_lh, zfs_li);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   160
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   161
		/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   162
		 * Note that we don't support the legacy auto-wholedisk support
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   163
		 * as above.  This hasn't been used in a very long time and we
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   164
		 * don't need to propagate its oddities to this edge condition.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   165
		 */
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   166
		if (error && vd->vdev_path != NULL &&
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   167
		    !spa_is_root(vd->vdev_spa))
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   168
			error = ldi_open_by_name(vd->vdev_path, spa_mode, kcred,
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   169
			    &dvd->vd_lh, zfs_li);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   170
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   171
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   172
	if (error)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
		vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   174
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   175
	return (error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   176
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   177
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   178
static int
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   179
vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   180
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   181
	vdev_disk_t *dvd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   182
	struct dk_minfo dkm;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   183
	int error;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   184
	dev_t dev;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   185
	int otyp;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   186
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   187
	error = vdev_disk_open_common(vd);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   188
	if (error)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   191
	dvd = vd->vdev_tsd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   193
	 * Once a device is opened, verify that the physical device path (if
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   194
	 * available) is up to date.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   195
	 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   196
	if (ldi_get_dev(dvd->vd_lh, &dev) == 0 &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   197
	    ldi_get_otyp(dvd->vd_lh, &otyp) == 0) {
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   198
		char *physpath, *minorname;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   199
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   200
		physpath = kmem_alloc(MAXPATHLEN, KM_SLEEP);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   201
		minorname = NULL;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   202
		if (ddi_dev_pathname(dev, otyp, physpath) == 0 &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   203
		    ldi_get_minor_name(dvd->vd_lh, &minorname) == 0 &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   204
		    (vd->vdev_physpath == NULL ||
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   205
		    strcmp(vd->vdev_physpath, physpath) != 0)) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   206
			if (vd->vdev_physpath)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   207
				spa_strfree(vd->vdev_physpath);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   208
			(void) strlcat(physpath, ":", MAXPATHLEN);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   209
			(void) strlcat(physpath, minorname, MAXPATHLEN);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   210
			vd->vdev_physpath = spa_strdup(physpath);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   211
		}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   212
		if (minorname)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   213
			kmem_free(minorname, strlen(minorname) + 1);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   214
		kmem_free(physpath, MAXPATHLEN);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   215
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   216
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   217
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
	 * Determine the actual size of the device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
	if (ldi_get_size(dvd->vd_lh, psize) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
		vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   225
	/*
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   226
	 * If we own the whole disk, try to enable disk write caching.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   227
	 * We ignore errors because it's OK if we can't do it.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   228
	 */
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
   229
	if (vd->vdev_wholedisk == 1) {
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   230
		int wce = 1;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   231
		(void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce,
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   232
		    FKIOCTL, kcred, NULL);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   233
	}
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
   234
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   235
	/*
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   236
	 * Determine the device's minimum transfer size.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   237
	 * If the ioctl isn't supported, assume DEV_BSIZE.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   238
	 */
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   239
	if (ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFO, (intptr_t)&dkm,
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   240
	    FKIOCTL, kcred, NULL) != 0)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   241
		dkm.dki_lbsize = DEV_BSIZE;
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
   242
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   243
	*ashift = highbit(MAX(dkm.dki_lbsize, SPA_MINBLOCKSIZE)) - 1;
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
   244
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   245
	/*
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   246
	 * Clear the nowritecache bit, so that on a vdev_reopen() we will
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   247
	 * try again.
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   248
	 */
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   249
	vd->vdev_nowritecache = B_FALSE;
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   250
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
vdev_disk_close(vdev_t *vd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
	vdev_disk_t *dvd = vd->vdev_tsd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
	if (dvd == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	if (dvd->vd_minor != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
		ddi_devid_str_free(dvd->vd_minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
	if (dvd->vd_devid != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
		ddi_devid_free(dvd->vd_devid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
	if (dvd->vd_lh != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
		(void) ldi_close(dvd->vd_lh, spa_mode, kcred);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
	kmem_free(dvd, sizeof (vdev_disk_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	vd->vdev_tsd = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   275
int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   276
vdev_disk_physio(ldi_handle_t vd_lh, caddr_t data, size_t size,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   277
    uint64_t offset, int flags)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   278
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   279
	buf_t *bp;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   280
	int error = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   281
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   282
	if (vd_lh == NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   283
		return (EINVAL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   284
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   285
	ASSERT(flags & B_READ || flags & B_WRITE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   286
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   287
	bp = getrbuf(KM_SLEEP);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   288
	bp->b_flags = flags | B_BUSY | B_NOCACHE | B_FAILFAST;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   289
	bp->b_bcount = size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   290
	bp->b_un.b_addr = (void *)data;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   291
	bp->b_lblkno = lbtodb(offset);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   292
	bp->b_bufsize = size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   293
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   294
	error = ldi_strategy(vd_lh, bp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   295
	ASSERT(error == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   296
	if ((error = biowait(bp)) == 0 && bp->b_resid != 0)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   297
		error = EIO;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   298
	freerbuf(bp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   299
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   300
	return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   301
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   302
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   303
static int
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   304
vdev_disk_probe_io(vdev_t *vd, caddr_t data, size_t size, uint64_t offset,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   305
    int flags)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   306
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   307
	int error = 0;
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6423
diff changeset
   308
	vdev_disk_t *dvd = vd ? vd->vdev_tsd : NULL;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   309
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   310
	if (vd == NULL || dvd == NULL || dvd->vd_lh == NULL)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   311
		return (EINVAL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   312
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   313
	error = vdev_disk_physio(dvd->vd_lh, data, size, offset, flags);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   314
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   315
	if (zio_injection_enabled && error == 0)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   316
		error = zio_handle_device_injection(vd, EIO);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   317
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   318
	return (error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   319
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   320
5369
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5329
diff changeset
   321
/*
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5329
diff changeset
   322
 * Determine if the underlying device is accessible by reading and writing
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5329
diff changeset
   323
 * to a known location. We must be able to do this during syncing context
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5329
diff changeset
   324
 * and thus we cannot set the vdev state directly.
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5329
diff changeset
   325
 */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   326
static int
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   327
vdev_disk_probe(vdev_t *vd)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   328
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   329
	uint64_t offset;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   330
	vdev_t *nvd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   331
	int l, error = 0, retries = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   332
	char *vl_pad;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   333
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   334
	if (vd == NULL)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   335
		return (EINVAL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   336
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   337
	/* Hijack the current vdev */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   338
	nvd = vd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   339
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   340
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   341
	 * Pick a random label to rewrite.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   342
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   343
	l = spa_get_random(VDEV_LABELS);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   344
	ASSERT(l < VDEV_LABELS);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   345
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   346
	offset = vdev_label_offset(vd->vdev_psize, l,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   347
	    offsetof(vdev_label_t, vl_pad));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   348
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   349
	vl_pad = kmem_alloc(VDEV_SKIP_SIZE, KM_SLEEP);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   350
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   351
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   352
	 * Try to read and write to a special location on the
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   353
	 * label. We use the existing vdev initially and only
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   354
	 * try to create and reopen it if we encounter a failure.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   355
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   356
	while ((error = vdev_disk_probe_io(nvd, vl_pad, VDEV_SKIP_SIZE,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   357
	    offset, B_READ)) != 0 && retries == 0) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   358
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   359
		nvd = kmem_zalloc(sizeof (vdev_t), KM_SLEEP);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   360
		if (vd->vdev_path)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   361
			nvd->vdev_path = spa_strdup(vd->vdev_path);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   362
		if (vd->vdev_physpath)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   363
			nvd->vdev_physpath = spa_strdup(vd->vdev_physpath);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   364
		if (vd->vdev_devid)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   365
			nvd->vdev_devid = spa_strdup(vd->vdev_devid);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   366
		nvd->vdev_wholedisk = vd->vdev_wholedisk;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   367
		nvd->vdev_guid = vd->vdev_guid;
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   368
		nvd->vdev_spa = vd->vdev_spa;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   369
		retries++;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   370
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   371
		error = vdev_disk_open_common(nvd);
5369
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5329
diff changeset
   372
		if (error)
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   373
			break;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   374
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   375
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   376
	if (!error) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   377
		error = vdev_disk_probe_io(nvd, vl_pad, VDEV_SKIP_SIZE,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   378
		    offset, B_WRITE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   379
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   380
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   381
	/* Clean up if we allocated a new vdev */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   382
	if (retries) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   383
		vdev_disk_close(nvd);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   384
		if (nvd->vdev_path)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   385
			spa_strfree(nvd->vdev_path);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   386
		if (nvd->vdev_physpath)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   387
			spa_strfree(nvd->vdev_physpath);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   388
		if (nvd->vdev_devid)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   389
			spa_strfree(nvd->vdev_devid);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   390
		kmem_free(nvd, sizeof (vdev_t));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   391
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   392
	kmem_free(vl_pad, VDEV_SKIP_SIZE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   393
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   394
	/* Reset the failing flag */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   395
	if (!error)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   396
		vd->vdev_is_failing = B_FALSE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   397
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   398
	return (error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   399
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   400
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
vdev_disk_io_intr(buf_t *bp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
	vdev_disk_buf_t *vdb = (vdev_disk_buf_t *)bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
	zio_t *zio = vdb->vdb_io;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
6976
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   407
	/*
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   408
	 * The rest of the zio stack only deals with EIO, ECKSUM, and ENXIO.
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   409
	 * Rather than teach the rest of the stack about other error
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   410
	 * possibilities (EFAULT, etc), we normalize the error value here.
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   411
	 */
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   412
	zio->io_error = (geterror(bp) != 0 ? EIO : 0);
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   413
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   414
	if (zio->io_error == 0 && bp->b_resid != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
		zio->io_error = EIO;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
	kmem_free(vdb, sizeof (vdev_disk_buf_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   419
	zio_interrupt(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
vdev_disk_ioctl_done(void *zio_arg, int error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
	zio_t *zio = zio_arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	zio->io_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   429
	zio_interrupt(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   432
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
vdev_disk_io_start(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
	vdev_disk_t *dvd = vd->vdev_tsd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
	vdev_disk_buf_t *vdb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
	buf_t *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
	int flags, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	if (zio->io_type == ZIO_TYPE_IOCTL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
		zio_vdev_io_bypass(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
		/* XXPOLICY */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   445
		if (!vdev_readable(vd)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
			zio->io_error = ENXIO;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   447
			return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
		switch (zio->io_cmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
		case DKIOCFLUSHWRITECACHE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 1773
diff changeset
   454
			if (zfs_nocacheflush)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 1773
diff changeset
   455
				break;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 1773
diff changeset
   456
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   457
			if (vd->vdev_nowritecache) {
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   458
				zio->io_error = ENOTSUP;
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   459
				break;
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   460
			}
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   461
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
			zio->io_dk_callback.dkc_callback = vdev_disk_ioctl_done;
5065
fcf530c3356e PSARC 2007/053 Per-Disk-Device support of non-volatile cache
gz161490
parents: 4455
diff changeset
   463
			zio->io_dk_callback.dkc_flag = FLUSH_VOLATILE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
			zio->io_dk_callback.dkc_cookie = zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
			error = ldi_ioctl(dvd->vd_lh, zio->io_cmd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
			    (uintptr_t)&zio->io_dk_callback,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
			    FKIOCTL, kcred, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
			if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
				/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
				 * The ioctl will be done asychronously,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
				 * and will call vdev_disk_ioctl_done()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
				 * upon completion.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
				 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   476
				return (ZIO_PIPELINE_STOP);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   477
			}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   478
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   479
			if (error == ENOTSUP || error == ENOTTY) {
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   480
				/*
4455
122ee9c0f54c 6456223 system hang after test suite run on usb disk
mishra
parents: 4451
diff changeset
   481
				 * If we get ENOTSUP or ENOTTY, we know that
122ee9c0f54c 6456223 system hang after test suite run on usb disk
mishra
parents: 4451
diff changeset
   482
				 * no future attempts will ever succeed.
122ee9c0f54c 6456223 system hang after test suite run on usb disk
mishra
parents: 4451
diff changeset
   483
				 * In this case we set a persistent bit so
122ee9c0f54c 6456223 system hang after test suite run on usb disk
mishra
parents: 4451
diff changeset
   484
				 * that we don't bother with the ioctl in the
122ee9c0f54c 6456223 system hang after test suite run on usb disk
mishra
parents: 4451
diff changeset
   485
				 * future.
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   486
				 */
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   487
				vd->vdev_nowritecache = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
			zio->io_error = error;
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   490
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
			zio->io_error = ENOTSUP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   497
		return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	if (zio->io_type == ZIO_TYPE_READ && vdev_cache_read(zio) == 0)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   501
		return (ZIO_PIPELINE_STOP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	if ((zio = vdev_queue_io(zio)) == NULL)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   504
		return (ZIO_PIPELINE_STOP);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   505
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   506
	if (zio->io_type == ZIO_TYPE_WRITE)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   507
		error = vdev_writeable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   508
	else
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   509
		error = vdev_readable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   510
	error = (vd->vdev_remove_wanted || vd->vdev_is_failing) ? ENXIO : error;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   511
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   512
	if (error) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   513
		zio->io_error = error;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   514
		zio_interrupt(zio);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   515
		return (ZIO_PIPELINE_STOP);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   516
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
	flags = (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
	flags |= B_BUSY | B_NOCACHE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
	if (zio->io_flags & ZIO_FLAG_FAILFAST)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
		flags |= B_FAILFAST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
	vdb = kmem_alloc(sizeof (vdev_disk_buf_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
	vdb->vdb_io = zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
	bp = &vdb->vdb_buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	bioinit(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
	bp->b_flags = flags;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	bp->b_bcount = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	bp->b_un.b_addr = zio->io_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
	bp->b_lblkno = lbtodb(zio->io_offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
	bp->b_bufsize = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	bp->b_iodone = (int (*)())vdev_disk_io_intr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
	error = ldi_strategy(dvd->vd_lh, bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
	/* ldi_strategy() will return non-zero only on programming errors */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	ASSERT(error == 0);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   539
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   540
	return (ZIO_PIPELINE_STOP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   543
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
vdev_disk_io_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
	vdev_queue_io_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
	if (zio->io_type == ZIO_TYPE_WRITE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
		vdev_cache_write(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1489
diff changeset
   551
	if (zio_injection_enabled && zio->io_error == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1489
diff changeset
   552
		zio->io_error = zio_handle_device_injection(zio->io_vd, EIO);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1489
diff changeset
   553
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   554
	/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   555
	 * If the device returned EIO, then attempt a DKIOCSTATE ioctl to see if
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   556
	 * the device has been removed.  If this is the case, then we trigger an
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   557
	 * asynchronous removal of the device. Otherwise, probe the device and
5369
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5329
diff changeset
   558
	 * make sure it's still accessible.
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   559
	 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   560
	if (zio->io_error == EIO) {
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   561
		vdev_t *vd = zio->io_vd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   562
		vdev_disk_t *dvd = vd->vdev_tsd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   563
		int state;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   564
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   565
		state = DKIO_NONE;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   566
		if (dvd && ldi_ioctl(dvd->vd_lh, DKIOCSTATE, (intptr_t)&state,
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   567
		    FKIOCTL, kcred, NULL) == 0 &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   568
		    state != DKIO_INSERTED) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   569
			vd->vdev_remove_wanted = B_TRUE;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   570
			spa_async_request(zio->io_spa, SPA_ASYNC_REMOVE);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   571
		} else if (vdev_probe(vd) != 0) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   572
			ASSERT(vd->vdev_ops->vdev_op_leaf);
6976
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   573
			if (!vd->vdev_is_failing) {
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   574
				vd->vdev_is_failing = B_TRUE;
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   575
				zfs_ereport_post(FM_EREPORT_ZFS_PROBE_FAILURE,
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   576
				    vd->vdev_spa, vd, zio, 0, 0);
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   577
			}
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   578
		}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   579
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   580
6615
333cfc13ec55 6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents: 6523
diff changeset
   581
	if (zio_injection_enabled && zio->io_error == 0)
333cfc13ec55 6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents: 6523
diff changeset
   582
		zio->io_error = zio_handle_label_injection(zio, EIO);
333cfc13ec55 6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents: 6523
diff changeset
   583
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   584
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
vdev_ops_t vdev_disk_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
	vdev_disk_open,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
	vdev_disk_close,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   590
	vdev_disk_probe,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
	vdev_default_asize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
	vdev_disk_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	vdev_disk_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
	NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
	VDEV_TYPE_DISK,		/* name of this vdev type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
	B_TRUE			/* leaf vdev */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
};
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   598
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   599
/*
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   600
 * Given the root disk device devid or pathname, read the label from
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   601
 * the device, and construct a configuration nvlist.
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   602
 */
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   603
int
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   604
vdev_disk_read_rootlabel(char *devpath, char *devid, nvlist_t **config)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   605
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   606
	ldi_handle_t vd_lh;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   607
	vdev_label_t *label;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   608
	uint64_t s, size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   609
	int l;
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   610
	ddi_devid_t tmpdevid;
7687
1132fbaf0c27 6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents: 7553
diff changeset
   611
	int error = -1;
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   612
	char *minor_name;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   613
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   614
	/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   615
	 * Read the device label and build the nvlist.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   616
	 */
7687
1132fbaf0c27 6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents: 7553
diff changeset
   617
	if (devid != NULL && ddi_devid_str_decode(devid, &tmpdevid,
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   618
	    &minor_name) == 0) {
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   619
		error = ldi_open_by_devid(tmpdevid, minor_name,
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   620
		    spa_mode, kcred, &vd_lh, zfs_li);
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   621
		ddi_devid_free(tmpdevid);
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   622
		ddi_devid_str_free(minor_name);
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   623
	}
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   624
7687
1132fbaf0c27 6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents: 7553
diff changeset
   625
	if (error && (error = ldi_open_by_name(devpath, FREAD, kcred, &vd_lh,
1132fbaf0c27 6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents: 7553
diff changeset
   626
	    zfs_li)))
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   627
		return (error);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   628
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   629
	if (ldi_get_size(vd_lh, &s)) {
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   630
		(void) ldi_close(vd_lh, FREAD, kcred);
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   631
		return (EIO);
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   632
	}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   633
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   634
	size = P2ALIGN_TYPED(s, sizeof (vdev_label_t), uint64_t);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   635
	label = kmem_alloc(sizeof (vdev_label_t), KM_SLEEP);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   636
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   637
	for (l = 0; l < VDEV_LABELS; l++) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   638
		uint64_t offset, state, txg = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   639
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   640
		/* read vdev label */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   641
		offset = vdev_label_offset(size, l, 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   642
		if (vdev_disk_physio(vd_lh, (caddr_t)label,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   643
		    VDEV_SKIP_SIZE + VDEV_BOOT_HEADER_SIZE +
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   644
		    VDEV_PHYS_SIZE, offset, B_READ) != 0)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   645
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   646
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   647
		if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   648
		    sizeof (label->vl_vdev_phys.vp_nvlist), config, 0) != 0) {
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   649
			*config = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   650
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   651
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   652
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   653
		if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   654
		    &state) != 0 || state >= POOL_STATE_DESTROYED) {
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   655
			nvlist_free(*config);
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   656
			*config = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   657
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   658
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   659
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   660
		if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   661
		    &txg) != 0 || txg == 0) {
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   662
			nvlist_free(*config);
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   663
			*config = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   664
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   665
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   666
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   667
		break;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   668
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   669
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   670
	kmem_free(label, sizeof (vdev_label_t));
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   671
	(void) ldi_close(vd_lh, FREAD, kcred);
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   672
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   673
	return (error);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   674
}