1 /*
2  * Copyright (c) 2020 iXsystems, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27 
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30 
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/conf.h>
35 #include <sys/kernel.h>
36 #include <sys/lock.h>
37 #include <sys/malloc.h>
38 #include <sys/mutex.h>
39 #include <sys/proc.h>
40 #include <sys/errno.h>
41 #include <sys/uio.h>
42 #include <sys/buf.h>
43 #include <sys/file.h>
44 #include <sys/kmem.h>
45 #include <sys/conf.h>
46 #include <sys/cmn_err.h>
47 #include <sys/stat.h>
48 #include <sys/zfs_ioctl.h>
49 #include <sys/zfs_vfsops.h>
50 #include <sys/zfs_znode.h>
51 #include <sys/zap.h>
52 #include <sys/spa.h>
53 #include <sys/spa_impl.h>
54 #include <sys/vdev.h>
55 #include <sys/vdev_impl.h>
56 #include <sys/arc_os.h>
57 #include <sys/dmu.h>
58 #include <sys/dsl_dir.h>
59 #include <sys/dsl_dataset.h>
60 #include <sys/dsl_prop.h>
61 #include <sys/dsl_deleg.h>
62 #include <sys/dmu_objset.h>
63 #include <sys/dmu_impl.h>
64 #include <sys/dmu_tx.h>
65 #include <sys/sunddi.h>
66 #include <sys/policy.h>
67 #include <sys/zone.h>
68 #include <sys/nvpair.h>
69 #include <sys/mount.h>
70 #include <sys/taskqueue.h>
71 #include <sys/sdt.h>
72 #include <sys/fs/zfs.h>
73 #include <sys/zfs_ctldir.h>
74 #include <sys/zfs_dir.h>
75 #include <sys/zfs_onexit.h>
76 #include <sys/zvol.h>
77 #include <sys/dsl_scan.h>
78 #include <sys/dmu_objset.h>
79 #include <sys/dmu_send.h>
80 #include <sys/dsl_destroy.h>
81 #include <sys/dsl_bookmark.h>
82 #include <sys/dsl_userhold.h>
83 #include <sys/zfeature.h>
84 #include <sys/zcp.h>
85 #include <sys/zio_checksum.h>
86 #include <sys/vdev_removal.h>
87 #include <sys/dsl_crypt.h>
88 
89 #include <sys/zfs_ioctl_compat.h>
90 #include <sys/zfs_context.h>
91 
92 #include <sys/arc_impl.h>
93 #include <sys/dsl_pool.h>
94 
95 #include <sys/vmmeter.h>
96 
97 SYSCTL_DECL(_vfs_zfs);
98 SYSCTL_NODE(_vfs_zfs, OID_AUTO, arc, CTLFLAG_RW, 0,
99 	"ZFS adaptive replacement cache");
100 SYSCTL_NODE(_vfs_zfs, OID_AUTO, brt, CTLFLAG_RW, 0,
101 	"ZFS Block Reference Table");
102 SYSCTL_NODE(_vfs_zfs, OID_AUTO, condense, CTLFLAG_RW, 0, "ZFS condense");
103 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dbuf, CTLFLAG_RW, 0, "ZFS disk buf cache");
104 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dbuf_cache, CTLFLAG_RW, 0,
105 	"ZFS disk buf cache");
106 SYSCTL_NODE(_vfs_zfs, OID_AUTO, deadman, CTLFLAG_RW, 0, "ZFS deadman");
107 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dedup, CTLFLAG_RW, 0, "ZFS dedup");
108 SYSCTL_NODE(_vfs_zfs, OID_AUTO, l2arc, CTLFLAG_RW, 0, "ZFS l2arc");
109 SYSCTL_NODE(_vfs_zfs, OID_AUTO, livelist, CTLFLAG_RW, 0, "ZFS livelist");
110 SYSCTL_NODE(_vfs_zfs, OID_AUTO, lua, CTLFLAG_RW, 0, "ZFS lua");
111 SYSCTL_NODE(_vfs_zfs, OID_AUTO, metaslab, CTLFLAG_RW, 0, "ZFS metaslab");
112 SYSCTL_NODE(_vfs_zfs, OID_AUTO, mg, CTLFLAG_RW, 0, "ZFS metaslab group");
113 SYSCTL_NODE(_vfs_zfs, OID_AUTO, multihost, CTLFLAG_RW, 0,
114 	"ZFS multihost protection");
115 SYSCTL_NODE(_vfs_zfs, OID_AUTO, prefetch, CTLFLAG_RW, 0, "ZFS prefetch");
116 SYSCTL_NODE(_vfs_zfs, OID_AUTO, reconstruct, CTLFLAG_RW, 0, "ZFS reconstruct");
117 SYSCTL_NODE(_vfs_zfs, OID_AUTO, recv, CTLFLAG_RW, 0, "ZFS receive");
118 SYSCTL_NODE(_vfs_zfs, OID_AUTO, send, CTLFLAG_RW, 0, "ZFS send");
119 SYSCTL_NODE(_vfs_zfs, OID_AUTO, spa, CTLFLAG_RW, 0, "ZFS space allocation");
120 SYSCTL_NODE(_vfs_zfs, OID_AUTO, trim, CTLFLAG_RW, 0, "ZFS TRIM");
121 SYSCTL_NODE(_vfs_zfs, OID_AUTO, txg, CTLFLAG_RW, 0, "ZFS transaction group");
122 SYSCTL_NODE(_vfs_zfs, OID_AUTO, vdev, CTLFLAG_RW, 0, "ZFS VDEV");
123 SYSCTL_NODE(_vfs_zfs, OID_AUTO, vnops, CTLFLAG_RW, 0, "ZFS VNOPS");
124 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zevent, CTLFLAG_RW, 0, "ZFS event");
125 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zil, CTLFLAG_RW, 0, "ZFS ZIL");
126 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zio, CTLFLAG_RW, 0, "ZFS ZIO");
127 
128 SYSCTL_NODE(_vfs_zfs_livelist, OID_AUTO, condense, CTLFLAG_RW, 0,
129 	"ZFS livelist condense");
130 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, cache, CTLFLAG_RW, 0, "ZFS VDEV Cache");
131 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, file, CTLFLAG_RW, 0, "ZFS VDEV file");
132 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, mirror, CTLFLAG_RD, 0,
133 	"ZFS VDEV mirror");
134 
135 SYSCTL_DECL(_vfs_zfs_version);
136 SYSCTL_CONST_STRING(_vfs_zfs_version, OID_AUTO, module, CTLFLAG_RD,
137 	(ZFS_META_VERSION "-" ZFS_META_RELEASE), "OpenZFS module version");
138 
139 /* arc.c */
140 
141 int
142 param_set_arc_u64(SYSCTL_HANDLER_ARGS)
143 {
144 	int err;
145 
146 	err = sysctl_handle_64(oidp, arg1, 0, req);
147 	if (err != 0 || req->newptr == NULL)
148 		return (err);
149 
150 	arc_tuning_update(B_TRUE);
151 
152 	return (0);
153 }
154 
155 int
156 param_set_arc_int(SYSCTL_HANDLER_ARGS)
157 {
158 	int err;
159 
160 	err = sysctl_handle_int(oidp, arg1, 0, req);
161 	if (err != 0 || req->newptr == NULL)
162 		return (err);
163 
164 	arc_tuning_update(B_TRUE);
165 
166 	return (0);
167 }
168 
169 int
170 param_set_arc_max(SYSCTL_HANDLER_ARGS)
171 {
172 	unsigned long val;
173 	int err;
174 
175 	val = zfs_arc_max;
176 	err = sysctl_handle_64(oidp, &val, 0, req);
177 	if (err != 0 || req->newptr == NULL)
178 		return (SET_ERROR(err));
179 
180 	if (val != 0 && (val < MIN_ARC_MAX || val <= arc_c_min ||
181 	    val >= arc_all_memory()))
182 		return (SET_ERROR(EINVAL));
183 
184 	zfs_arc_max = val;
185 	arc_tuning_update(B_TRUE);
186 
187 	/* Update the sysctl to the tuned value */
188 	if (val != 0)
189 		zfs_arc_max = arc_c_max;
190 
191 	return (0);
192 }
193 
194 /* BEGIN CSTYLED */
195 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_max,
196 	CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
197 	NULL, 0, param_set_arc_max, "LU",
198 	"Maximum ARC size in bytes (LEGACY)");
199 /* END CSTYLED */
200 
201 int
202 param_set_arc_min(SYSCTL_HANDLER_ARGS)
203 {
204 	unsigned long val;
205 	int err;
206 
207 	val = zfs_arc_min;
208 	err = sysctl_handle_64(oidp, &val, 0, req);
209 	if (err != 0 || req->newptr == NULL)
210 		return (SET_ERROR(err));
211 
212 	if (val != 0 && (val < 2ULL << SPA_MAXBLOCKSHIFT || val > arc_c_max))
213 		return (SET_ERROR(EINVAL));
214 
215 	zfs_arc_min = val;
216 	arc_tuning_update(B_TRUE);
217 
218 	/* Update the sysctl to the tuned value */
219 	if (val != 0)
220 		zfs_arc_min = arc_c_min;
221 
222 	return (0);
223 }
224 
225 /* BEGIN CSTYLED */
226 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_min,
227 	CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
228 	NULL, 0, param_set_arc_min, "LU",
229 	"Minimum ARC size in bytes (LEGACY)");
230 /* END CSTYLED */
231 
232 extern uint_t zfs_arc_free_target;
233 
234 int
235 param_set_arc_free_target(SYSCTL_HANDLER_ARGS)
236 {
237 	uint_t val;
238 	int err;
239 
240 	val = zfs_arc_free_target;
241 	err = sysctl_handle_int(oidp, &val, 0, req);
242 	if (err != 0 || req->newptr == NULL)
243 		return (err);
244 
245 	if (val < minfree)
246 		return (EINVAL);
247 	if (val > vm_cnt.v_page_count)
248 		return (EINVAL);
249 
250 	zfs_arc_free_target = val;
251 
252 	return (0);
253 }
254 
255 /*
256  * NOTE: This sysctl is CTLFLAG_RW not CTLFLAG_RWTUN due to its dependency on
257  * pagedaemon initialization.
258  */
259 /* BEGIN CSTYLED */
260 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_free_target,
261 	CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
262 	NULL, 0, param_set_arc_free_target, "IU",
263 	"Desired number of free pages below which ARC triggers reclaim"
264 	" (LEGACY)");
265 /* END CSTYLED */
266 
267 int
268 param_set_arc_no_grow_shift(SYSCTL_HANDLER_ARGS)
269 {
270 	int err, val;
271 
272 	val = arc_no_grow_shift;
273 	err = sysctl_handle_int(oidp, &val, 0, req);
274 	if (err != 0 || req->newptr == NULL)
275 		return (err);
276 
277 	if (val < 0 || val >= arc_shrink_shift)
278 		return (EINVAL);
279 
280 	arc_no_grow_shift = val;
281 
282 	return (0);
283 }
284 
285 /* BEGIN CSTYLED */
286 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_no_grow_shift,
287 	CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
288 	NULL, 0, param_set_arc_no_grow_shift, "I",
289 	"log2(fraction of ARC which must be free to allow growing) (LEGACY)");
290 /* END CSTYLED */
291 
292 extern uint64_t l2arc_write_max;
293 
294 /* BEGIN CSTYLED */
295 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_write_max,
296 	CTLFLAG_RWTUN, &l2arc_write_max, 0,
297 	"Max write bytes per interval (LEGACY)");
298 /* END CSTYLED */
299 
300 extern uint64_t l2arc_write_boost;
301 
302 /* BEGIN CSTYLED */
303 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_write_boost,
304 	CTLFLAG_RWTUN, &l2arc_write_boost, 0,
305 	"Extra write bytes during device warmup (LEGACY)");
306 /* END CSTYLED */
307 
308 extern uint64_t l2arc_headroom;
309 
310 /* BEGIN CSTYLED */
311 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_headroom,
312 	CTLFLAG_RWTUN, &l2arc_headroom, 0,
313 	"Number of max device writes to precache (LEGACY)");
314 /* END CSTYLED */
315 
316 extern uint64_t l2arc_headroom_boost;
317 
318 /* BEGIN CSTYLED */
319 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_headroom_boost,
320 	CTLFLAG_RWTUN, &l2arc_headroom_boost, 0,
321 	"Compressed l2arc_headroom multiplier (LEGACY)");
322 /* END CSTYLED */
323 
324 extern uint64_t l2arc_feed_secs;
325 
326 /* BEGIN CSTYLED */
327 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_feed_secs,
328 	CTLFLAG_RWTUN, &l2arc_feed_secs, 0,
329 	"Seconds between L2ARC writing (LEGACY)");
330 /* END CSTYLED */
331 
332 extern uint64_t l2arc_feed_min_ms;
333 
334 /* BEGIN CSTYLED */
335 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_feed_min_ms,
336 	CTLFLAG_RWTUN, &l2arc_feed_min_ms, 0,
337 	"Min feed interval in milliseconds (LEGACY)");
338 /* END CSTYLED */
339 
340 extern int l2arc_noprefetch;
341 
342 /* BEGIN CSTYLED */
343 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_noprefetch,
344 	CTLFLAG_RWTUN, &l2arc_noprefetch, 0,
345 	"Skip caching prefetched buffers (LEGACY)");
346 /* END CSTYLED */
347 
348 extern int l2arc_feed_again;
349 
350 /* BEGIN CSTYLED */
351 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_feed_again,
352 	CTLFLAG_RWTUN, &l2arc_feed_again, 0,
353 	"Turbo L2ARC warmup (LEGACY)");
354 /* END CSTYLED */
355 
356 extern int l2arc_norw;
357 
358 /* BEGIN CSTYLED */
359 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_norw,
360 	CTLFLAG_RWTUN, &l2arc_norw, 0,
361 	"No reads during writes (LEGACY)");
362 /* END CSTYLED */
363 
364 static int
365 param_get_arc_state_size(SYSCTL_HANDLER_ARGS)
366 {
367 	arc_state_t *state = (arc_state_t *)arg1;
368 	int64_t val;
369 
370 	val = zfs_refcount_count(&state->arcs_size[ARC_BUFC_DATA]) +
371 	    zfs_refcount_count(&state->arcs_size[ARC_BUFC_METADATA]);
372 	return (sysctl_handle_64(oidp, &val, 0, req));
373 }
374 
375 extern arc_state_t ARC_anon;
376 
377 /* BEGIN CSTYLED */
378 SYSCTL_PROC(_vfs_zfs, OID_AUTO, anon_size,
379 	CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
380 	&ARC_anon, 0, param_get_arc_state_size, "Q",
381 	"size of anonymous state");
382 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_metadata_esize, CTLFLAG_RD,
383 	&ARC_anon.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
384 	"size of evictable metadata in anonymous state");
385 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_data_esize, CTLFLAG_RD,
386 	&ARC_anon.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
387 	"size of evictable data in anonymous state");
388 /* END CSTYLED */
389 
390 extern arc_state_t ARC_mru;
391 
392 /* BEGIN CSTYLED */
393 SYSCTL_PROC(_vfs_zfs, OID_AUTO, mru_size,
394 	CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
395 	&ARC_mru, 0, param_get_arc_state_size, "Q",
396 	"size of mru state");
397 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_metadata_esize, CTLFLAG_RD,
398 	&ARC_mru.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
399 	"size of evictable metadata in mru state");
400 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_data_esize, CTLFLAG_RD,
401 	&ARC_mru.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
402 	"size of evictable data in mru state");
403 /* END CSTYLED */
404 
405 extern arc_state_t ARC_mru_ghost;
406 
407 /* BEGIN CSTYLED */
408 SYSCTL_PROC(_vfs_zfs, OID_AUTO, mru_ghost_size,
409 	CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
410 	&ARC_mru_ghost, 0, param_get_arc_state_size, "Q",
411 	"size of mru ghost state");
412 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_metadata_esize, CTLFLAG_RD,
413 	&ARC_mru_ghost.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
414 	"size of evictable metadata in mru ghost state");
415 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_data_esize, CTLFLAG_RD,
416 	&ARC_mru_ghost.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
417 	"size of evictable data in mru ghost state");
418 /* END CSTYLED */
419 
420 extern arc_state_t ARC_mfu;
421 
422 /* BEGIN CSTYLED */
423 SYSCTL_PROC(_vfs_zfs, OID_AUTO, mfu_size,
424 	CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
425 	&ARC_mfu, 0, param_get_arc_state_size, "Q",
426 	"size of mfu state");
427 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_metadata_esize, CTLFLAG_RD,
428 	&ARC_mfu.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
429 	"size of evictable metadata in mfu state");
430 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_data_esize, CTLFLAG_RD,
431 	&ARC_mfu.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
432 	"size of evictable data in mfu state");
433 /* END CSTYLED */
434 
435 extern arc_state_t ARC_mfu_ghost;
436 
437 /* BEGIN CSTYLED */
438 SYSCTL_PROC(_vfs_zfs, OID_AUTO, mfu_ghost_size,
439 	CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
440 	&ARC_mfu_ghost, 0, param_get_arc_state_size, "Q",
441 	"size of mfu ghost state");
442 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_metadata_esize, CTLFLAG_RD,
443 	&ARC_mfu_ghost.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
444 	"size of evictable metadata in mfu ghost state");
445 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_data_esize, CTLFLAG_RD,
446 	&ARC_mfu_ghost.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
447 	"size of evictable data in mfu ghost state");
448 /* END CSTYLED */
449 
450 extern arc_state_t ARC_uncached;
451 
452 /* BEGIN CSTYLED */
453 SYSCTL_PROC(_vfs_zfs, OID_AUTO, uncached_size,
454 	CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
455 	&ARC_uncached, 0, param_get_arc_state_size, "Q",
456 	"size of uncached state");
457 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, uncached_metadata_esize, CTLFLAG_RD,
458 	&ARC_uncached.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
459 	"size of evictable metadata in uncached state");
460 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, uncached_data_esize, CTLFLAG_RD,
461 	&ARC_uncached.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
462 	"size of evictable data in uncached state");
463 /* END CSTYLED */
464 
465 extern arc_state_t ARC_l2c_only;
466 
467 /* BEGIN CSTYLED */
468 SYSCTL_PROC(_vfs_zfs, OID_AUTO, l2c_only_size,
469 	CTLTYPE_S64 | CTLFLAG_RD | CTLFLAG_MPSAFE,
470 	&ARC_l2c_only, 0, param_get_arc_state_size, "Q",
471 	"size of l2c_only state");
472 /* END CSTYLED */
473 
474 /* dbuf.c */
475 
476 /* dmu.c */
477 
478 /* dmu_zfetch.c */
479 
480 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zfetch, CTLFLAG_RW, 0, "ZFS ZFETCH (LEGACY)");
481 
482 extern uint32_t	zfetch_max_distance;
483 
484 /* BEGIN CSTYLED */
485 SYSCTL_UINT(_vfs_zfs_zfetch, OID_AUTO, max_distance,
486 	CTLFLAG_RWTUN, &zfetch_max_distance, 0,
487 	"Max bytes to prefetch per stream (LEGACY)");
488 /* END CSTYLED */
489 
490 extern uint32_t	zfetch_max_idistance;
491 
492 /* BEGIN CSTYLED */
493 SYSCTL_UINT(_vfs_zfs_zfetch, OID_AUTO, max_idistance,
494 	CTLFLAG_RWTUN, &zfetch_max_idistance, 0,
495 	"Max bytes to prefetch indirects for per stream (LEGACY)");
496 /* END CSTYLED */
497 
498 /* dsl_pool.c */
499 
500 /* dnode.c */
501 
502 /* dsl_scan.c */
503 
504 /* metaslab.c */
505 
506 /*
507  * In pools where the log space map feature is not enabled we touch
508  * multiple metaslabs (and their respective space maps) with each
509  * transaction group. Thus, we benefit from having a small space map
510  * block size since it allows us to issue more I/O operations scattered
511  * around the disk. So a sane default for the space map block size
512  * is 8~16K.
513  */
514 extern int zfs_metaslab_sm_blksz_no_log;
515 
516 /* BEGIN CSTYLED */
517 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, sm_blksz_no_log,
518 	CTLFLAG_RDTUN, &zfs_metaslab_sm_blksz_no_log, 0,
519 	"Block size for space map in pools with log space map disabled.  "
520 	"Power of 2 greater than 4096.");
521 /* END CSTYLED */
522 
523 /*
524  * When the log space map feature is enabled, we accumulate a lot of
525  * changes per metaslab that are flushed once in a while so we benefit
526  * from a bigger block size like 128K for the metaslab space maps.
527  */
528 extern int zfs_metaslab_sm_blksz_with_log;
529 
530 /* BEGIN CSTYLED */
531 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, sm_blksz_with_log,
532 	CTLFLAG_RDTUN, &zfs_metaslab_sm_blksz_with_log, 0,
533 	"Block size for space map in pools with log space map enabled.  "
534 	"Power of 2 greater than 4096.");
535 /* END CSTYLED */
536 
537 /*
538  * The in-core space map representation is more compact than its on-disk form.
539  * The zfs_condense_pct determines how much more compact the in-core
540  * space map representation must be before we compact it on-disk.
541  * Values should be greater than or equal to 100.
542  */
543 extern uint_t zfs_condense_pct;
544 
545 /* BEGIN CSTYLED */
546 SYSCTL_UINT(_vfs_zfs, OID_AUTO, condense_pct,
547 	CTLFLAG_RWTUN, &zfs_condense_pct, 0,
548 	"Condense on-disk spacemap when it is more than this many percents"
549 	" of in-memory counterpart");
550 /* END CSTYLED */
551 
552 extern uint_t zfs_remove_max_segment;
553 
554 /* BEGIN CSTYLED */
555 SYSCTL_UINT(_vfs_zfs, OID_AUTO, remove_max_segment,
556 	CTLFLAG_RWTUN, &zfs_remove_max_segment, 0,
557 	"Largest contiguous segment ZFS will attempt to allocate when removing"
558 	" a device");
559 /* END CSTYLED */
560 
561 extern int zfs_removal_suspend_progress;
562 
563 /* BEGIN CSTYLED */
564 SYSCTL_INT(_vfs_zfs, OID_AUTO, removal_suspend_progress,
565 	CTLFLAG_RWTUN, &zfs_removal_suspend_progress, 0,
566 	"Ensures certain actions can happen while in the middle of a removal");
567 /* END CSTYLED */
568 
569 /*
570  * Minimum size which forces the dynamic allocator to change
571  * it's allocation strategy.  Once the space map cannot satisfy
572  * an allocation of this size then it switches to using more
573  * aggressive strategy (i.e search by size rather than offset).
574  */
575 extern uint64_t metaslab_df_alloc_threshold;
576 
577 /* BEGIN CSTYLED */
578 SYSCTL_QUAD(_vfs_zfs_metaslab, OID_AUTO, df_alloc_threshold,
579 	CTLFLAG_RWTUN, &metaslab_df_alloc_threshold, 0,
580 	"Minimum size which forces the dynamic allocator to change its"
581 	" allocation strategy");
582 /* END CSTYLED */
583 
584 /*
585  * The minimum free space, in percent, which must be available
586  * in a space map to continue allocations in a first-fit fashion.
587  * Once the space map's free space drops below this level we dynamically
588  * switch to using best-fit allocations.
589  */
590 extern uint_t metaslab_df_free_pct;
591 
592 /* BEGIN CSTYLED */
593 SYSCTL_UINT(_vfs_zfs_metaslab, OID_AUTO, df_free_pct,
594 	CTLFLAG_RWTUN, &metaslab_df_free_pct, 0,
595 	"The minimum free space, in percent, which must be available in a"
596 	" space map to continue allocations in a first-fit fashion");
597 /* END CSTYLED */
598 
599 /*
600  * Percentage of all cpus that can be used by the metaslab taskq.
601  */
602 extern int metaslab_load_pct;
603 
604 /* BEGIN CSTYLED */
605 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, load_pct,
606 	CTLFLAG_RWTUN, &metaslab_load_pct, 0,
607 	"Percentage of cpus that can be used by the metaslab taskq");
608 /* END CSTYLED */
609 
610 /*
611  * Max number of metaslabs per group to preload.
612  */
613 extern uint_t metaslab_preload_limit;
614 
615 /* BEGIN CSTYLED */
616 SYSCTL_UINT(_vfs_zfs_metaslab, OID_AUTO, preload_limit,
617 	CTLFLAG_RWTUN, &metaslab_preload_limit, 0,
618 	"Max number of metaslabs per group to preload");
619 /* END CSTYLED */
620 
621 /* mmp.c */
622 
623 int
624 param_set_multihost_interval(SYSCTL_HANDLER_ARGS)
625 {
626 	int err;
627 
628 	err = sysctl_handle_64(oidp, &zfs_multihost_interval, 0, req);
629 	if (err != 0 || req->newptr == NULL)
630 		return (err);
631 
632 	if (spa_mode_global != SPA_MODE_UNINIT)
633 		mmp_signal_all_threads();
634 
635 	return (0);
636 }
637 
638 /* spa.c */
639 
640 extern int zfs_ccw_retry_interval;
641 
642 /* BEGIN CSTYLED */
643 SYSCTL_INT(_vfs_zfs, OID_AUTO, ccw_retry_interval,
644 	CTLFLAG_RWTUN, &zfs_ccw_retry_interval, 0,
645 	"Configuration cache file write, retry after failure, interval"
646 	" (seconds)");
647 /* END CSTYLED */
648 
649 extern uint64_t zfs_max_missing_tvds_cachefile;
650 
651 /* BEGIN CSTYLED */
652 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_cachefile,
653 	CTLFLAG_RWTUN, &zfs_max_missing_tvds_cachefile, 0,
654 	"Allow importing pools with missing top-level vdevs in cache file");
655 /* END CSTYLED */
656 
657 extern uint64_t zfs_max_missing_tvds_scan;
658 
659 /* BEGIN CSTYLED */
660 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_scan,
661 	CTLFLAG_RWTUN, &zfs_max_missing_tvds_scan, 0,
662 	"Allow importing pools with missing top-level vdevs during scan");
663 /* END CSTYLED */
664 
665 /* spa_misc.c */
666 
667 extern int zfs_flags;
668 
669 static int
670 sysctl_vfs_zfs_debug_flags(SYSCTL_HANDLER_ARGS)
671 {
672 	int err, val;
673 
674 	val = zfs_flags;
675 	err = sysctl_handle_int(oidp, &val, 0, req);
676 	if (err != 0 || req->newptr == NULL)
677 		return (err);
678 
679 	/*
680 	 * ZFS_DEBUG_MODIFY must be enabled prior to boot so all
681 	 * arc buffers in the system have the necessary additional
682 	 * checksum data.  However, it is safe to disable at any
683 	 * time.
684 	 */
685 	if (!(zfs_flags & ZFS_DEBUG_MODIFY))
686 		val &= ~ZFS_DEBUG_MODIFY;
687 	zfs_flags = val;
688 
689 	return (0);
690 }
691 
692 /* BEGIN CSTYLED */
693 SYSCTL_PROC(_vfs_zfs, OID_AUTO, debugflags,
694 	CTLTYPE_UINT | CTLFLAG_MPSAFE | CTLFLAG_RWTUN, NULL, 0,
695 	sysctl_vfs_zfs_debug_flags, "IU", "Debug flags for ZFS testing.");
696 /* END CSTYLED */
697 
698 int
699 param_set_deadman_synctime(SYSCTL_HANDLER_ARGS)
700 {
701 	unsigned long val;
702 	int err;
703 
704 	val = zfs_deadman_synctime_ms;
705 	err = sysctl_handle_64(oidp, &val, 0, req);
706 	if (err != 0 || req->newptr == NULL)
707 		return (err);
708 	zfs_deadman_synctime_ms = val;
709 
710 	spa_set_deadman_synctime(MSEC2NSEC(zfs_deadman_synctime_ms));
711 
712 	return (0);
713 }
714 
715 int
716 param_set_deadman_ziotime(SYSCTL_HANDLER_ARGS)
717 {
718 	unsigned long val;
719 	int err;
720 
721 	val = zfs_deadman_ziotime_ms;
722 	err = sysctl_handle_64(oidp, &val, 0, req);
723 	if (err != 0 || req->newptr == NULL)
724 		return (err);
725 	zfs_deadman_ziotime_ms = val;
726 
727 	spa_set_deadman_ziotime(MSEC2NSEC(zfs_deadman_synctime_ms));
728 
729 	return (0);
730 }
731 
732 int
733 param_set_deadman_failmode(SYSCTL_HANDLER_ARGS)
734 {
735 	char buf[16];
736 	int rc;
737 
738 	if (req->newptr == NULL)
739 		strlcpy(buf, zfs_deadman_failmode, sizeof (buf));
740 
741 	rc = sysctl_handle_string(oidp, buf, sizeof (buf), req);
742 	if (rc || req->newptr == NULL)
743 		return (rc);
744 	if (strcmp(buf, zfs_deadman_failmode) == 0)
745 		return (0);
746 	if (strcmp(buf, "wait") == 0)
747 		zfs_deadman_failmode = "wait";
748 	if (strcmp(buf, "continue") == 0)
749 		zfs_deadman_failmode = "continue";
750 	if (strcmp(buf, "panic") == 0)
751 		zfs_deadman_failmode = "panic";
752 
753 	return (-param_set_deadman_failmode_common(buf));
754 }
755 
756 int
757 param_set_slop_shift(SYSCTL_HANDLER_ARGS)
758 {
759 	int val;
760 	int err;
761 
762 	val = spa_slop_shift;
763 	err = sysctl_handle_int(oidp, &val, 0, req);
764 	if (err != 0 || req->newptr == NULL)
765 		return (err);
766 
767 	if (val < 1 || val > 31)
768 		return (EINVAL);
769 
770 	spa_slop_shift = val;
771 
772 	return (0);
773 }
774 
775 /* spacemap.c */
776 
777 extern int space_map_ibs;
778 
779 /* BEGIN CSTYLED */
780 SYSCTL_INT(_vfs_zfs, OID_AUTO, space_map_ibs, CTLFLAG_RWTUN,
781 	&space_map_ibs, 0, "Space map indirect block shift");
782 /* END CSTYLED */
783 
784 
785 /* vdev.c */
786 
787 int
788 param_set_min_auto_ashift(SYSCTL_HANDLER_ARGS)
789 {
790 	int val;
791 	int err;
792 
793 	val = zfs_vdev_min_auto_ashift;
794 	err = sysctl_handle_int(oidp, &val, 0, req);
795 	if (err != 0 || req->newptr == NULL)
796 		return (SET_ERROR(err));
797 
798 	if (val < ASHIFT_MIN || val > zfs_vdev_max_auto_ashift)
799 		return (SET_ERROR(EINVAL));
800 
801 	zfs_vdev_min_auto_ashift = val;
802 
803 	return (0);
804 }
805 
806 /* BEGIN CSTYLED */
807 SYSCTL_PROC(_vfs_zfs, OID_AUTO, min_auto_ashift,
808 	CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
809 	&zfs_vdev_min_auto_ashift, sizeof (zfs_vdev_min_auto_ashift),
810 	param_set_min_auto_ashift, "IU",
811 	"Min ashift used when creating new top-level vdev. (LEGACY)");
812 /* END CSTYLED */
813 
814 int
815 param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)
816 {
817 	int val;
818 	int err;
819 
820 	val = zfs_vdev_max_auto_ashift;
821 	err = sysctl_handle_int(oidp, &val, 0, req);
822 	if (err != 0 || req->newptr == NULL)
823 		return (SET_ERROR(err));
824 
825 	if (val > ASHIFT_MAX || val < zfs_vdev_min_auto_ashift)
826 		return (SET_ERROR(EINVAL));
827 
828 	zfs_vdev_max_auto_ashift = val;
829 
830 	return (0);
831 }
832 
833 /* BEGIN CSTYLED */
834 SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift,
835 	CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
836 	&zfs_vdev_max_auto_ashift, sizeof (zfs_vdev_max_auto_ashift),
837 	param_set_max_auto_ashift, "IU",
838 	"Max ashift used when optimizing for logical -> physical sector size on"
839 	" new top-level vdevs. (LEGACY)");
840 /* END CSTYLED */
841 
842 /*
843  * Since the DTL space map of a vdev is not expected to have a lot of
844  * entries, we default its block size to 4K.
845  */
846 extern int zfs_vdev_dtl_sm_blksz;
847 
848 /* BEGIN CSTYLED */
849 SYSCTL_INT(_vfs_zfs, OID_AUTO, dtl_sm_blksz,
850 	CTLFLAG_RDTUN, &zfs_vdev_dtl_sm_blksz, 0,
851 	"Block size for DTL space map.  Power of 2 greater than 4096.");
852 /* END CSTYLED */
853 
854 /*
855  * vdev-wide space maps that have lots of entries written to them at
856  * the end of each transaction can benefit from a higher I/O bandwidth
857  * (e.g. vdev_obsolete_sm), thus we default their block size to 128K.
858  */
859 extern int zfs_vdev_standard_sm_blksz;
860 
861 /* BEGIN CSTYLED */
862 SYSCTL_INT(_vfs_zfs, OID_AUTO, standard_sm_blksz,
863 	CTLFLAG_RDTUN, &zfs_vdev_standard_sm_blksz, 0,
864 	"Block size for standard space map.  Power of 2 greater than 4096.");
865 /* END CSTYLED */
866 
867 extern int vdev_validate_skip;
868 
869 /* BEGIN CSTYLED */
870 SYSCTL_INT(_vfs_zfs, OID_AUTO, validate_skip,
871 	CTLFLAG_RDTUN, &vdev_validate_skip, 0,
872 	"Enable to bypass vdev_validate().");
873 /* END CSTYLED */
874 
875 /* vdev_cache.c */
876 
877 /* vdev_mirror.c */
878 
879 /* vdev_queue.c */
880 
881 extern uint_t zfs_vdev_max_active;
882 
883 /* BEGIN CSTYLED */
884 SYSCTL_UINT(_vfs_zfs, OID_AUTO, top_maxinflight,
885 	CTLFLAG_RWTUN, &zfs_vdev_max_active, 0,
886 	"The maximum number of I/Os of all types active for each device."
887 	" (LEGACY)");
888 /* END CSTYLED */
889 
890 extern uint_t zfs_vdev_def_queue_depth;
891 
892 /* BEGIN CSTYLED */
893 SYSCTL_UINT(_vfs_zfs_vdev, OID_AUTO, def_queue_depth,
894 	CTLFLAG_RWTUN, &zfs_vdev_def_queue_depth, 0,
895 	"Default queue depth for each allocator");
896 /* END CSTYLED */
897 
898 /* zio.c */
899 
900 /* BEGIN CSTYLED */
901 SYSCTL_INT(_vfs_zfs_zio, OID_AUTO, exclude_metadata,
902 	CTLFLAG_RDTUN, &zio_exclude_metadata, 0,
903 	"Exclude metadata buffers from dumps as well");
904 /* END CSTYLED */
905