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