xref: /freebsd/sys/contrib/openzfs/include/os/linux/kernel/linux/mod_compat.h (revision b1c1ee4429fcca8f69873a8be66184e68e1b19d7)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (C) 2016 Gvozden Neskovic <neskovic@gmail.com>.
25  * Copyright (c) 2020 by Delphix. All rights reserved.
26  */
27 
28 #ifndef _MOD_COMPAT_H
29 #define	_MOD_COMPAT_H
30 
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
33 
34 typedef const struct kernel_param zfs_kernel_param_t;
35 
36 #define	ZMOD_RW 0644
37 #define	ZMOD_RD 0444
38 
39 enum scope_prefix_types {
40 	zfs,
41 	zfs_arc,
42 	zfs_brt,
43 	zfs_condense,
44 	zfs_dbuf,
45 	zfs_dbuf_cache,
46 	zfs_deadman,
47 	zfs_dedup,
48 	zfs_l2arc,
49 	zfs_livelist,
50 	zfs_livelist_condense,
51 	zfs_lua,
52 	zfs_metaslab,
53 	zfs_mg,
54 	zfs_multihost,
55 	zfs_prefetch,
56 	zfs_reconstruct,
57 	zfs_recv,
58 	zfs_send,
59 	zfs_spa,
60 	zfs_trim,
61 	zfs_txg,
62 	zfs_vdev,
63 	zfs_vdev_disk,
64 	zfs_vdev_file,
65 	zfs_vdev_mirror,
66 	zfs_vol,
67 	zfs_vnops,
68 	zfs_zevent,
69 	zfs_zio,
70 	zfs_zil
71 };
72 
73 /*
74  * Our uint64 params are called U64 in part because we had them before Linux
75  * provided ULLONG param ops. Now it does, and we use them, but we retain the
76  * U64 name to keep many existing tunables working without issue.
77  */
78 #define	spl_param_set_u64	param_set_ullong
79 #define	spl_param_get_u64	param_get_ullong
80 #define	spl_param_ops_U64	param_ops_ullong
81 
82 /*
83  * We keep our own names for param ops to make expanding them in
84  * ZFS_MODULE_PARAM easy.
85  */
86 #define	spl_param_ops_INT	param_ops_int
87 #define	spl_param_ops_LONG	param_ops_long
88 #define	spl_param_ops_UINT	param_ops_uint
89 #define	spl_param_ops_ULONG	param_ops_ulong
90 #define	spl_param_ops_STRING	param_ops_charp
91 
92 /*
93  * Declare a module parameter / sysctl node
94  *
95  * "scope_prefix" the part of the sysctl / sysfs tree the node resides under
96  *   (currently a no-op on Linux)
97  * "name_prefix" the part of the variable name that will be excluded from the
98  *   exported names on platforms with a hierarchical namespace
99  * "name" the part of the variable that will be exposed on platforms with a
100  *    hierarchical namespace, or as name_prefix ## name on Linux
101  * "type" the variable type
102  * "perm" the permissions (read/write or read only)
103  * "desc" a brief description of the option
104  *
105  * Examples:
106  * ZFS_MODULE_PARAM(zfs_vdev_mirror, zfs_vdev_mirror_, rotating_inc, UINT,
107  * 	ZMOD_RW, "Rotating media load increment for non-seeking I/O's");
108  * on FreeBSD:
109  *   vfs.zfs.vdev.mirror.rotating_inc
110  * on Linux:
111  *   zfs_vdev_mirror_rotating_inc
112  *
113  * ZFS_MODULE_PARAM(zfs, , dmu_prefetch_max, UINT, ZMOD_RW,
114  * 	"Limit one prefetch call to this size");
115  * on FreeBSD:
116  *   vfs.zfs.dmu_prefetch_max
117  * on Linux:
118  *   dmu_prefetch_max
119  */
120 #define	ZFS_MODULE_PARAM(scope_prefix, name_prefix, name, type, perm, desc) \
121 	_Static_assert( \
122 	    sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
123 	    "" #scope_prefix " size mismatch with enum scope_prefix_types"); \
124 	module_param_cb(name_prefix ## name, &spl_param_ops_ ## type, \
125 	    &name_prefix ## name, perm); \
126 	MODULE_PARM_DESC(name_prefix ## name, desc)
127 
128 /*
129  * Declare a module parameter / sysctl node
130  *
131  * "scope_prefix" the part of the the sysctl / sysfs tree the node resides under
132  *   (currently a no-op on Linux)
133  * "name_prefix" the part of the variable name that will be excluded from the
134  *   exported names on platforms with a hierarchical namespace
135  * "name" the part of the variable that will be exposed on platforms with a
136  *    hierarchical namespace, or as name_prefix ## name on Linux
137  * "setfunc" setter function
138  * "getfunc" getter function
139  * "perm" the permissions (read/write or read only)
140  * "desc" a brief description of the option
141  *
142  * Examples:
143  * ZFS_MODULE_PARAM_CALL(zfs_spa, spa_, slop_shift, param_set_slop_shift,
144  * 	param_get_int, ZMOD_RW, "Reserved free space in pool");
145  * on FreeBSD:
146  *   vfs.zfs.spa_slop_shift
147  * on Linux:
148  *   spa_slop_shift
149  */
150 #define	ZFS_MODULE_PARAM_CALL( \
151     scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \
152 	_Static_assert( \
153 	    sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
154 	    "" #scope_prefix " size mismatch with enum scope_prefix_types"); \
155 	module_param_call(name_prefix ## name, setfunc, getfunc, \
156 	    &name_prefix ## name, perm); \
157 	MODULE_PARM_DESC(name_prefix ## name, desc)
158 
159 /*
160  * As above, but there is no variable with the name name_prefix ## name,
161  * so NULL is passed to module_param_call instead.
162  */
163 #define	ZFS_MODULE_VIRTUAL_PARAM_CALL( \
164     scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \
165 	_Static_assert( \
166 	    sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \
167 	    "" #scope_prefix " size mismatch with enum scope_prefix_types"); \
168 	module_param_call(name_prefix ## name, setfunc, getfunc, NULL, perm); \
169 	MODULE_PARM_DESC(name_prefix ## name, desc)
170 
171 #define	ZFS_MODULE_PARAM_ARGS	const char *buf, zfs_kernel_param_t *kp
172 
173 #endif	/* _MOD_COMPAT_H */
174