4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (C) 2016 Gvozden Neskovic <neskovic@gmail.com>.
24 * Copyright (c) 2020 by Delphix. All rights reserved.
30 #include <linux/module.h>
31 #include <linux/moduleparam.h>
34 * Despite constifying struct kernel_param_ops, some older kernels define a
35 * `__check_old_set_param()` function in their headers that checks for a
36 * non-constified `->set()`. This has long been fixed in Linux mainline, but
37 * since we support older kernels, we workaround it by using a preprocessor
38 * definition to disable it.
40 #define __check_old_set_param(_) (0)
42 typedef const struct kernel_param zfs_kernel_param_t
;
47 enum scope_prefix_types
{
58 zfs_livelist_condense
,
81 * While we define our own s64/u64 types, there is no reason to reimplement the
82 * existing Linux kernel types, so we use the preprocessor to remap our
83 * "custom" implementations to the kernel ones. This is done because the CPP
84 * does not allow us to write conditional definitions. The fourth definition
85 * exists because the CPP will not allow us to replace things like INT with int
86 * before string concatenation.
89 #define spl_param_set_int param_set_int
90 #define spl_param_get_int param_get_int
91 #define spl_param_ops_int param_ops_int
92 #define spl_param_ops_INT param_ops_int
94 #define spl_param_set_long param_set_long
95 #define spl_param_get_long param_get_long
96 #define spl_param_ops_long param_ops_long
97 #define spl_param_ops_LONG param_ops_long
99 #define spl_param_set_uint param_set_uint
100 #define spl_param_get_uint param_get_uint
101 #define spl_param_ops_uint param_ops_uint
102 #define spl_param_ops_UINT param_ops_uint
104 #define spl_param_set_ulong param_set_ulong
105 #define spl_param_get_ulong param_get_ulong
106 #define spl_param_ops_ulong param_ops_ulong
107 #define spl_param_ops_ULONG param_ops_ulong
109 #define spl_param_set_charp param_set_charp
110 #define spl_param_get_charp param_get_charp
111 #define spl_param_ops_charp param_ops_charp
112 #define spl_param_ops_STRING param_ops_charp
114 int spl_param_set_s64(const char *val
, zfs_kernel_param_t
*kp
);
115 extern int spl_param_get_s64(char *buffer
, zfs_kernel_param_t
*kp
);
116 extern const struct kernel_param_ops spl_param_ops_s64
;
117 #define spl_param_ops_S64 spl_param_ops_s64
119 extern int spl_param_set_u64(const char *val
, zfs_kernel_param_t
*kp
);
120 extern int spl_param_get_u64(char *buffer
, zfs_kernel_param_t
*kp
);
121 extern const struct kernel_param_ops spl_param_ops_u64
;
122 #define spl_param_ops_U64 spl_param_ops_u64
125 * Declare a module parameter / sysctl node
127 * "scope_prefix" the part of the sysctl / sysfs tree the node resides under
128 * (currently a no-op on Linux)
129 * "name_prefix" the part of the variable name that will be excluded from the
130 * exported names on platforms with a hierarchical namespace
131 * "name" the part of the variable that will be exposed on platforms with a
132 * hierarchical namespace, or as name_prefix ## name on Linux
133 * "type" the variable type
134 * "perm" the permissions (read/write or read only)
135 * "desc" a brief description of the option
138 * ZFS_MODULE_PARAM(zfs_vdev_mirror, zfs_vdev_mirror_, rotating_inc, UINT,
139 * ZMOD_RW, "Rotating media load increment for non-seeking I/O's");
141 * vfs.zfs.vdev.mirror.rotating_inc
143 * zfs_vdev_mirror_rotating_inc
145 * ZFS_MODULE_PARAM(zfs, , dmu_prefetch_max, UINT, ZMOD_RW,
146 * "Limit one prefetch call to this size");
148 * vfs.zfs.dmu_prefetch_max
152 #define ZFS_MODULE_PARAM(scope_prefix, name_prefix, name, type, perm, desc) \
154 sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
155 "" #scope_prefix " size mismatch with enum scope_prefix_types"); \
156 module_param_cb(name_prefix ## name, &spl_param_ops_ ## type, \
157 &name_prefix ## name, perm); \
158 MODULE_PARM_DESC(name_prefix ## name, desc)
161 * Declare a module parameter / sysctl node
163 * "scope_prefix" the part of the the sysctl / sysfs tree the node resides under
164 * (currently a no-op on Linux)
165 * "name_prefix" the part of the variable name that will be excluded from the
166 * exported names on platforms with a hierarchical namespace
167 * "name" the part of the variable that will be exposed on platforms with a
168 * hierarchical namespace, or as name_prefix ## name on Linux
169 * "setfunc" setter function
170 * "getfunc" getter function
171 * "perm" the permissions (read/write or read only)
172 * "desc" a brief description of the option
175 * ZFS_MODULE_PARAM_CALL(zfs_spa, spa_, slop_shift, param_set_slop_shift,
176 * param_get_int, ZMOD_RW, "Reserved free space in pool");
178 * vfs.zfs.spa_slop_shift
182 #define ZFS_MODULE_PARAM_CALL( \
183 scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \
185 sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
186 "" #scope_prefix " size mismatch with enum scope_prefix_types"); \
187 module_param_call(name_prefix ## name, setfunc, getfunc, \
188 &name_prefix ## name, perm); \
189 MODULE_PARM_DESC(name_prefix ## name, desc)
192 * As above, but there is no variable with the name name_prefix ## name,
193 * so NULL is passed to module_param_call instead.
195 #define ZFS_MODULE_VIRTUAL_PARAM_CALL( \
196 scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \
198 sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
199 "" #scope_prefix " size mismatch with enum scope_prefix_types"); \
200 module_param_call(name_prefix ## name, setfunc, getfunc, NULL, perm); \
201 MODULE_PARM_DESC(name_prefix ## name, desc)
203 #define ZFS_MODULE_PARAM_ARGS const char *buf, zfs_kernel_param_t *kp
205 #endif /* _MOD_COMPAT_H */