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
param_set_arc_u64(SYSCTL_HANDLER_ARGS)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
param_set_arc_int(SYSCTL_HANDLER_ARGS)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
param_set_arc_max(SYSCTL_HANDLER_ARGS)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
param_set_arc_min(SYSCTL_HANDLER_ARGS)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
param_set_arc_free_target(SYSCTL_HANDLER_ARGS)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
param_set_arc_no_grow_shift(SYSCTL_HANDLER_ARGS)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
param_get_arc_state_size(SYSCTL_HANDLER_ARGS)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 /* mmp.c */
600 
601 int
param_set_multihost_interval(SYSCTL_HANDLER_ARGS)602 param_set_multihost_interval(SYSCTL_HANDLER_ARGS)
603 {
604 	int err;
605 
606 	err = sysctl_handle_64(oidp, &zfs_multihost_interval, 0, req);
607 	if (err != 0 || req->newptr == NULL)
608 		return (err);
609 
610 	if (spa_mode_global != SPA_MODE_UNINIT)
611 		mmp_signal_all_threads();
612 
613 	return (0);
614 }
615 
616 /* spa.c */
617 
618 extern int zfs_ccw_retry_interval;
619 
620 /* BEGIN CSTYLED */
621 SYSCTL_INT(_vfs_zfs, OID_AUTO, ccw_retry_interval,
622 	CTLFLAG_RWTUN, &zfs_ccw_retry_interval, 0,
623 	"Configuration cache file write, retry after failure, interval"
624 	" (seconds)");
625 /* END CSTYLED */
626 
627 extern uint64_t zfs_max_missing_tvds_cachefile;
628 
629 /* BEGIN CSTYLED */
630 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_cachefile,
631 	CTLFLAG_RWTUN, &zfs_max_missing_tvds_cachefile, 0,
632 	"Allow importing pools with missing top-level vdevs in cache file");
633 /* END CSTYLED */
634 
635 extern uint64_t zfs_max_missing_tvds_scan;
636 
637 /* BEGIN CSTYLED */
638 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_scan,
639 	CTLFLAG_RWTUN, &zfs_max_missing_tvds_scan, 0,
640 	"Allow importing pools with missing top-level vdevs during scan");
641 /* END CSTYLED */
642 
643 /* spa_misc.c */
644 
645 extern int zfs_flags;
646 
647 static int
sysctl_vfs_zfs_debug_flags(SYSCTL_HANDLER_ARGS)648 sysctl_vfs_zfs_debug_flags(SYSCTL_HANDLER_ARGS)
649 {
650 	int err, val;
651 
652 	val = zfs_flags;
653 	err = sysctl_handle_int(oidp, &val, 0, req);
654 	if (err != 0 || req->newptr == NULL)
655 		return (err);
656 
657 	/*
658 	 * ZFS_DEBUG_MODIFY must be enabled prior to boot so all
659 	 * arc buffers in the system have the necessary additional
660 	 * checksum data.  However, it is safe to disable at any
661 	 * time.
662 	 */
663 	if (!(zfs_flags & ZFS_DEBUG_MODIFY))
664 		val &= ~ZFS_DEBUG_MODIFY;
665 	zfs_flags = val;
666 
667 	return (0);
668 }
669 
670 /* BEGIN CSTYLED */
671 SYSCTL_PROC(_vfs_zfs, OID_AUTO, debugflags,
672 	CTLTYPE_UINT | CTLFLAG_MPSAFE | CTLFLAG_RWTUN, NULL, 0,
673 	sysctl_vfs_zfs_debug_flags, "IU", "Debug flags for ZFS testing.");
674 /* END CSTYLED */
675 
676 int
param_set_deadman_synctime(SYSCTL_HANDLER_ARGS)677 param_set_deadman_synctime(SYSCTL_HANDLER_ARGS)
678 {
679 	unsigned long val;
680 	int err;
681 
682 	val = zfs_deadman_synctime_ms;
683 	err = sysctl_handle_64(oidp, &val, 0, req);
684 	if (err != 0 || req->newptr == NULL)
685 		return (err);
686 	zfs_deadman_synctime_ms = val;
687 
688 	spa_set_deadman_synctime(MSEC2NSEC(zfs_deadman_synctime_ms));
689 
690 	return (0);
691 }
692 
693 int
param_set_deadman_ziotime(SYSCTL_HANDLER_ARGS)694 param_set_deadman_ziotime(SYSCTL_HANDLER_ARGS)
695 {
696 	unsigned long val;
697 	int err;
698 
699 	val = zfs_deadman_ziotime_ms;
700 	err = sysctl_handle_64(oidp, &val, 0, req);
701 	if (err != 0 || req->newptr == NULL)
702 		return (err);
703 	zfs_deadman_ziotime_ms = val;
704 
705 	spa_set_deadman_ziotime(MSEC2NSEC(zfs_deadman_synctime_ms));
706 
707 	return (0);
708 }
709 
710 int
param_set_deadman_failmode(SYSCTL_HANDLER_ARGS)711 param_set_deadman_failmode(SYSCTL_HANDLER_ARGS)
712 {
713 	char buf[16];
714 	int rc;
715 
716 	if (req->newptr == NULL)
717 		strlcpy(buf, zfs_deadman_failmode, sizeof (buf));
718 
719 	rc = sysctl_handle_string(oidp, buf, sizeof (buf), req);
720 	if (rc || req->newptr == NULL)
721 		return (rc);
722 	if (strcmp(buf, zfs_deadman_failmode) == 0)
723 		return (0);
724 	if (strcmp(buf, "wait") == 0)
725 		zfs_deadman_failmode = "wait";
726 	if (strcmp(buf, "continue") == 0)
727 		zfs_deadman_failmode = "continue";
728 	if (strcmp(buf, "panic") == 0)
729 		zfs_deadman_failmode = "panic";
730 
731 	return (-param_set_deadman_failmode_common(buf));
732 }
733 
734 int
param_set_slop_shift(SYSCTL_HANDLER_ARGS)735 param_set_slop_shift(SYSCTL_HANDLER_ARGS)
736 {
737 	int val;
738 	int err;
739 
740 	val = spa_slop_shift;
741 	err = sysctl_handle_int(oidp, &val, 0, req);
742 	if (err != 0 || req->newptr == NULL)
743 		return (err);
744 
745 	if (val < 1 || val > 31)
746 		return (EINVAL);
747 
748 	spa_slop_shift = val;
749 
750 	return (0);
751 }
752 
753 /* spacemap.c */
754 
755 extern int space_map_ibs;
756 
757 /* BEGIN CSTYLED */
758 SYSCTL_INT(_vfs_zfs, OID_AUTO, space_map_ibs, CTLFLAG_RWTUN,
759 	&space_map_ibs, 0, "Space map indirect block shift");
760 /* END CSTYLED */
761 
762 
763 /* vdev.c */
764 
765 int
param_set_min_auto_ashift(SYSCTL_HANDLER_ARGS)766 param_set_min_auto_ashift(SYSCTL_HANDLER_ARGS)
767 {
768 	int val;
769 	int err;
770 
771 	val = zfs_vdev_min_auto_ashift;
772 	err = sysctl_handle_int(oidp, &val, 0, req);
773 	if (err != 0 || req->newptr == NULL)
774 		return (SET_ERROR(err));
775 
776 	if (val < ASHIFT_MIN || val > zfs_vdev_max_auto_ashift)
777 		return (SET_ERROR(EINVAL));
778 
779 	zfs_vdev_min_auto_ashift = val;
780 
781 	return (0);
782 }
783 
784 /* BEGIN CSTYLED */
785 SYSCTL_PROC(_vfs_zfs, OID_AUTO, min_auto_ashift,
786 	CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
787 	&zfs_vdev_min_auto_ashift, sizeof (zfs_vdev_min_auto_ashift),
788 	param_set_min_auto_ashift, "IU",
789 	"Min ashift used when creating new top-level vdev. (LEGACY)");
790 /* END CSTYLED */
791 
792 int
param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)793 param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)
794 {
795 	int val;
796 	int err;
797 
798 	val = zfs_vdev_max_auto_ashift;
799 	err = sysctl_handle_int(oidp, &val, 0, req);
800 	if (err != 0 || req->newptr == NULL)
801 		return (SET_ERROR(err));
802 
803 	if (val > ASHIFT_MAX || val < zfs_vdev_min_auto_ashift)
804 		return (SET_ERROR(EINVAL));
805 
806 	zfs_vdev_max_auto_ashift = val;
807 
808 	return (0);
809 }
810 
811 /* BEGIN CSTYLED */
812 SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift,
813 	CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
814 	&zfs_vdev_max_auto_ashift, sizeof (zfs_vdev_max_auto_ashift),
815 	param_set_max_auto_ashift, "IU",
816 	"Max ashift used when optimizing for logical -> physical sector size on"
817 	" new top-level vdevs. (LEGACY)");
818 /* END CSTYLED */
819 
820 /*
821  * Since the DTL space map of a vdev is not expected to have a lot of
822  * entries, we default its block size to 4K.
823  */
824 extern int zfs_vdev_dtl_sm_blksz;
825 
826 /* BEGIN CSTYLED */
827 SYSCTL_INT(_vfs_zfs, OID_AUTO, dtl_sm_blksz,
828 	CTLFLAG_RDTUN, &zfs_vdev_dtl_sm_blksz, 0,
829 	"Block size for DTL space map.  Power of 2 greater than 4096.");
830 /* END CSTYLED */
831 
832 /*
833  * vdev-wide space maps that have lots of entries written to them at
834  * the end of each transaction can benefit from a higher I/O bandwidth
835  * (e.g. vdev_obsolete_sm), thus we default their block size to 128K.
836  */
837 extern int zfs_vdev_standard_sm_blksz;
838 
839 /* BEGIN CSTYLED */
840 SYSCTL_INT(_vfs_zfs, OID_AUTO, standard_sm_blksz,
841 	CTLFLAG_RDTUN, &zfs_vdev_standard_sm_blksz, 0,
842 	"Block size for standard space map.  Power of 2 greater than 4096.");
843 /* END CSTYLED */
844 
845 extern int vdev_validate_skip;
846 
847 /* BEGIN CSTYLED */
848 SYSCTL_INT(_vfs_zfs, OID_AUTO, validate_skip,
849 	CTLFLAG_RDTUN, &vdev_validate_skip, 0,
850 	"Enable to bypass vdev_validate().");
851 /* END CSTYLED */
852 
853 /* vdev_mirror.c */
854 
855 /* vdev_queue.c */
856 
857 extern uint_t zfs_vdev_max_active;
858 
859 /* BEGIN CSTYLED */
860 SYSCTL_UINT(_vfs_zfs, OID_AUTO, top_maxinflight,
861 	CTLFLAG_RWTUN, &zfs_vdev_max_active, 0,
862 	"The maximum number of I/Os of all types active for each device."
863 	" (LEGACY)");
864 /* END CSTYLED */
865 
866 /* zio.c */
867 
868 /* BEGIN CSTYLED */
869 SYSCTL_INT(_vfs_zfs_zio, OID_AUTO, exclude_metadata,
870 	CTLFLAG_RDTUN, &zio_exclude_metadata, 0,
871 	"Exclude metadata buffers from dumps as well");
872 /* END CSTYLED */
873