Print this page
3949 ztest fault injection should avoid resilvering devices
3950 ztest: deadman fires when we're doing a scan
3951 ztest hang when running dedup test
3952 ztest: ztest_reguid test and ztest_fault_inject don't place nice together
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/vdev_file.c
+++ new/usr/src/uts/common/fs/zfs/vdev_file.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #include <sys/zfs_context.h>
27 27 #include <sys/spa.h>
28 28 #include <sys/spa_impl.h>
29 29 #include <sys/vdev_file.h>
30 30 #include <sys/vdev_impl.h>
31 31 #include <sys/zio.h>
32 32 #include <sys/fs/zfs.h>
33 33 #include <sys/fm/fs/zfs.h>
34 34
35 35 /*
36 36 * Virtual device vector for files.
37 37 */
38 38
39 39 static void
40 40 vdev_file_hold(vdev_t *vd)
41 41 {
42 42 ASSERT(vd->vdev_path != NULL);
43 43 }
44 44
45 45 static void
46 46 vdev_file_rele(vdev_t *vd)
47 47 {
48 48 ASSERT(vd->vdev_path != NULL);
49 49 }
50 50
51 51 static int
52 52 vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
53 53 uint64_t *ashift)
54 54 {
55 55 vdev_file_t *vf;
56 56 vnode_t *vp;
57 57 vattr_t vattr;
58 58 int error;
59 59
60 60 /*
61 61 * We must have a pathname, and it must be absolute.
62 62 */
63 63 if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
64 64 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
65 65 return (SET_ERROR(EINVAL));
66 66 }
67 67
68 68 /*
69 69 * Reopen the device if it's not currently open. Otherwise,
70 70 * just update the physical size of the device.
71 71 */
72 72 if (vd->vdev_tsd != NULL) {
73 73 ASSERT(vd->vdev_reopening);
74 74 vf = vd->vdev_tsd;
75 75 goto skip_open;
76 76 }
77 77
78 78 vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_SLEEP);
79 79
80 80 /*
81 81 * We always open the files from the root of the global zone, even if
82 82 * we're in a local zone. If the user has gotten to this point, the
83 83 * administrator has already decided that the pool should be available
84 84 * to local zone users, so the underlying devices should be as well.
85 85 */
86 86 ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
87 87 error = vn_openat(vd->vdev_path + 1, UIO_SYSSPACE,
88 88 spa_mode(vd->vdev_spa) | FOFFMAX, 0, &vp, 0, 0, rootdir, -1);
89 89
90 90 if (error) {
91 91 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
92 92 return (error);
93 93 }
94 94
95 95 vf->vf_vnode = vp;
96 96
97 97 #ifdef _KERNEL
98 98 /*
99 99 * Make sure it's a regular file.
100 100 */
101 101 if (vp->v_type != VREG) {
102 102 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
103 103 return (SET_ERROR(ENODEV));
104 104 }
105 105 #endif
106 106
107 107 skip_open:
108 108 /*
109 109 * Determine the physical size of the file.
110 110 */
111 111 vattr.va_mask = AT_SIZE;
112 112 error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred, NULL);
113 113 if (error) {
114 114 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
115 115 return (error);
116 116 }
117 117
118 118 *max_psize = *psize = vattr.va_size;
119 119 *ashift = SPA_MINBLOCKSHIFT;
120 120
121 121 return (0);
122 122 }
123 123
124 124 static void
125 125 vdev_file_close(vdev_t *vd)
126 126 {
127 127 vdev_file_t *vf = vd->vdev_tsd;
128 128
129 129 if (vd->vdev_reopening || vf == NULL)
130 130 return;
131 131
132 132 if (vf->vf_vnode != NULL) {
133 133 (void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred, NULL);
134 134 (void) VOP_CLOSE(vf->vf_vnode, spa_mode(vd->vdev_spa), 1, 0,
135 135 kcred, NULL);
136 136 VN_RELE(vf->vf_vnode);
137 137 }
138 138
139 139 vd->vdev_delayed_close = B_FALSE;
140 140 kmem_free(vf, sizeof (vdev_file_t));
141 141 vd->vdev_tsd = NULL;
142 142 }
143 143
144 144 /*
145 145 * Implements the interrupt side for file vdev types. This routine will be
146 146 * called when the I/O completes allowing us to transfer the I/O to the
147 147 * interrupt taskqs. For consistency, the code structure mimics disk vdev
148 148 * types.
149 149 */
150 150 static void
151 151 vdev_file_io_intr(buf_t *bp)
152 152 {
153 153 vdev_buf_t *vb = (vdev_buf_t *)bp;
154 154 zio_t *zio = vb->vb_io;
155 155
156 156 zio->io_error = (geterror(bp) != 0 ? EIO : 0);
157 157 if (zio->io_error == 0 && bp->b_resid != 0)
158 158 zio->io_error = SET_ERROR(ENOSPC);
159 159
160 160 kmem_free(vb, sizeof (vdev_buf_t));
161 161 zio_interrupt(zio);
162 162 }
163 163
164 164 static void
165 165 vdev_file_io_strategy(void *arg)
166 166 {
167 167 buf_t *bp = arg;
168 168 vnode_t *vp = bp->b_private;
169 169 ssize_t resid;
170 170 int error;
171 171
172 172 error = vn_rdwr((bp->b_flags & B_READ) ? UIO_READ : UIO_WRITE,
173 173 vp, bp->b_un.b_addr, bp->b_bcount, ldbtob(bp->b_lblkno),
174 174 UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
175 175
176 176 if (error == 0) {
177 177 bp->b_resid = resid;
↓ open down ↓ |
177 lines elided |
↑ open up ↑ |
178 178 biodone(bp);
179 179 } else {
180 180 bioerror(bp, error);
181 181 biodone(bp);
182 182 }
183 183 }
184 184
185 185 static int
186 186 vdev_file_io_start(zio_t *zio)
187 187 {
188 - spa_t *spa = zio->io_spa;
189 188 vdev_t *vd = zio->io_vd;
190 189 vdev_file_t *vf = vd->vdev_tsd;
191 190 vdev_buf_t *vb;
192 191 buf_t *bp;
193 192
194 193 if (zio->io_type == ZIO_TYPE_IOCTL) {
195 194 /* XXPOLICY */
196 195 if (!vdev_readable(vd)) {
197 196 zio->io_error = SET_ERROR(ENXIO);
198 197 return (ZIO_PIPELINE_CONTINUE);
199 198 }
200 199
201 200 switch (zio->io_cmd) {
202 201 case DKIOCFLUSHWRITECACHE:
203 202 zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
204 203 kcred, NULL);
205 204 break;
206 205 default:
207 206 zio->io_error = SET_ERROR(ENOTSUP);
208 207 }
209 208
210 209 return (ZIO_PIPELINE_CONTINUE);
211 210 }
212 211
213 212 vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
214 213
215 214 vb->vb_io = zio;
216 215 bp = &vb->vb_buf;
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
217 216
218 217 bioinit(bp);
219 218 bp->b_flags = (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE);
220 219 bp->b_bcount = zio->io_size;
221 220 bp->b_un.b_addr = zio->io_data;
222 221 bp->b_lblkno = lbtodb(zio->io_offset);
223 222 bp->b_bufsize = zio->io_size;
224 223 bp->b_private = vf->vf_vnode;
225 224 bp->b_iodone = (int (*)())vdev_file_io_intr;
226 225
227 - spa_taskq_dispatch_ent(spa, ZIO_TYPE_FREE, ZIO_TASKQ_ISSUE,
228 - vdev_file_io_strategy, bp, 0, &zio->io_tqent);
226 + VERIFY3U(taskq_dispatch(system_taskq, vdev_file_io_strategy, bp,
227 + TQ_SLEEP), !=, 0);
229 228
230 229 return (ZIO_PIPELINE_STOP);
231 230 }
232 231
233 232 /* ARGSUSED */
234 233 static void
235 234 vdev_file_io_done(zio_t *zio)
236 235 {
237 236 }
238 237
239 238 vdev_ops_t vdev_file_ops = {
240 239 vdev_file_open,
241 240 vdev_file_close,
242 241 vdev_default_asize,
243 242 vdev_file_io_start,
244 243 vdev_file_io_done,
245 244 NULL,
246 245 vdev_file_hold,
247 246 vdev_file_rele,
248 247 VDEV_TYPE_FILE, /* name of this vdev type */
249 248 B_TRUE /* leaf vdev */
250 249 };
251 250
252 251 /*
253 252 * From userland we access disks just like files.
254 253 */
255 254 #ifndef _KERNEL
256 255
257 256 vdev_ops_t vdev_disk_ops = {
258 257 vdev_file_open,
259 258 vdev_file_close,
260 259 vdev_default_asize,
261 260 vdev_file_io_start,
262 261 vdev_file_io_done,
263 262 NULL,
264 263 vdev_file_hold,
265 264 vdev_file_rele,
266 265 VDEV_TYPE_DISK, /* name of this vdev type */
267 266 B_TRUE /* leaf vdev */
268 267 };
269 268
270 269 #endif
↓ open down ↓ |
32 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX