Print this page
7938 Port ZOL #3712 disable LBA weighting on files and SSDs
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) 2011, 2015 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 #include <sys/abd.h>
35 35
36 36 /*
37 37 * Virtual device vector for files.
38 38 */
39 39
40 40 static void
41 41 vdev_file_hold(vdev_t *vd)
42 42 {
43 43 ASSERT(vd->vdev_path != NULL);
44 44 }
45 45
46 46 static void
47 47 vdev_file_rele(vdev_t *vd)
48 48 {
49 49 ASSERT(vd->vdev_path != NULL);
50 50 }
51 51
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
52 52 static int
53 53 vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
54 54 uint64_t *ashift)
55 55 {
56 56 vdev_file_t *vf;
57 57 vnode_t *vp;
58 58 vattr_t vattr;
59 59 int error;
60 60
61 61 /*
62 + * Rotational optimizations only make sense on block devices
63 + */
64 + vd->vdev_nonrot = B_TRUE;
65 +
66 + /*
62 67 * We must have a pathname, and it must be absolute.
63 68 */
64 69 if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
65 70 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
66 71 return (SET_ERROR(EINVAL));
67 72 }
68 73
69 74 /*
70 75 * Reopen the device if it's not currently open. Otherwise,
71 76 * just update the physical size of the device.
72 77 */
73 78 if (vd->vdev_tsd != NULL) {
74 79 ASSERT(vd->vdev_reopening);
75 80 vf = vd->vdev_tsd;
76 81 goto skip_open;
77 82 }
78 83
79 84 vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_SLEEP);
80 85
81 86 /*
82 87 * We always open the files from the root of the global zone, even if
83 88 * we're in a local zone. If the user has gotten to this point, the
84 89 * administrator has already decided that the pool should be available
85 90 * to local zone users, so the underlying devices should be as well.
86 91 */
87 92 ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
88 93 error = vn_openat(vd->vdev_path + 1, UIO_SYSSPACE,
89 94 spa_mode(vd->vdev_spa) | FOFFMAX, 0, &vp, 0, 0, rootdir, -1);
90 95
91 96 if (error) {
92 97 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
93 98 return (error);
94 99 }
95 100
96 101 vf->vf_vnode = vp;
97 102
98 103 #ifdef _KERNEL
99 104 /*
100 105 * Make sure it's a regular file.
101 106 */
102 107 if (vp->v_type != VREG) {
103 108 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
104 109 return (SET_ERROR(ENODEV));
105 110 }
106 111 #endif
107 112
108 113 skip_open:
109 114 /*
110 115 * Determine the physical size of the file.
111 116 */
112 117 vattr.va_mask = AT_SIZE;
113 118 error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred, NULL);
114 119 if (error) {
115 120 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
116 121 return (error);
117 122 }
118 123
119 124 *max_psize = *psize = vattr.va_size;
120 125 *ashift = SPA_MINBLOCKSHIFT;
121 126
122 127 return (0);
123 128 }
124 129
125 130 static void
126 131 vdev_file_close(vdev_t *vd)
127 132 {
128 133 vdev_file_t *vf = vd->vdev_tsd;
129 134
130 135 if (vd->vdev_reopening || vf == NULL)
131 136 return;
132 137
133 138 if (vf->vf_vnode != NULL) {
134 139 (void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred, NULL);
135 140 (void) VOP_CLOSE(vf->vf_vnode, spa_mode(vd->vdev_spa), 1, 0,
136 141 kcred, NULL);
137 142 VN_RELE(vf->vf_vnode);
138 143 }
139 144
140 145 vd->vdev_delayed_close = B_FALSE;
141 146 kmem_free(vf, sizeof (vdev_file_t));
142 147 vd->vdev_tsd = NULL;
143 148 }
144 149
145 150 /*
146 151 * Implements the interrupt side for file vdev types. This routine will be
147 152 * called when the I/O completes allowing us to transfer the I/O to the
148 153 * interrupt taskqs. For consistency, the code structure mimics disk vdev
149 154 * types.
150 155 */
151 156 static void
152 157 vdev_file_io_intr(buf_t *bp)
153 158 {
154 159 vdev_buf_t *vb = (vdev_buf_t *)bp;
155 160 zio_t *zio = vb->vb_io;
156 161
157 162 zio->io_error = (geterror(bp) != 0 ? EIO : 0);
158 163 if (zio->io_error == 0 && bp->b_resid != 0)
159 164 zio->io_error = SET_ERROR(ENOSPC);
160 165
161 166 if (zio->io_type == ZIO_TYPE_READ) {
162 167 abd_return_buf_copy(zio->io_abd, bp->b_un.b_addr, zio->io_size);
163 168 } else {
164 169 abd_return_buf(zio->io_abd, bp->b_un.b_addr, zio->io_size);
165 170 }
166 171
167 172 kmem_free(vb, sizeof (vdev_buf_t));
168 173 zio_delay_interrupt(zio);
169 174 }
170 175
171 176 static void
172 177 vdev_file_io_strategy(void *arg)
173 178 {
174 179 buf_t *bp = arg;
175 180 vnode_t *vp = bp->b_private;
176 181 ssize_t resid;
177 182 int error;
178 183
179 184 error = vn_rdwr((bp->b_flags & B_READ) ? UIO_READ : UIO_WRITE,
180 185 vp, bp->b_un.b_addr, bp->b_bcount, ldbtob(bp->b_lblkno),
181 186 UIO_SYSSPACE, 0, RLIM64_INFINITY, kcred, &resid);
182 187
183 188 if (error == 0) {
184 189 bp->b_resid = resid;
185 190 biodone(bp);
186 191 } else {
187 192 bioerror(bp, error);
188 193 biodone(bp);
189 194 }
190 195 }
191 196
192 197 static void
193 198 vdev_file_io_start(zio_t *zio)
194 199 {
195 200 vdev_t *vd = zio->io_vd;
196 201 vdev_file_t *vf = vd->vdev_tsd;
197 202 vdev_buf_t *vb;
198 203 buf_t *bp;
199 204
200 205 if (zio->io_type == ZIO_TYPE_IOCTL) {
201 206 /* XXPOLICY */
202 207 if (!vdev_readable(vd)) {
203 208 zio->io_error = SET_ERROR(ENXIO);
204 209 zio_interrupt(zio);
205 210 return;
206 211 }
207 212
208 213 switch (zio->io_cmd) {
209 214 case DKIOCFLUSHWRITECACHE:
210 215 zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
211 216 kcred, NULL);
212 217 break;
213 218 default:
214 219 zio->io_error = SET_ERROR(ENOTSUP);
215 220 }
216 221
217 222 zio_execute(zio);
218 223 return;
219 224 }
220 225
221 226 ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
222 227 zio->io_target_timestamp = zio_handle_io_delay(zio);
223 228
224 229 vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
225 230
226 231 vb->vb_io = zio;
227 232 bp = &vb->vb_buf;
228 233
229 234 bioinit(bp);
230 235 bp->b_flags = (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE);
231 236 bp->b_bcount = zio->io_size;
232 237
233 238 if (zio->io_type == ZIO_TYPE_READ) {
234 239 bp->b_un.b_addr =
235 240 abd_borrow_buf(zio->io_abd, zio->io_size);
236 241 } else {
237 242 bp->b_un.b_addr =
238 243 abd_borrow_buf_copy(zio->io_abd, zio->io_size);
239 244 }
240 245
241 246 bp->b_lblkno = lbtodb(zio->io_offset);
242 247 bp->b_bufsize = zio->io_size;
243 248 bp->b_private = vf->vf_vnode;
244 249 bp->b_iodone = (int (*)())vdev_file_io_intr;
245 250
246 251 VERIFY3U(taskq_dispatch(system_taskq, vdev_file_io_strategy, bp,
247 252 TQ_SLEEP), !=, 0);
248 253 }
249 254
250 255 /* ARGSUSED */
251 256 static void
252 257 vdev_file_io_done(zio_t *zio)
253 258 {
254 259 }
255 260
256 261 vdev_ops_t vdev_file_ops = {
257 262 vdev_file_open,
258 263 vdev_file_close,
259 264 vdev_default_asize,
260 265 vdev_file_io_start,
261 266 vdev_file_io_done,
262 267 NULL,
263 268 vdev_file_hold,
264 269 vdev_file_rele,
265 270 VDEV_TYPE_FILE, /* name of this vdev type */
266 271 B_TRUE /* leaf vdev */
267 272 };
268 273
269 274 /*
270 275 * From userland we access disks just like files.
271 276 */
272 277 #ifndef _KERNEL
273 278
274 279 vdev_ops_t vdev_disk_ops = {
275 280 vdev_file_open,
276 281 vdev_file_close,
277 282 vdev_default_asize,
278 283 vdev_file_io_start,
279 284 vdev_file_io_done,
280 285 NULL,
281 286 vdev_file_hold,
282 287 vdev_file_rele,
283 288 VDEV_TYPE_DISK, /* name of this vdev type */
284 289 B_TRUE /* leaf vdev */
285 290 };
286 291
287 292 #endif
↓ open down ↓ |
216 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX