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 /* 35 * Despite constifying struct kernel_param_ops, some older kernels define a 36 * `__check_old_set_param()` function in their headers that checks for a 37 * non-constified `->set()`. This has long been fixed in Linux mainline, but 38 * since we support older kernels, we workaround it by using a preprocessor 39 * definition to disable it. 40 */ 41 #define __check_old_set_param(_) (0) 42 43 typedef const struct kernel_param zfs_kernel_param_t; 44 45 #define ZMOD_RW 0644 46 #define ZMOD_RD 0444 47 48 enum scope_prefix_types { 49 zfs, 50 zfs_arc, 51 zfs_brt, 52 zfs_condense, 53 zfs_dbuf, 54 zfs_dbuf_cache, 55 zfs_deadman, 56 zfs_dedup, 57 zfs_l2arc, 58 zfs_livelist, 59 zfs_livelist_condense, 60 zfs_lua, 61 zfs_metaslab, 62 zfs_mg, 63 zfs_multihost, 64 zfs_prefetch, 65 zfs_reconstruct, 66 zfs_recv, 67 zfs_send, 68 zfs_spa, 69 zfs_trim, 70 zfs_txg, 71 zfs_vdev, 72 zfs_vdev_disk, 73 zfs_vdev_file, 74 zfs_vdev_mirror, 75 zfs_vnops, 76 zfs_zevent, 77 zfs_zio, 78 zfs_zil 79 }; 80 81 /* 82 * While we define our own s64/u64 types, there is no reason to reimplement the 83 * existing Linux kernel types, so we use the preprocessor to remap our 84 * "custom" implementations to the kernel ones. This is done because the CPP 85 * does not allow us to write conditional definitions. The fourth definition 86 * exists because the CPP will not allow us to replace things like INT with int 87 * before string concatenation. 88 */ 89 90 #define spl_param_set_int param_set_int 91 #define spl_param_get_int param_get_int 92 #define spl_param_ops_int param_ops_int 93 #define spl_param_ops_INT param_ops_int 94 95 #define spl_param_set_long param_set_long 96 #define spl_param_get_long param_get_long 97 #define spl_param_ops_long param_ops_long 98 #define spl_param_ops_LONG param_ops_long 99 100 #define spl_param_set_uint param_set_uint 101 #define spl_param_get_uint param_get_uint 102 #define spl_param_ops_uint param_ops_uint 103 #define spl_param_ops_UINT param_ops_uint 104 105 #define spl_param_set_ulong param_set_ulong 106 #define spl_param_get_ulong param_get_ulong 107 #define spl_param_ops_ulong param_ops_ulong 108 #define spl_param_ops_ULONG param_ops_ulong 109 110 #define spl_param_set_charp param_set_charp 111 #define spl_param_get_charp param_get_charp 112 #define spl_param_ops_charp param_ops_charp 113 #define spl_param_ops_STRING param_ops_charp 114 115 int spl_param_set_s64(const char *val, zfs_kernel_param_t *kp); 116 extern int spl_param_get_s64(char *buffer, zfs_kernel_param_t *kp); 117 extern const struct kernel_param_ops spl_param_ops_s64; 118 #define spl_param_ops_S64 spl_param_ops_s64 119 120 extern int spl_param_set_u64(const char *val, zfs_kernel_param_t *kp); 121 extern int spl_param_get_u64(char *buffer, zfs_kernel_param_t *kp); 122 extern const struct kernel_param_ops spl_param_ops_u64; 123 #define spl_param_ops_U64 spl_param_ops_u64 124 125 /* 126 * Declare a module parameter / sysctl node 127 * 128 * "scope_prefix" the part of the sysctl / sysfs tree the node resides under 129 * (currently a no-op on Linux) 130 * "name_prefix" the part of the variable name that will be excluded from the 131 * exported names on platforms with a hierarchical namespace 132 * "name" the part of the variable that will be exposed on platforms with a 133 * hierarchical namespace, or as name_prefix ## name on Linux 134 * "type" the variable type 135 * "perm" the permissions (read/write or read only) 136 * "desc" a brief description of the option 137 * 138 * Examples: 139 * ZFS_MODULE_PARAM(zfs_vdev_mirror, zfs_vdev_mirror_, rotating_inc, UINT, 140 * ZMOD_RW, "Rotating media load increment for non-seeking I/O's"); 141 * on FreeBSD: 142 * vfs.zfs.vdev.mirror.rotating_inc 143 * on Linux: 144 * zfs_vdev_mirror_rotating_inc 145 * 146 * ZFS_MODULE_PARAM(zfs, , dmu_prefetch_max, UINT, ZMOD_RW, 147 * "Limit one prefetch call to this size"); 148 * on FreeBSD: 149 * vfs.zfs.dmu_prefetch_max 150 * on Linux: 151 * dmu_prefetch_max 152 */ 153 #define ZFS_MODULE_PARAM(scope_prefix, name_prefix, name, type, perm, desc) \ 154 _Static_assert( \ 155 sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \ 156 "" #scope_prefix " size mismatch with enum scope_prefix_types"); \ 157 module_param_cb(name_prefix ## name, &spl_param_ops_ ## type, \ 158 &name_prefix ## name, perm); \ 159 MODULE_PARM_DESC(name_prefix ## name, desc) 160 161 /* 162 * Declare a module parameter / sysctl node 163 * 164 * "scope_prefix" the part of the the sysctl / sysfs tree the node resides under 165 * (currently a no-op on Linux) 166 * "name_prefix" the part of the variable name that will be excluded from the 167 * exported names on platforms with a hierarchical namespace 168 * "name" the part of the variable that will be exposed on platforms with a 169 * hierarchical namespace, or as name_prefix ## name on Linux 170 * "setfunc" setter function 171 * "getfunc" getter function 172 * "perm" the permissions (read/write or read only) 173 * "desc" a brief description of the option 174 * 175 * Examples: 176 * ZFS_MODULE_PARAM_CALL(zfs_spa, spa_, slop_shift, param_set_slop_shift, 177 * param_get_int, ZMOD_RW, "Reserved free space in pool"); 178 * on FreeBSD: 179 * vfs.zfs.spa_slop_shift 180 * on Linux: 181 * spa_slop_shift 182 */ 183 #define ZFS_MODULE_PARAM_CALL( \ 184 scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \ 185 _Static_assert( \ 186 sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \ 187 "" #scope_prefix " size mismatch with enum scope_prefix_types"); \ 188 module_param_call(name_prefix ## name, setfunc, getfunc, \ 189 &name_prefix ## name, perm); \ 190 MODULE_PARM_DESC(name_prefix ## name, desc) 191 192 /* 193 * As above, but there is no variable with the name name_prefix ## name, 194 * so NULL is passed to module_param_call instead. 195 */ 196 #define ZFS_MODULE_VIRTUAL_PARAM_CALL( \ 197 scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \ 198 _Static_assert( \ 199 sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \ 200 "" #scope_prefix " size mismatch with enum scope_prefix_types"); \ 201 module_param_call(name_prefix ## name, setfunc, getfunc, NULL, perm); \ 202 MODULE_PARM_DESC(name_prefix ## name, desc) 203 204 #define ZFS_MODULE_PARAM_ARGS const char *buf, zfs_kernel_param_t *kp 205 206 #endif /* _MOD_COMPAT_H */ 207