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