1eda14cbcSMatt Macy /* 2eda14cbcSMatt Macy * CDDL HEADER START 3eda14cbcSMatt Macy * 4eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 5eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 6eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 7eda14cbcSMatt Macy * 8eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0. 10eda14cbcSMatt Macy * See the License for the specific language governing permissions 11eda14cbcSMatt Macy * and limitations under the License. 12eda14cbcSMatt Macy * 13eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 14eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 16eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 17eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 18eda14cbcSMatt Macy * 19eda14cbcSMatt Macy * CDDL HEADER END 20eda14cbcSMatt Macy */ 21eda14cbcSMatt Macy 22eda14cbcSMatt Macy /* 23eda14cbcSMatt Macy * Copyright (C) 2016 Gvozden Neskovic <neskovic@gmail.com>. 242c48331dSMatt Macy * Copyright (c) 2020 by Delphix. All rights reserved. 25eda14cbcSMatt Macy */ 26eda14cbcSMatt Macy 27eda14cbcSMatt Macy #ifndef _MOD_COMPAT_H 28eda14cbcSMatt Macy #define _MOD_COMPAT_H 29eda14cbcSMatt Macy 30eda14cbcSMatt Macy #include <linux/module.h> 31eda14cbcSMatt Macy #include <linux/moduleparam.h> 32eda14cbcSMatt Macy 33dbd5678dSMartin Matuska /* 34dbd5678dSMartin Matuska * Despite constifying struct kernel_param_ops, some older kernels define a 35dbd5678dSMartin Matuska * `__check_old_set_param()` function in their headers that checks for a 36dbd5678dSMartin Matuska * non-constified `->set()`. This has long been fixed in Linux mainline, but 37dbd5678dSMartin Matuska * since we support older kernels, we workaround it by using a preprocessor 38dbd5678dSMartin Matuska * definition to disable it. 39dbd5678dSMartin Matuska */ 40dbd5678dSMartin Matuska #define __check_old_set_param(_) (0) 41dbd5678dSMartin Matuska 42eda14cbcSMatt Macy typedef const struct kernel_param zfs_kernel_param_t; 43eda14cbcSMatt Macy 44eda14cbcSMatt Macy #define ZMOD_RW 0644 45eda14cbcSMatt Macy #define ZMOD_RD 0444 46eda14cbcSMatt Macy 47eda14cbcSMatt Macy enum scope_prefix_types { 48eda14cbcSMatt Macy zfs, 49eda14cbcSMatt Macy zfs_arc, 502a58b312SMartin Matuska zfs_brt, 51eda14cbcSMatt Macy zfs_condense, 52eda14cbcSMatt Macy zfs_dbuf, 53eda14cbcSMatt Macy zfs_dbuf_cache, 54eda14cbcSMatt Macy zfs_deadman, 55eda14cbcSMatt Macy zfs_dedup, 56eda14cbcSMatt Macy zfs_l2arc, 57eda14cbcSMatt Macy zfs_livelist, 58eda14cbcSMatt Macy zfs_livelist_condense, 59eda14cbcSMatt Macy zfs_lua, 60eda14cbcSMatt Macy zfs_metaslab, 61eda14cbcSMatt Macy zfs_mg, 62eda14cbcSMatt Macy zfs_multihost, 63eda14cbcSMatt Macy zfs_prefetch, 64eda14cbcSMatt Macy zfs_reconstruct, 65eda14cbcSMatt Macy zfs_recv, 66eda14cbcSMatt Macy zfs_send, 67eda14cbcSMatt Macy zfs_spa, 68eda14cbcSMatt Macy zfs_trim, 69eda14cbcSMatt Macy zfs_txg, 70eda14cbcSMatt Macy zfs_vdev, 71783d3ff6SMartin Matuska zfs_vdev_disk, 722c48331dSMatt Macy zfs_vdev_file, 73eda14cbcSMatt Macy zfs_vdev_mirror, 747877fdebSMatt Macy zfs_vnops, 75eda14cbcSMatt Macy zfs_zevent, 76eda14cbcSMatt Macy zfs_zio, 77eda14cbcSMatt Macy zfs_zil 78eda14cbcSMatt Macy }; 79eda14cbcSMatt Macy 80eda14cbcSMatt Macy /* 81dbd5678dSMartin Matuska * While we define our own s64/u64 types, there is no reason to reimplement the 82dbd5678dSMartin Matuska * existing Linux kernel types, so we use the preprocessor to remap our 83dbd5678dSMartin Matuska * "custom" implementations to the kernel ones. This is done because the CPP 84dbd5678dSMartin Matuska * does not allow us to write conditional definitions. The fourth definition 85dbd5678dSMartin Matuska * exists because the CPP will not allow us to replace things like INT with int 86dbd5678dSMartin Matuska * before string concatenation. 87dbd5678dSMartin Matuska */ 88dbd5678dSMartin Matuska 89dbd5678dSMartin Matuska #define spl_param_set_int param_set_int 90dbd5678dSMartin Matuska #define spl_param_get_int param_get_int 91dbd5678dSMartin Matuska #define spl_param_ops_int param_ops_int 92dbd5678dSMartin Matuska #define spl_param_ops_INT param_ops_int 93dbd5678dSMartin Matuska 94dbd5678dSMartin Matuska #define spl_param_set_long param_set_long 95dbd5678dSMartin Matuska #define spl_param_get_long param_get_long 96dbd5678dSMartin Matuska #define spl_param_ops_long param_ops_long 97dbd5678dSMartin Matuska #define spl_param_ops_LONG param_ops_long 98dbd5678dSMartin Matuska 99dbd5678dSMartin Matuska #define spl_param_set_uint param_set_uint 100dbd5678dSMartin Matuska #define spl_param_get_uint param_get_uint 101dbd5678dSMartin Matuska #define spl_param_ops_uint param_ops_uint 102dbd5678dSMartin Matuska #define spl_param_ops_UINT param_ops_uint 103dbd5678dSMartin Matuska 104dbd5678dSMartin Matuska #define spl_param_set_ulong param_set_ulong 105dbd5678dSMartin Matuska #define spl_param_get_ulong param_get_ulong 106dbd5678dSMartin Matuska #define spl_param_ops_ulong param_ops_ulong 107dbd5678dSMartin Matuska #define spl_param_ops_ULONG param_ops_ulong 108dbd5678dSMartin Matuska 109dbd5678dSMartin Matuska #define spl_param_set_charp param_set_charp 110dbd5678dSMartin Matuska #define spl_param_get_charp param_get_charp 111dbd5678dSMartin Matuska #define spl_param_ops_charp param_ops_charp 112dbd5678dSMartin Matuska #define spl_param_ops_STRING param_ops_charp 113dbd5678dSMartin Matuska 114dbd5678dSMartin Matuska int spl_param_set_s64(const char *val, zfs_kernel_param_t *kp); 115dbd5678dSMartin Matuska extern int spl_param_get_s64(char *buffer, zfs_kernel_param_t *kp); 116dbd5678dSMartin Matuska extern const struct kernel_param_ops spl_param_ops_s64; 117dbd5678dSMartin Matuska #define spl_param_ops_S64 spl_param_ops_s64 118dbd5678dSMartin Matuska 119dbd5678dSMartin Matuska extern int spl_param_set_u64(const char *val, zfs_kernel_param_t *kp); 120dbd5678dSMartin Matuska extern int spl_param_get_u64(char *buffer, zfs_kernel_param_t *kp); 121dbd5678dSMartin Matuska extern const struct kernel_param_ops spl_param_ops_u64; 122dbd5678dSMartin Matuska #define spl_param_ops_U64 spl_param_ops_u64 123dbd5678dSMartin Matuska 124dbd5678dSMartin Matuska /* 125eda14cbcSMatt Macy * Declare a module parameter / sysctl node 126eda14cbcSMatt Macy * 12716038816SMartin Matuska * "scope_prefix" the part of the sysctl / sysfs tree the node resides under 128eda14cbcSMatt Macy * (currently a no-op on Linux) 129eda14cbcSMatt Macy * "name_prefix" the part of the variable name that will be excluded from the 130eda14cbcSMatt Macy * exported names on platforms with a hierarchical namespace 131eda14cbcSMatt Macy * "name" the part of the variable that will be exposed on platforms with a 132eda14cbcSMatt Macy * hierarchical namespace, or as name_prefix ## name on Linux 133eda14cbcSMatt Macy * "type" the variable type 134eda14cbcSMatt Macy * "perm" the permissions (read/write or read only) 135eda14cbcSMatt Macy * "desc" a brief description of the option 136eda14cbcSMatt Macy * 137eda14cbcSMatt Macy * Examples: 138eda14cbcSMatt Macy * ZFS_MODULE_PARAM(zfs_vdev_mirror, zfs_vdev_mirror_, rotating_inc, UINT, 139eda14cbcSMatt Macy * ZMOD_RW, "Rotating media load increment for non-seeking I/O's"); 140eda14cbcSMatt Macy * on FreeBSD: 141eda14cbcSMatt Macy * vfs.zfs.vdev.mirror.rotating_inc 142eda14cbcSMatt Macy * on Linux: 143eda14cbcSMatt Macy * zfs_vdev_mirror_rotating_inc 144eda14cbcSMatt Macy * 145eda14cbcSMatt Macy * ZFS_MODULE_PARAM(zfs, , dmu_prefetch_max, UINT, ZMOD_RW, 146eda14cbcSMatt Macy * "Limit one prefetch call to this size"); 147eda14cbcSMatt Macy * on FreeBSD: 148eda14cbcSMatt Macy * vfs.zfs.dmu_prefetch_max 149eda14cbcSMatt Macy * on Linux: 150eda14cbcSMatt Macy * dmu_prefetch_max 151eda14cbcSMatt Macy */ 152eda14cbcSMatt Macy #define ZFS_MODULE_PARAM(scope_prefix, name_prefix, name, type, perm, desc) \ 153c03c5b1cSMartin Matuska _Static_assert( \ 154c03c5b1cSMartin Matuska sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \ 155c03c5b1cSMartin Matuska "" #scope_prefix " size mismatch with enum scope_prefix_types"); \ 156dbd5678dSMartin Matuska module_param_cb(name_prefix ## name, &spl_param_ops_ ## type, \ 157dbd5678dSMartin Matuska &name_prefix ## name, perm); \ 158eda14cbcSMatt Macy MODULE_PARM_DESC(name_prefix ## name, desc) 159eda14cbcSMatt Macy 160eda14cbcSMatt Macy /* 161eda14cbcSMatt Macy * Declare a module parameter / sysctl node 162eda14cbcSMatt Macy * 163eda14cbcSMatt Macy * "scope_prefix" the part of the the sysctl / sysfs tree the node resides under 164eda14cbcSMatt Macy * (currently a no-op on Linux) 165eda14cbcSMatt Macy * "name_prefix" the part of the variable name that will be excluded from the 166eda14cbcSMatt Macy * exported names on platforms with a hierarchical namespace 167eda14cbcSMatt Macy * "name" the part of the variable that will be exposed on platforms with a 168eda14cbcSMatt Macy * hierarchical namespace, or as name_prefix ## name on Linux 169eda14cbcSMatt Macy * "setfunc" setter function 170eda14cbcSMatt Macy * "getfunc" getter function 171eda14cbcSMatt Macy * "perm" the permissions (read/write or read only) 172eda14cbcSMatt Macy * "desc" a brief description of the option 173eda14cbcSMatt Macy * 174eda14cbcSMatt Macy * Examples: 175eda14cbcSMatt Macy * ZFS_MODULE_PARAM_CALL(zfs_spa, spa_, slop_shift, param_set_slop_shift, 176eda14cbcSMatt Macy * param_get_int, ZMOD_RW, "Reserved free space in pool"); 177eda14cbcSMatt Macy * on FreeBSD: 178eda14cbcSMatt Macy * vfs.zfs.spa_slop_shift 179eda14cbcSMatt Macy * on Linux: 180eda14cbcSMatt Macy * spa_slop_shift 181eda14cbcSMatt Macy */ 182c03c5b1cSMartin Matuska #define ZFS_MODULE_PARAM_CALL( \ 183c03c5b1cSMartin Matuska scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \ 184c03c5b1cSMartin Matuska _Static_assert( \ 185c03c5b1cSMartin Matuska sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \ 186c03c5b1cSMartin Matuska "" #scope_prefix " size mismatch with enum scope_prefix_types"); \ 187c03c5b1cSMartin Matuska module_param_call(name_prefix ## name, setfunc, getfunc, \ 188c03c5b1cSMartin Matuska &name_prefix ## name, perm); \ 189eda14cbcSMatt Macy MODULE_PARM_DESC(name_prefix ## name, desc) 190eda14cbcSMatt Macy 1917877fdebSMatt Macy /* 1927877fdebSMatt Macy * As above, but there is no variable with the name name_prefix ## name, 1937877fdebSMatt Macy * so NULL is passed to module_param_call instead. 1947877fdebSMatt Macy */ 195c03c5b1cSMartin Matuska #define ZFS_MODULE_VIRTUAL_PARAM_CALL( \ 196c03c5b1cSMartin Matuska scope_prefix, name_prefix, name, setfunc, getfunc, perm, desc) \ 197c03c5b1cSMartin Matuska _Static_assert( \ 198c03c5b1cSMartin Matuska sizeof (scope_prefix) == sizeof (enum scope_prefix_types), \ 199c03c5b1cSMartin Matuska "" #scope_prefix " size mismatch with enum scope_prefix_types"); \ 2007877fdebSMatt Macy module_param_call(name_prefix ## name, setfunc, getfunc, NULL, perm); \ 2017877fdebSMatt Macy MODULE_PARM_DESC(name_prefix ## name, desc) 2027877fdebSMatt Macy 203eda14cbcSMatt Macy #define ZFS_MODULE_PARAM_ARGS const char *buf, zfs_kernel_param_t *kp 204eda14cbcSMatt Macy 205eda14cbcSMatt Macy #endif /* _MOD_COMPAT_H */ 206