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