xref: /freebsd-src/sys/contrib/openzfs/module/os/freebsd/zfs/sysctl_os.c (revision c14e17a49cdd72c8c05d12fbec631c409b14b9cb)
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/dmu.h>
57 #include <sys/dsl_dir.h>
58 #include <sys/dsl_dataset.h>
59 #include <sys/dsl_prop.h>
60 #include <sys/dsl_deleg.h>
61 #include <sys/dmu_objset.h>
62 #include <sys/dmu_impl.h>
63 #include <sys/dmu_tx.h>
64 #include <sys/sunddi.h>
65 #include <sys/policy.h>
66 #include <sys/zone.h>
67 #include <sys/nvpair.h>
68 #include <sys/mount.h>
69 #include <sys/taskqueue.h>
70 #include <sys/sdt.h>
71 #include <sys/fs/zfs.h>
72 #include <sys/zfs_ctldir.h>
73 #include <sys/zfs_dir.h>
74 #include <sys/zfs_onexit.h>
75 #include <sys/zvol.h>
76 #include <sys/dsl_scan.h>
77 #include <sys/dmu_objset.h>
78 #include <sys/dmu_send.h>
79 #include <sys/dsl_destroy.h>
80 #include <sys/dsl_bookmark.h>
81 #include <sys/dsl_userhold.h>
82 #include <sys/zfeature.h>
83 #include <sys/zcp.h>
84 #include <sys/zio_checksum.h>
85 #include <sys/vdev_removal.h>
86 #include <sys/dsl_crypt.h>
87 
88 #include <sys/zfs_ioctl_compat.h>
89 #include <sys/zfs_context.h>
90 
91 #include <sys/arc_impl.h>
92 #include <sys/dsl_pool.h>
93 
94 
95 /* BEGIN CSTYLED */
96 SYSCTL_DECL(_vfs_zfs);
97 SYSCTL_NODE(_vfs_zfs, OID_AUTO, arc, CTLFLAG_RW, 0, "ZFS adaptive replacement cache");
98 SYSCTL_NODE(_vfs_zfs, OID_AUTO, condense, CTLFLAG_RW, 0, "ZFS condense");
99 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dbuf, CTLFLAG_RW, 0, "ZFS disk buf cache");
100 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dbuf_cache, CTLFLAG_RW, 0, "ZFS disk buf cache");
101 SYSCTL_NODE(_vfs_zfs, OID_AUTO, deadman, CTLFLAG_RW, 0, "ZFS deadman");
102 SYSCTL_NODE(_vfs_zfs, OID_AUTO, dedup, CTLFLAG_RW, 0, "ZFS dedup");
103 SYSCTL_NODE(_vfs_zfs, OID_AUTO, l2arc, CTLFLAG_RW, 0, "ZFS l2arc");
104 SYSCTL_NODE(_vfs_zfs, OID_AUTO, livelist, CTLFLAG_RW, 0, "ZFS livelist");
105 SYSCTL_NODE(_vfs_zfs, OID_AUTO, lua, CTLFLAG_RW, 0, "ZFS lua");
106 SYSCTL_NODE(_vfs_zfs, OID_AUTO, metaslab, CTLFLAG_RW, 0, "ZFS metaslab");
107 SYSCTL_NODE(_vfs_zfs, OID_AUTO, mg, CTLFLAG_RW, 0, "ZFS metaslab group");
108 SYSCTL_NODE(_vfs_zfs, OID_AUTO, multihost, CTLFLAG_RW, 0, "ZFS multihost protection");
109 SYSCTL_NODE(_vfs_zfs, OID_AUTO, prefetch, CTLFLAG_RW, 0, "ZFS prefetch");
110 SYSCTL_NODE(_vfs_zfs, OID_AUTO, reconstruct, CTLFLAG_RW, 0, "ZFS reconstruct");
111 SYSCTL_NODE(_vfs_zfs, OID_AUTO, recv, CTLFLAG_RW, 0, "ZFS receive");
112 SYSCTL_NODE(_vfs_zfs, OID_AUTO, send, CTLFLAG_RW, 0, "ZFS send");
113 SYSCTL_NODE(_vfs_zfs, OID_AUTO, spa, CTLFLAG_RW, 0, "ZFS space allocation");
114 SYSCTL_NODE(_vfs_zfs, OID_AUTO, trim, CTLFLAG_RW, 0, "ZFS TRIM");
115 SYSCTL_NODE(_vfs_zfs, OID_AUTO, txg, CTLFLAG_RW, 0, "ZFS transaction group");
116 SYSCTL_NODE(_vfs_zfs, OID_AUTO, vdev, CTLFLAG_RW, 0, "ZFS VDEV");
117 SYSCTL_NODE(_vfs_zfs, OID_AUTO, vnops, CTLFLAG_RW, 0, "ZFS VNOPS");
118 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zevent, CTLFLAG_RW, 0, "ZFS event");
119 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zil, CTLFLAG_RW, 0, "ZFS ZIL");
120 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zio, CTLFLAG_RW, 0, "ZFS ZIO");
121 
122 SYSCTL_NODE(_vfs_zfs_livelist, OID_AUTO, condense, CTLFLAG_RW, 0,
123     "ZFS livelist condense");
124 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, cache, CTLFLAG_RW, 0, "ZFS VDEV Cache");
125 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, file, CTLFLAG_RW, 0, "ZFS VDEV file");
126 SYSCTL_NODE(_vfs_zfs_vdev, OID_AUTO, mirror, CTLFLAG_RD, 0,
127     "ZFS VDEV mirror");
128 
129 SYSCTL_DECL(_vfs_zfs_version);
130 SYSCTL_CONST_STRING(_vfs_zfs_version, OID_AUTO, module, CTLFLAG_RD,
131     (ZFS_META_VERSION "-" ZFS_META_RELEASE), "OpenZFS module version");
132 
133 extern arc_state_t ARC_anon;
134 extern arc_state_t ARC_mru;
135 extern arc_state_t ARC_mru_ghost;
136 extern arc_state_t ARC_mfu;
137 extern arc_state_t ARC_mfu_ghost;
138 extern arc_state_t ARC_l2c_only;
139 
140 /*
141  * minimum lifespan of a prefetch block in clock ticks
142  * (initialized in arc_init())
143  */
144 
145 /* arc.c */
146 
147 /* legacy compat */
148 extern uint64_t l2arc_write_max;	/* def max write size */
149 extern uint64_t l2arc_write_boost;	/* extra warmup write */
150 extern uint64_t l2arc_headroom;		/* # of dev writes */
151 extern uint64_t l2arc_headroom_boost;
152 extern uint64_t l2arc_feed_secs;	/* interval seconds */
153 extern uint64_t l2arc_feed_min_ms;	/* min interval msecs */
154 extern int l2arc_noprefetch;			/* don't cache prefetch bufs */
155 extern int l2arc_feed_again;			/* turbo warmup */
156 extern int l2arc_norw;			/* no reads during writes */
157 
158 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_write_max, CTLFLAG_RW,
159     &l2arc_write_max, 0, "max write size (LEGACY)");
160 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_write_boost, CTLFLAG_RW,
161     &l2arc_write_boost, 0, "extra write during warmup (LEGACY)");
162 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_headroom, CTLFLAG_RW,
163     &l2arc_headroom, 0, "number of dev writes (LEGACY)");
164 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_feed_secs, CTLFLAG_RW,
165     &l2arc_feed_secs, 0, "interval seconds (LEGACY)");
166 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2arc_feed_min_ms, CTLFLAG_RW,
167     &l2arc_feed_min_ms, 0, "min interval milliseconds (LEGACY)");
168 
169 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_noprefetch, CTLFLAG_RW,
170     &l2arc_noprefetch, 0, "don't cache prefetch bufs (LEGACY)");
171 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_feed_again, CTLFLAG_RW,
172     &l2arc_feed_again, 0, "turbo warmup (LEGACY)");
173 SYSCTL_INT(_vfs_zfs, OID_AUTO, l2arc_norw, CTLFLAG_RW,
174     &l2arc_norw, 0, "no reads during writes (LEGACY)");
175 #if 0
176 extern int zfs_compressed_arc_enabled;
177 SYSCTL_INT(_vfs_zfs, OID_AUTO, compressed_arc_enabled, CTLFLAG_RW,
178     &zfs_compressed_arc_enabled, 1, "compressed arc buffers (LEGACY)");
179 #endif
180 
181 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_size, CTLFLAG_RD,
182     &ARC_anon.arcs_size.rc_count, 0, "size of anonymous state");
183 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_metadata_esize, CTLFLAG_RD,
184     &ARC_anon.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
185     "size of anonymous state");
186 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, anon_data_esize, CTLFLAG_RD,
187     &ARC_anon.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
188     "size of anonymous state");
189 
190 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_size, CTLFLAG_RD,
191     &ARC_mru.arcs_size.rc_count, 0, "size of mru state");
192 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_metadata_esize, CTLFLAG_RD,
193     &ARC_mru.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
194     "size of metadata in mru state");
195 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_data_esize, CTLFLAG_RD,
196     &ARC_mru.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
197     "size of data in mru state");
198 
199 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_size, CTLFLAG_RD,
200     &ARC_mru_ghost.arcs_size.rc_count, 0, "size of mru ghost state");
201 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_metadata_esize, CTLFLAG_RD,
202     &ARC_mru_ghost.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
203     "size of metadata in mru ghost state");
204 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mru_ghost_data_esize, CTLFLAG_RD,
205     &ARC_mru_ghost.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
206     "size of data in mru ghost state");
207 
208 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_size, CTLFLAG_RD,
209     &ARC_mfu.arcs_size.rc_count, 0, "size of mfu state");
210 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_metadata_esize, CTLFLAG_RD,
211     &ARC_mfu.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
212     "size of metadata in mfu state");
213 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_data_esize, CTLFLAG_RD,
214     &ARC_mfu.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
215     "size of data in mfu state");
216 
217 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_size, CTLFLAG_RD,
218     &ARC_mfu_ghost.arcs_size.rc_count, 0, "size of mfu ghost state");
219 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_metadata_esize, CTLFLAG_RD,
220     &ARC_mfu_ghost.arcs_esize[ARC_BUFC_METADATA].rc_count, 0,
221     "size of metadata in mfu ghost state");
222 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, mfu_ghost_data_esize, CTLFLAG_RD,
223     &ARC_mfu_ghost.arcs_esize[ARC_BUFC_DATA].rc_count, 0,
224     "size of data in mfu ghost state");
225 
226 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, l2c_only_size, CTLFLAG_RD,
227     &ARC_l2c_only.arcs_size.rc_count, 0, "size of mru state");
228 
229 static int
230 sysctl_vfs_zfs_arc_no_grow_shift(SYSCTL_HANDLER_ARGS)
231 {
232 	int err, val;
233 
234 	val = arc_no_grow_shift;
235 	err = sysctl_handle_int(oidp, &val, 0, req);
236 	if (err != 0 || req->newptr == NULL)
237 		return (err);
238 
239         if (val < 0 || val >= arc_shrink_shift)
240 		return (EINVAL);
241 
242 	arc_no_grow_shift = val;
243 	return (0);
244 }
245 
246 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_no_grow_shift,
247     CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, NULL, sizeof (int),
248     sysctl_vfs_zfs_arc_no_grow_shift, "I",
249     "log2(fraction of ARC which must be free to allow growing)");
250 
251 int
252 param_set_arc_long(SYSCTL_HANDLER_ARGS)
253 {
254 	int err;
255 
256 	err = sysctl_handle_long(oidp, arg1, 0, req);
257 	if (err != 0 || req->newptr == NULL)
258 		return (err);
259 
260 	arc_tuning_update(B_TRUE);
261 
262 	return (0);
263 }
264 
265 int
266 param_set_arc_int(SYSCTL_HANDLER_ARGS)
267 {
268 	int err;
269 
270 	err = sysctl_handle_int(oidp, arg1, 0, req);
271 	if (err != 0 || req->newptr == NULL)
272 		return (err);
273 
274 	arc_tuning_update(B_TRUE);
275 
276 	return (0);
277 }
278 
279 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_min,
280     CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
281     &zfs_arc_min, sizeof (zfs_arc_min), param_set_arc_long, "LU",
282     "min arc size (LEGACY)");
283 SYSCTL_PROC(_vfs_zfs, OID_AUTO, arc_max,
284     CTLTYPE_ULONG | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
285     &zfs_arc_max, sizeof (zfs_arc_max), param_set_arc_long, "LU",
286     "max arc size (LEGACY)");
287 
288 /* dbuf.c */
289 
290 
291 /* dmu.c */
292 
293 /* dmu_zfetch.c */
294 SYSCTL_NODE(_vfs_zfs, OID_AUTO, zfetch, CTLFLAG_RW, 0, "ZFS ZFETCH (LEGACY)");
295 
296 /* max bytes to prefetch per stream (default 8MB) */
297 extern uint32_t	zfetch_max_distance;
298 SYSCTL_UINT(_vfs_zfs_zfetch, OID_AUTO, max_distance, CTLFLAG_RWTUN,
299     &zfetch_max_distance, 0, "Max bytes to prefetch per stream (LEGACY)");
300 
301 /* max bytes to prefetch indirects for per stream (default 64MB) */
302 extern uint32_t	zfetch_max_idistance;
303 SYSCTL_UINT(_vfs_zfs_zfetch, OID_AUTO, max_idistance, CTLFLAG_RWTUN,
304     &zfetch_max_idistance, 0,
305     "Max bytes to prefetch indirects for per stream (LEGACY)");
306 
307 /* dsl_pool.c */
308 
309 /* dnode.c */
310 extern int zfs_default_bs;
311 SYSCTL_INT(_vfs_zfs, OID_AUTO, default_bs, CTLFLAG_RWTUN,
312     &zfs_default_bs, 0, "Default dnode block shift");
313 
314 extern int zfs_default_ibs;
315 SYSCTL_INT(_vfs_zfs, OID_AUTO, default_ibs, CTLFLAG_RWTUN,
316     &zfs_default_ibs, 0, "Default dnode indirect block shift");
317 
318 
319 /* dsl_scan.c */
320 
321 /* metaslab.c */
322 
323 /*
324  * In pools where the log space map feature is not enabled we touch
325  * multiple metaslabs (and their respective space maps) with each
326  * transaction group. Thus, we benefit from having a small space map
327  * block size since it allows us to issue more I/O operations scattered
328  * around the disk. So a sane default for the space map block size
329  * is 8~16K.
330  */
331 extern int zfs_metaslab_sm_blksz_no_log;
332 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, sm_blksz_no_log, CTLFLAG_RDTUN,
333     &zfs_metaslab_sm_blksz_no_log, 0,
334     "Block size for space map in pools with log space map disabled.  "
335     "Power of 2 and greater than 4096.");
336 
337 /*
338  * When the log space map feature is enabled, we accumulate a lot of
339  * changes per metaslab that are flushed once in a while so we benefit
340  * from a bigger block size like 128K for the metaslab space maps.
341  */
342 extern int zfs_metaslab_sm_blksz_with_log;
343 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, sm_blksz_with_log, CTLFLAG_RDTUN,
344     &zfs_metaslab_sm_blksz_with_log, 0,
345     "Block size for space map in pools with log space map enabled.  "
346     "Power of 2 and greater than 4096.");
347 
348 /*
349  * The in-core space map representation is more compact than its on-disk form.
350  * The zfs_condense_pct determines how much more compact the in-core
351  * space map representation must be before we compact it on-disk.
352  * Values should be greater than or equal to 100.
353  */
354 extern int zfs_condense_pct;
355 SYSCTL_INT(_vfs_zfs, OID_AUTO, condense_pct, CTLFLAG_RWTUN,
356     &zfs_condense_pct, 0,
357     "Condense on-disk spacemap when it is more than this many percents"
358     " of in-memory counterpart");
359 
360 extern int zfs_remove_max_segment;
361 SYSCTL_INT(_vfs_zfs, OID_AUTO, remove_max_segment, CTLFLAG_RWTUN,
362     &zfs_remove_max_segment, 0, "Largest contiguous segment ZFS will attempt to"
363     " allocate when removing a device");
364 
365 extern int zfs_removal_suspend_progress;
366 SYSCTL_INT(_vfs_zfs, OID_AUTO, removal_suspend_progress, CTLFLAG_RWTUN,
367     &zfs_removal_suspend_progress, 0, "Ensures certain actions can happen while"
368     " in the middle of a removal");
369 
370 
371 /*
372  * Minimum size which forces the dynamic allocator to change
373  * it's allocation strategy.  Once the space map cannot satisfy
374  * an allocation of this size then it switches to using more
375  * aggressive strategy (i.e search by size rather than offset).
376  */
377 extern uint64_t metaslab_df_alloc_threshold;
378 SYSCTL_QUAD(_vfs_zfs_metaslab, OID_AUTO, df_alloc_threshold, CTLFLAG_RWTUN,
379     &metaslab_df_alloc_threshold, 0,
380     "Minimum size which forces the dynamic allocator to change it's allocation strategy");
381 
382 /*
383  * The minimum free space, in percent, which must be available
384  * in a space map to continue allocations in a first-fit fashion.
385  * Once the space map's free space drops below this level we dynamically
386  * switch to using best-fit allocations.
387  */
388 extern int metaslab_df_free_pct;
389 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, df_free_pct, CTLFLAG_RWTUN,
390     &metaslab_df_free_pct, 0,
391     "The minimum free space, in percent, which must be available in a "
392     "space map to continue allocations in a first-fit fashion");
393 
394 /*
395  * Percentage of all cpus that can be used by the metaslab taskq.
396  */
397 extern int metaslab_load_pct;
398 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, load_pct, CTLFLAG_RWTUN,
399     &metaslab_load_pct, 0,
400     "Percentage of cpus that can be used by the metaslab taskq");
401 
402 /*
403  * Max number of metaslabs per group to preload.
404  */
405 extern int metaslab_preload_limit;
406 SYSCTL_INT(_vfs_zfs_metaslab, OID_AUTO, preload_limit, CTLFLAG_RWTUN,
407     &metaslab_preload_limit, 0,
408     "Max number of metaslabs per group to preload");
409 
410 /* refcount.c */
411 extern int reference_tracking_enable;
412 SYSCTL_INT(_vfs_zfs, OID_AUTO, reference_tracking_enable, CTLFLAG_RDTUN,
413     &reference_tracking_enable, 0,
414     "Track reference holders to refcount_t objects, used mostly by ZFS");
415 
416 /* spa.c */
417 extern int zfs_ccw_retry_interval;
418 SYSCTL_INT(_vfs_zfs, OID_AUTO, ccw_retry_interval, CTLFLAG_RWTUN,
419     &zfs_ccw_retry_interval, 0,
420     "Configuration cache file write, retry after failure, interval (seconds)");
421 
422 extern uint64_t zfs_max_missing_tvds_cachefile;
423 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_cachefile, CTLFLAG_RWTUN,
424     &zfs_max_missing_tvds_cachefile, 0,
425     "allow importing pools with missing top-level vdevs in cache file");
426 
427 extern uint64_t zfs_max_missing_tvds_scan;
428 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, max_missing_tvds_scan, CTLFLAG_RWTUN,
429     &zfs_max_missing_tvds_scan, 0,
430     "allow importing pools with missing top-level vdevs during scan");
431 
432 /* spa_misc.c */
433 extern int zfs_flags;
434 static int
435 sysctl_vfs_zfs_debug_flags(SYSCTL_HANDLER_ARGS)
436 {
437 	int err, val;
438 
439 	val = zfs_flags;
440 	err = sysctl_handle_int(oidp, &val, 0, req);
441 	if (err != 0 || req->newptr == NULL)
442 		return (err);
443 
444 	/*
445 	 * ZFS_DEBUG_MODIFY must be enabled prior to boot so all
446 	 * arc buffers in the system have the necessary additional
447 	 * checksum data.  However, it is safe to disable at any
448 	 * time.
449 	 */
450 	if (!(zfs_flags & ZFS_DEBUG_MODIFY))
451 		val &= ~ZFS_DEBUG_MODIFY;
452 	zfs_flags = val;
453 
454 	return (0);
455 }
456 
457 SYSCTL_PROC(_vfs_zfs, OID_AUTO, debugflags,
458     CTLTYPE_UINT | CTLFLAG_MPSAFE | CTLFLAG_RWTUN, NULL, 0,
459     sysctl_vfs_zfs_debug_flags, "IU", "Debug flags for ZFS testing.");
460 
461 int
462 param_set_deadman_synctime(SYSCTL_HANDLER_ARGS)
463 {
464 	unsigned long val;
465 	int err;
466 
467 	val = zfs_deadman_synctime_ms;
468 	err = sysctl_handle_long(oidp, &val, 0, req);
469 	if (err != 0 || req->newptr == NULL)
470 		return (err);
471 	zfs_deadman_synctime_ms = val;
472 
473 	spa_set_deadman_synctime(MSEC2NSEC(zfs_deadman_synctime_ms));
474 
475 	return (0);
476 }
477 
478 int
479 param_set_deadman_ziotime(SYSCTL_HANDLER_ARGS)
480 {
481 	unsigned long val;
482 	int err;
483 
484 	val = zfs_deadman_ziotime_ms;
485 	err = sysctl_handle_long(oidp, &val, 0, req);
486 	if (err != 0 || req->newptr == NULL)
487 		return (err);
488 	zfs_deadman_ziotime_ms = val;
489 
490 	spa_set_deadman_ziotime(MSEC2NSEC(zfs_deadman_synctime_ms));
491 
492 	return (0);
493 }
494 
495 int
496 param_set_deadman_failmode(SYSCTL_HANDLER_ARGS)
497 {
498 	char buf[16];
499 	int rc;
500 
501 	if (req->newptr == NULL)
502 		strlcpy(buf, zfs_deadman_failmode, sizeof (buf));
503 
504 	rc = sysctl_handle_string(oidp, buf, sizeof (buf), req);
505 	if (rc || req->newptr == NULL)
506 		return (rc);
507 	if (strcmp(buf, zfs_deadman_failmode) == 0)
508 		return (0);
509 	if (!strcmp(buf,  "wait"))
510 		zfs_deadman_failmode = "wait";
511 	if (!strcmp(buf,  "continue"))
512 		zfs_deadman_failmode = "continue";
513 	if (!strcmp(buf,  "panic"))
514 		zfs_deadman_failmode = "panic";
515 
516 	return (-param_set_deadman_failmode_common(buf));
517 }
518 
519 
520 /* spacemap.c */
521 extern int space_map_ibs;
522 SYSCTL_INT(_vfs_zfs, OID_AUTO, space_map_ibs, CTLFLAG_RWTUN,
523     &space_map_ibs, 0, "Space map indirect block shift");
524 
525 
526 /* vdev.c */
527 int
528 param_set_min_auto_ashift(SYSCTL_HANDLER_ARGS)
529 {
530 	uint64_t val;
531 	int err;
532 
533 	val = zfs_vdev_min_auto_ashift;
534 	err = sysctl_handle_64(oidp, &val, 0, req);
535 	if (err != 0 || req->newptr == NULL)
536 		return (SET_ERROR(err));
537 
538 	if (val < ASHIFT_MIN || val > zfs_vdev_max_auto_ashift)
539 		return (SET_ERROR(EINVAL));
540 
541 	zfs_vdev_min_auto_ashift = val;
542 
543 	return (0);
544 }
545 
546 int
547 param_set_max_auto_ashift(SYSCTL_HANDLER_ARGS)
548 {
549 	uint64_t val;
550 	int err;
551 
552 	val = zfs_vdev_max_auto_ashift;
553 	err = sysctl_handle_64(oidp, &val, 0, req);
554 	if (err != 0 || req->newptr == NULL)
555 		return (SET_ERROR(err));
556 
557 	if (val > ASHIFT_MAX || val < zfs_vdev_min_auto_ashift)
558 		return (SET_ERROR(EINVAL));
559 
560 	zfs_vdev_max_auto_ashift = val;
561 
562 	return (0);
563 }
564 
565 SYSCTL_PROC(_vfs_zfs, OID_AUTO, min_auto_ashift,
566     CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
567     &zfs_vdev_min_auto_ashift, sizeof (zfs_vdev_min_auto_ashift),
568     param_set_min_auto_ashift, "QU",
569     "Min ashift used when creating new top-level vdev. (LEGACY)");
570 SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift,
571     CTLTYPE_U64 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
572     &zfs_vdev_max_auto_ashift, sizeof (zfs_vdev_max_auto_ashift),
573     param_set_max_auto_ashift, "QU",
574     "Max ashift used when optimizing for logical -> physical sector size on "
575     "new top-level vdevs. (LEGACY)");
576 
577 /*
578  * Since the DTL space map of a vdev is not expected to have a lot of
579  * entries, we default its block size to 4K.
580  */
581 extern int zfs_vdev_dtl_sm_blksz;
582 SYSCTL_INT(_vfs_zfs, OID_AUTO, dtl_sm_blksz, CTLFLAG_RDTUN,
583     &zfs_vdev_dtl_sm_blksz, 0,
584     "Block size for DTL space map.  Power of 2 and greater than 4096.");
585 
586 /*
587  * vdev-wide space maps that have lots of entries written to them at
588  * the end of each transaction can benefit from a higher I/O bandwidth
589  * (e.g. vdev_obsolete_sm), thus we default their block size to 128K.
590  */
591 extern int zfs_vdev_standard_sm_blksz;
592 SYSCTL_INT(_vfs_zfs, OID_AUTO, standard_sm_blksz, CTLFLAG_RDTUN,
593     &zfs_vdev_standard_sm_blksz, 0,
594     "Block size for standard space map.  Power of 2 and greater than 4096.");
595 
596 extern int vdev_validate_skip;
597 SYSCTL_INT(_vfs_zfs, OID_AUTO, validate_skip, CTLFLAG_RDTUN,
598     &vdev_validate_skip, 0,
599     "Enable to bypass vdev_validate().");
600 
601 
602 /* vdev_cache.c */
603 
604 /* vdev_mirror.c */
605 /*
606  * The load configuration settings below are tuned by default for
607  * the case where all devices are of the same rotational type.
608  *
609  * If there is a mixture of rotating and non-rotating media, setting
610  * non_rotating_seek_inc to 0 may well provide better results as it
611  * will direct more reads to the non-rotating vdevs which are more
612  * likely to have a higher performance.
613  */
614 
615 
616 /* vdev_queue.c */
617 #define	ZFS_VDEV_QUEUE_KNOB_MIN(name)					\
618 extern uint32_t zfs_vdev_ ## name ## _min_active;				\
619 SYSCTL_UINT(_vfs_zfs_vdev, OID_AUTO, name ## _min_active, CTLFLAG_RWTUN,\
620     &zfs_vdev_ ## name ## _min_active, 0,				\
621     "Initial number of I/O requests of type " #name			\
622     " active for each device");
623 
624 #define	ZFS_VDEV_QUEUE_KNOB_MAX(name)					\
625 extern uint32_t zfs_vdev_ ## name ## _max_active;				\
626 SYSCTL_UINT(_vfs_zfs_vdev, OID_AUTO, name ## _max_active, CTLFLAG_RWTUN, \
627     &zfs_vdev_ ## name ## _max_active, 0,				\
628     "Maximum number of I/O requests of type " #name			\
629     " active for each device");
630 
631 
632 #undef ZFS_VDEV_QUEUE_KNOB
633 
634 extern uint32_t zfs_vdev_max_active;
635 SYSCTL_UINT(_vfs_zfs, OID_AUTO, top_maxinflight, CTLFLAG_RWTUN,
636     &zfs_vdev_max_active, 0,
637     "The maximum number of I/Os of all types active for each device. (LEGACY)");
638 
639 extern int zfs_vdev_def_queue_depth;
640 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, def_queue_depth, CTLFLAG_RWTUN,
641     &zfs_vdev_def_queue_depth, 0,
642     "Default queue depth for each allocator");
643 
644 /*extern uint64_t zfs_multihost_history;
645 SYSCTL_UQUAD(_vfs_zfs, OID_AUTO, multihost_history, CTLFLAG_RWTUN,
646     &zfs_multihost_history, 0,
647     "Historical staticists for the last N multihost updates");*/
648 
649 #ifdef notyet
650 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, trim_on_init, CTLFLAG_RW,
651     &vdev_trim_on_init, 0, "Enable/disable full vdev trim on initialisation");
652 #endif
653 
654 
655 /* zio.c */
656 #if defined(__LP64__)
657 int zio_use_uma = 1;
658 #else
659 int zio_use_uma = 0;
660 #endif
661 
662 SYSCTL_INT(_vfs_zfs_zio, OID_AUTO, use_uma, CTLFLAG_RDTUN, &zio_use_uma, 0,
663     "Use uma(9) for ZIO allocations");
664 SYSCTL_INT(_vfs_zfs_zio, OID_AUTO, exclude_metadata, CTLFLAG_RDTUN, &zio_exclude_metadata, 0,
665     "Exclude metadata buffers from dumps as well");
666 
667 int
668 param_set_slop_shift(SYSCTL_HANDLER_ARGS)
669 {
670 	int val;
671 	int err;
672 
673 	val = *(int *)arg1;
674 
675 	err = sysctl_handle_int(oidp, &val, 0, req);
676 	if (err != 0 || req->newptr == NULL)
677 		return (err);
678 
679 	if (val < 1 || val > 31)
680 		return (EINVAL);
681 
682 	*(int *)arg1 = val;
683 
684 	return (0);
685 }
686 
687 int
688 param_set_multihost_interval(SYSCTL_HANDLER_ARGS)
689 {
690 	int err;
691 
692 	err = sysctl_handle_long(oidp, arg1, 0, req);
693 	if (err != 0 || req->newptr == NULL)
694 		return (err);
695 
696 	if (spa_mode_global != SPA_MODE_UNINIT)
697 		mmp_signal_all_threads();
698 
699 	return (0);
700 }
701