usr/src/uts/common/fs/zfs/vdev_disk.c
author Jonathan Adams <Jonathan.Adams@Sun.COM>
Tue, 22 Sep 2009 17:11:54 -0700
changeset 10614 4f397871da47
parent 10575 2a8816c5173b
child 10850 bb29ac73664d
permissions -rw-r--r--
PSARC 2009/497 zfs checksum ereport payload additions 6867188 zfs checksum ereports could be more informative
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
/*
8876
59d2e67b4b65 6803822 Reboot after replacement of system disk in a ZFS mirror drops to grub> prompt
Lin Ling <Lin.Ling@Sun.COM>
parents: 8269
diff changeset
    22
 * Copyright 2009 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
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
    48
vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
{
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
    50
	spa_t *spa = vd->vdev_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
	vdev_disk_t *dvd;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
    52
	struct dk_minfo dkm;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
    53
	int error;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
    54
	dev_t dev;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
    55
	int otyp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
	 * We must have a pathname, and it must be absolute.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
	if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
		return (EINVAL);
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
	dvd = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_disk_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
	 * When opening a disk device, we want to preserve the user's original
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	 * intent.  We always want to open the device by the path the user gave
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
	 * us, even if it is one of multiple paths to the save device.  But we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
	 * also want to be able to survive disks being removed/recabled.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
	 * Therefore the sequence of opening devices is:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
	 *
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
    74
	 * 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
    75
	 *    'whole_disk' property, attempt to fix the path by appending 's0'.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	 * 2. If the devid of the device matches the stored value, return
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	 *    success.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
	 * 3. Otherwise, the device may have moved.  Try opening the device
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
	 *    by the devid instead.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
	 *
9988
4066d8f807e9 6852962 zpool attach on root pool in a guest LDOM fails with cannot attach new device must be a single disk
George Wilson <George.Wilson@Sun.COM>
parents: 9725
diff changeset
    83
	 * If the vdev is part of the root pool, we avoid opening it by path
4066d8f807e9 6852962 zpool attach on root pool in a guest LDOM fails with cannot attach new device must be a single disk
George Wilson <George.Wilson@Sun.COM>
parents: 9725
diff changeset
    84
	 * unless we're adding (i.e. attaching) it to the vdev namespace.
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
    85
	 * 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
    86
	 * 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
    87
	 * 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
    88
	 * file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	if (vd->vdev_devid != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
		if (ddi_devid_str_decode(vd->vdev_devid, &dvd->vd_devid,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
		    &dvd->vd_minor) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
			vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
			return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	error = EINVAL;		/* presume failure */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
9988
4066d8f807e9 6852962 zpool attach on root pool in a guest LDOM fails with cannot attach new device must be a single disk
George Wilson <George.Wilson@Sun.COM>
parents: 9725
diff changeset
   100
	if (vd->vdev_path != NULL && (!spa_is_root(spa) ||
4066d8f807e9 6852962 zpool attach on root pool in a guest LDOM fails with cannot attach new device must be a single disk
George Wilson <George.Wilson@Sun.COM>
parents: 9725
diff changeset
   101
	    spa_lookup_by_guid(spa, vd->vdev_guid, B_FALSE) == NULL)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
		ddi_devid_t devid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   104
		if (vd->vdev_wholedisk == -1ULL) {
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   105
			size_t len = strlen(vd->vdev_path) + 3;
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   106
			char *buf = kmem_alloc(len, KM_SLEEP);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   107
			ldi_handle_t lh;
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   108
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   109
			(void) snprintf(buf, len, "%ss0", vd->vdev_path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   111
			if (ldi_open_by_name(buf, spa_mode(spa), kcred,
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   112
			    &lh, zfs_li) == 0) {
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   113
				spa_strfree(vd->vdev_path);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   114
				vd->vdev_path = buf;
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   115
				vd->vdev_wholedisk = 1ULL;
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   116
				(void) ldi_close(lh, spa_mode(spa), kcred);
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   117
			} else {
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   118
				kmem_free(buf, len);
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   119
			}
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   120
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   122
		error = ldi_open_by_name(vd->vdev_path, spa_mode(spa), kcred,
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   123
		    &dvd->vd_lh, zfs_li);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
		 * Compare the devid to the stored value.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
		if (error == 0 && vd->vdev_devid != NULL &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
		    ldi_get_devid(dvd->vd_lh, &devid) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
			if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
				error = EINVAL;
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   132
				(void) ldi_close(dvd->vd_lh, spa_mode(spa),
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   133
				    kcred);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
				dvd->vd_lh = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
			ddi_devid_free(devid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
		}
1171
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   138
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   139
		/*
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   140
		 * If we succeeded in opening the device, but 'vdev_wholedisk'
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   141
		 * is not yet set, then this must be a slice.
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   142
		 */
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   143
		if (error == 0 && vd->vdev_wholedisk == -1ULL)
b501e9f31cab 6344272 re-think how whole disks are stored
eschrock
parents: 789
diff changeset
   144
			vd->vdev_wholedisk = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
	 * If we were unable to open by path, or the devid check fails, open by
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
	 * devid instead.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
	if (error != 0 && vd->vdev_devid != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
		error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor,
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   153
		    spa_mode(spa), kcred, &dvd->vd_lh, zfs_li);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   155
	/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   156
	 * If all else fails, then try opening by physical path (if available)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   157
	 * 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
   158
	 * as reliable as the devid, this will give us something, and the higher
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   159
	 * level vdev validation will prevent us from opening the wrong device.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   160
	 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   161
	if (error) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   162
		if (vd->vdev_physpath != NULL &&
8269
03a7e9050cfd 6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
   163
		    (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != NODEV)
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   164
			error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode(spa),
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   165
			    kcred, &dvd->vd_lh, zfs_li);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   166
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   167
		/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   168
		 * Note that we don't support the legacy auto-wholedisk support
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   169
		 * 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
   170
		 * don't need to propagate its oddities to this edge condition.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   171
		 */
9988
4066d8f807e9 6852962 zpool attach on root pool in a guest LDOM fails with cannot attach new device must be a single disk
George Wilson <George.Wilson@Sun.COM>
parents: 9725
diff changeset
   172
		if (error && vd->vdev_path != NULL && (!spa_is_root(spa) ||
4066d8f807e9 6852962 zpool attach on root pool in a guest LDOM fails with cannot attach new device must be a single disk
George Wilson <George.Wilson@Sun.COM>
parents: 9725
diff changeset
   173
		    spa_lookup_by_guid(spa, vd->vdev_guid, B_FALSE) == NULL))
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   174
			error = ldi_open_by_name(vd->vdev_path, spa_mode(spa),
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   175
			    kcred, &dvd->vd_lh, zfs_li);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   176
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   177
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   178
	if (error) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
		vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   180
		return (error);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   181
	}
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   182
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
	/*
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   184
	 * Once a device is opened, verify that the physical device path (if
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   185
	 * available) is up to date.
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   186
	 */
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   187
	if (ldi_get_dev(dvd->vd_lh, &dev) == 0 &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   188
	    ldi_get_otyp(dvd->vd_lh, &otyp) == 0) {
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   189
		char *physpath, *minorname;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   190
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   191
		physpath = kmem_alloc(MAXPATHLEN, KM_SLEEP);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   192
		minorname = NULL;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   193
		if (ddi_dev_pathname(dev, otyp, physpath) == 0 &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   194
		    ldi_get_minor_name(dvd->vd_lh, &minorname) == 0 &&
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   195
		    (vd->vdev_physpath == NULL ||
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   196
		    strcmp(vd->vdev_physpath, physpath) != 0)) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   197
			if (vd->vdev_physpath)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   198
				spa_strfree(vd->vdev_physpath);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   199
			(void) strlcat(physpath, ":", MAXPATHLEN);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   200
			(void) strlcat(physpath, minorname, MAXPATHLEN);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   201
			vd->vdev_physpath = spa_strdup(physpath);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   202
		}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   203
		if (minorname)
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   204
			kmem_free(minorname, strlen(minorname) + 1);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   205
		kmem_free(physpath, MAXPATHLEN);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   206
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   207
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   208
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
	 * Determine the actual size of the device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
	if (ldi_get_size(dvd->vd_lh, psize) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
		vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   216
	/*
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   217
	 * If we own the whole disk, try to enable disk write caching.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   218
	 * We ignore errors because it's OK if we can't do it.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   219
	 */
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
   220
	if (vd->vdev_wholedisk == 1) {
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   221
		int wce = 1;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   222
		(void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce,
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   223
		    FKIOCTL, kcred, NULL);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   224
	}
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
   225
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   226
	/*
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   227
	 * Determine the device's minimum transfer size.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   228
	 * If the ioctl isn't supported, assume DEV_BSIZE.
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   229
	 */
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   230
	if (ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFO, (intptr_t)&dkm,
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   231
	    FKIOCTL, kcred, NULL) != 0)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   232
		dkm.dki_lbsize = DEV_BSIZE;
1489
fa842259660e 6322205 Enable disk write cache if ZFS owns the disk
webaker
parents: 1171
diff changeset
   233
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   234
	*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
   235
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   236
	/*
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   237
	 * 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
   238
	 * try again.
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   239
	 */
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   240
	vd->vdev_nowritecache = B_FALSE;
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   241
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
vdev_disk_close(vdev_t *vd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
	vdev_disk_t *dvd = vd->vdev_tsd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	if (dvd == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	if (dvd->vd_minor != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
		ddi_devid_str_free(dvd->vd_minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
	if (dvd->vd_devid != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
		ddi_devid_free(dvd->vd_devid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
	if (dvd->vd_lh != NULL)
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   260
		(void) ldi_close(dvd->vd_lh, spa_mode(vd->vdev_spa), kcred);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	kmem_free(dvd, sizeof (vdev_disk_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
	vd->vdev_tsd = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   266
int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   267
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
   268
    uint64_t offset, int flags)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   269
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   270
	buf_t *bp;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   271
	int error = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   272
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   273
	if (vd_lh == NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   274
		return (EINVAL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   275
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   276
	ASSERT(flags & B_READ || flags & B_WRITE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   277
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   278
	bp = getrbuf(KM_SLEEP);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   279
	bp->b_flags = flags | B_BUSY | B_NOCACHE | B_FAILFAST;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   280
	bp->b_bcount = size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   281
	bp->b_un.b_addr = (void *)data;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   282
	bp->b_lblkno = lbtodb(offset);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   283
	bp->b_bufsize = size;
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
	error = ldi_strategy(vd_lh, bp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   286
	ASSERT(error == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   287
	if ((error = biowait(bp)) == 0 && bp->b_resid != 0)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   288
		error = EIO;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   289
	freerbuf(bp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   290
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   291
	return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   292
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   293
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
vdev_disk_io_intr(buf_t *bp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	vdev_disk_buf_t *vdb = (vdev_disk_buf_t *)bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	zio_t *zio = vdb->vdb_io;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
6976
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   300
	/*
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   301
	 * 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
   302
	 * 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
   303
	 * possibilities (EFAULT, etc), we normalize the error value here.
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   304
	 */
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   305
	zio->io_error = (geterror(bp) != 0 ? EIO : 0);
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   306
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6673
diff changeset
   307
	if (zio->io_error == 0 && bp->b_resid != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
		zio->io_error = EIO;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	kmem_free(vdb, sizeof (vdev_disk_buf_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   312
	zio_interrupt(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
static void
7762
067dd33ef32c 6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
   316
vdev_disk_ioctl_free(zio_t *zio)
067dd33ef32c 6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
   317
{
067dd33ef32c 6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
   318
	kmem_free(zio->io_vsd, sizeof (struct dk_callback));
067dd33ef32c 6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
   319
}
067dd33ef32c 6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
   320
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10575
diff changeset
   321
static const zio_vsd_ops_t vdev_disk_vsd_ops = {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10575
diff changeset
   322
	vdev_disk_ioctl_free,
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10575
diff changeset
   323
	zio_vsd_default_cksum_report
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10575
diff changeset
   324
};
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10575
diff changeset
   325
7762
067dd33ef32c 6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
   326
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
vdev_disk_ioctl_done(void *zio_arg, int error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
	zio_t *zio = zio_arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
	zio->io_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   333
	zio_interrupt(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   336
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
vdev_disk_io_start(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
	vdev_disk_t *dvd = vd->vdev_tsd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
	vdev_disk_buf_t *vdb;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   342
	struct dk_callback *dkc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
	buf_t *bp;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   344
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
	if (zio->io_type == ZIO_TYPE_IOCTL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
		/* XXPOLICY */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   348
		if (!vdev_readable(vd)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
			zio->io_error = ENXIO;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   350
			return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
		switch (zio->io_cmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
		case DKIOCFLUSHWRITECACHE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 1773
diff changeset
   357
			if (zfs_nocacheflush)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 1773
diff changeset
   358
				break;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 1773
diff changeset
   359
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   360
			if (vd->vdev_nowritecache) {
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   361
				zio->io_error = ENOTSUP;
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   362
				break;
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   363
			}
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   364
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   365
			zio->io_vsd = dkc = kmem_alloc(sizeof (*dkc), KM_SLEEP);
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10575
diff changeset
   366
			zio->io_vsd_ops = &vdev_disk_vsd_ops;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   367
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   368
			dkc->dkc_callback = vdev_disk_ioctl_done;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   369
			dkc->dkc_flag = FLUSH_VOLATILE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   370
			dkc->dkc_cookie = zio;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
			error = ldi_ioctl(dvd->vd_lh, zio->io_cmd,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   373
			    (uintptr_t)dkc, FKIOCTL, kcred, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
			if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
				/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
				 * The ioctl will be done asychronously,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
				 * and will call vdev_disk_ioctl_done()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
				 * upon completion.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
				 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   381
				return (ZIO_PIPELINE_STOP);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   382
			}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   383
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   384
			if (error == ENOTSUP || error == ENOTTY) {
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   385
				/*
4455
122ee9c0f54c 6456223 system hang after test suite run on usb disk
mishra
parents: 4451
diff changeset
   386
				 * 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
   387
				 * no future attempts will ever succeed.
122ee9c0f54c 6456223 system hang after test suite run on usb disk
mishra
parents: 4451
diff changeset
   388
				 * 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
   389
				 * 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
   390
				 * future.
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   391
				 */
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   392
				vd->vdev_nowritecache = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
			zio->io_error = error;
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1732
diff changeset
   395
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
			zio->io_error = ENOTSUP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   402
		return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
	vdb = kmem_alloc(sizeof (vdev_disk_buf_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
	vdb->vdb_io = zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
	bp = &vdb->vdb_buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
	bioinit(bp);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   411
	bp->b_flags = B_BUSY | B_NOCACHE |
9725
0bf7402e8022 6843014 ZFS B_FAILFAST handling is broken
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9616
diff changeset
   412
	    (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE);
0bf7402e8022 6843014 ZFS B_FAILFAST handling is broken
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9616
diff changeset
   413
	if (!(zio->io_flags & (ZIO_FLAG_IO_RETRY | ZIO_FLAG_TRYHARD)))
0bf7402e8022 6843014 ZFS B_FAILFAST handling is broken
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9616
diff changeset
   414
		bp->b_flags |= B_FAILFAST;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
	bp->b_bcount = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
	bp->b_un.b_addr = zio->io_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
	bp->b_lblkno = lbtodb(zio->io_offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
	bp->b_bufsize = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
	bp->b_iodone = (int (*)())vdev_disk_io_intr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
	/* ldi_strategy() will return non-zero only on programming errors */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   422
	VERIFY(ldi_strategy(dvd->vd_lh, bp) == 0);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   423
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5369
diff changeset
   424
	return (ZIO_PIPELINE_STOP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   427
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
vdev_disk_io_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   430
	vdev_t *vd = zio->io_vd;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1489
diff changeset
   431
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   432
	/*
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   433
	 * If the device returned EIO, then attempt a DKIOCSTATE ioctl to see if
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   434
	 * 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
   435
	 * 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
   436
	 * make sure it's still accessible.
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   437
	 */
10575
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   438
	if (zio->io_error == EIO && !vd->vdev_remove_wanted) {
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   439
		vdev_disk_t *dvd = vd->vdev_tsd;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   440
		int state = DKIO_NONE;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5065
diff changeset
   441
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   442
		if (ldi_ioctl(dvd->vd_lh, DKIOCSTATE, (intptr_t)&state,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7687
diff changeset
   443
		    FKIOCTL, kcred, NULL) == 0 && state != DKIO_INSERTED) {
10575
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   444
			/*
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   445
			 * We post the resource as soon as possible, instead of
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   446
			 * when the async removal actually happens, because the
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   447
			 * DE is using this information to discard previous I/O
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   448
			 * errors.
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   449
			 */
2a8816c5173b 6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9988
diff changeset
   450
			zfs_post_remove(zio->io_spa, vd);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   451
			vd->vdev_remove_wanted = B_TRUE;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   452
			spa_async_request(zio->io_spa, SPA_ASYNC_REMOVE);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   453
		}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 2986
diff changeset
   454
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
vdev_ops_t vdev_disk_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	vdev_disk_open,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	vdev_disk_close,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	vdev_default_asize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	vdev_disk_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	vdev_disk_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
	NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	VDEV_TYPE_DISK,		/* name of this vdev type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
	B_TRUE			/* leaf vdev */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
};
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   467
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   468
/*
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   469
 * 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
   470
 * the device, and construct a configuration nvlist.
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   471
 */
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   472
int
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   473
vdev_disk_read_rootlabel(char *devpath, char *devid, nvlist_t **config)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   474
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   475
	ldi_handle_t vd_lh;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   476
	vdev_label_t *label;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   477
	uint64_t s, size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   478
	int l;
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   479
	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
   480
	int error = -1;
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   481
	char *minor_name;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   482
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   483
	/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   484
	 * Read the device label and build the nvlist.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   485
	 */
7687
1132fbaf0c27 6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents: 7553
diff changeset
   486
	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
   487
	    &minor_name) == 0) {
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   488
		error = ldi_open_by_devid(tmpdevid, minor_name,
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   489
		    FREAD, kcred, &vd_lh, zfs_li);
7147
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   490
		ddi_devid_free(tmpdevid);
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   491
		ddi_devid_str_free(minor_name);
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   492
	}
1e1d75c88283 6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents: 6976
diff changeset
   493
7687
1132fbaf0c27 6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents: 7553
diff changeset
   494
	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
   495
	    zfs_li)))
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   496
		return (error);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   497
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   498
	if (ldi_get_size(vd_lh, &s)) {
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   499
		(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
   500
		return (EIO);
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   501
	}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   502
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   503
	size = P2ALIGN_TYPED(s, sizeof (vdev_label_t), uint64_t);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   504
	label = kmem_alloc(sizeof (vdev_label_t), KM_SLEEP);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   505
9616
b12e6357efad 6820274 grub could do a better job of finding a menu.lst file
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8876
diff changeset
   506
	*config = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   507
	for (l = 0; l < VDEV_LABELS; l++) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   508
		uint64_t offset, state, txg = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   509
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   510
		/* read vdev label */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   511
		offset = vdev_label_offset(size, l, 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   512
		if (vdev_disk_physio(vd_lh, (caddr_t)label,
8876
59d2e67b4b65 6803822 Reboot after replacement of system disk in a ZFS mirror drops to grub> prompt
Lin Ling <Lin.Ling@Sun.COM>
parents: 8269
diff changeset
   513
		    VDEV_SKIP_SIZE + VDEV_PHYS_SIZE, offset, B_READ) != 0)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   514
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   515
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   516
		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
   517
		    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
   518
			*config = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   519
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   520
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   521
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   522
		if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   523
		    &state) != 0 || state >= POOL_STATE_DESTROYED) {
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   524
			nvlist_free(*config);
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   525
			*config = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   526
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   527
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   528
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   529
		if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   530
		    &txg) != 0 || txg == 0) {
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   531
			nvlist_free(*config);
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   532
			*config = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   533
			continue;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   534
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   535
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   536
		break;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   537
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   538
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   539
	kmem_free(label, sizeof (vdev_label_t));
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   540
	(void) ldi_close(vd_lh, FREAD, kcred);
9616
b12e6357efad 6820274 grub could do a better job of finding a menu.lst file
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8876
diff changeset
   541
	if (*config == NULL)
b12e6357efad 6820274 grub could do a better job of finding a menu.lst file
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8876
diff changeset
   542
		error = EIDRM;
6673
be079d6124af 6697301 deadlock between ZFS and devfs can hang system
eschrock
parents: 6615
diff changeset
   543
7539
e3f4b4b9f982 6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents: 7147
diff changeset
   544
	return (error);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5530
diff changeset
   545
}