author | Jeff Bonwick <Jeff.Bonwick@Sun.COM> |
Thu, 29 Apr 2010 13:37:53 -0700 | |
changeset 12285 | d736d62dcca2 |
parent 12247 | 5bcd281629f8 |
child 13570 | 3411fd5f1589 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
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 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
12208
008d9e6b6072
6931570 Add flash devices' VID/PID to disk table to advertising 4K physical sector size.
bo zhou - Sun Microsystems - Beijing China <Bo.Zhou@Sun.COM>
parents:
11958
diff
changeset
|
22 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
789 | 23 |
*/ |
24 |
||
25 |
#include <sys/zfs_context.h> |
|
11958
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
26 |
#include <sys/spa_impl.h> |
6423 | 27 |
#include <sys/refcount.h> |
789 | 28 |
#include <sys/vdev_disk.h> |
29 |
#include <sys/vdev_impl.h> |
|
30 |
#include <sys/fs/zfs.h> |
|
31 |
#include <sys/zio.h> |
|
1171 | 32 |
#include <sys/sunldi.h> |
6976
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6673
diff
changeset
|
33 |
#include <sys/fm/fs/zfs.h> |
789 | 34 |
|
35 |
/* |
|
36 |
* Virtual device vector for disks. |
|
37 |
*/ |
|
38 |
||
39 |
extern ldi_ident_t zfs_li; |
|
40 |
||
41 |
typedef struct vdev_disk_buf { |
|
42 |
buf_t vdb_buf; |
|
43 |
zio_t *vdb_io; |
|
44 |
} vdev_disk_buf_t; |
|
45 |
||
11958
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
46 |
static void |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
47 |
vdev_disk_hold(vdev_t *vd) |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
48 |
{ |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
49 |
ddi_devid_t devid; |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
50 |
char *minor; |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
51 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
52 |
ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER)); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
53 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
54 |
/* |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
55 |
* We must have a pathname, and it must be absolute. |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
56 |
*/ |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
57 |
if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
58 |
return; |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
59 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
60 |
/* |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
61 |
* Only prefetch path and devid info if the device has |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
62 |
* never been opened. |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
63 |
*/ |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
64 |
if (vd->vdev_tsd != NULL) |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
65 |
return; |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
66 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
67 |
if (vd->vdev_wholedisk == -1ULL) { |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
68 |
size_t len = strlen(vd->vdev_path) + 3; |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
69 |
char *buf = kmem_alloc(len, KM_SLEEP); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
70 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
71 |
(void) snprintf(buf, len, "%ss0", vd->vdev_path); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
72 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
73 |
(void) ldi_vp_from_name(buf, &vd->vdev_name_vp); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
74 |
kmem_free(buf, len); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
75 |
} |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
76 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
77 |
if (vd->vdev_name_vp == NULL) |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
78 |
(void) ldi_vp_from_name(vd->vdev_path, &vd->vdev_name_vp); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
79 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
80 |
if (vd->vdev_devid != NULL && |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
81 |
ddi_devid_str_decode(vd->vdev_devid, &devid, &minor) == 0) { |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
82 |
(void) ldi_vp_from_devid(devid, minor, &vd->vdev_devid_vp); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
83 |
ddi_devid_str_free(minor); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
84 |
ddi_devid_free(devid); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
85 |
} |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
86 |
} |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
87 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
88 |
static void |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
89 |
vdev_disk_rele(vdev_t *vd) |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
90 |
{ |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
91 |
ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER)); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
92 |
|
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
93 |
if (vd->vdev_name_vp) { |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
94 |
VN_RELE_ASYNC(vd->vdev_name_vp, |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
95 |
dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool)); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
96 |
vd->vdev_name_vp = NULL; |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
97 |
} |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
98 |
if (vd->vdev_devid_vp) { |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
99 |
VN_RELE_ASYNC(vd->vdev_devid_vp, |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
100 |
dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool)); |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
101 |
vd->vdev_devid_vp = NULL; |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
102 |
} |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
103 |
} |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
104 |
|
789 | 105 |
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
|
106 |
vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift) |
789 | 107 |
{ |
8241
5a60f16123ba
6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7762
diff
changeset
|
108 |
spa_t *spa = vd->vdev_spa; |
789 | 109 |
vdev_disk_t *dvd; |
12208
008d9e6b6072
6931570 Add flash devices' VID/PID to disk table to advertising 4K physical sector size.
bo zhou - Sun Microsystems - Beijing China <Bo.Zhou@Sun.COM>
parents:
11958
diff
changeset
|
110 |
struct dk_minfo_ext dkmext; |
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
|
111 |
int error; |
5329 | 112 |
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
|
113 |
int otyp; |
789 | 114 |
|
115 |
/* |
|
116 |
* We must have a pathname, and it must be absolute. |
|
117 |
*/ |
|
118 |
if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') { |
|
119 |
vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; |
|
120 |
return (EINVAL); |
|
121 |
} |
|
122 |
||
10850
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
123 |
/* |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
124 |
* Reopen the device if it's not currently open. Otherwise, |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
125 |
* just update the physical size of the device. |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
126 |
*/ |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
127 |
if (vd->vdev_tsd != NULL) { |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
128 |
ASSERT(vd->vdev_reopening); |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
129 |
dvd = vd->vdev_tsd; |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
130 |
goto skip_open; |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
131 |
} |
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
132 |
|
789 | 133 |
dvd = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_disk_t), KM_SLEEP); |
134 |
||
135 |
/* |
|
136 |
* When opening a disk device, we want to preserve the user's original |
|
137 |
* intent. We always want to open the device by the path the user gave |
|
138 |
* us, even if it is one of multiple paths to the save device. But we |
|
139 |
* also want to be able to survive disks being removed/recabled. |
|
140 |
* Therefore the sequence of opening devices is: |
|
141 |
* |
|
1171 | 142 |
* 1. Try opening the device by path. For legacy pools without the |
143 |
* 'whole_disk' property, attempt to fix the path by appending 's0'. |
|
789 | 144 |
* |
145 |
* 2. If the devid of the device matches the stored value, return |
|
146 |
* success. |
|
147 |
* |
|
148 |
* 3. Otherwise, the device may have moved. Try opening the device |
|
149 |
* by the devid instead. |
|
150 |
*/ |
|
151 |
if (vd->vdev_devid != NULL) { |
|
152 |
if (ddi_devid_str_decode(vd->vdev_devid, &dvd->vd_devid, |
|
153 |
&dvd->vd_minor) != 0) { |
|
154 |
vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; |
|
155 |
return (EINVAL); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
error = EINVAL; /* presume failure */ |
|
160 |
||
10850
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
161 |
if (vd->vdev_path != NULL) { |
789 | 162 |
ddi_devid_t devid; |
163 |
||
1171 | 164 |
if (vd->vdev_wholedisk == -1ULL) { |
165 |
size_t len = strlen(vd->vdev_path) + 3; |
|
166 |
char *buf = kmem_alloc(len, KM_SLEEP); |
|
167 |
ldi_handle_t lh; |
|
168 |
||
169 |
(void) snprintf(buf, len, "%ss0", vd->vdev_path); |
|
789 | 170 |
|
8241
5a60f16123ba
6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7762
diff
changeset
|
171 |
if (ldi_open_by_name(buf, spa_mode(spa), kcred, |
1171 | 172 |
&lh, zfs_li) == 0) { |
173 |
spa_strfree(vd->vdev_path); |
|
174 |
vd->vdev_path = buf; |
|
175 |
vd->vdev_wholedisk = 1ULL; |
|
8241
5a60f16123ba
6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7762
diff
changeset
|
176 |
(void) ldi_close(lh, spa_mode(spa), kcred); |
1171 | 177 |
} else { |
178 |
kmem_free(buf, len); |
|
179 |
} |
|
180 |
} |
|
789 | 181 |
|
8241
5a60f16123ba
6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7762
diff
changeset
|
182 |
error = ldi_open_by_name(vd->vdev_path, spa_mode(spa), kcred, |
1171 | 183 |
&dvd->vd_lh, zfs_li); |
789 | 184 |
|
185 |
/* |
|
186 |
* Compare the devid to the stored value. |
|
187 |
*/ |
|
188 |
if (error == 0 && vd->vdev_devid != NULL && |
|
189 |
ldi_get_devid(dvd->vd_lh, &devid) == 0) { |
|
190 |
if (ddi_devid_compare(devid, dvd->vd_devid) != 0) { |
|
191 |
error = EINVAL; |
|
8241
5a60f16123ba
6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7762
diff
changeset
|
192 |
(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
|
193 |
kcred); |
789 | 194 |
dvd->vd_lh = NULL; |
195 |
} |
|
196 |
ddi_devid_free(devid); |
|
197 |
} |
|
1171 | 198 |
|
199 |
/* |
|
200 |
* If we succeeded in opening the device, but 'vdev_wholedisk' |
|
201 |
* is not yet set, then this must be a slice. |
|
202 |
*/ |
|
203 |
if (error == 0 && vd->vdev_wholedisk == -1ULL) |
|
204 |
vd->vdev_wholedisk = 0; |
|
789 | 205 |
} |
206 |
||
207 |
/* |
|
208 |
* If we were unable to open by path, or the devid check fails, open by |
|
209 |
* devid instead. |
|
210 |
*/ |
|
211 |
if (error != 0 && vd->vdev_devid != NULL) |
|
212 |
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
|
213 |
spa_mode(spa), kcred, &dvd->vd_lh, zfs_li); |
789 | 214 |
|
4451 | 215 |
/* |
216 |
* If all else fails, then try opening by physical path (if available) |
|
217 |
* or the logical path (if we failed due to the devid check). While not |
|
218 |
* as reliable as the devid, this will give us something, and the higher |
|
219 |
* level vdev validation will prevent us from opening the wrong device. |
|
220 |
*/ |
|
221 |
if (error) { |
|
222 |
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
|
223 |
(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
|
224 |
error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode(spa), |
4451 | 225 |
kcred, &dvd->vd_lh, zfs_li); |
226 |
||
227 |
/* |
|
228 |
* Note that we don't support the legacy auto-wholedisk support |
|
229 |
* as above. This hasn't been used in a very long time and we |
|
230 |
* don't need to propagate its oddities to this edge condition. |
|
231 |
*/ |
|
10850
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
232 |
if (error && vd->vdev_path != NULL) |
8241
5a60f16123ba
6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7762
diff
changeset
|
233 |
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
|
234 |
kcred, &dvd->vd_lh, zfs_li); |
4451 | 235 |
} |
236 |
||
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
|
237 |
if (error) { |
789 | 238 |
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
|
239 |
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
|
240 |
} |
5329 | 241 |
|
789 | 242 |
/* |
4451 | 243 |
* Once a device is opened, verify that the physical device path (if |
244 |
* available) is up to date. |
|
245 |
*/ |
|
246 |
if (ldi_get_dev(dvd->vd_lh, &dev) == 0 && |
|
247 |
ldi_get_otyp(dvd->vd_lh, &otyp) == 0) { |
|
5329 | 248 |
char *physpath, *minorname; |
249 |
||
4451 | 250 |
physpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
251 |
minorname = NULL; |
|
252 |
if (ddi_dev_pathname(dev, otyp, physpath) == 0 && |
|
253 |
ldi_get_minor_name(dvd->vd_lh, &minorname) == 0 && |
|
254 |
(vd->vdev_physpath == NULL || |
|
255 |
strcmp(vd->vdev_physpath, physpath) != 0)) { |
|
256 |
if (vd->vdev_physpath) |
|
257 |
spa_strfree(vd->vdev_physpath); |
|
258 |
(void) strlcat(physpath, ":", MAXPATHLEN); |
|
259 |
(void) strlcat(physpath, minorname, MAXPATHLEN); |
|
260 |
vd->vdev_physpath = spa_strdup(physpath); |
|
261 |
} |
|
262 |
if (minorname) |
|
263 |
kmem_free(minorname, strlen(minorname) + 1); |
|
264 |
kmem_free(physpath, MAXPATHLEN); |
|
265 |
} |
|
266 |
||
10850
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
267 |
skip_open: |
4451 | 268 |
/* |
789 | 269 |
* Determine the actual size of the device. |
270 |
*/ |
|
271 |
if (ldi_get_size(dvd->vd_lh, psize) != 0) { |
|
272 |
vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; |
|
273 |
return (EINVAL); |
|
274 |
} |
|
275 |
||
1732 | 276 |
/* |
277 |
* If we own the whole disk, try to enable disk write caching. |
|
278 |
* We ignore errors because it's OK if we can't do it. |
|
279 |
*/ |
|
1489
fa842259660e
6322205 Enable disk write cache if ZFS owns the disk
webaker
parents:
1171
diff
changeset
|
280 |
if (vd->vdev_wholedisk == 1) { |
1732 | 281 |
int wce = 1; |
282 |
(void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce, |
|
283 |
FKIOCTL, kcred, NULL); |
|
284 |
} |
|
1489
fa842259660e
6322205 Enable disk write cache if ZFS owns the disk
webaker
parents:
1171
diff
changeset
|
285 |
|
1732 | 286 |
/* |
287 |
* Determine the device's minimum transfer size. |
|
288 |
* If the ioctl isn't supported, assume DEV_BSIZE. |
|
289 |
*/ |
|
12208
008d9e6b6072
6931570 Add flash devices' VID/PID to disk table to advertising 4K physical sector size.
bo zhou - Sun Microsystems - Beijing China <Bo.Zhou@Sun.COM>
parents:
11958
diff
changeset
|
290 |
if (ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFOEXT, (intptr_t)&dkmext, |
1732 | 291 |
FKIOCTL, kcred, NULL) != 0) |
12208
008d9e6b6072
6931570 Add flash devices' VID/PID to disk table to advertising 4K physical sector size.
bo zhou - Sun Microsystems - Beijing China <Bo.Zhou@Sun.COM>
parents:
11958
diff
changeset
|
292 |
dkmext.dki_pbsize = DEV_BSIZE; |
1489
fa842259660e
6322205 Enable disk write cache if ZFS owns the disk
webaker
parents:
1171
diff
changeset
|
293 |
|
12208
008d9e6b6072
6931570 Add flash devices' VID/PID to disk table to advertising 4K physical sector size.
bo zhou - Sun Microsystems - Beijing China <Bo.Zhou@Sun.COM>
parents:
11958
diff
changeset
|
294 |
*ashift = highbit(MAX(dkmext.dki_pbsize, SPA_MINBLOCKSIZE)) - 1; |
1489
fa842259660e
6322205 Enable disk write cache if ZFS owns the disk
webaker
parents:
1171
diff
changeset
|
295 |
|
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
296 |
/* |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
297 |
* 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
|
298 |
* try again. |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
299 |
*/ |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
300 |
vd->vdev_nowritecache = B_FALSE; |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
301 |
|
789 | 302 |
return (0); |
303 |
} |
|
304 |
||
305 |
static void |
|
306 |
vdev_disk_close(vdev_t *vd) |
|
307 |
{ |
|
308 |
vdev_disk_t *dvd = vd->vdev_tsd; |
|
309 |
||
10850
bb29ac73664d
6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents:
10614
diff
changeset
|
310 |
if (vd->vdev_reopening || dvd == NULL) |
789 | 311 |
return; |
312 |
||
313 |
if (dvd->vd_minor != NULL) |
|
314 |
ddi_devid_str_free(dvd->vd_minor); |
|
315 |
||
316 |
if (dvd->vd_devid != NULL) |
|
317 |
ddi_devid_free(dvd->vd_devid); |
|
318 |
||
319 |
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
|
320 |
(void) ldi_close(dvd->vd_lh, spa_mode(vd->vdev_spa), kcred); |
789 | 321 |
|
12247
5bcd281629f8
6911420 ZFS device removal detection should work with SCSAv3
George Wilson <George.Wilson@Sun.COM>
parents:
12208
diff
changeset
|
322 |
vd->vdev_delayed_close = B_FALSE; |
789 | 323 |
kmem_free(dvd, sizeof (vdev_disk_t)); |
324 |
vd->vdev_tsd = NULL; |
|
325 |
} |
|
326 |
||
6423 | 327 |
int |
328 |
vdev_disk_physio(ldi_handle_t vd_lh, caddr_t data, size_t size, |
|
329 |
uint64_t offset, int flags) |
|
330 |
{ |
|
331 |
buf_t *bp; |
|
332 |
int error = 0; |
|
333 |
||
334 |
if (vd_lh == NULL) |
|
335 |
return (EINVAL); |
|
336 |
||
337 |
ASSERT(flags & B_READ || flags & B_WRITE); |
|
338 |
||
339 |
bp = getrbuf(KM_SLEEP); |
|
340 |
bp->b_flags = flags | B_BUSY | B_NOCACHE | B_FAILFAST; |
|
341 |
bp->b_bcount = size; |
|
342 |
bp->b_un.b_addr = (void *)data; |
|
343 |
bp->b_lblkno = lbtodb(offset); |
|
344 |
bp->b_bufsize = size; |
|
345 |
||
346 |
error = ldi_strategy(vd_lh, bp); |
|
347 |
ASSERT(error == 0); |
|
348 |
if ((error = biowait(bp)) == 0 && bp->b_resid != 0) |
|
349 |
error = EIO; |
|
350 |
freerbuf(bp); |
|
351 |
||
352 |
return (error); |
|
353 |
} |
|
354 |
||
789 | 355 |
static void |
356 |
vdev_disk_io_intr(buf_t *bp) |
|
357 |
{ |
|
358 |
vdev_disk_buf_t *vdb = (vdev_disk_buf_t *)bp; |
|
359 |
zio_t *zio = vdb->vdb_io; |
|
360 |
||
6976
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6673
diff
changeset
|
361 |
/* |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6673
diff
changeset
|
362 |
* 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
|
363 |
* 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
|
364 |
* possibilities (EFAULT, etc), we normalize the error value here. |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6673
diff
changeset
|
365 |
*/ |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6673
diff
changeset
|
366 |
zio->io_error = (geterror(bp) != 0 ? EIO : 0); |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6673
diff
changeset
|
367 |
|
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6673
diff
changeset
|
368 |
if (zio->io_error == 0 && bp->b_resid != 0) |
789 | 369 |
zio->io_error = EIO; |
370 |
||
371 |
kmem_free(vdb, sizeof (vdev_disk_buf_t)); |
|
372 |
||
5530 | 373 |
zio_interrupt(zio); |
789 | 374 |
} |
375 |
||
376 |
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
|
377 |
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
|
378 |
{ |
067dd33ef32c
6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7754
diff
changeset
|
379 |
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
|
380 |
} |
067dd33ef32c
6754498 assertion failure in dbuf_leaf_sync() - and test coverage gap in ztest
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7754
diff
changeset
|
381 |
|
10614
4f397871da47
PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
10575
diff
changeset
|
382 |
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
|
383 |
vdev_disk_ioctl_free, |
4f397871da47
PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
10575
diff
changeset
|
384 |
zio_vsd_default_cksum_report |
4f397871da47
PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
10575
diff
changeset
|
385 |
}; |
4f397871da47
PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents:
10575
diff
changeset
|
386 |
|
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
|
387 |
static void |
789 | 388 |
vdev_disk_ioctl_done(void *zio_arg, int error) |
389 |
{ |
|
390 |
zio_t *zio = zio_arg; |
|
391 |
||
392 |
zio->io_error = error; |
|
393 |
||
5530 | 394 |
zio_interrupt(zio); |
789 | 395 |
} |
396 |
||
5530 | 397 |
static int |
789 | 398 |
vdev_disk_io_start(zio_t *zio) |
399 |
{ |
|
400 |
vdev_t *vd = zio->io_vd; |
|
401 |
vdev_disk_t *dvd = vd->vdev_tsd; |
|
402 |
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
|
403 |
struct dk_callback *dkc; |
789 | 404 |
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
|
405 |
int error; |
789 | 406 |
|
407 |
if (zio->io_type == ZIO_TYPE_IOCTL) { |
|
408 |
/* XXPOLICY */ |
|
5329 | 409 |
if (!vdev_readable(vd)) { |
789 | 410 |
zio->io_error = ENXIO; |
5530 | 411 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 412 |
} |
413 |
||
414 |
switch (zio->io_cmd) { |
|
415 |
||
416 |
case DKIOCFLUSHWRITECACHE: |
|
417 |
||
2885 | 418 |
if (zfs_nocacheflush) |
419 |
break; |
|
420 |
||
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
421 |
if (vd->vdev_nowritecache) { |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
422 |
zio->io_error = ENOTSUP; |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
423 |
break; |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
424 |
} |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
425 |
|
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
|
426 |
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
|
427 |
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
|
428 |
|
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7687
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
dkc->dkc_cookie = zio; |
789 | 432 |
|
433 |
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
|
434 |
(uintptr_t)dkc, FKIOCTL, kcred, NULL); |
789 | 435 |
|
436 |
if (error == 0) { |
|
437 |
/* |
|
438 |
* The ioctl will be done asychronously, |
|
439 |
* and will call vdev_disk_ioctl_done() |
|
440 |
* upon completion. |
|
441 |
*/ |
|
5530 | 442 |
return (ZIO_PIPELINE_STOP); |
443 |
} |
|
444 |
||
445 |
if (error == ENOTSUP || error == ENOTTY) { |
|
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
446 |
/* |
4455
122ee9c0f54c
6456223 system hang after test suite run on usb disk
mishra
parents:
4451
diff
changeset
|
447 |
* 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
|
448 |
* no future attempts will ever succeed. |
122ee9c0f54c
6456223 system hang after test suite run on usb disk
mishra
parents:
4451
diff
changeset
|
449 |
* 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
|
450 |
* 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
|
451 |
* future. |
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
452 |
*/ |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
453 |
vd->vdev_nowritecache = B_TRUE; |
789 | 454 |
} |
455 |
zio->io_error = error; |
|
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1732
diff
changeset
|
456 |
|
789 | 457 |
break; |
458 |
||
459 |
default: |
|
460 |
zio->io_error = ENOTSUP; |
|
461 |
} |
|
462 |
||
5530 | 463 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 464 |
} |
465 |
||
466 |
vdb = kmem_alloc(sizeof (vdev_disk_buf_t), KM_SLEEP); |
|
467 |
||
468 |
vdb->vdb_io = zio; |
|
469 |
bp = &vdb->vdb_buf; |
|
470 |
||
471 |
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
|
472 |
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
|
473 |
(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
|
474 |
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
|
475 |
bp->b_flags |= B_FAILFAST; |
789 | 476 |
bp->b_bcount = zio->io_size; |
477 |
bp->b_un.b_addr = zio->io_data; |
|
478 |
bp->b_lblkno = lbtodb(zio->io_offset); |
|
479 |
bp->b_bufsize = zio->io_size; |
|
480 |
bp->b_iodone = (int (*)())vdev_disk_io_intr; |
|
481 |
||
482 |
/* 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
|
483 |
VERIFY(ldi_strategy(dvd->vd_lh, bp) == 0); |
5530 | 484 |
|
485 |
return (ZIO_PIPELINE_STOP); |
|
789 | 486 |
} |
487 |
||
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
|
488 |
static void |
789 | 489 |
vdev_disk_io_done(zio_t *zio) |
490 |
{ |
|
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
|
491 |
vdev_t *vd = zio->io_vd; |
1544 | 492 |
|
4451 | 493 |
/* |
494 |
* If the device returned EIO, then attempt a DKIOCSTATE ioctl to see if |
|
495 |
* the device has been removed. If this is the case, then we trigger an |
|
5329 | 496 |
* 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
|
497 |
* make sure it's still accessible. |
4451 | 498 |
*/ |
10575
2a8816c5173b
6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
9988
diff
changeset
|
499 |
if (zio->io_error == EIO && !vd->vdev_remove_wanted) { |
5329 | 500 |
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
|
501 |
int state = DKIO_NONE; |
5329 | 502 |
|
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
|
503 |
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
|
504 |
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
|
505 |
/* |
2a8816c5173b
6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
9988
diff
changeset
|
506 |
* 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
|
507 |
* 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
|
508 |
* 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
|
509 |
* errors. |
2a8816c5173b
6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
9988
diff
changeset
|
510 |
*/ |
2a8816c5173b
6882196 resource.* events shouldn't be posted during spa_tryimport()
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
9988
diff
changeset
|
511 |
zfs_post_remove(zio->io_spa, vd); |
4451 | 512 |
vd->vdev_remove_wanted = B_TRUE; |
513 |
spa_async_request(zio->io_spa, SPA_ASYNC_REMOVE); |
|
12247
5bcd281629f8
6911420 ZFS device removal detection should work with SCSAv3
George Wilson <George.Wilson@Sun.COM>
parents:
12208
diff
changeset
|
514 |
} else if (!vd->vdev_delayed_close) { |
5bcd281629f8
6911420 ZFS device removal detection should work with SCSAv3
George Wilson <George.Wilson@Sun.COM>
parents:
12208
diff
changeset
|
515 |
vd->vdev_delayed_close = B_TRUE; |
4451 | 516 |
} |
517 |
} |
|
789 | 518 |
} |
519 |
||
520 |
vdev_ops_t vdev_disk_ops = { |
|
521 |
vdev_disk_open, |
|
522 |
vdev_disk_close, |
|
523 |
vdev_default_asize, |
|
524 |
vdev_disk_io_start, |
|
525 |
vdev_disk_io_done, |
|
526 |
NULL, |
|
11958
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
527 |
vdev_disk_hold, |
575ffe1e978d
6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents:
10850
diff
changeset
|
528 |
vdev_disk_rele, |
789 | 529 |
VDEV_TYPE_DISK, /* name of this vdev type */ |
530 |
B_TRUE /* leaf vdev */ |
|
531 |
}; |
|
6423 | 532 |
|
533 |
/* |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
534 |
* 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
|
535 |
* the device, and construct a configuration nvlist. |
6423 | 536 |
*/ |
7539
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
537 |
int |
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
538 |
vdev_disk_read_rootlabel(char *devpath, char *devid, nvlist_t **config) |
6423 | 539 |
{ |
540 |
ldi_handle_t vd_lh; |
|
541 |
vdev_label_t *label; |
|
542 |
uint64_t s, size; |
|
543 |
int l; |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
544 |
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
|
545 |
int error = -1; |
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
546 |
char *minor_name; |
6423 | 547 |
|
548 |
/* |
|
549 |
* Read the device label and build the nvlist. |
|
550 |
*/ |
|
7687
1132fbaf0c27
6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents:
7553
diff
changeset
|
551 |
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
|
552 |
&minor_name) == 0) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
553 |
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
|
554 |
FREAD, kcred, &vd_lh, zfs_li); |
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
555 |
ddi_devid_free(tmpdevid); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
556 |
ddi_devid_str_free(minor_name); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
557 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
6976
diff
changeset
|
558 |
|
7687
1132fbaf0c27
6750475 can't boot off a mirrored root with a failed disk
Lin Ling <Lin.Ling@Sun.COM>
parents:
7553
diff
changeset
|
559 |
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
|
560 |
zfs_li))) |
7539
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
561 |
return (error); |
6423 | 562 |
|
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6615
diff
changeset
|
563 |
if (ldi_get_size(vd_lh, &s)) { |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6615
diff
changeset
|
564 |
(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
|
565 |
return (EIO); |
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6615
diff
changeset
|
566 |
} |
6423 | 567 |
|
568 |
size = P2ALIGN_TYPED(s, sizeof (vdev_label_t), uint64_t); |
|
569 |
label = kmem_alloc(sizeof (vdev_label_t), KM_SLEEP); |
|
570 |
||
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
|
571 |
*config = NULL; |
6423 | 572 |
for (l = 0; l < VDEV_LABELS; l++) { |
573 |
uint64_t offset, state, txg = 0; |
|
574 |
||
575 |
/* read vdev label */ |
|
576 |
offset = vdev_label_offset(size, l, 0); |
|
577 |
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
|
578 |
VDEV_SKIP_SIZE + VDEV_PHYS_SIZE, offset, B_READ) != 0) |
6423 | 579 |
continue; |
580 |
||
581 |
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
|
582 |
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
|
583 |
*config = NULL; |
6423 | 584 |
continue; |
585 |
} |
|
586 |
||
7539
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
587 |
if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE, |
6423 | 588 |
&state) != 0 || state >= POOL_STATE_DESTROYED) { |
7539
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
589 |
nvlist_free(*config); |
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
590 |
*config = NULL; |
6423 | 591 |
continue; |
592 |
} |
|
593 |
||
7539
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
594 |
if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG, |
6423 | 595 |
&txg) != 0 || txg == 0) { |
7539
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
596 |
nvlist_free(*config); |
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
597 |
*config = NULL; |
6423 | 598 |
continue; |
599 |
} |
|
600 |
||
601 |
break; |
|
602 |
} |
|
603 |
||
604 |
kmem_free(label, sizeof (vdev_label_t)); |
|
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6615
diff
changeset
|
605 |
(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
|
606 |
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
|
607 |
error = EIDRM; |
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6615
diff
changeset
|
608 |
|
7539
e3f4b4b9f982
6724326 better "can't mountroot" message
Lin Ling <Lin.Ling@Sun.COM>
parents:
7147
diff
changeset
|
609 |
return (error); |
6423 | 610 |
} |