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