├── AUTHORS ├── LICENSE ├── NOTICE ├── README.md ├── config ├── kernel-ctl-table-name.m4 ├── kernel-fallocate-pax.m4 ├── kernel-group-info.m4 ├── kernel-inode-lock.m4 ├── kernel-kmem-cache.m4 ├── kernel-kmem.m4 ├── kernel-kuidgid.m4 ├── kernel-pde-data.m4 ├── kernel-rw.m4 ├── kernel-rwsem.m4 ├── kernel-sched.m4 ├── kernel-set-fs-pwd.m4 ├── kernel-shrinker.m4 ├── kernel-spinlock.m4 ├── kernel-timer.m4 ├── kernel-trim-unused-symbols.m4 ├── kernel-urange-sleep.m4 ├── kernel-vfs-fsync.m4 ├── kernel-vfs-getattr.m4 ├── kernel-wait.m4 └── kernel-zlib.m4 ├── include └── spl │ ├── rpc │ └── xdr.h │ └── sys │ ├── acl.h │ ├── atomic.h │ ├── byteorder.h │ ├── callb.h │ ├── callo.h │ ├── cmn_err.h │ ├── condvar.h │ ├── console.h │ ├── cred.h │ ├── ctype.h │ ├── debug.h │ ├── disp.h │ ├── dkio.h │ ├── dkioc_free_util.h │ ├── fcntl.h │ ├── file.h │ ├── inttypes.h │ ├── isa_defs.h │ ├── kmem.h │ ├── kmem_cache.h │ ├── kobj.h │ ├── kstat.h │ ├── list.h │ ├── mode.h │ ├── mutex.h │ ├── param.h │ ├── proc.h │ ├── processor.h │ ├── random.h │ ├── rwlock.h │ ├── shrinker.h │ ├── sid.h │ ├── signal.h │ ├── stat.h │ ├── strings.h │ ├── sunddi.h │ ├── sysmacros.h │ ├── systeminfo.h │ ├── taskq.h │ ├── thread.h │ ├── time.h │ ├── timer.h │ ├── tsd.h │ ├── types.h │ ├── types32.h │ ├── uio.h │ ├── user.h │ ├── vfs.h │ ├── vmem.h │ ├── vmsystm.h │ ├── vnode.h │ ├── wait.h │ ├── zmod.h │ └── zone.h ├── man └── man5 │ └── spl-module-parameters.5 └── module └── spl ├── THIRDPARTYLICENSE.gplv2 ├── THIRDPARTYLICENSE.gplv2.descrip ├── spl-atomic.c ├── spl-condvar.c ├── spl-cred.c ├── spl-err.c ├── spl-generic.c ├── spl-kmem-cache.c ├── spl-kmem.c ├── spl-kobj.c ├── spl-kstat.c ├── spl-mutex.c ├── spl-proc.c ├── spl-rwlock.c ├── spl-taskq.c ├── spl-thread.c ├── spl-tsd.c ├── spl-vmem.c ├── spl-vnode.c ├── spl-xdr.c └── spl-zlib.c /AUTHORS: -------------------------------------------------------------------------------- 1 | Original author and maintainer. 2 | 3 | Brian Behlendorf 4 | 5 | Additionally the following individuals have all made contributions 6 | to the project and deserve to be acknowledged. 7 | 8 | Alex Zhuravlev 9 | Brian J. Murrell 10 | Chris Dunlap 11 | Chris Dunlop 12 | Darik Horn 13 | Etienne Dechamps 14 | Gunnar Beutner 15 | Jorgen Lundman 16 | Lars Johannsen 17 | Li Wei 18 | Massimo Maggi 19 | Ned Bass 20 | Neependra Khare 21 | Prakash Surya 22 | Ricardo Correia 23 | Richard Yao 24 | Steven Johnson 25 | Yuxuan Shui 26 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This work was produced under the auspices of the U.S. Department of Energy by 2 | Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344. 3 | 4 | This work was prepared as an account of work sponsored by an agency of the 5 | United States Government. Neither the United States Government nor Lawrence 6 | Livermore National Security, LLC, nor any of their employees makes any warranty, 7 | expressed or implied, or assumes any legal liability or responsibility for the 8 | accuracy, completeness, or usefulness of any information, apparatus, product, or 9 | process disclosed, or represents that its use would not infringe privately owned 10 | rights. Reference herein to any specific commercial product, process, or service 11 | by trade name, trademark, manufacturer, or otherwise does not necessarily 12 | constitute or imply its endorsement, recommendation, or favoring by the United 13 | States Government or Lawrence Livermore National Security, LLC. The views and 14 | opinions of authors expressed herein do not necessarily state or reflect those 15 | of the United States Government or Lawrence Livermore National Security, LLC, 16 | and shall not be used for advertising or product endorsement purposes. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![img](http://zfsonlinux.org/images/zfs-linux.png) 2 | 3 | The Solaris Porting Layer, SPL, is a Linux kernel module which provides a 4 | compatibility layer used by the [ZFS on Linux](http://zfsonlinux.org) project. 5 | 6 | # Installation 7 | 8 | The latest version of the SPL is maintained as part of the ZFS on Linux 9 | Github repository: 10 | 11 | * Latest Version: https://github.com/zfsonlinux/zfs 12 | 13 | Cloning this repository is only needed when building version 0.7.x or earlier. 14 | 15 | * Version 0.7.x: https://github.com/zfsonlinux/spl/tree/spl-0.7-release 16 | * Version 0.6.5.x: https://github.com/zfsonlinux/spl/tree/spl-0.6.5-release 17 | 18 | # Release 19 | 20 | The SPL is released under a GPLv2 license. For more details see the NOTICE 21 | and LICENSE files; `UCRL-CODE-235197` 22 | -------------------------------------------------------------------------------- /config/kernel-ctl-table-name.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 2.6.33 API change, 3 | dnl # Removed .ctl_name from struct ctl_table. 4 | dnl # 5 | AC_DEFUN([SPL_AC_CTL_NAME], [ 6 | AC_MSG_CHECKING([whether struct ctl_table has ctl_name]) 7 | SPL_LINUX_TRY_COMPILE([ 8 | #include 9 | ],[ 10 | struct ctl_table ctl __attribute__ ((unused)); 11 | ctl.ctl_name = 0; 12 | ],[ 13 | AC_MSG_RESULT(yes) 14 | AC_DEFINE(HAVE_CTL_NAME, 1, [struct ctl_table has ctl_name]) 15 | ],[ 16 | AC_MSG_RESULT(no) 17 | ]) 18 | ]) 19 | -------------------------------------------------------------------------------- /config/kernel-fallocate-pax.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # PaX Linux 2.6.38 - 3.x API 3 | dnl # 4 | AC_DEFUN([SPL_AC_PAX_KERNEL_FILE_FALLOCATE], [ 5 | AC_MSG_CHECKING([whether fops->fallocate() exists]) 6 | SPL_LINUX_TRY_COMPILE([ 7 | #include 8 | ],[ 9 | long (*fallocate) (struct file *, int, loff_t, loff_t) = NULL; 10 | struct file_operations_no_const fops __attribute__ ((unused)) = { 11 | .fallocate = fallocate, 12 | }; 13 | ],[ 14 | AC_MSG_RESULT(yes) 15 | AC_DEFINE(HAVE_FILE_FALLOCATE, 1, [fops->fallocate() exists]) 16 | ],[ 17 | AC_MSG_RESULT(no) 18 | ]) 19 | ]) 20 | -------------------------------------------------------------------------------- /config/kernel-group-info.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 4.9 API change 3 | dnl # group_info changed from 2d array via >blocks to 1d array via ->gid 4 | dnl # 5 | AC_DEFUN([SPL_AC_GROUP_INFO_GID], [ 6 | AC_MSG_CHECKING([whether group_info->gid exists]) 7 | tmp_flags="$EXTRA_KCFLAGS" 8 | EXTRA_KCFLAGS="-Werror" 9 | SPL_LINUX_TRY_COMPILE([ 10 | #include 11 | ],[ 12 | struct group_info *gi = groups_alloc(1); 13 | gi->gid[0] = KGIDT_INIT(0); 14 | ],[ 15 | AC_MSG_RESULT(yes) 16 | AC_DEFINE(HAVE_GROUP_INFO_GID, 1, [group_info->gid exists]) 17 | ],[ 18 | AC_MSG_RESULT(no) 19 | ]) 20 | EXTRA_KCFLAGS="$tmp_flags" 21 | ]) 22 | -------------------------------------------------------------------------------- /config/kernel-inode-lock.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 4.7 API change 3 | dnl # i_mutex is changed to i_rwsem. Instead of directly using 4 | dnl # i_mutex/i_rwsem, we should use inode_lock() and inode_lock_shared() 5 | dnl # We test inode_lock_shared because inode_lock is introduced earlier. 6 | dnl # 7 | AC_DEFUN([SPL_AC_INODE_LOCK], [ 8 | AC_MSG_CHECKING([whether inode_lock_shared() exists]) 9 | tmp_flags="$EXTRA_KCFLAGS" 10 | EXTRA_KCFLAGS="-Werror" 11 | SPL_LINUX_TRY_COMPILE([ 12 | #include 13 | ],[ 14 | struct inode *inode = NULL; 15 | inode_lock_shared(inode); 16 | ],[ 17 | AC_MSG_RESULT(yes) 18 | AC_DEFINE(HAVE_INODE_LOCK_SHARED, 1, [yes]) 19 | ],[ 20 | AC_MSG_RESULT(no) 21 | ]) 22 | EXTRA_KCFLAGS="$tmp_flags" 23 | ]) 24 | -------------------------------------------------------------------------------- /config/kernel-kmem-cache.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 2.6.35 API change, 3 | dnl # The cachep->gfpflags member was renamed cachep->allocflags. These are 4 | dnl # private allocation flags which are applied when allocating a new slab 5 | dnl # in kmem_getpages(). Unfortunately there is no public API for setting 6 | dnl # non-default flags. 7 | dnl # 8 | AC_DEFUN([SPL_AC_KMEM_CACHE_ALLOCFLAGS], [ 9 | AC_MSG_CHECKING([whether struct kmem_cache has allocflags]) 10 | SPL_LINUX_TRY_COMPILE([ 11 | #include 12 | ],[ 13 | struct kmem_cache cachep __attribute__ ((unused)); 14 | cachep.allocflags = GFP_KERNEL; 15 | ],[ 16 | AC_MSG_RESULT(yes) 17 | AC_DEFINE(HAVE_KMEM_CACHE_ALLOCFLAGS, 1, 18 | [struct kmem_cache has allocflags]) 19 | ],[ 20 | AC_MSG_RESULT(no) 21 | 22 | AC_MSG_CHECKING([whether struct kmem_cache has gfpflags]) 23 | SPL_LINUX_TRY_COMPILE([ 24 | #include 25 | ],[ 26 | struct kmem_cache cachep __attribute__ ((unused)); 27 | cachep.gfpflags = GFP_KERNEL; 28 | ],[ 29 | AC_MSG_RESULT(yes) 30 | AC_DEFINE(HAVE_KMEM_CACHE_GFPFLAGS, 1, 31 | [struct kmem_cache has gfpflags]) 32 | ],[ 33 | AC_MSG_RESULT(no) 34 | ]) 35 | ]) 36 | ]) 37 | 38 | dnl # 39 | dnl # grsecurity API change, 40 | dnl # kmem_cache_create() with SLAB_USERCOPY flag replaced by 41 | dnl # kmem_cache_create_usercopy(). 42 | dnl # 43 | AC_DEFUN([SPL_AC_KMEM_CACHE_CREATE_USERCOPY], [ 44 | AC_MSG_CHECKING([whether kmem_cache_create_usercopy() exists]) 45 | tmp_flags="$EXTRA_KCFLAGS" 46 | EXTRA_KCFLAGS="-Werror" 47 | SPL_LINUX_TRY_COMPILE([ 48 | #include 49 | static void ctor(void *foo) 50 | { 51 | // fake ctor 52 | } 53 | ],[ 54 | struct kmem_cache *skc_linux_cache; 55 | const char *name = "test"; 56 | size_t size = 4096; 57 | size_t align = 8; 58 | unsigned long flags = 0; 59 | size_t useroffset = 0; 60 | size_t usersize = size - useroffset; 61 | 62 | skc_linux_cache = kmem_cache_create_usercopy( 63 | name, size, align, flags, useroffset, usersize, ctor); 64 | ],[ 65 | AC_MSG_RESULT(yes) 66 | AC_DEFINE(HAVE_KMEM_CACHE_CREATE_USERCOPY, 1, 67 | [kmem_cache_create_usercopy() exists]) 68 | ],[ 69 | AC_MSG_RESULT(no) 70 | ]) 71 | EXTRA_KCFLAGS="$tmp_flags" 72 | ]) 73 | -------------------------------------------------------------------------------- /config/kernel-kmem.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # Enabled by default it provides a minimal level of memory tracking. 3 | dnl # A total count of bytes allocated is kept for each alloc and free. 4 | dnl # Then at module unload time a report to the console will be printed 5 | dnl # if memory was leaked. 6 | dnl # 7 | AC_DEFUN([SPL_AC_DEBUG_KMEM], [ 8 | AC_ARG_ENABLE([debug-kmem], 9 | [AS_HELP_STRING([--enable-debug-kmem], 10 | [Enable basic kmem accounting @<:@default=no@:>@])], 11 | [], 12 | [enable_debug_kmem=no]) 13 | 14 | AS_IF([test "x$enable_debug_kmem" = xyes], 15 | [ 16 | KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM" 17 | DEBUG_KMEM="_with_debug_kmem" 18 | AC_DEFINE([DEBUG_KMEM], [1], 19 | [Define to 1 to enable basic kmem accounting]) 20 | ], [ 21 | DEBUG_KMEM="_without_debug_kmem" 22 | ]) 23 | 24 | AC_SUBST(DEBUG_KMEM) 25 | AC_MSG_CHECKING([whether basic kmem accounting is enabled]) 26 | AC_MSG_RESULT([$enable_debug_kmem]) 27 | ]) 28 | 29 | dnl # 30 | dnl # Disabled by default it provides detailed memory tracking. This 31 | dnl # feature also requires --enable-debug-kmem to be set. When enabled 32 | dnl # not only will total bytes be tracked but also the location of every 33 | dnl # alloc and free. When the SPL module is unloaded a list of all leaked 34 | dnl # addresses and where they were allocated will be dumped to the console. 35 | dnl # Enabling this feature has a significant impact on performance but it 36 | dnl # makes finding memory leaks pretty straight forward. 37 | dnl # 38 | AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [ 39 | AC_ARG_ENABLE([debug-kmem-tracking], 40 | [AS_HELP_STRING([--enable-debug-kmem-tracking], 41 | [Enable detailed kmem tracking @<:@default=no@:>@])], 42 | [], 43 | [enable_debug_kmem_tracking=no]) 44 | 45 | AS_IF([test "x$enable_debug_kmem_tracking" = xyes], 46 | [ 47 | KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING" 48 | DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking" 49 | AC_DEFINE([DEBUG_KMEM_TRACKING], [1], 50 | [Define to 1 to enable detailed kmem tracking]) 51 | ], [ 52 | DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking" 53 | ]) 54 | 55 | AC_SUBST(DEBUG_KMEM_TRACKING) 56 | AC_MSG_CHECKING([whether detailed kmem tracking is enabled]) 57 | AC_MSG_RESULT([$enable_debug_kmem_tracking]) 58 | ]) 59 | -------------------------------------------------------------------------------- /config/kernel-kuidgid.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # User namespaces, use kuid_t in place of uid_t 3 | dnl # where available. Not strictly a user namespaces thing 4 | dnl # but it should prevent surprises 5 | dnl # 6 | AC_DEFUN([SPL_AC_KUIDGID_T], [ 7 | AC_MSG_CHECKING([whether kuid_t/kgid_t is available]) 8 | SPL_LINUX_TRY_COMPILE([ 9 | #include 10 | ], [ 11 | kuid_t userid = KUIDT_INIT(0); 12 | kgid_t groupid = KGIDT_INIT(0); 13 | ],[ 14 | SPL_LINUX_TRY_COMPILE([ 15 | #include 16 | ], [ 17 | kuid_t userid = 0; 18 | kgid_t groupid = 0; 19 | ],[ 20 | AC_MSG_RESULT(yes; optional) 21 | ],[ 22 | AC_MSG_RESULT(yes; mandatory) 23 | AC_DEFINE(HAVE_KUIDGID_T, 1, [kuid_t/kgid_t in use]) 24 | ]) 25 | ],[ 26 | AC_MSG_RESULT(no) 27 | ]) 28 | ]) 29 | -------------------------------------------------------------------------------- /config/kernel-pde-data.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 3.10 API change, 3 | dnl # PDE is replaced by PDE_DATA 4 | dnl # 5 | AC_DEFUN([SPL_AC_PDE_DATA], [ 6 | AC_MSG_CHECKING([whether PDE_DATA() is available]) 7 | SPL_LINUX_TRY_COMPILE_SYMBOL([ 8 | #include 9 | ], [ 10 | PDE_DATA(NULL); 11 | ], [PDE_DATA], [], [ 12 | AC_MSG_RESULT(yes) 13 | AC_DEFINE(HAVE_PDE_DATA, 1, [yes]) 14 | ],[ 15 | AC_MSG_RESULT(no) 16 | ]) 17 | ]) 18 | -------------------------------------------------------------------------------- /config/kernel-rw.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 4.14 API change 3 | dnl # kernel_write() which was introduced in 3.9 was updated to take 4 | dnl # the offset as a pointer which is needed by vn_rdwr(). 5 | dnl # 6 | AC_DEFUN([SPL_AC_KERNEL_WRITE], [ 7 | AC_MSG_CHECKING([whether kernel_write() takes loff_t pointer]) 8 | tmp_flags="$EXTRA_KCFLAGS" 9 | EXTRA_KCFLAGS="-Werror" 10 | SPL_LINUX_TRY_COMPILE([ 11 | #include 12 | ],[ 13 | struct file *file = NULL; 14 | const void *buf = NULL; 15 | size_t count = 0; 16 | loff_t *pos = NULL; 17 | ssize_t ret; 18 | 19 | ret = kernel_write(file, buf, count, pos); 20 | ],[ 21 | AC_MSG_RESULT(yes) 22 | AC_DEFINE(HAVE_KERNEL_WRITE_PPOS, 1, 23 | [kernel_write() take loff_t pointer]) 24 | ],[ 25 | AC_MSG_RESULT(no) 26 | ]) 27 | EXTRA_KCFLAGS="$tmp_flags" 28 | ]) 29 | 30 | dnl # 31 | dnl # 4.14 API change 32 | dnl # kernel_read() which has existed for forever was updated to take 33 | dnl # the offset as a pointer which is needed by vn_rdwr(). 34 | dnl # 35 | AC_DEFUN([SPL_AC_KERNEL_READ], [ 36 | AC_MSG_CHECKING([whether kernel_read() takes loff_t pointer]) 37 | tmp_flags="$EXTRA_KCFLAGS" 38 | EXTRA_KCFLAGS="-Werror" 39 | SPL_LINUX_TRY_COMPILE([ 40 | #include 41 | ],[ 42 | struct file *file = NULL; 43 | void *buf = NULL; 44 | size_t count = 0; 45 | loff_t *pos = NULL; 46 | ssize_t ret; 47 | 48 | ret = kernel_read(file, buf, count, pos); 49 | ],[ 50 | AC_MSG_RESULT(yes) 51 | AC_DEFINE(HAVE_KERNEL_READ_PPOS, 1, 52 | [kernel_read() take loff_t pointer]) 53 | ],[ 54 | AC_MSG_RESULT(no) 55 | ]) 56 | EXTRA_KCFLAGS="$tmp_flags" 57 | ]) 58 | -------------------------------------------------------------------------------- /config/kernel-rwsem.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 3.1 API Change 3 | dnl # 4 | dnl # The rw_semaphore.wait_lock member was changed from spinlock_t to 5 | dnl # raw_spinlock_t at commit ddb6c9b58a19edcfac93ac670b066c836ff729f1. 6 | dnl # 7 | AC_DEFUN([SPL_AC_RWSEM_SPINLOCK_IS_RAW], [ 8 | AC_MSG_CHECKING([whether struct rw_semaphore member wait_lock is raw]) 9 | tmp_flags="$EXTRA_KCFLAGS" 10 | EXTRA_KCFLAGS="-Werror" 11 | SPL_LINUX_TRY_COMPILE([ 12 | #include 13 | ],[ 14 | struct rw_semaphore dummy_semaphore __attribute__ ((unused)); 15 | raw_spinlock_t dummy_lock __attribute__ ((unused)) = 16 | __RAW_SPIN_LOCK_INITIALIZER(dummy_lock); 17 | dummy_semaphore.wait_lock = dummy_lock; 18 | ],[ 19 | AC_MSG_RESULT(yes) 20 | AC_DEFINE(RWSEM_SPINLOCK_IS_RAW, 1, 21 | [struct rw_semaphore member wait_lock is raw_spinlock_t]) 22 | ],[ 23 | AC_MSG_RESULT(no) 24 | ]) 25 | EXTRA_KCFLAGS="$tmp_flags" 26 | ]) 27 | 28 | dnl # 29 | dnl # 3.16 API Change 30 | dnl # 31 | dnl # rwsem-spinlock "->activity" changed to "->count" 32 | dnl # 33 | AC_DEFUN([SPL_AC_RWSEM_ACTIVITY], [ 34 | AC_MSG_CHECKING([whether struct rw_semaphore has member activity]) 35 | tmp_flags="$EXTRA_KCFLAGS" 36 | EXTRA_KCFLAGS="-Werror" 37 | SPL_LINUX_TRY_COMPILE([ 38 | #include 39 | ],[ 40 | struct rw_semaphore dummy_semaphore __attribute__ ((unused)); 41 | dummy_semaphore.activity = 0; 42 | ],[ 43 | AC_MSG_RESULT(yes) 44 | AC_DEFINE(HAVE_RWSEM_ACTIVITY, 1, 45 | [struct rw_semaphore has member activity]) 46 | ],[ 47 | AC_MSG_RESULT(no) 48 | ]) 49 | EXTRA_KCFLAGS="$tmp_flags" 50 | ]) 51 | 52 | dnl # 53 | dnl # 4.8 API Change 54 | dnl # 55 | dnl # rwsem "->count" changed to atomic_long_t type 56 | dnl # 57 | AC_DEFUN([SPL_AC_RWSEM_ATOMIC_LONG_COUNT], [ 58 | AC_MSG_CHECKING( 59 | [whether struct rw_semaphore has atomic_long_t member count]) 60 | tmp_flags="$EXTRA_KCFLAGS" 61 | EXTRA_KCFLAGS="-Werror" 62 | SPL_LINUX_TRY_COMPILE([ 63 | #include 64 | ],[ 65 | DECLARE_RWSEM(dummy_semaphore); 66 | (void) atomic_long_read(&dummy_semaphore.count); 67 | ],[ 68 | AC_MSG_RESULT(yes) 69 | AC_DEFINE(HAVE_RWSEM_ATOMIC_LONG_COUNT, 1, 70 | [struct rw_semaphore has atomic_long_t member count]) 71 | ],[ 72 | AC_MSG_RESULT(no) 73 | ]) 74 | EXTRA_KCFLAGS="$tmp_flags" 75 | ]) 76 | -------------------------------------------------------------------------------- /config/kernel-sched.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 3.9 API change, 3 | dnl # Moved things from linux/sched.h to linux/sched/rt.h 4 | dnl # 5 | AC_DEFUN([SPL_AC_SCHED_RT_HEADER], 6 | [AC_MSG_CHECKING([whether header linux/sched/rt.h exists]) 7 | SPL_LINUX_TRY_COMPILE([ 8 | #include 9 | #include 10 | ],[ 11 | return 0; 12 | ],[ 13 | AC_DEFINE(HAVE_SCHED_RT_HEADER, 1, [linux/sched/rt.h exists]) 14 | AC_MSG_RESULT(yes) 15 | ],[ 16 | AC_MSG_RESULT(no) 17 | ]) 18 | ]) 19 | 20 | dnl # 21 | dnl # 4.11 API change, 22 | dnl # Moved things from linux/sched.h to linux/sched/signal.h 23 | dnl # 24 | AC_DEFUN([SPL_AC_SCHED_SIGNAL_HEADER], 25 | [AC_MSG_CHECKING([whether header linux/sched/signal.h exists]) 26 | SPL_LINUX_TRY_COMPILE([ 27 | #include 28 | #include 29 | ],[ 30 | return 0; 31 | ],[ 32 | AC_DEFINE(HAVE_SCHED_SIGNAL_HEADER, 1, [linux/sched/signal.h exists]) 33 | AC_MSG_RESULT(yes) 34 | ],[ 35 | AC_MSG_RESULT(no) 36 | ]) 37 | ]) 38 | dnl # 39 | dnl # 3.19 API change 40 | dnl # The io_schedule_timeout() function is present in all 2.6.32 kernels 41 | dnl # but it was not exported until Linux 3.19. The RHEL 7.x kernels which 42 | dnl # are based on a 3.10 kernel do export this symbol. 43 | dnl # 44 | AC_DEFUN([SPL_AC_IO_SCHEDULE_TIMEOUT], [ 45 | AC_MSG_CHECKING([whether io_schedule_timeout() is available]) 46 | SPL_LINUX_TRY_COMPILE_SYMBOL([ 47 | #include 48 | ], [ 49 | (void) io_schedule_timeout(1); 50 | ], [io_schedule_timeout], [], [ 51 | AC_MSG_RESULT(yes) 52 | AC_DEFINE(HAVE_IO_SCHEDULE_TIMEOUT, 1, [yes]) 53 | ],[ 54 | AC_MSG_RESULT(no) 55 | ]) 56 | ]) 57 | -------------------------------------------------------------------------------- /config/kernel-set-fs-pwd.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 3.9 API change 3 | dnl # set_fs_pwd takes const struct path * 4 | dnl # 5 | AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST], 6 | tmp_flags="$EXTRA_KCFLAGS" 7 | EXTRA_KCFLAGS="-Werror" 8 | [AC_MSG_CHECKING([whether set_fs_pwd() requires const struct path *]) 9 | SPL_LINUX_TRY_COMPILE([ 10 | #include 11 | #include 12 | #include 13 | void (*const set_fs_pwd_func) 14 | (struct fs_struct *, const struct path *) 15 | = set_fs_pwd; 16 | ],[ 17 | return 0; 18 | ],[ 19 | AC_MSG_RESULT(yes) 20 | AC_DEFINE(HAVE_SET_FS_PWD_WITH_CONST, 1, 21 | [set_fs_pwd() needs const path *]) 22 | ],[ 23 | SPL_LINUX_TRY_COMPILE([ 24 | #include 25 | #include 26 | #include 27 | void (*const set_fs_pwd_func) 28 | (struct fs_struct *, struct path *) 29 | = set_fs_pwd; 30 | ],[ 31 | return 0; 32 | ],[ 33 | AC_MSG_RESULT(no) 34 | ],[ 35 | AC_MSG_ERROR(unknown) 36 | ]) 37 | ]) 38 | EXTRA_KCFLAGS="$tmp_flags" 39 | ]) 40 | -------------------------------------------------------------------------------- /config/kernel-shrinker.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[ 2 | tmp_flags="$EXTRA_KCFLAGS" 3 | EXTRA_KCFLAGS="-Werror" 4 | dnl # 5 | dnl # 2.6.23 to 2.6.34 API change 6 | dnl # ->shrink(int nr_to_scan, gfp_t gfp_mask) 7 | dnl # 8 | AC_MSG_CHECKING([whether old 2-argument shrinker exists]) 9 | SPL_LINUX_TRY_COMPILE([ 10 | #include 11 | 12 | int shrinker_cb(int nr_to_scan, gfp_t gfp_mask); 13 | ],[ 14 | struct shrinker cache_shrinker = { 15 | .shrink = shrinker_cb, 16 | .seeks = DEFAULT_SEEKS, 17 | }; 18 | register_shrinker(&cache_shrinker); 19 | ],[ 20 | AC_MSG_RESULT(yes) 21 | AC_DEFINE(HAVE_2ARGS_OLD_SHRINKER_CALLBACK, 1, 22 | [old shrinker callback wants 2 args]) 23 | ],[ 24 | AC_MSG_RESULT(no) 25 | dnl # 26 | dnl # 2.6.35 - 2.6.39 API change 27 | dnl # ->shrink(struct shrinker *, 28 | dnl # int nr_to_scan, gfp_t gfp_mask) 29 | dnl # 30 | AC_MSG_CHECKING([whether old 3-argument shrinker exists]) 31 | SPL_LINUX_TRY_COMPILE([ 32 | #include 33 | 34 | int shrinker_cb(struct shrinker *, int nr_to_scan, 35 | gfp_t gfp_mask); 36 | ],[ 37 | struct shrinker cache_shrinker = { 38 | .shrink = shrinker_cb, 39 | .seeks = DEFAULT_SEEKS, 40 | }; 41 | register_shrinker(&cache_shrinker); 42 | ],[ 43 | AC_MSG_RESULT(yes) 44 | AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1, 45 | [old shrinker callback wants 3 args]) 46 | ],[ 47 | AC_MSG_RESULT(no) 48 | dnl # 49 | dnl # 3.0 - 3.11 API change 50 | dnl # ->shrink(struct shrinker *, 51 | dnl # struct shrink_control *sc) 52 | dnl # 53 | AC_MSG_CHECKING( 54 | [whether new 2-argument shrinker exists]) 55 | SPL_LINUX_TRY_COMPILE([ 56 | #include 57 | 58 | int shrinker_cb(struct shrinker *, 59 | struct shrink_control *sc); 60 | ],[ 61 | struct shrinker cache_shrinker = { 62 | .shrink = shrinker_cb, 63 | .seeks = DEFAULT_SEEKS, 64 | }; 65 | register_shrinker(&cache_shrinker); 66 | ],[ 67 | AC_MSG_RESULT(yes) 68 | AC_DEFINE(HAVE_2ARGS_NEW_SHRINKER_CALLBACK, 1, 69 | [new shrinker callback wants 2 args]) 70 | ],[ 71 | AC_MSG_RESULT(no) 72 | dnl # 73 | dnl # 3.12 API change, 74 | dnl # ->shrink() is logically split in to 75 | dnl # ->count_objects() and ->scan_objects() 76 | dnl # 77 | AC_MSG_CHECKING( 78 | [whether ->count_objects callback exists]) 79 | SPL_LINUX_TRY_COMPILE([ 80 | #include 81 | 82 | unsigned long shrinker_cb( 83 | struct shrinker *, 84 | struct shrink_control *sc); 85 | ],[ 86 | struct shrinker cache_shrinker = { 87 | .count_objects = shrinker_cb, 88 | .scan_objects = shrinker_cb, 89 | .seeks = DEFAULT_SEEKS, 90 | }; 91 | register_shrinker(&cache_shrinker); 92 | ],[ 93 | AC_MSG_RESULT(yes) 94 | AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK, 95 | 1, [->count_objects exists]) 96 | ],[ 97 | AC_MSG_ERROR(error) 98 | ]) 99 | ]) 100 | ]) 101 | ]) 102 | EXTRA_KCFLAGS="$tmp_flags" 103 | ]) 104 | 105 | dnl # 106 | dnl # 2.6.39 API change, 107 | dnl # Shrinker adjust to use common shrink_control structure. 108 | dnl # 109 | AC_DEFUN([SPL_AC_SHRINK_CONTROL_STRUCT], [ 110 | AC_MSG_CHECKING([whether struct shrink_control exists]) 111 | SPL_LINUX_TRY_COMPILE([ 112 | #include 113 | ],[ 114 | struct shrink_control sc __attribute__ ((unused)); 115 | 116 | sc.nr_to_scan = 0; 117 | sc.gfp_mask = GFP_KERNEL; 118 | ],[ 119 | AC_MSG_RESULT(yes) 120 | AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1, 121 | [struct shrink_control exists]) 122 | ],[ 123 | AC_MSG_RESULT(no) 124 | ]) 125 | ]) 126 | -------------------------------------------------------------------------------- /config/kernel-spinlock.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 2.6.36 API change, 3 | dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to 4 | dnl # a spinlock_t to improve the fastpath performance. 5 | dnl # 6 | AC_DEFUN([SPL_AC_FS_STRUCT_SPINLOCK], [ 7 | AC_MSG_CHECKING([whether struct fs_struct uses spinlock_t]) 8 | tmp_flags="$EXTRA_KCFLAGS" 9 | EXTRA_KCFLAGS="-Werror" 10 | SPL_LINUX_TRY_COMPILE([ 11 | #include 12 | #include 13 | ],[ 14 | static struct fs_struct fs; 15 | spin_lock_init(&fs.lock); 16 | ],[ 17 | AC_MSG_RESULT(yes) 18 | AC_DEFINE(HAVE_FS_STRUCT_SPINLOCK, 1, 19 | [struct fs_struct uses spinlock_t]) 20 | ],[ 21 | AC_MSG_RESULT(no) 22 | ]) 23 | EXTRA_KCFLAGS="$tmp_flags" 24 | ]) 25 | -------------------------------------------------------------------------------- /config/kernel-timer.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 4.15 API change 3 | dnl # https://lkml.org/lkml/2017/11/25/90 4 | dnl # Check if timer_list.func get passed a timer_list or an unsigned long 5 | dnl # (older kernels). Also sanity check the from_timer() and timer_setup() 6 | dnl # macros are available as well, since they will be used in the same newer 7 | dnl # kernels that support the new timer_list.func signature. 8 | dnl # 9 | AC_DEFUN([SPL_AC_KERNEL_TIMER_FUNCTION_TIMER_LIST], [ 10 | AC_MSG_CHECKING([whether timer_list.function gets a timer_list]) 11 | tmp_flags="$EXTRA_KCFLAGS" 12 | EXTRA_KCFLAGS="-Werror" 13 | SPL_LINUX_TRY_COMPILE([ 14 | #include 15 | void task_expire(struct timer_list *tl) {} 16 | ],[ 17 | #ifndef from_timer 18 | #error "No from_timer() macro" 19 | #endif 20 | 21 | struct timer_list timer; 22 | timer.function = task_expire; 23 | timer_setup(&timer, NULL, 0); 24 | ],[ 25 | AC_MSG_RESULT(yes) 26 | AC_DEFINE(HAVE_KERNEL_TIMER_FUNCTION_TIMER_LIST, 1, 27 | [timer_list.function gets a timer_list]) 28 | ],[ 29 | AC_MSG_RESULT(no) 30 | ]) 31 | EXTRA_KCFLAGS="$tmp_flags" 32 | ]) 33 | -------------------------------------------------------------------------------- /config/kernel-trim-unused-symbols.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # config trim unused symbols, 3 | dnl # Verify the kernel has CONFIG_TRIM_UNUSED_KSYMS DISABLED. 4 | dnl # 5 | AC_DEFUN([SPL_AC_CONFIG_TRIM_UNUSED_KSYMS], [ 6 | AC_MSG_CHECKING([whether CONFIG_TRIM_UNUSED_KSYM is disabled]) 7 | SPL_LINUX_TRY_COMPILE([ 8 | #if defined(CONFIG_TRIM_UNUSED_KSYMS) 9 | #error CONFIG_TRIM_UNUSED_KSYMS not defined 10 | #endif 11 | ],[ ],[ 12 | AC_MSG_RESULT([yes]) 13 | ],[ 14 | AC_MSG_RESULT([no]) 15 | AC_MSG_ERROR([ 16 | *** This kernel has unused symbols trimming enabled, please disable. 17 | *** Rebuild the kernel with CONFIG_TRIM_UNUSED_KSYMS=n set.]) 18 | ]) 19 | ]) 20 | -------------------------------------------------------------------------------- /config/kernel-urange-sleep.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 2.6.36 API compatibility. 3 | dnl # Added usleep_range timer. 4 | dnl # usleep_range is a finer precision implementation of msleep 5 | dnl # designed to be a drop-in replacement for udelay where a precise 6 | dnl # sleep / busy-wait is unnecessary. 7 | dnl # 8 | AC_DEFUN([SPL_AC_USLEEP_RANGE], [ 9 | AC_MSG_CHECKING([whether usleep_range() is available]) 10 | SPL_LINUX_TRY_COMPILE([ 11 | #include 12 | ],[ 13 | usleep_range(0, 0); 14 | ],[ 15 | AC_MSG_RESULT(yes) 16 | AC_DEFINE(HAVE_USLEEP_RANGE, 1, 17 | [usleep_range is available]) 18 | ],[ 19 | AC_MSG_RESULT(no) 20 | ]) 21 | ]) 22 | -------------------------------------------------------------------------------- /config/kernel-vfs-fsync.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 2.6.35 API change, 3 | dnl # Unused 'struct dentry *' removed from vfs_fsync() prototype. 4 | dnl # 5 | AC_DEFUN([SPL_AC_2ARGS_VFS_FSYNC], [ 6 | AC_MSG_CHECKING([whether vfs_fsync() wants 2 args]) 7 | SPL_LINUX_TRY_COMPILE([ 8 | #include 9 | ],[ 10 | vfs_fsync(NULL, 0); 11 | ],[ 12 | AC_MSG_RESULT(yes) 13 | AC_DEFINE(HAVE_2ARGS_VFS_FSYNC, 1, [vfs_fsync() wants 2 args]) 14 | ],[ 15 | AC_MSG_RESULT(no) 16 | ]) 17 | ]) 18 | -------------------------------------------------------------------------------- /config/kernel-vfs-getattr.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 4.11 API, a528d35e@torvalds/linux 3 | dnl # vfs_getattr(const struct path *p, struct kstat *s, u32 m, unsigned int f) 4 | dnl # 5 | AC_DEFUN([SPL_AC_4ARGS_VFS_GETATTR], [ 6 | AC_MSG_CHECKING([whether vfs_getattr() wants 4 args]) 7 | SPL_LINUX_TRY_COMPILE([ 8 | #include 9 | ],[ 10 | vfs_getattr((const struct path *)NULL, 11 | (struct kstat *)NULL, 12 | (u32)0, 13 | (unsigned int)0); 14 | ],[ 15 | AC_MSG_RESULT(yes) 16 | AC_DEFINE(HAVE_4ARGS_VFS_GETATTR, 1, 17 | [vfs_getattr wants 4 args]) 18 | ],[ 19 | AC_MSG_RESULT(no) 20 | ]) 21 | ]) 22 | 23 | dnl # 24 | dnl # 3.9 API 25 | dnl # vfs_getattr(struct path *p, struct kstat *s) 26 | dnl # 27 | AC_DEFUN([SPL_AC_2ARGS_VFS_GETATTR], [ 28 | AC_MSG_CHECKING([whether vfs_getattr() wants 2 args]) 29 | SPL_LINUX_TRY_COMPILE([ 30 | #include 31 | ],[ 32 | vfs_getattr((struct path *) NULL, 33 | (struct kstat *)NULL); 34 | ],[ 35 | AC_MSG_RESULT(yes) 36 | AC_DEFINE(HAVE_2ARGS_VFS_GETATTR, 1, 37 | [vfs_getattr wants 2 args]) 38 | ],[ 39 | AC_MSG_RESULT(no) 40 | ]) 41 | ]) 42 | 43 | dnl # 44 | dnl # <3.9 API 45 | dnl # vfs_getattr(struct vfsmount *v, struct dentry *d, struct kstat *k) 46 | dnl # 47 | AC_DEFUN([SPL_AC_3ARGS_VFS_GETATTR], [ 48 | AC_MSG_CHECKING([whether vfs_getattr() wants 3 args]) 49 | SPL_LINUX_TRY_COMPILE([ 50 | #include 51 | ],[ 52 | vfs_getattr((struct vfsmount *)NULL, 53 | (struct dentry *)NULL, 54 | (struct kstat *)NULL); 55 | ],[ 56 | AC_MSG_RESULT(yes) 57 | AC_DEFINE(HAVE_3ARGS_VFS_GETATTR, 1, 58 | [vfs_getattr wants 3 args]) 59 | ],[ 60 | AC_MSG_RESULT(no) 61 | ]) 62 | ]) 63 | -------------------------------------------------------------------------------- /config/kernel-wait.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # 3.17 API change, 3 | dnl # wait_on_bit() no longer requires an action argument. The former 4 | dnl # "wait_on_bit" interface required an 'action' function to be provided 5 | dnl # which does the actual waiting. There were over 20 such functions in the 6 | dnl # kernel, many of them identical, though most cases can be satisfied by one 7 | dnl # of just two functions: one which uses io_schedule() and one which just 8 | dnl # uses schedule(). This API change was made to consolidate all of those 9 | dnl # redundant wait functions. 10 | dnl # 11 | AC_DEFUN([SPL_AC_WAIT_ON_BIT], [ 12 | AC_MSG_CHECKING([whether wait_on_bit() takes an action]) 13 | SPL_LINUX_TRY_COMPILE([ 14 | #include 15 | ],[ 16 | int (*action)(void *) = NULL; 17 | wait_on_bit(NULL, 0, action, 0); 18 | ],[ 19 | AC_MSG_RESULT(yes) 20 | AC_DEFINE(HAVE_WAIT_ON_BIT_ACTION, 1, [yes]) 21 | ],[ 22 | AC_MSG_RESULT(no) 23 | ]) 24 | ]) 25 | dnl # 26 | dnl # 4.13 API change 27 | dnl # Renamed struct wait_queue -> struct wait_queue_entry. 28 | dnl # 29 | AC_DEFUN([SPL_AC_WAIT_QUEUE_ENTRY_T], [ 30 | AC_MSG_CHECKING([whether wait_queue_entry_t exists]) 31 | SPL_LINUX_TRY_COMPILE([ 32 | #include 33 | ],[ 34 | wait_queue_entry_t *entry __attribute__ ((unused)); 35 | ],[ 36 | AC_MSG_RESULT(yes) 37 | AC_DEFINE(HAVE_WAIT_QUEUE_ENTRY_T, 1, 38 | [wait_queue_entry_t exists]) 39 | ],[ 40 | AC_MSG_RESULT(no) 41 | ]) 42 | ]) 43 | 44 | dnl # 45 | dnl # 4.13 API change 46 | dnl # Renamed wait_queue_head::task_list -> wait_queue_head::head 47 | dnl # Renamed wait_queue_entry::task_list -> wait_queue_entry::entry 48 | dnl # 49 | AC_DEFUN([SPL_AC_WAIT_QUEUE_HEAD_ENTRY], [ 50 | AC_MSG_CHECKING([whether wq_head->head and wq_entry->entry exist]) 51 | SPL_LINUX_TRY_COMPILE([ 52 | #include 53 | 54 | #ifdef HAVE_WAIT_QUEUE_ENTRY_T 55 | typedef wait_queue_head_t spl_wait_queue_head_t; 56 | typedef wait_queue_entry_t spl_wait_queue_entry_t; 57 | #else 58 | typedef wait_queue_head_t spl_wait_queue_head_t; 59 | typedef wait_queue_t spl_wait_queue_entry_t; 60 | #endif 61 | ],[ 62 | spl_wait_queue_head_t wq_head; 63 | spl_wait_queue_entry_t wq_entry; 64 | struct list_head *head __attribute__ ((unused)); 65 | struct list_head *entry __attribute__ ((unused)); 66 | 67 | head = &wq_head.head; 68 | entry = &wq_entry.entry; 69 | ],[ 70 | AC_MSG_RESULT(yes) 71 | AC_DEFINE(HAVE_WAIT_QUEUE_HEAD_ENTRY, 1, 72 | [wq_head->head and wq_entry->entry exist]) 73 | ],[ 74 | AC_MSG_RESULT(no) 75 | ]) 76 | ]) 77 | -------------------------------------------------------------------------------- /config/kernel-zlib.m4: -------------------------------------------------------------------------------- 1 | dnl # 2 | dnl # zlib inflate compat, 3 | dnl # Verify the kernel has CONFIG_ZLIB_INFLATE support enabled. 4 | dnl # 5 | AC_DEFUN([SPL_AC_CONFIG_ZLIB_INFLATE], [ 6 | AC_MSG_CHECKING([whether CONFIG_ZLIB_INFLATE is defined]) 7 | SPL_LINUX_TRY_COMPILE([ 8 | #if !defined(CONFIG_ZLIB_INFLATE) && \ 9 | !defined(CONFIG_ZLIB_INFLATE_MODULE) 10 | #error CONFIG_ZLIB_INFLATE not defined 11 | #endif 12 | ],[ ],[ 13 | AC_MSG_RESULT([yes]) 14 | ],[ 15 | AC_MSG_RESULT([no]) 16 | AC_MSG_ERROR([ 17 | *** This kernel does not include the required zlib inflate support. 18 | *** Rebuild the kernel with CONFIG_ZLIB_INFLATE=y|m set.]) 19 | ]) 20 | ]) 21 | 22 | dnl # 23 | dnl # zlib deflate compat, 24 | dnl # Verify the kernel has CONFIG_ZLIB_DEFLATE support enabled. 25 | dnl # 26 | AC_DEFUN([SPL_AC_CONFIG_ZLIB_DEFLATE], [ 27 | AC_MSG_CHECKING([whether CONFIG_ZLIB_DEFLATE is defined]) 28 | SPL_LINUX_TRY_COMPILE([ 29 | #if !defined(CONFIG_ZLIB_DEFLATE) && \ 30 | !defined(CONFIG_ZLIB_DEFLATE_MODULE) 31 | #error CONFIG_ZLIB_DEFLATE not defined 32 | #endif 33 | ],[ ],[ 34 | AC_MSG_RESULT([yes]) 35 | ],[ 36 | AC_MSG_RESULT([no]) 37 | AC_MSG_ERROR([ 38 | *** This kernel does not include the required zlib deflate support. 39 | *** Rebuild the kernel with CONFIG_ZLIB_DEFLATE=y|m set.]) 40 | ]) 41 | ]) 42 | 43 | dnl # 44 | dnl # 2.6.39 API compat, 45 | dnl # The function zlib_deflate_workspacesize() now take 2 arguments. 46 | dnl # This was done to avoid always having to allocate the maximum size 47 | dnl # workspace (268K). The caller can now specific the windowBits and 48 | dnl # memLevel compression parameters to get a smaller workspace. 49 | dnl # 50 | AC_DEFUN([SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE], 51 | [AC_MSG_CHECKING([whether zlib_deflate_workspacesize() wants 2 args]) 52 | SPL_LINUX_TRY_COMPILE([ 53 | #include 54 | ],[ 55 | return zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL); 56 | ],[ 57 | AC_MSG_RESULT(yes) 58 | AC_DEFINE(HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE, 1, 59 | [zlib_deflate_workspacesize() wants 2 args]) 60 | ],[ 61 | AC_MSG_RESULT(no) 62 | ]) 63 | ]) 64 | -------------------------------------------------------------------------------- /include/spl/rpc/xdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008 Sun Microsystems, Inc. 3 | * Written by Ricardo Correia 4 | * 5 | * This file is part of the SPL, Solaris Porting Layer. 6 | * For details, see . 7 | * 8 | * The SPL is free software; you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License as published by the 10 | * Free Software Foundation; either version 2 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along 19 | * with the SPL. If not, see . 20 | */ 21 | 22 | #ifndef _SPL_RPC_XDR_H 23 | #define _SPL_RPC_XDR_H 24 | 25 | #include 26 | 27 | typedef int bool_t; 28 | 29 | /* 30 | * XDR enums and types. 31 | */ 32 | enum xdr_op { 33 | XDR_ENCODE, 34 | XDR_DECODE 35 | }; 36 | 37 | struct xdr_ops; 38 | 39 | typedef struct { 40 | struct xdr_ops *x_ops; /* Let caller know xdrmem_create() succeeds */ 41 | caddr_t x_addr; /* Current buffer addr */ 42 | caddr_t x_addr_end; /* End of the buffer */ 43 | enum xdr_op x_op; /* Stream direction */ 44 | } XDR; 45 | 46 | typedef bool_t (*xdrproc_t)(XDR *xdrs, void *ptr); 47 | 48 | struct xdr_ops { 49 | bool_t (*xdr_control)(XDR *, int, void *); 50 | 51 | bool_t (*xdr_char)(XDR *, char *); 52 | bool_t (*xdr_u_short)(XDR *, unsigned short *); 53 | bool_t (*xdr_u_int)(XDR *, unsigned *); 54 | bool_t (*xdr_u_longlong_t)(XDR *, u_longlong_t *); 55 | 56 | bool_t (*xdr_opaque)(XDR *, caddr_t, const uint_t); 57 | bool_t (*xdr_string)(XDR *, char **, const uint_t); 58 | bool_t (*xdr_array)(XDR *, caddr_t *, uint_t *, const uint_t, 59 | const uint_t, const xdrproc_t); 60 | }; 61 | 62 | /* 63 | * XDR control operator. 64 | */ 65 | #define XDR_GET_BYTES_AVAIL 1 66 | 67 | struct xdr_bytesrec { 68 | bool_t xc_is_last_record; 69 | size_t xc_num_avail; 70 | }; 71 | 72 | /* 73 | * XDR functions. 74 | */ 75 | void xdrmem_create(XDR *xdrs, const caddr_t addr, const uint_t size, 76 | const enum xdr_op op); 77 | 78 | /* Currently not needed. If needed later, we'll add it to struct xdr_ops */ 79 | #define xdr_destroy(xdrs) ((void) 0) 80 | 81 | #define xdr_control(xdrs, req, info) \ 82 | (xdrs)->x_ops->xdr_control((xdrs), (req), (info)) 83 | 84 | /* 85 | * For precaution, the following are defined as static inlines instead of macros 86 | * to get some amount of type safety. 87 | * 88 | * Also, macros wouldn't work in the case where typecasting is done, because it 89 | * must be possible to reference the functions' addresses by these names. 90 | */ 91 | static inline bool_t xdr_char(XDR *xdrs, char *cp) 92 | { 93 | return (xdrs->x_ops->xdr_char(xdrs, cp)); 94 | } 95 | 96 | static inline bool_t xdr_u_short(XDR *xdrs, unsigned short *usp) 97 | { 98 | return (xdrs->x_ops->xdr_u_short(xdrs, usp)); 99 | } 100 | 101 | static inline bool_t xdr_short(XDR *xdrs, short *sp) 102 | { 103 | BUILD_BUG_ON(sizeof (short) != 2); 104 | return (xdrs->x_ops->xdr_u_short(xdrs, (unsigned short *) sp)); 105 | } 106 | 107 | static inline bool_t xdr_u_int(XDR *xdrs, unsigned *up) 108 | { 109 | return (xdrs->x_ops->xdr_u_int(xdrs, up)); 110 | } 111 | 112 | static inline bool_t xdr_int(XDR *xdrs, int *ip) 113 | { 114 | BUILD_BUG_ON(sizeof (int) != 4); 115 | return (xdrs->x_ops->xdr_u_int(xdrs, (unsigned *)ip)); 116 | } 117 | 118 | static inline bool_t xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp) 119 | { 120 | return (xdrs->x_ops->xdr_u_longlong_t(xdrs, ullp)); 121 | } 122 | 123 | static inline bool_t xdr_longlong_t(XDR *xdrs, longlong_t *llp) 124 | { 125 | BUILD_BUG_ON(sizeof (longlong_t) != 8); 126 | return (xdrs->x_ops->xdr_u_longlong_t(xdrs, (u_longlong_t *)llp)); 127 | } 128 | 129 | /* 130 | * Fixed-length opaque data. 131 | */ 132 | static inline bool_t xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt) 133 | { 134 | return (xdrs->x_ops->xdr_opaque(xdrs, cp, cnt)); 135 | } 136 | 137 | /* 138 | * Variable-length string. 139 | * The *sp buffer must have (maxsize + 1) bytes. 140 | */ 141 | static inline bool_t xdr_string(XDR *xdrs, char **sp, const uint_t maxsize) 142 | { 143 | return (xdrs->x_ops->xdr_string(xdrs, sp, maxsize)); 144 | } 145 | 146 | /* 147 | * Variable-length arrays. 148 | */ 149 | static inline bool_t xdr_array(XDR *xdrs, caddr_t *arrp, uint_t *sizep, 150 | const uint_t maxsize, const uint_t elsize, const xdrproc_t elproc) 151 | { 152 | return xdrs->x_ops->xdr_array(xdrs, arrp, sizep, maxsize, elsize, 153 | elproc); 154 | } 155 | 156 | #endif /* SPL_RPC_XDR_H */ 157 | -------------------------------------------------------------------------------- /include/spl/sys/acl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_ACL_H 26 | #define _SPL_ACL_H 27 | 28 | #include 29 | 30 | typedef struct ace { 31 | uid_t a_who; 32 | uint32_t a_access_mask; 33 | uint16_t a_flags; 34 | uint16_t a_type; 35 | } ace_t; 36 | 37 | typedef struct ace_object { 38 | uid_t a_who; /* uid or gid */ 39 | uint32_t a_access_mask; /* read,write,... */ 40 | uint16_t a_flags; /* see below */ 41 | uint16_t a_type; /* allow or deny */ 42 | uint8_t a_obj_type[16]; /* obj type */ 43 | uint8_t a_inherit_obj_type[16]; /* inherit obj */ 44 | } ace_object_t; 45 | 46 | #define MAX_ACL_ENTRIES 1024 47 | 48 | #define ACE_READ_DATA 0x00000001 49 | #define ACE_LIST_DIRECTORY 0x00000001 50 | #define ACE_WRITE_DATA 0x00000002 51 | #define ACE_ADD_FILE 0x00000002 52 | #define ACE_APPEND_DATA 0x00000004 53 | #define ACE_ADD_SUBDIRECTORY 0x00000004 54 | #define ACE_READ_NAMED_ATTRS 0x00000008 55 | #define ACE_WRITE_NAMED_ATTRS 0x00000010 56 | #define ACE_EXECUTE 0x00000020 57 | #define ACE_DELETE_CHILD 0x00000040 58 | #define ACE_READ_ATTRIBUTES 0x00000080 59 | #define ACE_WRITE_ATTRIBUTES 0x00000100 60 | #define ACE_DELETE 0x00010000 61 | #define ACE_READ_ACL 0x00020000 62 | #define ACE_WRITE_ACL 0x00040000 63 | #define ACE_WRITE_OWNER 0x00080000 64 | #define ACE_SYNCHRONIZE 0x00100000 65 | 66 | #define ACE_FILE_INHERIT_ACE 0x0001 67 | #define ACE_DIRECTORY_INHERIT_ACE 0x0002 68 | #define ACE_NO_PROPAGATE_INHERIT_ACE 0x0004 69 | #define ACE_INHERIT_ONLY_ACE 0x0008 70 | #define ACE_SUCCESSFUL_ACCESS_ACE_FLAG 0x0010 71 | #define ACE_FAILED_ACCESS_ACE_FLAG 0x0020 72 | #define ACE_IDENTIFIER_GROUP 0x0040 73 | #define ACE_INHERITED_ACE 0x0080 74 | #define ACE_OWNER 0x1000 75 | #define ACE_GROUP 0x2000 76 | #define ACE_EVERYONE 0x4000 77 | 78 | #define ACE_ACCESS_ALLOWED_ACE_TYPE 0x0000 79 | #define ACE_ACCESS_DENIED_ACE_TYPE 0x0001 80 | #define ACE_SYSTEM_AUDIT_ACE_TYPE 0x0002 81 | #define ACE_SYSTEM_ALARM_ACE_TYPE 0x0003 82 | 83 | #define ACL_AUTO_INHERIT 0x0001 84 | #define ACL_PROTECTED 0x0002 85 | #define ACL_DEFAULTED 0x0004 86 | #define ACL_FLAGS_ALL (ACL_AUTO_INHERIT|ACL_PROTECTED|ACL_DEFAULTED) 87 | 88 | #define ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE 0x04 89 | #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 90 | #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 91 | #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 92 | #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 93 | #define ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE 0x09 94 | #define ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE 0x0A 95 | #define ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE 0x0B 96 | #define ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE 0x0C 97 | #define ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE 0x0D 98 | #define ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE 0x0E 99 | #define ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE 0x0F 100 | #define ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE 0x10 101 | 102 | #define ACE_ALL_TYPES 0x001F 103 | 104 | #define ACE_TYPE_FLAGS (ACE_OWNER|ACE_GROUP|ACE_EVERYONE|ACE_IDENTIFIER_GROUP) 105 | 106 | /* BEGIN CSTYLED */ 107 | #define ACE_ALL_PERMS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \ 108 | ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \ 109 | ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \ 110 | ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \ 111 | ACE_WRITE_OWNER|ACE_SYNCHRONIZE) 112 | /* END CSTYLED */ 113 | 114 | #define VSA_ACE 0x0010 115 | #define VSA_ACECNT 0x0020 116 | #define VSA_ACE_ALLTYPES 0x0040 117 | #define VSA_ACE_ACLFLAGS 0x0080 118 | 119 | #endif /* _SPL_ACL_H */ 120 | -------------------------------------------------------------------------------- /include/spl/sys/atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_ATOMIC_H 26 | #define _SPL_ATOMIC_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /* 33 | * Map the atomic_* functions to the Linux counterparts. This relies on the 34 | * fact that the atomic types are internally really a uint32 or uint64. If 35 | * this were to change an alternate approach would be needed. 36 | * 37 | * N.B. Due to the limitations of the original API atomicity is not strictly 38 | * preserved when using the 64-bit functions on a 32-bit system. In order 39 | * to support this all consumers would need to be updated to use the Linux 40 | * provided atomic_t and atomic64_t types. 41 | */ 42 | #define atomic_inc_32(v) atomic_inc((atomic_t *)(v)) 43 | #define atomic_dec_32(v) atomic_dec((atomic_t *)(v)) 44 | #define atomic_add_32(v, i) atomic_add((i), (atomic_t *)(v)) 45 | #define atomic_sub_32(v, i) atomic_sub((i), (atomic_t *)(v)) 46 | #define atomic_inc_32_nv(v) atomic_inc_return((atomic_t *)(v)) 47 | #define atomic_dec_32_nv(v) atomic_dec_return((atomic_t *)(v)) 48 | #define atomic_add_32_nv(v, i) atomic_add_return((i), (atomic_t *)(v)) 49 | #define atomic_sub_32_nv(v, i) atomic_sub_return((i), (atomic_t *)(v)) 50 | #define atomic_cas_32(v, x, y) atomic_cmpxchg((atomic_t *)(v), x, y) 51 | #define atomic_swap_32(v, x) atomic_xchg((atomic_t *)(v), x) 52 | #define atomic_inc_64(v) atomic64_inc((atomic64_t *)(v)) 53 | #define atomic_dec_64(v) atomic64_dec((atomic64_t *)(v)) 54 | #define atomic_add_64(v, i) atomic64_add((i), (atomic64_t *)(v)) 55 | #define atomic_sub_64(v, i) atomic64_sub((i), (atomic64_t *)(v)) 56 | #define atomic_inc_64_nv(v) atomic64_inc_return((atomic64_t *)(v)) 57 | #define atomic_dec_64_nv(v) atomic64_dec_return((atomic64_t *)(v)) 58 | #define atomic_add_64_nv(v, i) atomic64_add_return((i), (atomic64_t *)(v)) 59 | #define atomic_sub_64_nv(v, i) atomic64_sub_return((i), (atomic64_t *)(v)) 60 | #define atomic_cas_64(v, x, y) atomic64_cmpxchg((atomic64_t *)(v), x, y) 61 | #define atomic_swap_64(v, x) atomic64_xchg((atomic64_t *)(v), x) 62 | 63 | #ifdef _LP64 64 | static __inline__ void * 65 | atomic_cas_ptr(volatile void *target, void *cmp, void *newval) 66 | { 67 | return ((void *)atomic_cas_64((volatile uint64_t *)target, 68 | (uint64_t)cmp, (uint64_t)newval)); 69 | } 70 | #else /* _LP64 */ 71 | static __inline__ void * 72 | atomic_cas_ptr(volatile void *target, void *cmp, void *newval) 73 | { 74 | return ((void *)atomic_cas_32((volatile uint32_t *)target, 75 | (uint32_t)cmp, (uint32_t)newval)); 76 | } 77 | #endif /* _LP64 */ 78 | 79 | #endif /* _SPL_ATOMIC_H */ 80 | -------------------------------------------------------------------------------- /include/spl/sys/byteorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_BYTEORDER_H 26 | #define _SPL_BYTEORDER_H 27 | 28 | #include 29 | #include 30 | 31 | #define BSWAP_8(x) ((x) & 0xff) 32 | #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) 33 | #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) 34 | #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) 35 | 36 | #define LE_16(x) cpu_to_le16(x) 37 | #define LE_32(x) cpu_to_le32(x) 38 | #define LE_64(x) cpu_to_le64(x) 39 | #define BE_16(x) cpu_to_be16(x) 40 | #define BE_32(x) cpu_to_be32(x) 41 | #define BE_64(x) cpu_to_be64(x) 42 | 43 | #define BE_IN8(xa) \ 44 | *((uint8_t *)(xa)) 45 | 46 | #define BE_IN16(xa) \ 47 | (((uint16_t)BE_IN8(xa) << 8) | BE_IN8((uint8_t *)(xa)+1)) 48 | 49 | #define BE_IN32(xa) \ 50 | (((uint32_t)BE_IN16(xa) << 16) | BE_IN16((uint8_t *)(xa)+2)) 51 | 52 | #ifdef _BIG_ENDIAN 53 | static __inline__ uint64_t 54 | htonll(uint64_t n) 55 | { 56 | return (n); 57 | } 58 | 59 | static __inline__ uint64_t 60 | ntohll(uint64_t n) 61 | { 62 | return (n); 63 | } 64 | #else 65 | static __inline__ uint64_t 66 | htonll(uint64_t n) 67 | { 68 | return ((((uint64_t)htonl(n)) << 32) + htonl(n >> 32)); 69 | } 70 | 71 | static __inline__ uint64_t 72 | ntohll(uint64_t n) 73 | { 74 | return ((((uint64_t)ntohl(n)) << 32) + ntohl(n >> 32)); 75 | } 76 | #endif 77 | 78 | #endif /* SPL_BYTEORDER_H */ 79 | -------------------------------------------------------------------------------- /include/spl/sys/callb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_CALLB_H 26 | #define _SPL_CALLB_H 27 | 28 | #include 29 | #include 30 | 31 | #define CALLB_CPR_ASSERT(cp) ASSERT(MUTEX_HELD((cp)->cc_lockp)); 32 | 33 | typedef struct callb_cpr { 34 | kmutex_t *cc_lockp; 35 | } callb_cpr_t; 36 | 37 | #define CALLB_CPR_INIT(cp, lockp, func, name) { \ 38 | (cp)->cc_lockp = lockp; \ 39 | } 40 | 41 | #define CALLB_CPR_SAFE_BEGIN(cp) { \ 42 | CALLB_CPR_ASSERT(cp); \ 43 | } 44 | 45 | #define CALLB_CPR_SAFE_END(cp, lockp) { \ 46 | CALLB_CPR_ASSERT(cp); \ 47 | } 48 | 49 | #define CALLB_CPR_EXIT(cp) { \ 50 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 51 | mutex_exit((cp)->cc_lockp); \ 52 | } 53 | 54 | #endif /* _SPL_CALLB_H */ 55 | -------------------------------------------------------------------------------- /include/spl/sys/callo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2013 Lawrence Livermore National Security, LLC. 3 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 4 | * Written by Brian Behlendorf . 5 | * UCRL-CODE-235197 6 | * 7 | * This file is part of the SPL, Solaris Porting Layer. 8 | * For details, see . 9 | * 10 | * The SPL is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU General Public License as published by the 12 | * Free Software Foundation; either version 2 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with the SPL. If not, see . 22 | */ 23 | 24 | #ifndef _SPL_CALLO_H 25 | #define _SPL_CALLO_H 26 | 27 | /* 28 | * Callout flags: 29 | * 30 | * CALLOUT_FLAG_ROUNDUP 31 | * Roundup the expiration time to the next resolution boundary. 32 | * If this flag is not specified, the expiration time is rounded down. 33 | * CALLOUT_FLAG_ABSOLUTE 34 | * Normally, the expiration passed to the timeout API functions is an 35 | * expiration interval. If this flag is specified, then it is 36 | * interpreted as the expiration time itself. 37 | * CALLOUT_FLAG_HRESTIME 38 | * Normally, callouts are not affected by changes to system time 39 | * (hrestime). This flag is used to create a callout that is affected 40 | * by system time. If system time changes, these timers must be 41 | * handled in a special way (see callout.c). These are used by condition 42 | * variables and LWP timers that need this behavior. 43 | * CALLOUT_FLAG_32BIT 44 | * Legacy interfaces timeout() and realtime_timeout() pass this flag 45 | * to timeout_generic() to indicate that a 32-bit ID should be allocated. 46 | */ 47 | #define CALLOUT_FLAG_ROUNDUP 0x1 48 | #define CALLOUT_FLAG_ABSOLUTE 0x2 49 | #define CALLOUT_FLAG_HRESTIME 0x4 50 | #define CALLOUT_FLAG_32BIT 0x8 51 | 52 | #endif /* _SPL_CALLB_H */ 53 | -------------------------------------------------------------------------------- /include/spl/sys/cmn_err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_CMN_ERR_H 26 | #define _SPL_CMN_ERR_H 27 | 28 | #include 29 | 30 | #define CE_CONT 0 /* continuation */ 31 | #define CE_NOTE 1 /* notice */ 32 | #define CE_WARN 2 /* warning */ 33 | #define CE_PANIC 3 /* panic */ 34 | #define CE_IGNORE 4 /* print nothing */ 35 | 36 | extern void cmn_err(int, const char *, ...); 37 | extern void vcmn_err(int, const char *, va_list); 38 | extern void vpanic(const char *, va_list); 39 | 40 | #define fm_panic panic 41 | 42 | #endif /* SPL_CMN_ERR_H */ 43 | -------------------------------------------------------------------------------- /include/spl/sys/condvar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_CONDVAR_H 26 | #define _SPL_CONDVAR_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /* 35 | * The kcondvar_t struct is protected by mutex taken externally before 36 | * calling any of the wait/signal funs, and passed into the wait funs. 37 | */ 38 | #define CV_MAGIC 0x346545f4 39 | #define CV_DESTROY 0x346545f5 40 | 41 | typedef struct { 42 | int cv_magic; 43 | spl_wait_queue_head_t cv_event; 44 | spl_wait_queue_head_t cv_destroy; 45 | atomic_t cv_refs; 46 | atomic_t cv_waiters; 47 | kmutex_t *cv_mutex; 48 | } kcondvar_t; 49 | 50 | typedef enum { CV_DEFAULT = 0, CV_DRIVER } kcv_type_t; 51 | 52 | extern void __cv_init(kcondvar_t *, char *, kcv_type_t, void *); 53 | extern void __cv_destroy(kcondvar_t *); 54 | extern void __cv_wait(kcondvar_t *, kmutex_t *); 55 | extern void __cv_wait_io(kcondvar_t *, kmutex_t *); 56 | extern void __cv_wait_sig(kcondvar_t *, kmutex_t *); 57 | extern clock_t __cv_timedwait(kcondvar_t *, kmutex_t *, clock_t); 58 | extern clock_t __cv_timedwait_io(kcondvar_t *, kmutex_t *, clock_t); 59 | extern clock_t __cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t); 60 | extern clock_t cv_timedwait_hires(kcondvar_t *, kmutex_t *, hrtime_t, 61 | hrtime_t res, int flag); 62 | extern clock_t cv_timedwait_sig_hires(kcondvar_t *, kmutex_t *, hrtime_t, 63 | hrtime_t res, int flag); 64 | extern void __cv_signal(kcondvar_t *); 65 | extern void __cv_broadcast(kcondvar_t *c); 66 | 67 | #define cv_init(cvp, name, type, arg) __cv_init(cvp, name, type, arg) 68 | #define cv_destroy(cvp) __cv_destroy(cvp) 69 | #define cv_wait(cvp, mp) __cv_wait(cvp, mp) 70 | #define cv_wait_io(cvp, mp) __cv_wait_io(cvp, mp) 71 | #define cv_wait_sig(cvp, mp) __cv_wait_sig(cvp, mp) 72 | #define cv_wait_interruptible(cvp, mp) cv_wait_sig(cvp, mp) 73 | #define cv_timedwait(cvp, mp, t) __cv_timedwait(cvp, mp, t) 74 | #define cv_timedwait_io(cvp, mp, t) __cv_timedwait_io(cvp, mp, t) 75 | #define cv_timedwait_sig(cvp, mp, t) __cv_timedwait_sig(cvp, mp, t) 76 | #define cv_timedwait_interruptible(cvp, mp, t) cv_timedwait_sig(cvp, mp, t) 77 | #define cv_signal(cvp) __cv_signal(cvp) 78 | #define cv_broadcast(cvp) __cv_broadcast(cvp) 79 | 80 | #endif /* _SPL_CONDVAR_H */ 81 | -------------------------------------------------------------------------------- /include/spl/sys/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_CONSOLE_H 26 | #define _SPL_CONSOLE_H 27 | 28 | void 29 | console_vprintf(const char *fmt, va_list args) 30 | { 31 | vprintk(fmt, args); 32 | } 33 | 34 | void 35 | console_printf(const char *fmt, ...) 36 | { 37 | va_list args; 38 | 39 | va_start(args, fmt); 40 | console_vprintf(fmt, args); 41 | va_end(args); 42 | } 43 | 44 | #endif /* _SPL_CONSOLE_H */ 45 | -------------------------------------------------------------------------------- /include/spl/sys/cred.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_CRED_H 26 | #define _SPL_CRED_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | typedef struct cred cred_t; 34 | 35 | #define kcred ((cred_t *)(init_task.cred)) 36 | #define CRED() ((cred_t *)current_cred()) 37 | 38 | /* Linux 4.9 API change, GROUP_AT was removed */ 39 | #ifndef GROUP_AT 40 | #define GROUP_AT(gi, i) ((gi)->gid[i]) 41 | #endif 42 | 43 | #ifdef HAVE_KUIDGID_T 44 | 45 | #define KUID_TO_SUID(x) (__kuid_val(x)) 46 | #define KGID_TO_SGID(x) (__kgid_val(x)) 47 | #define SUID_TO_KUID(x) (KUIDT_INIT(x)) 48 | #define SGID_TO_KGID(x) (KGIDT_INIT(x)) 49 | #define KGIDP_TO_SGIDP(x) (&(x)->val) 50 | 51 | #else /* HAVE_KUIDGID_T */ 52 | 53 | #define KUID_TO_SUID(x) (x) 54 | #define KGID_TO_SGID(x) (x) 55 | #define SUID_TO_KUID(x) (x) 56 | #define SGID_TO_KGID(x) (x) 57 | #define KGIDP_TO_SGIDP(x) (x) 58 | 59 | #endif /* HAVE_KUIDGID_T */ 60 | 61 | extern void crhold(cred_t *cr); 62 | extern void crfree(cred_t *cr); 63 | extern uid_t crgetuid(const cred_t *cr); 64 | extern uid_t crgetruid(const cred_t *cr); 65 | extern uid_t crgetsuid(const cred_t *cr); 66 | extern uid_t crgetfsuid(const cred_t *cr); 67 | extern gid_t crgetgid(const cred_t *cr); 68 | extern gid_t crgetrgid(const cred_t *cr); 69 | extern gid_t crgetsgid(const cred_t *cr); 70 | extern gid_t crgetfsgid(const cred_t *cr); 71 | extern int crgetngroups(const cred_t *cr); 72 | extern gid_t *crgetgroups(const cred_t *cr); 73 | extern int groupmember(gid_t gid, const cred_t *cr); 74 | 75 | #endif /* _SPL_CRED_H */ 76 | -------------------------------------------------------------------------------- /include/spl/sys/ctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_CTYPE_H 26 | #define _SPL_CTYPE_H 27 | 28 | #include 29 | 30 | #endif /* SPL_CTYPE_H */ 31 | -------------------------------------------------------------------------------- /include/spl/sys/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | /* 26 | * Available Solaris debug functions. All of the ASSERT() macros will be 27 | * compiled out when NDEBUG is defined, this is the default behavior for 28 | * the SPL. To enable assertions use the --enable-debug with configure. 29 | * The VERIFY() functions are never compiled out and cannot be disabled. 30 | * 31 | * PANIC() - Panic the node and print message. 32 | * ASSERT() - Assert X is true, if not panic. 33 | * ASSERTV() - Wraps a variable declaration which is only used by ASSERT(). 34 | * ASSERT3B() - Assert boolean X OP Y is true, if not panic. 35 | * ASSERT3S() - Assert signed X OP Y is true, if not panic. 36 | * ASSERT3U() - Assert unsigned X OP Y is true, if not panic. 37 | * ASSERT3P() - Assert pointer X OP Y is true, if not panic. 38 | * ASSERT0() - Assert value is zero, if not panic. 39 | * VERIFY() - Verify X is true, if not panic. 40 | * VERIFY3B() - Verify boolean X OP Y is true, if not panic. 41 | * VERIFY3S() - Verify signed X OP Y is true, if not panic. 42 | * VERIFY3U() - Verify unsigned X OP Y is true, if not panic. 43 | * VERIFY3P() - Verify pointer X OP Y is true, if not panic. 44 | * VERIFY0() - Verify value is zero, if not panic. 45 | */ 46 | 47 | #ifndef _SPL_DEBUG_H 48 | #define _SPL_DEBUG_H 49 | 50 | /* 51 | * Common DEBUG functionality. 52 | */ 53 | int spl_panic(const char *file, const char *func, int line, 54 | const char *fmt, ...); 55 | void spl_dumpstack(void); 56 | 57 | /* BEGIN CSTYLED */ 58 | #define PANIC(fmt, a...) \ 59 | spl_panic(__FILE__, __FUNCTION__, __LINE__, fmt, ## a) 60 | 61 | #define VERIFY(cond) \ 62 | (void) (unlikely(!(cond)) && \ 63 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ 64 | "%s", "VERIFY(" #cond ") failed\n")) 65 | 66 | #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) do { \ 67 | TYPE _verify3_left = (TYPE)(LEFT); \ 68 | TYPE _verify3_right = (TYPE)(RIGHT); \ 69 | if (!(_verify3_left OP _verify3_right)) \ 70 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ 71 | "VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \ 72 | "failed (" FMT " " #OP " " FMT ")\n", \ 73 | CAST (_verify3_left), CAST (_verify3_right)); \ 74 | } while (0) 75 | 76 | #define VERIFY3B(x,y,z) VERIFY3_IMPL(x, y, z, boolean_t, "%d", (boolean_t)) 77 | #define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long)) 78 | #define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \ 79 | (unsigned long long)) 80 | #define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *)) 81 | #define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long)) 82 | 83 | #define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__) 84 | #define CTASSERT(x) { _CTASSERT(x, __LINE__); } 85 | #define _CTASSERT(x, y) __CTASSERT(x, y) 86 | #define __CTASSERT(x, y) \ 87 | typedef char __attribute__ ((unused)) \ 88 | __compile_time_assertion__ ## y[(x) ? 1 : -1] 89 | 90 | /* 91 | * Debugging disabled (--disable-debug) 92 | */ 93 | #ifdef NDEBUG 94 | 95 | #define SPL_DEBUG_STR "" 96 | #define ASSERT(x) ((void)0) 97 | #define ASSERTV(x) 98 | #define ASSERT3B(x,y,z) ((void)0) 99 | #define ASSERT3S(x,y,z) ((void)0) 100 | #define ASSERT3U(x,y,z) ((void)0) 101 | #define ASSERT3P(x,y,z) ((void)0) 102 | #define ASSERT0(x) ((void)0) 103 | #define IMPLY(A, B) ((void)0) 104 | #define EQUIV(A, B) ((void)0) 105 | 106 | /* 107 | * Debugging enabled (--enable-debug) 108 | */ 109 | #else 110 | 111 | #define SPL_DEBUG_STR " (DEBUG mode)" 112 | #define ASSERT(cond) VERIFY(cond) 113 | #define ASSERTV(x) x 114 | #define ASSERT3B(x,y,z) VERIFY3B(x, y, z) 115 | #define ASSERT3S(x,y,z) VERIFY3S(x, y, z) 116 | #define ASSERT3U(x,y,z) VERIFY3U(x, y, z) 117 | #define ASSERT3P(x,y,z) VERIFY3P(x, y, z) 118 | #define ASSERT0(x) VERIFY0(x) 119 | #define IMPLY(A, B) \ 120 | ((void)(((!(A)) || (B)) || \ 121 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ 122 | "(" #A ") implies (" #B ")"))) 123 | #define EQUIV(A, B) \ 124 | ((void)((!!(A) == !!(B)) || \ 125 | spl_panic(__FILE__, __FUNCTION__, __LINE__, \ 126 | "(" #A ") is equivalent to (" #B ")"))) 127 | /* END CSTYLED */ 128 | 129 | #endif /* NDEBUG */ 130 | 131 | #endif /* SPL_DEBUG_H */ 132 | -------------------------------------------------------------------------------- /include/spl/sys/disp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_DISP_H 26 | #define _SPL_DISP_H 27 | 28 | #include 29 | 30 | #define kpreempt(unused) schedule() 31 | #define kpreempt_disable() preempt_disable() 32 | #define kpreempt_enable() preempt_enable() 33 | 34 | #endif /* SPL_DISP_H */ 35 | -------------------------------------------------------------------------------- /include/spl/sys/dkio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_DKIO_H 26 | #define _SPL_DKIO_H 27 | 28 | #define DFL_SZ(num_exts) \ 29 | (sizeof (dkioc_free_list_t) + (num_exts - 1) * 16) 30 | 31 | #define DKIOC (0x04 << 8) 32 | #define DKIOCFLUSHWRITECACHE (DKIOC|34) /* flush cache to phys medium */ 33 | 34 | /* 35 | * ioctl to free space (e.g. SCSI UNMAP) off a disk. 36 | * Pass a dkioc_free_list_t containing a list of extents to be freed. 37 | */ 38 | #define DKIOCFREE (DKIOC|50) 39 | 40 | #endif /* _SPL_DKIO_H */ 41 | -------------------------------------------------------------------------------- /include/spl/sys/dkioc_free_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_DKIOC_UTIL_H 26 | #define _SPL_DKIOC_UTIL_H 27 | 28 | #include 29 | 30 | typedef struct dkioc_free_list_ext_s { 31 | uint64_t dfle_start; 32 | uint64_t dfle_length; 33 | } dkioc_free_list_ext_t; 34 | 35 | typedef struct dkioc_free_list_s { 36 | uint64_t dfl_flags; 37 | uint64_t dfl_num_exts; 38 | int64_t dfl_offset; 39 | 40 | /* 41 | * N.B. this is only an internal debugging API! This is only called 42 | * from debug builds of sd for pre-release checking. Remove before GA! 43 | */ 44 | void (*dfl_ck_func)(uint64_t, uint64_t, void *); 45 | void *dfl_ck_arg; 46 | 47 | dkioc_free_list_ext_t dfl_exts[1]; 48 | } dkioc_free_list_t; 49 | 50 | static inline void dfl_free(dkioc_free_list_t *dfl) { 51 | vmem_free(dfl, DFL_SZ(dfl->dfl_num_exts)); 52 | } 53 | 54 | static inline dkioc_free_list_t *dfl_alloc(uint64_t dfl_num_exts, int flags) { 55 | return (vmem_zalloc(DFL_SZ(dfl_num_exts), flags)); 56 | } 57 | 58 | #endif /* _SPL_DKIOC_UTIL_H */ 59 | -------------------------------------------------------------------------------- /include/spl/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Lawrence Livermore National Security, LLC. 3 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 4 | * Written by Brian Behlendorf . 5 | * UCRL-CODE-235197 6 | * 7 | * This file is part of the SPL, Solaris Porting Layer. 8 | * For details, see . 9 | * 10 | * The SPL is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU General Public License as published by the 12 | * Free Software Foundation; either version 2 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with the SPL. If not, see . 22 | */ 23 | 24 | #ifndef _SPL_FCNTL_H 25 | #define _SPL_FCNTL_H 26 | 27 | #include 28 | 29 | #define F_FREESP 11 30 | 31 | #ifdef CONFIG_64BIT 32 | typedef struct flock flock64_t; 33 | #else 34 | typedef struct flock64 flock64_t; 35 | #endif /* CONFIG_64BIT */ 36 | 37 | #endif /* _SPL_FCNTL_H */ 38 | -------------------------------------------------------------------------------- /include/spl/sys/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_FILE_H 26 | #define _SPL_FILE_H 27 | 28 | #define FIGNORECASE 0x00080000 29 | #define FKIOCTL 0x80000000 30 | #define ED_CASE_CONFLICT 0x10 31 | 32 | #ifdef HAVE_INODE_LOCK_SHARED 33 | #define spl_inode_lock(ip) inode_lock(ip) 34 | #define spl_inode_unlock(ip) inode_unlock(ip) 35 | #define spl_inode_lock_shared(ip) inode_lock_shared(ip) 36 | #define spl_inode_unlock_shared(ip) inode_unlock_shared(ip) 37 | #define spl_inode_trylock(ip) inode_trylock(ip) 38 | #define spl_inode_trylock_shared(ip) inode_trylock_shared(ip) 39 | #define spl_inode_is_locked(ip) inode_is_locked(ip) 40 | #define spl_inode_lock_nested(ip, s) inode_lock_nested(ip, s) 41 | #else 42 | #define spl_inode_lock(ip) mutex_lock(&(ip)->i_mutex) 43 | #define spl_inode_unlock(ip) mutex_unlock(&(ip)->i_mutex) 44 | #define spl_inode_lock_shared(ip) mutex_lock(&(ip)->i_mutex) 45 | #define spl_inode_unlock_shared(ip) mutex_unlock(&(ip)->i_mutex) 46 | #define spl_inode_trylock(ip) mutex_trylock(&(ip)->i_mutex) 47 | #define spl_inode_trylock_shared(ip) mutex_trylock(&(ip)->i_mutex) 48 | #define spl_inode_is_locked(ip) mutex_is_locked(&(ip)->i_mutex) 49 | #define spl_inode_lock_nested(ip, s) mutex_lock_nested(&(ip)->i_mutex, s) 50 | #endif 51 | 52 | #endif /* SPL_FILE_H */ 53 | -------------------------------------------------------------------------------- /include/spl/sys/inttypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_INTTYPES_H 26 | #define _SPL_INTTYPES_H 27 | 28 | #endif /* SPL_INTTYPES_H */ 29 | -------------------------------------------------------------------------------- /include/spl/sys/isa_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_ISA_DEFS_H 26 | #define _SPL_ISA_DEFS_H 27 | 28 | /* x86_64 arch specific defines */ 29 | #if defined(__x86_64) || defined(__x86_64__) 30 | 31 | #if !defined(__x86_64) 32 | #define __x86_64 33 | #endif 34 | 35 | #if !defined(__amd64) 36 | #define __amd64 37 | #endif 38 | 39 | #if !defined(__x86) 40 | #define __x86 41 | #endif 42 | 43 | #if !defined(_LP64) 44 | #define _LP64 45 | #endif 46 | 47 | #define _ALIGNMENT_REQUIRED 1 48 | 49 | 50 | /* i386 arch specific defines */ 51 | #elif defined(__i386) || defined(__i386__) 52 | 53 | #if !defined(__i386) 54 | #define __i386 55 | #endif 56 | 57 | #if !defined(__x86) 58 | #define __x86 59 | #endif 60 | 61 | #if !defined(_ILP32) 62 | #define _ILP32 63 | #endif 64 | 65 | #define _ALIGNMENT_REQUIRED 0 66 | 67 | /* powerpc (ppc64) arch specific defines */ 68 | #elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) 69 | 70 | #if !defined(__powerpc) 71 | #define __powerpc 72 | #endif 73 | 74 | #if !defined(__powerpc__) 75 | #define __powerpc__ 76 | #endif 77 | 78 | #if defined(__powerpc64__) 79 | #if !defined(_LP64) 80 | #define _LP64 81 | #endif 82 | #else 83 | #if !defined(_ILP32) 84 | #define _ILP32 85 | #endif 86 | #endif 87 | 88 | /* 89 | * Illumos doesn't define _ALIGNMENT_REQUIRED for PPC, so default to 1 90 | * out of paranoia. 91 | */ 92 | #define _ALIGNMENT_REQUIRED 1 93 | 94 | /* arm arch specific defines */ 95 | #elif defined(__arm) || defined(__arm__) || defined(__aarch64__) 96 | 97 | #if !defined(__arm) 98 | #define __arm 99 | #endif 100 | 101 | #if !defined(__arm__) 102 | #define __arm__ 103 | #endif 104 | 105 | #if defined(__aarch64__) 106 | #if !defined(_LP64) 107 | #define _LP64 108 | #endif 109 | #else 110 | #if !defined(_ILP32) 111 | #define _ILP32 112 | #endif 113 | #endif 114 | 115 | #if defined(__ARMEL__) || defined(__AARCH64EL__) 116 | #define _LITTLE_ENDIAN 117 | #else 118 | #define _BIG_ENDIAN 119 | #endif 120 | 121 | /* 122 | * Illumos doesn't define _ALIGNMENT_REQUIRED for ARM, so default to 1 123 | * out of paranoia. 124 | */ 125 | #define _ALIGNMENT_REQUIRED 1 126 | 127 | /* sparc arch specific defines */ 128 | #elif defined(__sparc) || defined(__sparc__) 129 | 130 | #if !defined(__sparc) 131 | #define __sparc 132 | #endif 133 | 134 | #if !defined(__sparc__) 135 | #define __sparc__ 136 | #endif 137 | 138 | #if defined(__arch64__) 139 | #if !defined(_LP64) 140 | #define _LP64 141 | #endif 142 | #else 143 | #if !defined(_ILP32) 144 | #define _ILP32 145 | #endif 146 | #endif 147 | 148 | #define _BIG_ENDIAN 149 | #define _SUNOS_VTOC_16 150 | #define _ALIGNMENT_REQUIRED 1 151 | 152 | /* s390 arch specific defines */ 153 | #elif defined(__s390__) 154 | #if defined(__s390x__) 155 | #if !defined(_LP64) 156 | #define _LP64 157 | #endif 158 | #else 159 | #if !defined(_ILP32) 160 | #define _ILP32 161 | #endif 162 | #endif 163 | 164 | #define _BIG_ENDIAN 165 | 166 | /* 167 | * Illumos doesn't define _ALIGNMENT_REQUIRED for s390, so default to 1 168 | * out of paranoia. 169 | */ 170 | #define _ALIGNMENT_REQUIRED 1 171 | 172 | /* MIPS arch specific defines */ 173 | #elif defined(__mips__) 174 | 175 | #if defined(__MIPSEB__) 176 | #define _BIG_ENDIAN 177 | #elif defined(__MIPSEL__) 178 | #define _LITTLE_ENDIAN 179 | #else 180 | #error MIPS no endian specified 181 | #endif 182 | 183 | #ifndef _LP64 184 | #define _ILP32 185 | #endif 186 | 187 | #define _SUNOS_VTOC_16 188 | 189 | /* 190 | * Illumos doesn't define _ALIGNMENT_REQUIRED for MIPS, so default to 1 191 | * out of paranoia. 192 | */ 193 | #define _ALIGNMENT_REQUIRED 1 194 | 195 | #else 196 | /* 197 | * Currently supported: 198 | * x86_64, i386, arm, powerpc, s390, sparc, and mips 199 | */ 200 | #error "Unsupported ISA type" 201 | #endif 202 | 203 | #if defined(_ILP32) && defined(_LP64) 204 | #error "Both _ILP32 and _LP64 are defined" 205 | #endif 206 | 207 | #if !defined(_ILP32) && !defined(_LP64) 208 | #error "Neither _ILP32 or _LP64 are defined" 209 | #endif 210 | 211 | #include 212 | 213 | #if defined(__LITTLE_ENDIAN) && !defined(_LITTLE_ENDIAN) 214 | #define _LITTLE_ENDIAN __LITTLE_ENDIAN 215 | #endif 216 | 217 | #if defined(__BIG_ENDIAN) && !defined(_BIG_ENDIAN) 218 | #define _BIG_ENDIAN __BIG_ENDIAN 219 | #endif 220 | 221 | #if defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) 222 | #error "Both _LITTLE_ENDIAN and _BIG_ENDIAN are defined" 223 | #endif 224 | 225 | #if !defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) 226 | #error "Neither _LITTLE_ENDIAN or _BIG_ENDIAN are defined" 227 | #endif 228 | 229 | #endif /* _SPL_ISA_DEFS_H */ 230 | -------------------------------------------------------------------------------- /include/spl/sys/kmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_KMEM_H 26 | #define _SPL_KMEM_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | extern int kmem_debugging(void); 33 | extern char *kmem_vasprintf(const char *fmt, va_list ap); 34 | extern char *kmem_asprintf(const char *fmt, ...); 35 | extern char *strdup(const char *str); 36 | extern void strfree(char *str); 37 | 38 | /* 39 | * Memory allocation interfaces 40 | */ 41 | #define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */ 42 | #define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ 43 | #define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */ 44 | #define KM_ZERO 0x1000 /* zero the allocation */ 45 | #define KM_VMEM 0x2000 /* caller is vmem_* wrapper */ 46 | 47 | #define KM_PUBLIC_MASK (KM_SLEEP | KM_NOSLEEP | KM_PUSHPAGE) 48 | 49 | static int spl_fstrans_check(void); 50 | 51 | /* 52 | * Convert a KM_* flags mask to its Linux GFP_* counterpart. The conversion 53 | * function is context aware which means that KM_SLEEP allocations can be 54 | * safely used in syncing contexts which have set PF_FSTRANS. 55 | */ 56 | static inline gfp_t 57 | kmem_flags_convert(int flags) 58 | { 59 | gfp_t lflags = __GFP_NOWARN | __GFP_COMP; 60 | 61 | if (flags & KM_NOSLEEP) { 62 | lflags |= GFP_ATOMIC | __GFP_NORETRY; 63 | } else { 64 | lflags |= GFP_KERNEL; 65 | if (spl_fstrans_check()) 66 | lflags &= ~(__GFP_IO|__GFP_FS); 67 | } 68 | 69 | if (flags & KM_PUSHPAGE) 70 | lflags |= __GFP_HIGH; 71 | 72 | if (flags & KM_ZERO) 73 | lflags |= __GFP_ZERO; 74 | 75 | return (lflags); 76 | } 77 | 78 | typedef struct { 79 | struct task_struct *fstrans_thread; 80 | unsigned int saved_flags; 81 | } fstrans_cookie_t; 82 | 83 | /* 84 | * Introduced in Linux 3.9, however this cannot be solely relied on before 85 | * Linux 3.18 as it doesn't turn off __GFP_FS as it should. 86 | */ 87 | #ifdef PF_MEMALLOC_NOIO 88 | #define __SPL_PF_MEMALLOC_NOIO (PF_MEMALLOC_NOIO) 89 | #else 90 | #define __SPL_PF_MEMALLOC_NOIO (0) 91 | #endif 92 | 93 | /* 94 | * PF_FSTRANS is removed from Linux 4.12 95 | */ 96 | #ifdef PF_FSTRANS 97 | #define __SPL_PF_FSTRANS (PF_FSTRANS) 98 | #else 99 | #define __SPL_PF_FSTRANS (0) 100 | #endif 101 | 102 | #define SPL_FSTRANS (__SPL_PF_FSTRANS|__SPL_PF_MEMALLOC_NOIO) 103 | 104 | static inline fstrans_cookie_t 105 | spl_fstrans_mark(void) 106 | { 107 | fstrans_cookie_t cookie; 108 | 109 | BUILD_BUG_ON(SPL_FSTRANS == 0); 110 | 111 | cookie.fstrans_thread = current; 112 | cookie.saved_flags = current->flags & SPL_FSTRANS; 113 | current->flags |= SPL_FSTRANS; 114 | 115 | return (cookie); 116 | } 117 | 118 | static inline void 119 | spl_fstrans_unmark(fstrans_cookie_t cookie) 120 | { 121 | ASSERT3P(cookie.fstrans_thread, ==, current); 122 | ASSERT((current->flags & SPL_FSTRANS) == SPL_FSTRANS); 123 | 124 | current->flags &= ~SPL_FSTRANS; 125 | current->flags |= cookie.saved_flags; 126 | } 127 | 128 | static inline int 129 | spl_fstrans_check(void) 130 | { 131 | return (current->flags & SPL_FSTRANS); 132 | } 133 | 134 | /* 135 | * specifically used to check PF_FSTRANS flag, cannot be relied on for 136 | * checking spl_fstrans_mark(). 137 | */ 138 | static inline int 139 | __spl_pf_fstrans_check(void) 140 | { 141 | return (current->flags & __SPL_PF_FSTRANS); 142 | } 143 | 144 | #ifdef HAVE_ATOMIC64_T 145 | #define kmem_alloc_used_add(size) atomic64_add(size, &kmem_alloc_used) 146 | #define kmem_alloc_used_sub(size) atomic64_sub(size, &kmem_alloc_used) 147 | #define kmem_alloc_used_read() atomic64_read(&kmem_alloc_used) 148 | #define kmem_alloc_used_set(size) atomic64_set(&kmem_alloc_used, size) 149 | extern atomic64_t kmem_alloc_used; 150 | extern unsigned long long kmem_alloc_max; 151 | #else /* HAVE_ATOMIC64_T */ 152 | #define kmem_alloc_used_add(size) atomic_add(size, &kmem_alloc_used) 153 | #define kmem_alloc_used_sub(size) atomic_sub(size, &kmem_alloc_used) 154 | #define kmem_alloc_used_read() atomic_read(&kmem_alloc_used) 155 | #define kmem_alloc_used_set(size) atomic_set(&kmem_alloc_used, size) 156 | extern atomic_t kmem_alloc_used; 157 | extern unsigned long long kmem_alloc_max; 158 | #endif /* HAVE_ATOMIC64_T */ 159 | 160 | extern unsigned int spl_kmem_alloc_warn; 161 | extern unsigned int spl_kmem_alloc_max; 162 | 163 | #define kmem_alloc(sz, fl) spl_kmem_alloc((sz), (fl), __func__, __LINE__) 164 | #define kmem_zalloc(sz, fl) spl_kmem_zalloc((sz), (fl), __func__, __LINE__) 165 | #define kmem_free(ptr, sz) spl_kmem_free((ptr), (sz)) 166 | 167 | extern void *spl_kmem_alloc(size_t sz, int fl, const char *func, int line); 168 | extern void *spl_kmem_zalloc(size_t sz, int fl, const char *func, int line); 169 | extern void spl_kmem_free(const void *ptr, size_t sz); 170 | 171 | /* 172 | * The following functions are only available for internal use. 173 | */ 174 | extern void *spl_kmem_alloc_impl(size_t size, int flags, int node); 175 | extern void *spl_kmem_alloc_debug(size_t size, int flags, int node); 176 | extern void *spl_kmem_alloc_track(size_t size, int flags, 177 | const char *func, int line, int node); 178 | extern void spl_kmem_free_impl(const void *buf, size_t size); 179 | extern void spl_kmem_free_debug(const void *buf, size_t size); 180 | extern void spl_kmem_free_track(const void *buf, size_t size); 181 | 182 | extern int spl_kmem_init(void); 183 | extern void spl_kmem_fini(void); 184 | 185 | #endif /* _SPL_KMEM_H */ 186 | -------------------------------------------------------------------------------- /include/spl/sys/kobj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_KOBJ_H 26 | #define _SPL_KOBJ_H 27 | 28 | #include 29 | 30 | typedef struct _buf { 31 | vnode_t *vp; 32 | } _buf_t; 33 | 34 | typedef struct _buf buf_t; 35 | 36 | extern struct _buf *kobj_open_file(const char *name); 37 | extern void kobj_close_file(struct _buf *file); 38 | extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, 39 | unsigned off); 40 | extern int kobj_get_filesize(struct _buf *file, uint64_t *size); 41 | 42 | #endif /* SPL_KOBJ_H */ 43 | -------------------------------------------------------------------------------- /include/spl/sys/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_LIST_H 26 | #define _SPL_LIST_H 27 | 28 | #include 29 | #include 30 | 31 | /* 32 | * NOTE: I have implemented the Solaris list API in terms of the native 33 | * linux API. This has certain advantages in terms of leveraging the linux 34 | * list debugging infrastructure, but it also means that the internals of a 35 | * list differ slightly than on Solaris. This is not a problem as long as 36 | * all callers stick to the published API. The two major differences are: 37 | * 38 | * 1) A list_node_t is mapped to a linux list_head struct which changes 39 | * the name of the list_next/list_prev pointers to next/prev respectively. 40 | * 41 | * 2) A list_node_t which is not attached to a list on Solaris is denoted 42 | * by having its list_next/list_prev pointers set to NULL. Under linux 43 | * the next/prev pointers are set to LIST_POISON1 and LIST_POISON2 44 | * respectively. At this moment this only impacts the implementation 45 | * of the list_link_init() and list_link_active() functions. 46 | */ 47 | 48 | typedef struct list_head list_node_t; 49 | 50 | typedef struct list { 51 | size_t list_size; 52 | size_t list_offset; 53 | list_node_t list_head; 54 | } list_t; 55 | 56 | #define list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset)) 57 | #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset)) 58 | 59 | static inline int 60 | list_is_empty(list_t *list) 61 | { 62 | return (list_empty(&list->list_head)); 63 | } 64 | 65 | static inline void 66 | list_link_init(list_node_t *node) 67 | { 68 | node->next = LIST_POISON1; 69 | node->prev = LIST_POISON2; 70 | } 71 | 72 | static inline void 73 | list_create(list_t *list, size_t size, size_t offset) 74 | { 75 | list->list_size = size; 76 | list->list_offset = offset; 77 | INIT_LIST_HEAD(&list->list_head); 78 | } 79 | 80 | static inline void 81 | list_destroy(list_t *list) 82 | { 83 | list_del(&list->list_head); 84 | } 85 | 86 | static inline void 87 | list_insert_head(list_t *list, void *object) 88 | { 89 | list_add(list_d2l(list, object), &list->list_head); 90 | } 91 | 92 | static inline void 93 | list_insert_tail(list_t *list, void *object) 94 | { 95 | list_add_tail(list_d2l(list, object), &list->list_head); 96 | } 97 | 98 | static inline void 99 | list_insert_after(list_t *list, void *object, void *nobject) 100 | { 101 | if (object == NULL) 102 | list_insert_head(list, nobject); 103 | else 104 | list_add(list_d2l(list, nobject), list_d2l(list, object)); 105 | } 106 | 107 | static inline void 108 | list_insert_before(list_t *list, void *object, void *nobject) 109 | { 110 | if (object == NULL) 111 | list_insert_tail(list, nobject); 112 | else 113 | list_add_tail(list_d2l(list, nobject), list_d2l(list, object)); 114 | } 115 | 116 | static inline void 117 | list_remove(list_t *list, void *object) 118 | { 119 | list_del(list_d2l(list, object)); 120 | } 121 | 122 | static inline void * 123 | list_remove_head(list_t *list) 124 | { 125 | list_node_t *head = list->list_head.next; 126 | if (head == &list->list_head) 127 | return (NULL); 128 | 129 | list_del(head); 130 | return (list_object(list, head)); 131 | } 132 | 133 | static inline void * 134 | list_remove_tail(list_t *list) 135 | { 136 | list_node_t *tail = list->list_head.prev; 137 | if (tail == &list->list_head) 138 | return (NULL); 139 | 140 | list_del(tail); 141 | return (list_object(list, tail)); 142 | } 143 | 144 | static inline void * 145 | list_head(list_t *list) 146 | { 147 | if (list_is_empty(list)) 148 | return (NULL); 149 | 150 | return (list_object(list, list->list_head.next)); 151 | } 152 | 153 | static inline void * 154 | list_tail(list_t *list) 155 | { 156 | if (list_is_empty(list)) 157 | return (NULL); 158 | 159 | return (list_object(list, list->list_head.prev)); 160 | } 161 | 162 | static inline void * 163 | list_next(list_t *list, void *object) 164 | { 165 | list_node_t *node = list_d2l(list, object); 166 | 167 | if (node->next != &list->list_head) 168 | return (list_object(list, node->next)); 169 | 170 | return (NULL); 171 | } 172 | 173 | static inline void * 174 | list_prev(list_t *list, void *object) 175 | { 176 | list_node_t *node = list_d2l(list, object); 177 | 178 | if (node->prev != &list->list_head) 179 | return (list_object(list, node->prev)); 180 | 181 | return (NULL); 182 | } 183 | 184 | static inline int 185 | list_link_active(list_node_t *node) 186 | { 187 | return (node->next != LIST_POISON1) && (node->prev != LIST_POISON2); 188 | } 189 | 190 | static inline void 191 | spl_list_move_tail(list_t *dst, list_t *src) 192 | { 193 | list_splice_init(&src->list_head, dst->list_head.prev); 194 | } 195 | 196 | #define list_move_tail(dst, src) spl_list_move_tail(dst, src) 197 | 198 | static inline void 199 | list_link_replace(list_node_t *old_node, list_node_t *new_node) 200 | { 201 | new_node->next = old_node->next; 202 | new_node->prev = old_node->prev; 203 | old_node->prev->next = new_node; 204 | old_node->next->prev = new_node; 205 | list_link_init(old_node); 206 | } 207 | 208 | #endif /* SPL_LIST_H */ 209 | -------------------------------------------------------------------------------- /include/spl/sys/mode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_MODE_H 26 | #define _SPL_MODE_H 27 | 28 | #define IFTOVT(mode) vn_mode_to_vtype(mode) 29 | #define VTTOIF(vtype) vn_vtype_to_mode(vtype) 30 | #define MAKEIMODE(T, M) (VTTOIF(T) | ((M) & ~S_IFMT)) 31 | 32 | #endif /* SPL_MODE_H */ 33 | -------------------------------------------------------------------------------- /include/spl/sys/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_MUTEX_H 26 | #define _SPL_MUTEX_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | typedef enum { 33 | MUTEX_DEFAULT = 0, 34 | MUTEX_SPIN = 1, 35 | MUTEX_ADAPTIVE = 2, 36 | MUTEX_NOLOCKDEP = 3 37 | } kmutex_type_t; 38 | 39 | typedef struct { 40 | struct mutex m_mutex; 41 | spinlock_t m_lock; /* used for serializing mutex_exit */ 42 | kthread_t *m_owner; 43 | #ifdef CONFIG_LOCKDEP 44 | kmutex_type_t m_type; 45 | #endif /* CONFIG_LOCKDEP */ 46 | } kmutex_t; 47 | 48 | #define MUTEX(mp) (&((mp)->m_mutex)) 49 | 50 | static inline void 51 | spl_mutex_set_owner(kmutex_t *mp) 52 | { 53 | mp->m_owner = current; 54 | } 55 | 56 | static inline void 57 | spl_mutex_clear_owner(kmutex_t *mp) 58 | { 59 | mp->m_owner = NULL; 60 | } 61 | 62 | #define mutex_owner(mp) (ACCESS_ONCE((mp)->m_owner)) 63 | #define mutex_owned(mp) (mutex_owner(mp) == current) 64 | #define MUTEX_HELD(mp) mutex_owned(mp) 65 | #define MUTEX_NOT_HELD(mp) (!MUTEX_HELD(mp)) 66 | 67 | #ifdef CONFIG_LOCKDEP 68 | static inline void 69 | spl_mutex_set_type(kmutex_t *mp, kmutex_type_t type) 70 | { 71 | mp->m_type = type; 72 | } 73 | static inline void 74 | spl_mutex_lockdep_off_maybe(kmutex_t *mp) \ 75 | { \ 76 | if (mp && mp->m_type == MUTEX_NOLOCKDEP) \ 77 | lockdep_off(); \ 78 | } 79 | static inline void 80 | spl_mutex_lockdep_on_maybe(kmutex_t *mp) \ 81 | { \ 82 | if (mp && mp->m_type == MUTEX_NOLOCKDEP) \ 83 | lockdep_on(); \ 84 | } 85 | #else /* CONFIG_LOCKDEP */ 86 | #define spl_mutex_set_type(mp, type) 87 | #define spl_mutex_lockdep_off_maybe(mp) 88 | #define spl_mutex_lockdep_on_maybe(mp) 89 | #endif /* CONFIG_LOCKDEP */ 90 | 91 | /* 92 | * The following functions must be a #define and not static inline. 93 | * This ensures that the native linux mutex functions (lock/unlock) 94 | * will be correctly located in the users code which is important 95 | * for the built in kernel lock analysis tools 96 | */ 97 | #undef mutex_init 98 | #define mutex_init(mp, name, type, ibc) \ 99 | { \ 100 | static struct lock_class_key __key; \ 101 | ASSERT(type == MUTEX_DEFAULT || type == MUTEX_NOLOCKDEP); \ 102 | \ 103 | __mutex_init(MUTEX(mp), (name) ? (#name) : (#mp), &__key); \ 104 | spin_lock_init(&(mp)->m_lock); \ 105 | spl_mutex_clear_owner(mp); \ 106 | spl_mutex_set_type(mp, type); \ 107 | } 108 | 109 | #undef mutex_destroy 110 | #define mutex_destroy(mp) \ 111 | { \ 112 | VERIFY3P(mutex_owner(mp), ==, NULL); \ 113 | } 114 | 115 | /* BEGIN CSTYLED */ 116 | #define mutex_tryenter(mp) \ 117 | ({ \ 118 | int _rc_; \ 119 | \ 120 | spl_mutex_lockdep_off_maybe(mp); \ 121 | if ((_rc_ = mutex_trylock(MUTEX(mp))) == 1) \ 122 | spl_mutex_set_owner(mp); \ 123 | spl_mutex_lockdep_on_maybe(mp); \ 124 | \ 125 | _rc_; \ 126 | }) 127 | /* END CSTYLED */ 128 | 129 | #ifdef CONFIG_DEBUG_LOCK_ALLOC 130 | #define mutex_enter_nested(mp, subclass) \ 131 | { \ 132 | ASSERT3P(mutex_owner(mp), !=, current); \ 133 | spl_mutex_lockdep_off_maybe(mp); \ 134 | mutex_lock_nested(MUTEX(mp), (subclass)); \ 135 | spl_mutex_lockdep_on_maybe(mp); \ 136 | spl_mutex_set_owner(mp); \ 137 | } 138 | #else /* CONFIG_DEBUG_LOCK_ALLOC */ 139 | #define mutex_enter_nested(mp, subclass) \ 140 | { \ 141 | ASSERT3P(mutex_owner(mp), !=, current); \ 142 | spl_mutex_lockdep_off_maybe(mp); \ 143 | mutex_lock(MUTEX(mp)); \ 144 | spl_mutex_lockdep_on_maybe(mp); \ 145 | spl_mutex_set_owner(mp); \ 146 | } 147 | #endif /* CONFIG_DEBUG_LOCK_ALLOC */ 148 | 149 | #define mutex_enter(mp) mutex_enter_nested((mp), 0) 150 | 151 | /* 152 | * The reason for the spinlock: 153 | * 154 | * The Linux mutex is designed with a fast-path/slow-path design such that it 155 | * does not guarantee serialization upon itself, allowing a race where latter 156 | * acquirers finish mutex_unlock before former ones. 157 | * 158 | * The race renders it unsafe to be used for serializing the freeing of an 159 | * object in which the mutex is embedded, where the latter acquirer could go 160 | * on to free the object while the former one is still doing mutex_unlock and 161 | * causing memory corruption. 162 | * 163 | * However, there are many places in ZFS where the mutex is used for 164 | * serializing object freeing, and the code is shared among other OSes without 165 | * this issue. Thus, we need the spinlock to force the serialization on 166 | * mutex_exit(). 167 | * 168 | * See http://lwn.net/Articles/575477/ for the information about the race. 169 | */ 170 | #define mutex_exit(mp) \ 171 | { \ 172 | spl_mutex_clear_owner(mp); \ 173 | spin_lock(&(mp)->m_lock); \ 174 | spl_mutex_lockdep_off_maybe(mp); \ 175 | mutex_unlock(MUTEX(mp)); \ 176 | spl_mutex_lockdep_on_maybe(mp); \ 177 | spin_unlock(&(mp)->m_lock); \ 178 | /* NOTE: do not dereference mp after this point */ \ 179 | } 180 | 181 | int spl_mutex_init(void); 182 | void spl_mutex_fini(void); 183 | 184 | #endif /* _SPL_MUTEX_H */ 185 | -------------------------------------------------------------------------------- /include/spl/sys/param.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_PARAM_H 26 | #define _SPL_PARAM_H 27 | 28 | #include 29 | 30 | /* Pages to bytes and back */ 31 | #define ptob(pages) ((pages) << PAGE_SHIFT) 32 | #define btop(bytes) ((bytes) >> PAGE_SHIFT) 33 | 34 | #define MAXUID UINT32_MAX 35 | 36 | #endif /* SPL_PARAM_H */ 37 | -------------------------------------------------------------------------------- /include/spl/sys/proc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_PROC_H 26 | #define _SPL_PROC_H 27 | 28 | #include 29 | 30 | extern struct proc_dir_entry *proc_spl_kstat; 31 | 32 | int spl_proc_init(void); 33 | void spl_proc_fini(void); 34 | 35 | #endif /* SPL_PROC_H */ 36 | -------------------------------------------------------------------------------- /include/spl/sys/processor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_PROCESSOR_H 26 | #define _SPL_PROCESSOR_H 27 | 28 | #define getcpuid() smp_processor_id() 29 | 30 | typedef int processorid_t; 31 | 32 | #endif /* _SPL_PROCESSOR_H */ 33 | -------------------------------------------------------------------------------- /include/spl/sys/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_RANDOM_H 26 | #define _SPL_RANDOM_H 27 | 28 | #include 29 | #include 30 | 31 | static __inline__ int 32 | random_get_bytes(uint8_t *ptr, size_t len) 33 | { 34 | get_random_bytes((void *)ptr, (int)len); 35 | return (0); 36 | } 37 | 38 | extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); 39 | 40 | #endif /* _SPL_RANDOM_H */ 41 | -------------------------------------------------------------------------------- /include/spl/sys/shrinker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_SHRINKER_H 26 | #define _SPL_SHRINKER_H 27 | 28 | #include 29 | #include 30 | 31 | #if !defined(HAVE_SHRINK_CONTROL_STRUCT) 32 | struct shrink_control { 33 | gfp_t gfp_mask; 34 | unsigned long nr_to_scan; 35 | }; 36 | #endif /* HAVE_SHRINK_CONTROL_STRUCT */ 37 | 38 | /* 39 | * Due to frequent changes in the shrinker API the following 40 | * compatibility wrappers should be used. They are as follows: 41 | * 42 | * SPL_SHRINKER_DECLARE is used to declare the shrinker which is 43 | * passed to spl_register_shrinker()/spl_unregister_shrinker(). Use 44 | * shrinker_name to set the shrinker variable name, shrinker_callback 45 | * to set the callback function, and seek_cost to define the cost of 46 | * reclaiming an object. 47 | * 48 | * SPL_SHRINKER_DECLARE(shrinker_name, shrinker_callback, seek_cost); 49 | * 50 | * SPL_SHRINKER_CALLBACK_FWD_DECLARE is used when a forward declaration 51 | * of the shrinker callback function is required. Only the callback 52 | * function needs to be passed. 53 | * 54 | * SPL_SHRINKER_CALLBACK_FWD_DECLARE(shrinker_callback); 55 | * 56 | * SPL_SHRINKER_CALLBACK_WRAPPER is used to declare the callback function 57 | * which is registered with the shrinker. This function will call your 58 | * custom shrinker which must use the following prototype. Notice the 59 | * leading __'s, these must be appended to the callback_function name. 60 | * 61 | * int __shrinker_callback(struct shrinker *, struct shrink_control *) 62 | * SPL_SHRINKER_CALLBACK_WRAPPER(shrinker_callback);a 63 | * 64 | * 65 | * Example: 66 | * 67 | * SPL_SHRINKER_CALLBACK_FWD_DECLARE(my_shrinker_fn); 68 | * SPL_SHRINKER_DECLARE(my_shrinker, my_shrinker_fn, 1); 69 | * 70 | * static int 71 | * __my_shrinker_fn(struct shrinker *shrink, struct shrink_control *sc) 72 | * { 73 | * if (sc->nr_to_scan) { 74 | * ...scan objects in the cache and reclaim them... 75 | * } 76 | * 77 | * ...calculate number of objects in the cache... 78 | * 79 | * return (number of objects in the cache); 80 | * } 81 | * SPL_SHRINKER_CALLBACK_WRAPPER(my_shrinker_fn); 82 | */ 83 | 84 | #define spl_register_shrinker(x) register_shrinker(x) 85 | #define spl_unregister_shrinker(x) unregister_shrinker(x) 86 | 87 | /* 88 | * Linux 2.6.23 - 2.6.34 Shrinker API Compatibility. 89 | */ 90 | #if defined(HAVE_2ARGS_OLD_SHRINKER_CALLBACK) 91 | #define SPL_SHRINKER_DECLARE(s, x, y) \ 92 | static struct shrinker s = { \ 93 | .shrink = x, \ 94 | .seeks = y \ 95 | } 96 | 97 | #define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \ 98 | static int fn(int nr_to_scan, unsigned int gfp_mask) 99 | 100 | #define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \ 101 | static int \ 102 | fn(int nr_to_scan, unsigned int gfp_mask) \ 103 | { \ 104 | struct shrink_control sc; \ 105 | \ 106 | sc.nr_to_scan = nr_to_scan; \ 107 | sc.gfp_mask = gfp_mask; \ 108 | \ 109 | return (__ ## fn(NULL, &sc)); \ 110 | } 111 | 112 | /* 113 | * Linux 2.6.35 to 2.6.39 Shrinker API Compatibility. 114 | */ 115 | #elif defined(HAVE_3ARGS_SHRINKER_CALLBACK) 116 | #define SPL_SHRINKER_DECLARE(s, x, y) \ 117 | static struct shrinker s = { \ 118 | .shrink = x, \ 119 | .seeks = y \ 120 | } 121 | 122 | #define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \ 123 | static int fn(struct shrinker *, int, unsigned int) 124 | 125 | #define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \ 126 | static int \ 127 | fn(struct shrinker *shrink, int nr_to_scan, unsigned int gfp_mask) \ 128 | { \ 129 | struct shrink_control sc; \ 130 | \ 131 | sc.nr_to_scan = nr_to_scan; \ 132 | sc.gfp_mask = gfp_mask; \ 133 | \ 134 | return (__ ## fn(shrink, &sc)); \ 135 | } 136 | 137 | /* 138 | * Linux 3.0 to 3.11 Shrinker API Compatibility. 139 | */ 140 | #elif defined(HAVE_2ARGS_NEW_SHRINKER_CALLBACK) 141 | #define SPL_SHRINKER_DECLARE(s, x, y) \ 142 | static struct shrinker s = { \ 143 | .shrink = x, \ 144 | .seeks = y \ 145 | } 146 | 147 | #define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \ 148 | static int fn(struct shrinker *, struct shrink_control *) 149 | 150 | #define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \ 151 | static int \ 152 | fn(struct shrinker *shrink, struct shrink_control *sc) \ 153 | { \ 154 | return (__ ## fn(shrink, sc)); \ 155 | } 156 | 157 | /* 158 | * Linux 3.12 and later Shrinker API Compatibility. 159 | */ 160 | #elif defined(HAVE_SPLIT_SHRINKER_CALLBACK) 161 | #define SPL_SHRINKER_DECLARE(s, x, y) \ 162 | static struct shrinker s = { \ 163 | .count_objects = x ## _count_objects, \ 164 | .scan_objects = x ## _scan_objects, \ 165 | .seeks = y \ 166 | } 167 | 168 | #define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \ 169 | static unsigned long fn ## _count_objects(struct shrinker *, \ 170 | struct shrink_control *); \ 171 | static unsigned long fn ## _scan_objects(struct shrinker *, \ 172 | struct shrink_control *) 173 | 174 | #define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \ 175 | static unsigned long \ 176 | fn ## _count_objects(struct shrinker *shrink, struct shrink_control *sc)\ 177 | { \ 178 | int __ret__; \ 179 | \ 180 | sc->nr_to_scan = 0; \ 181 | __ret__ = __ ## fn(NULL, sc); \ 182 | \ 183 | /* Errors may not be returned and must be converted to zeros */ \ 184 | return ((__ret__ < 0) ? 0 : __ret__); \ 185 | } \ 186 | \ 187 | static unsigned long \ 188 | fn ## _scan_objects(struct shrinker *shrink, struct shrink_control *sc) \ 189 | { \ 190 | int __ret__; \ 191 | \ 192 | __ret__ = __ ## fn(NULL, sc); \ 193 | return ((__ret__ < 0) ? SHRINK_STOP : __ret__); \ 194 | } 195 | #else 196 | /* 197 | * Linux 2.x to 2.6.22, or a newer shrinker API has been introduced. 198 | */ 199 | #error "Unknown shrinker callback" 200 | #endif 201 | 202 | #if defined(HAVE_SPLIT_SHRINKER_CALLBACK) 203 | typedef unsigned long spl_shrinker_t; 204 | #else 205 | typedef int spl_shrinker_t; 206 | #define SHRINK_STOP (-1) 207 | #endif 208 | 209 | #endif /* SPL_SHRINKER_H */ 210 | -------------------------------------------------------------------------------- /include/spl/sys/sid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_SID_H 26 | #define _SPL_SID_H 27 | 28 | typedef struct ksiddomain { 29 | char *kd_name; 30 | } ksiddomain_t; 31 | 32 | typedef enum ksid_index { 33 | KSID_USER, 34 | KSID_GROUP, 35 | KSID_OWNER, 36 | KSID_COUNT 37 | } ksid_index_t; 38 | 39 | typedef int ksid_t; 40 | 41 | static inline ksiddomain_t * 42 | ksid_lookupdomain(const char *dom) 43 | { 44 | ksiddomain_t *kd; 45 | int len = strlen(dom); 46 | 47 | kd = kmem_zalloc(sizeof (ksiddomain_t), KM_SLEEP); 48 | kd->kd_name = kmem_zalloc(len + 1, KM_SLEEP); 49 | memcpy(kd->kd_name, dom, len); 50 | 51 | return (kd); 52 | } 53 | 54 | static inline void 55 | ksiddomain_rele(ksiddomain_t *ksid) 56 | { 57 | kmem_free(ksid->kd_name, strlen(ksid->kd_name) + 1); 58 | kmem_free(ksid, sizeof (ksiddomain_t)); 59 | } 60 | 61 | #endif /* _SPL_SID_H */ 62 | -------------------------------------------------------------------------------- /include/spl/sys/signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_SIGNAL_H 26 | #define _SPL_SIGNAL_H 27 | 28 | #include 29 | 30 | #ifdef HAVE_SCHED_SIGNAL_HEADER 31 | #include 32 | #endif 33 | 34 | #define FORREAL 0 /* Usual side-effects */ 35 | #define JUSTLOOKING 1 /* Don't stop the process */ 36 | 37 | /* 38 | * The "why" argument indicates the allowable side-effects of the call: 39 | * 40 | * FORREAL: Extract the next pending signal from p_sig into p_cursig; 41 | * stop the process if a stop has been requested or if a traced signal 42 | * is pending. 43 | * 44 | * JUSTLOOKING: Don't stop the process, just indicate whether or not 45 | * a signal might be pending (FORREAL is needed to tell for sure). 46 | */ 47 | static __inline__ int 48 | issig(int why) 49 | { 50 | ASSERT(why == FORREAL || why == JUSTLOOKING); 51 | 52 | return (signal_pending(current)); 53 | } 54 | 55 | #endif /* SPL_SIGNAL_H */ 56 | -------------------------------------------------------------------------------- /include/spl/sys/stat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_STAT_H 26 | #define _SPL_STAT_H 27 | 28 | #include 29 | 30 | #endif /* SPL_STAT_H */ 31 | -------------------------------------------------------------------------------- /include/spl/sys/strings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Lawrence Livermore National Security, LLC. 3 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 4 | * UCRL-CODE-235197 5 | * 6 | * This file is part of the SPL, Solaris Porting Layer. 7 | * For details, see . 8 | * 9 | * The SPL is free software; you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License as published by the 11 | * Free Software Foundation; either version 2 of the License, or (at your 12 | * option) any later version. 13 | * 14 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with the SPL. If not, see . 21 | */ 22 | #ifndef _SPL_SYS_STRINGS_H 23 | #define _SPL_SYS_STRINGS_H 24 | 25 | #include 26 | 27 | #define bzero(ptr, size) memset(ptr, 0, size) 28 | #define bcopy(src, dest, size) memmove(dest, src, size) 29 | #define bcmp(src, dest, size) memcmp((src), (dest), (size_t)(size)) 30 | 31 | #endif /* _SPL_SYS_STRINGS_H */ 32 | -------------------------------------------------------------------------------- /include/spl/sys/sunddi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_SUNDDI_H 26 | #define _SPL_SUNDDI_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | typedef int ddi_devid_t; 35 | 36 | #define DDI_DEV_T_NONE ((dev_t)-1) 37 | #define DDI_DEV_T_ANY ((dev_t)-2) 38 | #define DI_MAJOR_T_UNKNOWN ((major_t)0) 39 | 40 | #define DDI_PROP_DONTPASS 0x0001 41 | #define DDI_PROP_CANSLEEP 0x0002 42 | 43 | #define DDI_SUCCESS 0 44 | #define DDI_FAILURE -1 45 | 46 | #define ddi_prop_lookup_string(x1, x2, x3, x4, x5) (*x5 = NULL) 47 | #define ddi_prop_free(x) (void)0 48 | #define ddi_root_node() (void)0 49 | 50 | extern int ddi_strtoul(const char *, char **, int, unsigned long *); 51 | extern int ddi_strtol(const char *, char **, int, long *); 52 | extern int ddi_strtoull(const char *, char **, int, unsigned long long *); 53 | extern int ddi_strtoll(const char *, char **, int, long long *); 54 | 55 | extern int ddi_copyin(const void *from, void *to, size_t len, int flags); 56 | extern int ddi_copyout(const void *from, void *to, size_t len, int flags); 57 | 58 | #endif /* SPL_SUNDDI_H */ 59 | -------------------------------------------------------------------------------- /include/spl/sys/sysmacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_SYSMACROS_H 26 | #define _SPL_SYSMACROS_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef HAVE_SCHED_RT_HEADER 37 | #include 38 | #endif 39 | 40 | #ifndef _KERNEL 41 | #define _KERNEL __KERNEL__ 42 | #endif 43 | 44 | #define FALSE 0 45 | #define TRUE 1 46 | 47 | #define INT8_MAX (127) 48 | #define INT8_MIN (-128) 49 | #define UINT8_MAX (255) 50 | #define UINT8_MIN (0) 51 | 52 | #define INT16_MAX (32767) 53 | #define INT16_MIN (-32768) 54 | #define UINT16_MAX (65535) 55 | #define UINT16_MIN (0) 56 | 57 | #define INT32_MAX INT_MAX 58 | #define INT32_MIN INT_MIN 59 | #define UINT32_MAX UINT_MAX 60 | #define UINT32_MIN UINT_MIN 61 | 62 | #define INT64_MAX LLONG_MAX 63 | #define INT64_MIN LLONG_MIN 64 | #define UINT64_MAX ULLONG_MAX 65 | #define UINT64_MIN ULLONG_MIN 66 | 67 | #define NBBY 8 68 | 69 | #define MAXMSGLEN 256 70 | #define MAXNAMELEN 256 71 | #define MAXPATHLEN 4096 72 | #define MAXOFFSET_T LLONG_MAX 73 | #define MAXBSIZE 8192 74 | #define DEV_BSIZE 512 75 | #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 76 | 77 | #define proc_pageout NULL 78 | #define curproc current 79 | #define max_ncpus num_possible_cpus() 80 | #define boot_ncpus num_online_cpus() 81 | #define CPU_SEQID smp_processor_id() 82 | #define _NOTE(x) 83 | #define is_system_labeled() 0 84 | 85 | #ifndef RLIM64_INFINITY 86 | #define RLIM64_INFINITY (~0ULL) 87 | #endif 88 | 89 | /* 90 | * 0..MAX_PRIO-1: Process priority 91 | * 0..MAX_RT_PRIO-1: RT priority tasks 92 | * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks 93 | * 94 | * Treat shim tasks as SCHED_NORMAL tasks 95 | */ 96 | #define minclsyspri (MAX_PRIO-1) 97 | #define maxclsyspri (MAX_RT_PRIO) 98 | #define defclsyspri (DEFAULT_PRIO) 99 | 100 | #ifndef NICE_TO_PRIO 101 | #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) 102 | #endif 103 | #ifndef PRIO_TO_NICE 104 | #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20) 105 | #endif 106 | 107 | /* 108 | * Missing macros 109 | */ 110 | #ifndef PAGESIZE 111 | #define PAGESIZE PAGE_SIZE 112 | #endif 113 | 114 | #ifndef PAGESHIFT 115 | #define PAGESHIFT PAGE_SHIFT 116 | #endif 117 | 118 | /* Dtrace probes do not exist in the linux kernel */ 119 | #ifdef DTRACE_PROBE 120 | #undef DTRACE_PROBE 121 | #endif /* DTRACE_PROBE */ 122 | #define DTRACE_PROBE(a) ((void)0) 123 | 124 | #ifdef DTRACE_PROBE1 125 | #undef DTRACE_PROBE1 126 | #endif /* DTRACE_PROBE1 */ 127 | #define DTRACE_PROBE1(a, b, c) ((void)0) 128 | 129 | #ifdef DTRACE_PROBE2 130 | #undef DTRACE_PROBE2 131 | #endif /* DTRACE_PROBE2 */ 132 | #define DTRACE_PROBE2(a, b, c, d, e) ((void)0) 133 | 134 | #ifdef DTRACE_PROBE3 135 | #undef DTRACE_PROBE3 136 | #endif /* DTRACE_PROBE3 */ 137 | #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) 138 | 139 | #ifdef DTRACE_PROBE4 140 | #undef DTRACE_PROBE4 141 | #endif /* DTRACE_PROBE4 */ 142 | #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) 143 | 144 | /* Missing globals */ 145 | extern char spl_version[32]; 146 | extern unsigned long spl_hostid; 147 | 148 | /* Missing misc functions */ 149 | extern uint32_t zone_get_hostid(void *zone); 150 | extern void spl_setup(void); 151 | extern void spl_cleanup(void); 152 | 153 | #define highbit(x) __fls(x) 154 | #define lowbit(x) __ffs(x) 155 | 156 | #define highbit64(x) fls64(x) 157 | #define makedevice(maj, min) makedev(maj, min) 158 | 159 | /* common macros */ 160 | #ifndef MIN 161 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 162 | #endif 163 | #ifndef MAX 164 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) 165 | #endif 166 | #ifndef ABS 167 | #define ABS(a) ((a) < 0 ? -(a) : (a)) 168 | #endif 169 | #ifndef DIV_ROUND_UP 170 | #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 171 | #endif 172 | #ifndef roundup 173 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) 174 | #endif 175 | #ifndef howmany 176 | #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 177 | #endif 178 | 179 | /* 180 | * Compatibility macros/typedefs needed for Solaris -> Linux port 181 | */ 182 | #define P2ALIGN(x, align) ((x) & -(align)) 183 | #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) 184 | #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1) 185 | #define P2PHASE(x, align) ((x) & ((align) - 1)) 186 | #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 187 | #define ISP2(x) (((x) & ((x) - 1)) == 0) 188 | #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) 189 | #define P2BOUNDARY(off, len, align) \ 190 | (((off) ^ ((off) + (len) - 1)) > (align) - 1) 191 | 192 | /* 193 | * Typed version of the P2* macros. These macros should be used to ensure 194 | * that the result is correctly calculated based on the data type of (x), 195 | * which is passed in as the last argument, regardless of the data 196 | * type of the alignment. For example, if (x) is of type uint64_t, 197 | * and we want to round it up to a page boundary using "PAGESIZE" as 198 | * the alignment, we can do either 199 | * 200 | * P2ROUNDUP(x, (uint64_t)PAGESIZE) 201 | * or 202 | * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t) 203 | */ 204 | #define P2ALIGN_TYPED(x, align, type) \ 205 | ((type)(x) & -(type)(align)) 206 | #define P2PHASE_TYPED(x, align, type) \ 207 | ((type)(x) & ((type)(align) - 1)) 208 | #define P2NPHASE_TYPED(x, align, type) \ 209 | (-(type)(x) & ((type)(align) - 1)) 210 | #define P2ROUNDUP_TYPED(x, align, type) \ 211 | ((((type)(x) - 1) | ((type)(align) - 1)) + 1) 212 | #define P2END_TYPED(x, align, type) \ 213 | (-(~(type)(x) & -(type)(align))) 214 | #define P2PHASEUP_TYPED(x, align, phase, type) \ 215 | ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align))) 216 | #define P2CROSS_TYPED(x, y, align, type) \ 217 | (((type)(x) ^ (type)(y)) > (type)(align) - 1) 218 | #define P2SAMEHIGHBIT_TYPED(x, y, type) \ 219 | (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y))) 220 | 221 | #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof) 222 | 223 | /* avoid any possibility of clashing with version */ 224 | 225 | #define offsetof(s, m) ((size_t)(&(((s *)0)->m))) 226 | #endif 227 | 228 | #endif /* _SPL_SYSMACROS_H */ 229 | -------------------------------------------------------------------------------- /include/spl/sys/systeminfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_SYSTEMINFO_H 26 | #define _SPL_SYSTEMINFO_H 27 | 28 | #define HW_HOSTID_LEN 11 /* minimum buffer size needed */ 29 | /* to hold a decimal or hex */ 30 | /* hostid string */ 31 | 32 | /* Supplemental definitions for Linux. */ 33 | #define HW_HOSTID_PATH "/etc/hostid" /* binary configuration file */ 34 | #define HW_HOSTID_MASK 0xFFFFFFFF /* significant hostid bits */ 35 | 36 | #endif /* SPL_SYSTEMINFO_H */ 37 | -------------------------------------------------------------------------------- /include/spl/sys/taskq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_TASKQ_H 26 | #define _SPL_TASKQ_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #define TASKQ_NAMELEN 31 39 | 40 | #define TASKQ_PREPOPULATE 0x00000001 41 | #define TASKQ_CPR_SAFE 0x00000002 42 | #define TASKQ_DYNAMIC 0x00000004 43 | #define TASKQ_THREADS_CPU_PCT 0x00000008 44 | #define TASKQ_DC_BATCH 0x00000010 45 | #define TASKQ_ACTIVE 0x80000000 46 | 47 | /* 48 | * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as 49 | * KM_SLEEP/KM_NOSLEEP. TQ_NOQUEUE/TQ_NOALLOC are set particularly 50 | * large so as not to conflict with already used GFP_* defines. 51 | */ 52 | #define TQ_SLEEP 0x00000000 53 | #define TQ_NOSLEEP 0x00000001 54 | #define TQ_PUSHPAGE 0x00000002 55 | #define TQ_NOQUEUE 0x01000000 56 | #define TQ_NOALLOC 0x02000000 57 | #define TQ_NEW 0x04000000 58 | #define TQ_FRONT 0x08000000 59 | 60 | /* 61 | * Reserved taskqid values. 62 | */ 63 | #define TASKQID_INVALID ((taskqid_t)0) 64 | #define TASKQID_INITIAL ((taskqid_t)1) 65 | 66 | /* 67 | * spin_lock(lock) and spin_lock_nested(lock,0) are equivalent, 68 | * so TQ_LOCK_DYNAMIC must not evaluate to 0 69 | */ 70 | typedef enum tq_lock_role { 71 | TQ_LOCK_GENERAL = 0, 72 | TQ_LOCK_DYNAMIC = 1, 73 | } tq_lock_role_t; 74 | 75 | typedef unsigned long taskqid_t; 76 | typedef void (task_func_t)(void *); 77 | 78 | typedef struct taskq { 79 | spinlock_t tq_lock; /* protects taskq_t */ 80 | char *tq_name; /* taskq name */ 81 | int tq_instance; /* instance of tq_name */ 82 | struct list_head tq_thread_list; /* list of all threads */ 83 | struct list_head tq_active_list; /* list of active threads */ 84 | int tq_nactive; /* # of active threads */ 85 | int tq_nthreads; /* # of existing threads */ 86 | int tq_nspawn; /* # of threads being spawned */ 87 | int tq_maxthreads; /* # of threads maximum */ 88 | int tq_pri; /* priority */ 89 | int tq_minalloc; /* min taskq_ent_t pool size */ 90 | int tq_maxalloc; /* max taskq_ent_t pool size */ 91 | int tq_nalloc; /* cur taskq_ent_t pool size */ 92 | uint_t tq_flags; /* flags */ 93 | taskqid_t tq_next_id; /* next pend/work id */ 94 | taskqid_t tq_lowest_id; /* lowest pend/work id */ 95 | struct list_head tq_free_list; /* free taskq_ent_t's */ 96 | struct list_head tq_pend_list; /* pending taskq_ent_t's */ 97 | struct list_head tq_prio_list; /* priority taskq_ent_t's */ 98 | struct list_head tq_delay_list; /* delayed taskq_ent_t's */ 99 | struct list_head tq_taskqs; /* all taskq_t's */ 100 | spl_wait_queue_head_t tq_work_waitq; /* new work waitq */ 101 | spl_wait_queue_head_t tq_wait_waitq; /* wait waitq */ 102 | tq_lock_role_t tq_lock_class; /* class when taking tq_lock */ 103 | } taskq_t; 104 | 105 | typedef struct taskq_ent { 106 | spinlock_t tqent_lock; 107 | spl_wait_queue_head_t tqent_waitq; 108 | struct timer_list tqent_timer; 109 | struct list_head tqent_list; 110 | taskqid_t tqent_id; 111 | task_func_t *tqent_func; 112 | void *tqent_arg; 113 | taskq_t *tqent_taskq; 114 | uintptr_t tqent_flags; 115 | unsigned long tqent_birth; 116 | } taskq_ent_t; 117 | 118 | #define TQENT_FLAG_PREALLOC 0x1 119 | #define TQENT_FLAG_CANCEL 0x2 120 | 121 | typedef struct taskq_thread { 122 | struct list_head tqt_thread_list; 123 | struct list_head tqt_active_list; 124 | struct task_struct *tqt_thread; 125 | taskq_t *tqt_tq; 126 | taskqid_t tqt_id; 127 | taskq_ent_t *tqt_task; 128 | uintptr_t tqt_flags; 129 | } taskq_thread_t; 130 | 131 | /* Global system-wide dynamic task queue available for all consumers */ 132 | extern taskq_t *system_taskq; 133 | /* Global dynamic task queue for long delay */ 134 | extern taskq_t *system_delay_taskq; 135 | 136 | /* List of all taskqs */ 137 | extern struct list_head tq_list; 138 | extern struct rw_semaphore tq_list_sem; 139 | 140 | extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); 141 | extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *, 142 | uint_t, clock_t); 143 | extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, 144 | taskq_ent_t *); 145 | extern int taskq_empty_ent(taskq_ent_t *); 146 | extern void taskq_init_ent(taskq_ent_t *); 147 | extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); 148 | extern void taskq_destroy(taskq_t *); 149 | extern void taskq_wait_id(taskq_t *, taskqid_t); 150 | extern void taskq_wait_outstanding(taskq_t *, taskqid_t); 151 | extern void taskq_wait(taskq_t *); 152 | extern int taskq_cancel_id(taskq_t *, taskqid_t); 153 | extern int taskq_member(taskq_t *, kthread_t *); 154 | 155 | #define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \ 156 | taskq_create(name, nthreads, pri, min, max, flags) 157 | #define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \ 158 | taskq_create(name, nthreads, maxclsyspri, min, max, flags) 159 | 160 | int spl_taskq_init(void); 161 | void spl_taskq_fini(void); 162 | 163 | #endif /* _SPL_TASKQ_H */ 164 | -------------------------------------------------------------------------------- /include/spl/sys/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_THREAD_H 26 | #define _SPL_THREAD_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | /* 37 | * Thread interfaces 38 | */ 39 | #define TP_MAGIC 0x53535353 40 | 41 | #define TS_SLEEP TASK_INTERRUPTIBLE 42 | #define TS_RUN TASK_RUNNING 43 | #define TS_ZOMB EXIT_ZOMBIE 44 | #define TS_STOPPED TASK_STOPPED 45 | 46 | typedef void (*thread_func_t)(void *); 47 | 48 | /* BEGIN CSTYLED */ 49 | #define thread_create(stk, stksize, func, arg, len, pp, state, pri) \ 50 | __thread_create(stk, stksize, (thread_func_t)func, \ 51 | #func, arg, len, pp, state, pri) 52 | /* END CSTYLED */ 53 | 54 | #define thread_exit() __thread_exit() 55 | #define thread_join(t) VERIFY(0) 56 | #define curthread current 57 | #define getcomm() current->comm 58 | #define getpid() current->pid 59 | 60 | extern kthread_t *__thread_create(caddr_t stk, size_t stksize, 61 | thread_func_t func, const char *name, void *args, size_t len, proc_t *pp, 62 | int state, pri_t pri); 63 | extern void __thread_exit(void); 64 | extern struct task_struct *spl_kthread_create(int (*func)(void *), 65 | void *data, const char namefmt[], ...); 66 | 67 | extern proc_t p0; 68 | 69 | #endif /* _SPL_THREAD_H */ 70 | -------------------------------------------------------------------------------- /include/spl/sys/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_TIME_H 26 | #define _SPL_TIME_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #if defined(CONFIG_64BIT) 34 | #define TIME_MAX INT64_MAX 35 | #define TIME_MIN INT64_MIN 36 | #else 37 | #define TIME_MAX INT32_MAX 38 | #define TIME_MIN INT32_MIN 39 | #endif 40 | 41 | #define SEC 1 42 | #define MILLISEC 1000 43 | #define MICROSEC 1000000 44 | #define NANOSEC 1000000000 45 | 46 | #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC)) 47 | #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC)) 48 | 49 | #define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC)) 50 | #define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC)) 51 | 52 | #define NSEC2SEC(n) ((n) / (NANOSEC / SEC)) 53 | #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC)) 54 | 55 | static const int hz = HZ; 56 | 57 | #define TIMESPEC_OVERFLOW(ts) \ 58 | ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX) 59 | 60 | static inline void 61 | gethrestime(timestruc_t *now) 62 | { 63 | *now = current_kernel_time(); 64 | } 65 | 66 | static inline time_t 67 | gethrestime_sec(void) 68 | { 69 | struct timespec ts; 70 | ts = current_kernel_time(); 71 | return (ts.tv_sec); 72 | } 73 | 74 | static inline hrtime_t 75 | gethrtime(void) 76 | { 77 | struct timespec now; 78 | getrawmonotonic(&now); 79 | return (((hrtime_t)now.tv_sec * NSEC_PER_SEC) + now.tv_nsec); 80 | } 81 | 82 | #endif /* _SPL_TIME_H */ 83 | -------------------------------------------------------------------------------- /include/spl/sys/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_TIMER_H 26 | #define _SPL_TIMER_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #define lbolt ((clock_t)jiffies) 35 | #define lbolt64 ((int64_t)get_jiffies_64()) 36 | 37 | #define ddi_get_lbolt() ((clock_t)jiffies) 38 | #define ddi_get_lbolt64() ((int64_t)get_jiffies_64()) 39 | 40 | #define ddi_time_before(a, b) (typecheck(clock_t, a) && \ 41 | typecheck(clock_t, b) && \ 42 | ((a) - (b) < 0)) 43 | #define ddi_time_after(a, b) ddi_time_before(b, a) 44 | #define ddi_time_before_eq(a, b) (!ddi_time_after(a, b)) 45 | #define ddi_time_after_eq(a, b) ddi_time_before_eq(b, a) 46 | 47 | #define ddi_time_before64(a, b) (typecheck(int64_t, a) && \ 48 | typecheck(int64_t, b) && \ 49 | ((a) - (b) < 0)) 50 | #define ddi_time_after64(a, b) ddi_time_before64(b, a) 51 | #define ddi_time_before_eq64(a, b) (!ddi_time_after64(a, b)) 52 | #define ddi_time_after_eq64(a, b) ddi_time_before_eq64(b, a) 53 | 54 | #define delay(ticks) schedule_timeout_uninterruptible(ticks) 55 | 56 | /* usleep_range() introduced in 2.6.36 */ 57 | #ifndef HAVE_USLEEP_RANGE 58 | static inline void 59 | usleep_range(unsigned long min, unsigned long max) 60 | { 61 | unsigned int min_ms = min / USEC_PER_MSEC; 62 | 63 | if (min >= MAX_UDELAY_MS) 64 | msleep(min_ms); 65 | else 66 | udelay(min); 67 | } 68 | #endif /* HAVE_USLEEP_RANGE */ 69 | 70 | #define SEC_TO_TICK(sec) ((sec) * HZ) 71 | #define MSEC_TO_TICK(ms) msecs_to_jiffies(ms) 72 | #define USEC_TO_TICK(us) usecs_to_jiffies(us) 73 | #define NSEC_TO_TICK(ns) usecs_to_jiffies(ns / NSEC_PER_USEC) 74 | 75 | #endif /* _SPL_TIMER_H */ 76 | -------------------------------------------------------------------------------- /include/spl/sys/tsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Lawrence Livermore National Security, LLC. 3 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 4 | * Written by Brian Behlendorf . 5 | * UCRL-CODE-235197 6 | * 7 | * This file is part of the SPL, Solaris Porting Layer. 8 | * For details, see . 9 | * 10 | * The SPL is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU General Public License as published by the 12 | * Free Software Foundation; either version 2 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with the SPL. If not, see . 22 | */ 23 | 24 | #ifndef _SPL_TSD_H 25 | #define _SPL_TSD_H 26 | 27 | #include 28 | 29 | #define TSD_HASH_TABLE_BITS_DEFAULT 9 30 | #define TSD_KEYS_MAX 32768 31 | #define DTOR_PID (PID_MAX_LIMIT+1) 32 | #define PID_KEY (TSD_KEYS_MAX+1) 33 | 34 | typedef void (*dtor_func_t)(void *); 35 | 36 | extern int tsd_set(uint_t, void *); 37 | extern void *tsd_get(uint_t); 38 | extern void *tsd_get_by_thread(uint_t, kthread_t *); 39 | extern void tsd_create(uint_t *, dtor_func_t); 40 | extern void tsd_destroy(uint_t *); 41 | extern void tsd_exit(void); 42 | 43 | int spl_tsd_init(void); 44 | void spl_tsd_fini(void); 45 | 46 | #endif /* _SPL_TSD_H */ 47 | -------------------------------------------------------------------------------- /include/spl/sys/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_TYPES_H 26 | #define _SPL_TYPES_H 27 | 28 | #include 29 | 30 | #ifndef ULLONG_MAX 31 | #define ULLONG_MAX (~0ULL) 32 | #endif 33 | 34 | #ifndef LLONG_MAX 35 | #define LLONG_MAX ((long long)(~0ULL>>1)) 36 | #endif 37 | 38 | typedef enum { 39 | B_FALSE = 0, 40 | B_TRUE = 1 41 | } boolean_t; 42 | 43 | typedef unsigned char uchar_t; 44 | typedef unsigned short ushort_t; 45 | typedef unsigned int uint_t; 46 | typedef unsigned long ulong_t; 47 | typedef unsigned long long u_longlong_t; 48 | typedef long long longlong_t; 49 | 50 | typedef unsigned long intptr_t; 51 | typedef unsigned long long rlim64_t; 52 | 53 | typedef struct task_struct kthread_t; 54 | typedef struct task_struct proc_t; 55 | 56 | typedef struct timespec timestruc_t; 57 | typedef struct timespec timespec_t; 58 | typedef longlong_t hrtime_t; 59 | 60 | typedef int id_t; 61 | typedef short pri_t; 62 | typedef short index_t; 63 | typedef longlong_t offset_t; 64 | typedef u_longlong_t u_offset_t; 65 | typedef ulong_t pgcnt_t; 66 | 67 | typedef int major_t; 68 | typedef int minor_t; 69 | 70 | #endif /* _SPL_TYPES_H */ 71 | -------------------------------------------------------------------------------- /include/spl/sys/types32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_TYPES32_H 26 | #define _SPL_TYPES32_H 27 | 28 | #include 29 | 30 | typedef uint32_t caddr32_t; 31 | typedef int32_t daddr32_t; 32 | typedef int32_t time32_t; 33 | typedef uint32_t size32_t; 34 | 35 | #endif /* _SPL_TYPES32_H */ 36 | -------------------------------------------------------------------------------- /include/spl/sys/uio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Copyright (c) 2015 by Chunwei Chen. All rights reserved. 5 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 6 | * Written by Brian Behlendorf . 7 | * UCRL-CODE-235197 8 | * 9 | * This file is part of the SPL, Solaris Porting Layer. 10 | * For details, see . 11 | * 12 | * The SPL is free software; you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License as published by the 14 | * Free Software Foundation; either version 2 of the License, or (at your 15 | * option) any later version. 16 | * 17 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20 | * for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License along 23 | * with the SPL. If not, see . 24 | */ 25 | 26 | #ifndef _SPL_UIO_H 27 | #define _SPL_UIO_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | typedef struct iovec iovec_t; 35 | 36 | typedef enum uio_rw { 37 | UIO_READ = 0, 38 | UIO_WRITE = 1, 39 | } uio_rw_t; 40 | 41 | typedef enum uio_seg { 42 | UIO_USERSPACE = 0, 43 | UIO_SYSSPACE = 1, 44 | UIO_USERISPACE = 2, 45 | UIO_BVEC = 3, 46 | } uio_seg_t; 47 | 48 | typedef struct uio { 49 | union { 50 | const struct iovec *uio_iov; 51 | const struct bio_vec *uio_bvec; 52 | }; 53 | int uio_iovcnt; 54 | offset_t uio_loffset; 55 | uio_seg_t uio_segflg; 56 | uint16_t uio_fmode; 57 | uint16_t uio_extflg; 58 | offset_t uio_limit; 59 | ssize_t uio_resid; 60 | size_t uio_skip; 61 | } uio_t; 62 | 63 | typedef struct aio_req { 64 | uio_t *aio_uio; 65 | void *aio_private; 66 | } aio_req_t; 67 | 68 | typedef enum xuio_type { 69 | UIOTYPE_ASYNCIO, 70 | UIOTYPE_ZEROCOPY, 71 | } xuio_type_t; 72 | 73 | 74 | #define UIOA_IOV_MAX 16 75 | 76 | typedef struct uioa_page_s { 77 | int uioa_pfncnt; 78 | void **uioa_ppp; 79 | caddr_t uioa_base; 80 | size_t uioa_len; 81 | } uioa_page_t; 82 | 83 | typedef struct xuio { 84 | uio_t xu_uio; 85 | enum xuio_type xu_type; 86 | union { 87 | struct { 88 | uint32_t xu_a_state; 89 | ssize_t xu_a_mbytes; 90 | uioa_page_t *xu_a_lcur; 91 | void **xu_a_lppp; 92 | void *xu_a_hwst[4]; 93 | uioa_page_t xu_a_locked[UIOA_IOV_MAX]; 94 | } xu_aio; 95 | 96 | struct { 97 | int xu_zc_rw; 98 | void *xu_zc_priv; 99 | } xu_zc; 100 | } xu_ext; 101 | } xuio_t; 102 | 103 | #define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv 104 | #define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw 105 | 106 | #endif /* SPL_UIO_H */ 107 | -------------------------------------------------------------------------------- /include/spl/sys/user.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Cluster Inc. 3 | * Produced at ClusterHQ Inc (cf, DISCLAIMER). 4 | * Written by Richard Yao . 5 | * 6 | * This file is part of the SPL, Solaris Porting Layer. 7 | * For details, see . 8 | * 9 | * The SPL is free software; you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License as published by the 11 | * Free Software Foundation; either version 2 of the License, or (at your 12 | * option) any later version. 13 | * 14 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 | * for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with the SPL. If not, see . 21 | */ 22 | 23 | #ifndef _SPL_USER_H 24 | #define _SPL_USER_H 25 | 26 | /* 27 | * We have uf_info_t for areleasef(). We implement areleasef() using a global 28 | * linked list of all open file descriptors with the task structs referenced, 29 | * so accessing the correct descriptor from areleasef() only requires knowing 30 | * about the Linux task_struct. Since this is internal to our compatibility 31 | * layer, we make it an opaque type. 32 | * 33 | * XXX: If the descriptor changes under us and we do not do a getf() between 34 | * the change and using it, we would get an incorrect reference. 35 | */ 36 | 37 | struct uf_info; 38 | typedef struct uf_info uf_info_t; 39 | 40 | #define P_FINFO(x) ((uf_info_t *)x) 41 | 42 | #endif /* SPL_USER_H */ 43 | -------------------------------------------------------------------------------- /include/spl/sys/vfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_ZFS_H 26 | #define _SPL_ZFS_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define MAXFIDSZ 64 37 | 38 | typedef struct spl_fid { 39 | union { 40 | long fid_pad; 41 | struct { 42 | ushort_t len; /* length of data in bytes */ 43 | char data[MAXFIDSZ]; /* data (variable len) */ 44 | } _fid; 45 | } un; 46 | } fid_t; 47 | 48 | #define fid_len un._fid.len 49 | #define fid_data un._fid.data 50 | 51 | #endif /* SPL_ZFS_H */ 52 | -------------------------------------------------------------------------------- /include/spl/sys/vmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_VMEM_H 26 | #define _SPL_VMEM_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | typedef struct vmem { } vmem_t; 33 | 34 | extern vmem_t *heap_arena; 35 | extern vmem_t *zio_alloc_arena; 36 | extern vmem_t *zio_arena; 37 | 38 | extern size_t vmem_size(vmem_t *vmp, int typemask); 39 | 40 | /* 41 | * Memory allocation interfaces 42 | */ 43 | #define VMEM_ALLOC 0x01 44 | #define VMEM_FREE 0x02 45 | 46 | #ifndef VMALLOC_TOTAL 47 | #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START) 48 | #endif 49 | 50 | /* 51 | * vmem_* is an interface to a low level arena-based memory allocator on 52 | * Illumos that is used to allocate virtual address space. The kmem SLAB 53 | * allocator allocates slabs from it. Then the generic allocation functions 54 | * kmem_{alloc,zalloc,free}() are layered on top of SLAB allocators. 55 | * 56 | * On Linux, the primary means of doing allocations is via kmalloc(), which 57 | * is similarly layered on top of something called the buddy allocator. The 58 | * buddy allocator is not available to kernel modules, it uses physical 59 | * memory addresses rather than virtual memory addresses and is prone to 60 | * fragmentation. 61 | * 62 | * Linux sets aside a relatively small address space for in-kernel virtual 63 | * memory from which allocations can be done using vmalloc(). It might seem 64 | * like a good idea to use vmalloc() to implement something similar to 65 | * Illumos' allocator. However, this has the following problems: 66 | * 67 | * 1. Page directory table allocations are hard coded to use GFP_KERNEL. 68 | * Consequently, any KM_PUSHPAGE or KM_NOSLEEP allocations done using 69 | * vmalloc() will not have proper semantics. 70 | * 71 | * 2. Address space exhaustion is a real issue on 32-bit platforms where 72 | * only a few 100MB are available. The kernel will handle it by spinning 73 | * when it runs out of address space. 74 | * 75 | * 3. All vmalloc() allocations and frees are protected by a single global 76 | * lock which serializes all allocations. 77 | * 78 | * 4. Accessing /proc/meminfo and /proc/vmallocinfo will iterate the entire 79 | * list. The former will sum the allocations while the latter will print 80 | * them to user space in a way that user space can keep the lock held 81 | * indefinitely. When the total number of mapped allocations is large 82 | * (several 100,000) a large amount of time will be spent waiting on locks. 83 | * 84 | * 5. Linux has a wait_on_bit() locking primitive that assumes physical 85 | * memory is used, it simply does not work on virtual memory. Certain 86 | * Linux structures (e.g. the superblock) use them and might be embedded 87 | * into a structure from Illumos. This makes using Linux virtual memory 88 | * unsafe in certain situations. 89 | * 90 | * It follows that we cannot obtain identical semantics to those on Illumos. 91 | * Consequently, we implement the kmem_{alloc,zalloc,free}() functions in 92 | * such a way that they can be used as drop-in replacements for small vmem_* 93 | * allocations (8MB in size or smaller) and map vmem_{alloc,zalloc,free}() 94 | * to them. 95 | */ 96 | 97 | #define vmem_alloc(sz, fl) spl_vmem_alloc((sz), (fl), __func__, __LINE__) 98 | #define vmem_zalloc(sz, fl) spl_vmem_zalloc((sz), (fl), __func__, __LINE__) 99 | #define vmem_free(ptr, sz) spl_vmem_free((ptr), (sz)) 100 | #define vmem_qcache_reap(ptr) ((void)0) 101 | 102 | extern void *spl_vmem_alloc(size_t sz, int fl, const char *func, int line); 103 | extern void *spl_vmem_zalloc(size_t sz, int fl, const char *func, int line); 104 | extern void spl_vmem_free(const void *ptr, size_t sz); 105 | 106 | int spl_vmem_init(void); 107 | void spl_vmem_fini(void); 108 | 109 | #endif /* _SPL_VMEM_H */ 110 | -------------------------------------------------------------------------------- /include/spl/sys/vmsystm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_VMSYSTM_H 26 | #define _SPL_VMSYSTM_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define membar_producer() smp_wmb() 37 | #define physmem totalram_pages 38 | #define freemem (nr_free_pages() + \ 39 | global_page_state(NR_INACTIVE_FILE) + \ 40 | global_page_state(NR_INACTIVE_ANON) + \ 41 | global_page_state(NR_SLAB_RECLAIMABLE)) 42 | 43 | #define xcopyin(from, to, size) copy_from_user(to, from, size) 44 | #define xcopyout(from, to, size) copy_to_user(to, from, size) 45 | 46 | static __inline__ int 47 | copyin(const void *from, void *to, size_t len) 48 | { 49 | /* On error copyin routine returns -1 */ 50 | if (xcopyin(from, to, len)) 51 | return (-1); 52 | 53 | return (0); 54 | } 55 | 56 | static __inline__ int 57 | copyout(const void *from, void *to, size_t len) 58 | { 59 | /* On error copyout routine returns -1 */ 60 | if (xcopyout(from, to, len)) 61 | return (-1); 62 | 63 | return (0); 64 | } 65 | 66 | static __inline__ int 67 | copyinstr(const void *from, void *to, size_t len, size_t *done) 68 | { 69 | size_t rc; 70 | 71 | if (len == 0) 72 | return (-ENAMETOOLONG); 73 | 74 | /* XXX: Should return ENAMETOOLONG if 'strlen(from) > len' */ 75 | 76 | memset(to, 0, len); 77 | rc = copyin(from, to, len - 1); 78 | if (done != NULL) 79 | *done = rc; 80 | 81 | return (0); 82 | } 83 | 84 | #endif /* SPL_VMSYSTM_H */ 85 | -------------------------------------------------------------------------------- /include/spl/sys/vnode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_VNODE_H 26 | #define _SPL_VNODE_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | /* 46 | * Prior to linux-2.6.33 only O_DSYNC semantics were implemented and 47 | * they used the O_SYNC flag. As of linux-2.6.33 the this behavior 48 | * was properly split in to O_SYNC and O_DSYNC respectively. 49 | */ 50 | #ifndef O_DSYNC 51 | #define O_DSYNC O_SYNC 52 | #endif 53 | 54 | #define FREAD 1 55 | #define FWRITE 2 56 | #define FCREAT O_CREAT 57 | #define FTRUNC O_TRUNC 58 | #define FOFFMAX O_LARGEFILE 59 | #define FSYNC O_SYNC 60 | #define FDSYNC O_DSYNC 61 | #define FRSYNC O_SYNC 62 | #define FEXCL O_EXCL 63 | #define FDIRECT O_DIRECT 64 | #define FAPPEND O_APPEND 65 | 66 | #define FNODSYNC 0x10000 /* fsync pseudo flag */ 67 | #define FNOFOLLOW 0x20000 /* don't follow symlinks */ 68 | 69 | #define F_FREESP 11 /* Free file space */ 70 | 71 | 72 | /* 73 | * The vnode AT_ flags are mapped to the Linux ATTR_* flags. 74 | * This allows them to be used safely with an iattr structure. 75 | * The AT_XVATTR flag has been added and mapped to the upper 76 | * bit range to avoid conflicting with the standard Linux set. 77 | */ 78 | #undef AT_UID 79 | #undef AT_GID 80 | 81 | #define AT_MODE ATTR_MODE 82 | #define AT_UID ATTR_UID 83 | #define AT_GID ATTR_GID 84 | #define AT_SIZE ATTR_SIZE 85 | #define AT_ATIME ATTR_ATIME 86 | #define AT_MTIME ATTR_MTIME 87 | #define AT_CTIME ATTR_CTIME 88 | 89 | #define ATTR_XVATTR (1 << 31) 90 | #define AT_XVATTR ATTR_XVATTR 91 | 92 | #define ATTR_IATTR_MASK (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE | \ 93 | ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_FILE) 94 | 95 | #define CRCREAT 0x01 96 | #define RMFILE 0x02 97 | 98 | #define B_INVAL 0x01 99 | #define B_TRUNC 0x02 100 | 101 | #define LOOKUP_DIR 0x01 102 | #define LOOKUP_XATTR 0x02 103 | #define CREATE_XATTR_DIR 0x04 104 | #define ATTR_NOACLCHECK 0x20 105 | 106 | typedef enum vtype { 107 | VNON = 0, 108 | VREG = 1, 109 | VDIR = 2, 110 | VBLK = 3, 111 | VCHR = 4, 112 | VLNK = 5, 113 | VFIFO = 6, 114 | VDOOR = 7, 115 | VPROC = 8, 116 | VSOCK = 9, 117 | VPORT = 10, 118 | VBAD = 11 119 | } vtype_t; 120 | 121 | typedef struct vattr { 122 | enum vtype va_type; /* vnode type */ 123 | uint_t va_mask; /* attribute bit-mask */ 124 | ushort_t va_mode; /* acc mode */ 125 | uid_t va_uid; /* owner uid */ 126 | gid_t va_gid; /* owner gid */ 127 | long va_fsid; /* fs id */ 128 | long va_nodeid; /* node # */ 129 | uint32_t va_nlink; /* # links */ 130 | uint64_t va_size; /* file size */ 131 | struct timespec va_atime; /* last acc */ 132 | struct timespec va_mtime; /* last mod */ 133 | struct timespec va_ctime; /* last chg */ 134 | dev_t va_rdev; /* dev */ 135 | uint64_t va_nblocks; /* space used */ 136 | uint32_t va_blksize; /* block size */ 137 | uint32_t va_seq; /* sequence */ 138 | struct dentry *va_dentry; /* dentry to wire */ 139 | } vattr_t; 140 | 141 | typedef struct vnode { 142 | struct file *v_file; 143 | kmutex_t v_lock; /* protects vnode fields */ 144 | uint_t v_flag; /* vnode flags (see below) */ 145 | uint_t v_count; /* reference count */ 146 | void *v_data; /* private data for fs */ 147 | struct vfs *v_vfsp; /* ptr to containing VFS */ 148 | struct stdata *v_stream; /* associated stream */ 149 | enum vtype v_type; /* vnode type */ 150 | dev_t v_rdev; /* device (VCHR, VBLK) */ 151 | gfp_t v_gfp_mask; /* original mapping gfp mask */ 152 | } vnode_t; 153 | 154 | typedef struct vn_file { 155 | int f_fd; /* linux fd for lookup */ 156 | struct task_struct *f_task; /* linux task this fd belongs to */ 157 | struct file *f_file; /* linux file struct */ 158 | atomic_t f_ref; /* ref count */ 159 | kmutex_t f_lock; /* struct lock */ 160 | loff_t f_offset; /* offset */ 161 | vnode_t *f_vnode; /* vnode */ 162 | struct list_head f_list; /* list referenced file_t's */ 163 | } file_t; 164 | 165 | extern vnode_t *vn_alloc(int flag); 166 | void vn_free(vnode_t *vp); 167 | extern vtype_t vn_mode_to_vtype(mode_t); 168 | extern mode_t vn_vtype_to_mode(vtype_t); 169 | extern int vn_open(const char *path, uio_seg_t seg, int flags, int mode, 170 | vnode_t **vpp, int x1, void *x2); 171 | extern int vn_openat(const char *path, uio_seg_t seg, int flags, int mode, 172 | vnode_t **vpp, int x1, void *x2, vnode_t *vp, int fd); 173 | extern int vn_rdwr(uio_rw_t uio, vnode_t *vp, void *addr, ssize_t len, 174 | offset_t off, uio_seg_t seg, int x1, rlim64_t x2, 175 | void *x3, ssize_t *residp); 176 | extern int vn_close(vnode_t *vp, int flags, int x1, int x2, void *x3, void *x4); 177 | extern int vn_seek(vnode_t *vp, offset_t o, offset_t *op, void *ct); 178 | 179 | extern int vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4); 180 | extern int vn_fsync(vnode_t *vp, int flags, void *x3, void *x4); 181 | extern int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag, 182 | offset_t offset, void *x6, void *x7); 183 | extern file_t *vn_getf(int fd); 184 | extern void vn_releasef(int fd); 185 | extern void vn_areleasef(int fd, uf_info_t *fip); 186 | extern int vn_set_pwd(const char *filename); 187 | 188 | int spl_vn_init(void); 189 | void spl_vn_fini(void); 190 | 191 | #define VOP_CLOSE vn_close 192 | #define VOP_SEEK vn_seek 193 | #define VOP_GETATTR vn_getattr 194 | #define VOP_FSYNC vn_fsync 195 | #define VOP_SPACE vn_space 196 | #define VOP_PUTPAGE(vp, o, s, f, x1, x2) ((void)0) 197 | #define vn_is_readonly(vp) 0 198 | #define getf vn_getf 199 | #define releasef vn_releasef 200 | #define areleasef vn_areleasef 201 | 202 | extern vnode_t *rootdir; 203 | 204 | #endif /* SPL_VNODE_H */ 205 | -------------------------------------------------------------------------------- /include/spl/sys/wait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2014 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_WAIT_H 26 | #define _SPL_WAIT_H 27 | 28 | #include 29 | #include 30 | 31 | #ifndef HAVE_WAIT_ON_BIT_ACTION 32 | #define spl_wait_on_bit(word, bit, mode) wait_on_bit(word, bit, mode) 33 | #else 34 | 35 | static inline int 36 | spl_bit_wait(void *word) 37 | { 38 | schedule(); 39 | return (0); 40 | } 41 | 42 | #define spl_wait_on_bit(word, bit, mode) \ 43 | wait_on_bit(word, bit, spl_bit_wait, mode) 44 | 45 | #endif /* HAVE_WAIT_ON_BIT_ACTION */ 46 | 47 | #ifdef HAVE_WAIT_QUEUE_ENTRY_T 48 | typedef wait_queue_head_t spl_wait_queue_head_t; 49 | typedef wait_queue_entry_t spl_wait_queue_entry_t; 50 | #else 51 | typedef wait_queue_head_t spl_wait_queue_head_t; 52 | typedef wait_queue_t spl_wait_queue_entry_t; 53 | #endif 54 | 55 | #endif /* SPL_WAIT_H */ 56 | -------------------------------------------------------------------------------- /include/spl/sys/zmod.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * 25 | * z_compress_level/z_uncompress are nearly identical copies of the 26 | * compress2/uncompress functions provided by the official zlib package 27 | * available at http://zlib.net/. The only changes made we to slightly 28 | * adapt the functions called to match the linux kernel implementation 29 | * of zlib. The full zlib license follows: 30 | * 31 | * zlib.h -- interface of the 'zlib' general purpose compression library 32 | * version 1.2.5, April 19th, 2010 33 | * 34 | * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 35 | * 36 | * This software is provided 'as-is', without any express or implied 37 | * warranty. In no event will the authors be held liable for any damages 38 | * arising from the use of this software. 39 | * 40 | * Permission is granted to anyone to use this software for any purpose, 41 | * including commercial applications, and to alter it and redistribute it 42 | * freely, subject to the following restrictions: 43 | * 44 | * 1. The origin of this software must not be misrepresented; you must not 45 | * claim that you wrote the original software. If you use this software 46 | * in a product, an acknowledgment in the product documentation would be 47 | * appreciated but is not required. 48 | * 2. Altered source versions must be plainly marked as such, and must not be 49 | * misrepresented as being the original software. 50 | * 3. This notice may not be removed or altered from any source distribution. 51 | * 52 | * Jean-loup Gailly 53 | * Mark Adler 54 | */ 55 | 56 | #ifndef _SPL_ZMOD_H 57 | #define _SPL_ZMOD_H 58 | 59 | #include 60 | #include 61 | 62 | #ifdef HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE 63 | #define spl_zlib_deflate_workspacesize(wb, ml) \ 64 | zlib_deflate_workspacesize(wb, ml) 65 | #else 66 | #define spl_zlib_deflate_workspacesize(wb, ml) \ 67 | zlib_deflate_workspacesize() 68 | #endif /* HAVE_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE */ 69 | 70 | extern int z_compress_level(void *dest, size_t *destLen, const void *source, 71 | size_t sourceLen, int level); 72 | extern int z_uncompress(void *dest, size_t *destLen, const void *source, 73 | size_t sourceLen); 74 | 75 | int spl_zlib_init(void); 76 | void spl_zlib_fini(void); 77 | 78 | #endif /* SPL_ZMOD_H */ 79 | -------------------------------------------------------------------------------- /include/spl/sys/zone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #ifndef _SPL_ZONE_H 26 | #define _SPL_ZONE_H 27 | 28 | #include 29 | 30 | #define GLOBAL_ZONEID 0 31 | 32 | #define zone_dataset_visible(x, y) (1) 33 | #define crgetzoneid(x) (GLOBAL_ZONEID) 34 | #define INGLOBALZONE(z) (1) 35 | 36 | #endif /* SPL_ZONE_H */ 37 | -------------------------------------------------------------------------------- /module/spl/THIRDPARTYLICENSE.gplv2.descrip: -------------------------------------------------------------------------------- 1 | COMPATIBILITY LAYER FOR OPENZFS ON LINUX 2 | -------------------------------------------------------------------------------- /module/spl/spl-atomic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * Solaris Porting Layer (SPL) Atomic Implementation. 25 | */ 26 | 27 | #include 28 | 29 | #ifdef ATOMIC_SPINLOCK 30 | /* Global atomic lock declarations */ 31 | DEFINE_SPINLOCK(atomic32_lock); 32 | DEFINE_SPINLOCK(atomic64_lock); 33 | 34 | EXPORT_SYMBOL(atomic32_lock); 35 | EXPORT_SYMBOL(atomic64_lock); 36 | #endif /* ATOMIC_SPINLOCK */ 37 | -------------------------------------------------------------------------------- /module/spl/spl-cred.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * Solaris Porting Layer (SPL) Credential Implementation. 25 | */ 26 | 27 | #include 28 | 29 | static int 30 | #ifdef HAVE_KUIDGID_T 31 | cr_groups_search(const struct group_info *group_info, kgid_t grp) 32 | #else 33 | cr_groups_search(const struct group_info *group_info, gid_t grp) 34 | #endif 35 | { 36 | unsigned int left, right, mid; 37 | int cmp; 38 | 39 | if (!group_info) 40 | return (0); 41 | 42 | left = 0; 43 | right = group_info->ngroups; 44 | while (left < right) { 45 | mid = (left + right) / 2; 46 | cmp = KGID_TO_SGID(grp) - 47 | KGID_TO_SGID(GROUP_AT(group_info, mid)); 48 | 49 | if (cmp > 0) 50 | left = mid + 1; 51 | else if (cmp < 0) 52 | right = mid; 53 | else 54 | return (1); 55 | } 56 | return (0); 57 | } 58 | 59 | /* Hold a reference on the credential */ 60 | void 61 | crhold(cred_t *cr) 62 | { 63 | (void) get_cred((const cred_t *)cr); 64 | } 65 | 66 | /* Free a reference on the credential */ 67 | void 68 | crfree(cred_t *cr) 69 | { 70 | put_cred((const cred_t *)cr); 71 | } 72 | 73 | /* Return the number of supplemental groups */ 74 | int 75 | crgetngroups(const cred_t *cr) 76 | { 77 | struct group_info *gi; 78 | int rc; 79 | 80 | gi = cr->group_info; 81 | rc = gi->ngroups; 82 | #ifndef HAVE_GROUP_INFO_GID 83 | /* 84 | * For Linux <= 4.8, 85 | * crgetgroups will only returns gi->blocks[0], which contains only 86 | * the first NGROUPS_PER_BLOCK groups. 87 | */ 88 | if (rc > NGROUPS_PER_BLOCK) { 89 | WARN_ON_ONCE(1); 90 | rc = NGROUPS_PER_BLOCK; 91 | } 92 | #endif 93 | return (rc); 94 | } 95 | 96 | /* 97 | * Return an array of supplemental gids. The returned address is safe 98 | * to use as long as the caller has taken a reference with crhold(). 99 | * 100 | * Linux 4.9 API change, group_info changed from 2d array via ->blocks to 1d 101 | * array via ->gid. 102 | */ 103 | gid_t * 104 | crgetgroups(const cred_t *cr) 105 | { 106 | struct group_info *gi; 107 | gid_t *gids = NULL; 108 | 109 | gi = cr->group_info; 110 | #ifdef HAVE_GROUP_INFO_GID 111 | gids = KGIDP_TO_SGIDP(gi->gid); 112 | #else 113 | if (gi->nblocks > 0) 114 | gids = KGIDP_TO_SGIDP(gi->blocks[0]); 115 | #endif 116 | return (gids); 117 | } 118 | 119 | /* Check if the passed gid is available in supplied credential. */ 120 | int 121 | groupmember(gid_t gid, const cred_t *cr) 122 | { 123 | struct group_info *gi; 124 | int rc; 125 | 126 | gi = cr->group_info; 127 | rc = cr_groups_search(gi, SGID_TO_KGID(gid)); 128 | 129 | return (rc); 130 | } 131 | 132 | /* Return the effective user id */ 133 | uid_t 134 | crgetuid(const cred_t *cr) 135 | { 136 | return (KUID_TO_SUID(cr->euid)); 137 | } 138 | 139 | /* Return the real user id */ 140 | uid_t 141 | crgetruid(const cred_t *cr) 142 | { 143 | return (KUID_TO_SUID(cr->uid)); 144 | } 145 | 146 | /* Return the saved user id */ 147 | uid_t 148 | crgetsuid(const cred_t *cr) 149 | { 150 | return (KUID_TO_SUID(cr->suid)); 151 | } 152 | 153 | /* Return the filesystem user id */ 154 | uid_t 155 | crgetfsuid(const cred_t *cr) 156 | { 157 | return (KUID_TO_SUID(cr->fsuid)); 158 | } 159 | 160 | /* Return the effective group id */ 161 | gid_t 162 | crgetgid(const cred_t *cr) 163 | { 164 | return (KGID_TO_SGID(cr->egid)); 165 | } 166 | 167 | /* Return the real group id */ 168 | gid_t 169 | crgetrgid(const cred_t *cr) 170 | { 171 | return (KGID_TO_SGID(cr->gid)); 172 | } 173 | 174 | /* Return the saved group id */ 175 | gid_t 176 | crgetsgid(const cred_t *cr) 177 | { 178 | return (KGID_TO_SGID(cr->sgid)); 179 | } 180 | 181 | /* Return the filesystem group id */ 182 | gid_t 183 | crgetfsgid(const cred_t *cr) 184 | { 185 | return (KGID_TO_SGID(cr->fsgid)); 186 | } 187 | 188 | EXPORT_SYMBOL(crhold); 189 | EXPORT_SYMBOL(crfree); 190 | EXPORT_SYMBOL(crgetuid); 191 | EXPORT_SYMBOL(crgetruid); 192 | EXPORT_SYMBOL(crgetsuid); 193 | EXPORT_SYMBOL(crgetfsuid); 194 | EXPORT_SYMBOL(crgetgid); 195 | EXPORT_SYMBOL(crgetrgid); 196 | EXPORT_SYMBOL(crgetsgid); 197 | EXPORT_SYMBOL(crgetfsgid); 198 | EXPORT_SYMBOL(crgetngroups); 199 | EXPORT_SYMBOL(crgetgroups); 200 | EXPORT_SYMBOL(groupmember); 201 | -------------------------------------------------------------------------------- /module/spl/spl-err.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * Solaris Porting Layer (SPL) Error Implementation. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | /* 32 | * It is often useful to actually have the panic crash the node so you 33 | * can then get notified of the event, get the crashdump for later 34 | * analysis and other such goodies. 35 | * But we would still default to the current default of not to do that. 36 | */ 37 | /* BEGIN CSTYLED */ 38 | unsigned int spl_panic_halt; 39 | module_param(spl_panic_halt, uint, 0644); 40 | MODULE_PARM_DESC(spl_panic_halt, "Cause kernel panic on assertion failures"); 41 | /* END CSTYLED */ 42 | 43 | /* 44 | * Limit the number of stack traces dumped to not more than 5 every 45 | * 60 seconds to prevent denial-of-service attacks from debug code. 46 | */ 47 | DEFINE_RATELIMIT_STATE(dumpstack_ratelimit_state, 60 * HZ, 5); 48 | 49 | void 50 | spl_dumpstack(void) 51 | { 52 | if (__ratelimit(&dumpstack_ratelimit_state)) { 53 | printk("Showing stack for process %d\n", current->pid); 54 | dump_stack(); 55 | } 56 | } 57 | EXPORT_SYMBOL(spl_dumpstack); 58 | 59 | int 60 | spl_panic(const char *file, const char *func, int line, const char *fmt, ...) 61 | { 62 | const char *newfile; 63 | char msg[MAXMSGLEN]; 64 | va_list ap; 65 | 66 | newfile = strrchr(file, '/'); 67 | if (newfile != NULL) 68 | newfile = newfile + 1; 69 | else 70 | newfile = file; 71 | 72 | va_start(ap, fmt); 73 | (void) vsnprintf(msg, sizeof (msg), fmt, ap); 74 | va_end(ap); 75 | 76 | printk(KERN_EMERG "%s", msg); 77 | printk(KERN_EMERG "PANIC at %s:%d:%s()\n", newfile, line, func); 78 | if (spl_panic_halt) 79 | panic("%s", msg); 80 | 81 | spl_dumpstack(); 82 | 83 | /* Halt the thread to facilitate further debugging */ 84 | set_current_state(TASK_UNINTERRUPTIBLE); 85 | while (1) 86 | schedule(); 87 | 88 | /* Unreachable */ 89 | return (1); 90 | } 91 | EXPORT_SYMBOL(spl_panic); 92 | 93 | void 94 | vcmn_err(int ce, const char *fmt, va_list ap) 95 | { 96 | char msg[MAXMSGLEN]; 97 | 98 | vsnprintf(msg, MAXMSGLEN - 1, fmt, ap); 99 | 100 | switch (ce) { 101 | case CE_IGNORE: 102 | break; 103 | case CE_CONT: 104 | printk("%s", msg); 105 | break; 106 | case CE_NOTE: 107 | printk(KERN_NOTICE "NOTICE: %s\n", msg); 108 | break; 109 | case CE_WARN: 110 | printk(KERN_WARNING "WARNING: %s\n", msg); 111 | break; 112 | case CE_PANIC: 113 | printk(KERN_EMERG "PANIC: %s\n", msg); 114 | spl_dumpstack(); 115 | 116 | /* Halt the thread to facilitate further debugging */ 117 | set_current_state(TASK_UNINTERRUPTIBLE); 118 | while (1) 119 | schedule(); 120 | } 121 | } /* vcmn_err() */ 122 | EXPORT_SYMBOL(vcmn_err); 123 | 124 | void 125 | cmn_err(int ce, const char *fmt, ...) 126 | { 127 | va_list ap; 128 | 129 | va_start(ap, fmt); 130 | vcmn_err(ce, fmt, ap); 131 | va_end(ap); 132 | } /* cmn_err() */ 133 | EXPORT_SYMBOL(cmn_err); 134 | -------------------------------------------------------------------------------- /module/spl/spl-kobj.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * Solaris Porting Layer (SPL) Kobj Implementation. 25 | */ 26 | 27 | #include 28 | 29 | struct _buf * 30 | kobj_open_file(const char *name) 31 | { 32 | struct _buf *file; 33 | vnode_t *vp; 34 | int rc; 35 | 36 | file = kmalloc(sizeof (_buf_t), kmem_flags_convert(KM_SLEEP)); 37 | if (file == NULL) 38 | return ((_buf_t *)-1UL); 39 | 40 | if ((rc = vn_open(name, UIO_SYSSPACE, FREAD, 0644, &vp, 0, 0))) { 41 | kfree(file); 42 | return ((_buf_t *)-1UL); 43 | } 44 | 45 | file->vp = vp; 46 | 47 | return (file); 48 | } /* kobj_open_file() */ 49 | EXPORT_SYMBOL(kobj_open_file); 50 | 51 | void 52 | kobj_close_file(struct _buf *file) 53 | { 54 | VOP_CLOSE(file->vp, 0, 0, 0, 0, 0); 55 | kfree(file); 56 | } /* kobj_close_file() */ 57 | EXPORT_SYMBOL(kobj_close_file); 58 | 59 | int 60 | kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off) 61 | { 62 | ssize_t resid; 63 | 64 | if (vn_rdwr(UIO_READ, file->vp, buf, size, (offset_t)off, 65 | UIO_SYSSPACE, 0, 0, 0, &resid) != 0) 66 | return (-1); 67 | 68 | return (size - resid); 69 | } /* kobj_read_file() */ 70 | EXPORT_SYMBOL(kobj_read_file); 71 | 72 | int 73 | kobj_get_filesize(struct _buf *file, uint64_t *size) 74 | { 75 | vattr_t vap; 76 | int rc; 77 | 78 | rc = VOP_GETATTR(file->vp, &vap, 0, 0, NULL); 79 | if (rc) 80 | return (rc); 81 | 82 | *size = vap.va_size; 83 | 84 | return (rc); 85 | } /* kobj_get_filesize() */ 86 | EXPORT_SYMBOL(kobj_get_filesize); 87 | -------------------------------------------------------------------------------- /module/spl/spl-mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * Solaris Porting Layer (SPL) Mutex Implementation. 25 | */ 26 | 27 | #include 28 | 29 | int spl_mutex_init(void) { return 0; } 30 | void spl_mutex_fini(void) { } 31 | -------------------------------------------------------------------------------- /module/spl/spl-rwlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * Solaris Porting Layer (SPL) Reader/Writer Lock Implementation. 25 | */ 26 | 27 | #include 28 | 29 | #if defined(CONFIG_PREEMPT_RT_FULL) 30 | 31 | #include 32 | #define RT_MUTEX_OWNER_MASKALL 1UL 33 | 34 | static int 35 | __rwsem_tryupgrade(struct rw_semaphore *rwsem) 36 | { 37 | 38 | ASSERT((struct task_struct *) 39 | ((unsigned long)rwsem->lock.owner & ~RT_MUTEX_OWNER_MASKALL) == 40 | current); 41 | 42 | /* 43 | * Under the realtime patch series, rwsem is implemented as a 44 | * single mutex held by readers and writers alike. However, 45 | * this implementation would prevent a thread from taking a 46 | * read lock twice, as the mutex would already be locked on 47 | * the second attempt. Therefore the implementation allows a 48 | * single thread to take a rwsem as read lock multiple times 49 | * tracking that nesting as read_depth counter. 50 | */ 51 | if (rwsem->read_depth <= 1) { 52 | /* 53 | * In case, the current thread has not taken the lock 54 | * more than once as read lock, we can allow an 55 | * upgrade to a write lock. rwsem_rt.h implements 56 | * write locks as read_depth == 0. 57 | */ 58 | rwsem->read_depth = 0; 59 | return (1); 60 | } 61 | return (0); 62 | } 63 | #elif defined(CONFIG_RWSEM_GENERIC_SPINLOCK) 64 | static int 65 | __rwsem_tryupgrade(struct rw_semaphore *rwsem) 66 | { 67 | int ret = 0; 68 | unsigned long flags; 69 | spl_rwsem_lock_irqsave(&rwsem->wait_lock, flags); 70 | if (RWSEM_COUNT(rwsem) == SPL_RWSEM_SINGLE_READER_VALUE && 71 | list_empty(&rwsem->wait_list)) { 72 | ret = 1; 73 | RWSEM_COUNT(rwsem) = SPL_RWSEM_SINGLE_WRITER_VALUE; 74 | } 75 | spl_rwsem_unlock_irqrestore(&rwsem->wait_lock, flags); 76 | return (ret); 77 | } 78 | #elif defined(HAVE_RWSEM_ATOMIC_LONG_COUNT) 79 | static int 80 | __rwsem_tryupgrade(struct rw_semaphore *rwsem) 81 | { 82 | long val; 83 | val = atomic_long_cmpxchg(&rwsem->count, SPL_RWSEM_SINGLE_READER_VALUE, 84 | SPL_RWSEM_SINGLE_WRITER_VALUE); 85 | return (val == SPL_RWSEM_SINGLE_READER_VALUE); 86 | } 87 | #else 88 | static int 89 | __rwsem_tryupgrade(struct rw_semaphore *rwsem) 90 | { 91 | typeof(rwsem->count) val; 92 | val = cmpxchg(&rwsem->count, SPL_RWSEM_SINGLE_READER_VALUE, 93 | SPL_RWSEM_SINGLE_WRITER_VALUE); 94 | return (val == SPL_RWSEM_SINGLE_READER_VALUE); 95 | } 96 | #endif 97 | 98 | int 99 | rwsem_tryupgrade(struct rw_semaphore *rwsem) 100 | { 101 | if (__rwsem_tryupgrade(rwsem)) { 102 | rwsem_release(&rwsem->dep_map, 1, _RET_IP_); 103 | rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_); 104 | #ifdef CONFIG_RWSEM_SPIN_ON_OWNER 105 | rwsem->owner = current; 106 | #endif 107 | return (1); 108 | } 109 | return (0); 110 | } 111 | EXPORT_SYMBOL(rwsem_tryupgrade); 112 | 113 | int spl_rw_init(void) { return 0; } 114 | void spl_rw_fini(void) { } 115 | -------------------------------------------------------------------------------- /module/spl/spl-thread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * Solaris Porting Layer (SPL) Thread Implementation. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | /* 32 | * Thread interfaces 33 | */ 34 | typedef struct thread_priv_s { 35 | unsigned long tp_magic; /* Magic */ 36 | int tp_name_size; /* Name size */ 37 | char *tp_name; /* Name (without _thread suffix) */ 38 | void (*tp_func)(void *); /* Registered function */ 39 | void *tp_args; /* Args to be passed to function */ 40 | size_t tp_len; /* Len to be passed to function */ 41 | int tp_state; /* State to start thread at */ 42 | pri_t tp_pri; /* Priority to start threat at */ 43 | } thread_priv_t; 44 | 45 | static int 46 | thread_generic_wrapper(void *arg) 47 | { 48 | thread_priv_t *tp = (thread_priv_t *)arg; 49 | void (*func)(void *); 50 | void *args; 51 | 52 | ASSERT(tp->tp_magic == TP_MAGIC); 53 | func = tp->tp_func; 54 | args = tp->tp_args; 55 | set_current_state(tp->tp_state); 56 | set_user_nice((kthread_t *)current, PRIO_TO_NICE(tp->tp_pri)); 57 | kmem_free(tp->tp_name, tp->tp_name_size); 58 | kmem_free(tp, sizeof (thread_priv_t)); 59 | 60 | if (func) 61 | func(args); 62 | 63 | return (0); 64 | } 65 | 66 | void 67 | __thread_exit(void) 68 | { 69 | tsd_exit(); 70 | complete_and_exit(NULL, 0); 71 | /* Unreachable */ 72 | } 73 | EXPORT_SYMBOL(__thread_exit); 74 | 75 | /* 76 | * thread_create() may block forever if it cannot create a thread or 77 | * allocate memory. This is preferable to returning a NULL which Solaris 78 | * style callers likely never check for... since it can't fail. 79 | */ 80 | kthread_t * 81 | __thread_create(caddr_t stk, size_t stksize, thread_func_t func, 82 | const char *name, void *args, size_t len, proc_t *pp, int state, pri_t pri) 83 | { 84 | thread_priv_t *tp; 85 | struct task_struct *tsk; 86 | char *p; 87 | 88 | /* Option pp is simply ignored */ 89 | /* Variable stack size unsupported */ 90 | ASSERT(stk == NULL); 91 | 92 | tp = kmem_alloc(sizeof (thread_priv_t), KM_PUSHPAGE); 93 | if (tp == NULL) 94 | return (NULL); 95 | 96 | tp->tp_magic = TP_MAGIC; 97 | tp->tp_name_size = strlen(name) + 1; 98 | 99 | tp->tp_name = kmem_alloc(tp->tp_name_size, KM_PUSHPAGE); 100 | if (tp->tp_name == NULL) { 101 | kmem_free(tp, sizeof (thread_priv_t)); 102 | return (NULL); 103 | } 104 | 105 | strncpy(tp->tp_name, name, tp->tp_name_size); 106 | 107 | /* 108 | * Strip trailing "_thread" from passed name which will be the func 109 | * name since the exposed API has no parameter for passing a name. 110 | */ 111 | p = strstr(tp->tp_name, "_thread"); 112 | if (p) 113 | p[0] = '\0'; 114 | 115 | tp->tp_func = func; 116 | tp->tp_args = args; 117 | tp->tp_len = len; 118 | tp->tp_state = state; 119 | tp->tp_pri = pri; 120 | 121 | tsk = spl_kthread_create(thread_generic_wrapper, (void *)tp, 122 | "%s", tp->tp_name); 123 | if (IS_ERR(tsk)) 124 | return (NULL); 125 | 126 | wake_up_process(tsk); 127 | return ((kthread_t *)tsk); 128 | } 129 | EXPORT_SYMBOL(__thread_create); 130 | 131 | /* 132 | * spl_kthread_create - Wrapper providing pre-3.13 semantics for 133 | * kthread_create() in which it is not killable and less likely 134 | * to return -ENOMEM. 135 | */ 136 | struct task_struct * 137 | spl_kthread_create(int (*func)(void *), void *data, const char namefmt[], ...) 138 | { 139 | struct task_struct *tsk; 140 | va_list args; 141 | char name[TASK_COMM_LEN]; 142 | 143 | va_start(args, namefmt); 144 | vsnprintf(name, sizeof (name), namefmt, args); 145 | va_end(args); 146 | do { 147 | tsk = kthread_create(func, data, "%s", name); 148 | if (IS_ERR(tsk)) { 149 | if (signal_pending(current)) { 150 | clear_thread_flag(TIF_SIGPENDING); 151 | continue; 152 | } 153 | if (PTR_ERR(tsk) == -ENOMEM) 154 | continue; 155 | return (NULL); 156 | } else 157 | return (tsk); 158 | } while (1); 159 | } 160 | EXPORT_SYMBOL(spl_kthread_create); 161 | -------------------------------------------------------------------------------- /module/spl/spl-vmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | vmem_t *heap_arena = NULL; 32 | EXPORT_SYMBOL(heap_arena); 33 | 34 | vmem_t *zio_alloc_arena = NULL; 35 | EXPORT_SYMBOL(zio_alloc_arena); 36 | 37 | vmem_t *zio_arena = NULL; 38 | EXPORT_SYMBOL(zio_arena); 39 | 40 | #define VMEM_FLOOR_SIZE (4 * 1024 * 1024) /* 4MB floor */ 41 | 42 | /* 43 | * Return approximate virtual memory usage based on these assumptions: 44 | * 45 | * 1) The major SPL consumer of virtual memory is the kmem cache. 46 | * 2) Memory allocated with vmem_alloc() is short lived and can be ignored. 47 | * 3) Allow a 4MB floor as a generous pad given normal consumption. 48 | * 4) The spl_kmem_cache_sem only contends with cache create/destroy. 49 | */ 50 | size_t 51 | vmem_size(vmem_t *vmp, int typemask) 52 | { 53 | spl_kmem_cache_t *skc; 54 | size_t alloc = VMEM_FLOOR_SIZE; 55 | 56 | if ((typemask & VMEM_ALLOC) && (typemask & VMEM_FREE)) 57 | return (VMALLOC_TOTAL); 58 | 59 | 60 | down_read(&spl_kmem_cache_sem); 61 | list_for_each_entry(skc, &spl_kmem_cache_list, skc_list) { 62 | if (skc->skc_flags & KMC_VMEM) 63 | alloc += skc->skc_slab_size * skc->skc_slab_total; 64 | } 65 | up_read(&spl_kmem_cache_sem); 66 | 67 | if (typemask & VMEM_ALLOC) 68 | return (MIN(alloc, VMALLOC_TOTAL)); 69 | else if (typemask & VMEM_FREE) 70 | return (MAX(VMALLOC_TOTAL - alloc, 0)); 71 | else 72 | return (0); 73 | } 74 | EXPORT_SYMBOL(vmem_size); 75 | 76 | /* 77 | * Public vmem_alloc(), vmem_zalloc() and vmem_free() interfaces. 78 | */ 79 | void * 80 | spl_vmem_alloc(size_t size, int flags, const char *func, int line) 81 | { 82 | ASSERT0(flags & ~KM_PUBLIC_MASK); 83 | 84 | flags |= KM_VMEM; 85 | 86 | #if !defined(DEBUG_KMEM) 87 | return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE)); 88 | #elif !defined(DEBUG_KMEM_TRACKING) 89 | return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE)); 90 | #else 91 | return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE)); 92 | #endif 93 | } 94 | EXPORT_SYMBOL(spl_vmem_alloc); 95 | 96 | void * 97 | spl_vmem_zalloc(size_t size, int flags, const char *func, int line) 98 | { 99 | ASSERT0(flags & ~KM_PUBLIC_MASK); 100 | 101 | flags |= (KM_VMEM | KM_ZERO); 102 | 103 | #if !defined(DEBUG_KMEM) 104 | return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE)); 105 | #elif !defined(DEBUG_KMEM_TRACKING) 106 | return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE)); 107 | #else 108 | return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE)); 109 | #endif 110 | } 111 | EXPORT_SYMBOL(spl_vmem_zalloc); 112 | 113 | void 114 | spl_vmem_free(const void *buf, size_t size) 115 | { 116 | #if !defined(DEBUG_KMEM) 117 | return (spl_kmem_free_impl(buf, size)); 118 | #elif !defined(DEBUG_KMEM_TRACKING) 119 | return (spl_kmem_free_debug(buf, size)); 120 | #else 121 | return (spl_kmem_free_track(buf, size)); 122 | #endif 123 | } 124 | EXPORT_SYMBOL(spl_vmem_free); 125 | 126 | int 127 | spl_vmem_init(void) 128 | { 129 | return (0); 130 | } 131 | 132 | void 133 | spl_vmem_fini(void) 134 | { 135 | } 136 | -------------------------------------------------------------------------------- /module/spl/spl-zlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | * Copyright (C) 2007 The Regents of the University of California. 4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5 | * Written by Brian Behlendorf . 6 | * UCRL-CODE-235197 7 | * 8 | * This file is part of the SPL, Solaris Porting Layer. 9 | * For details, see . 10 | * 11 | * The SPL is free software; you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License as published by the 13 | * Free Software Foundation; either version 2 of the License, or (at your 14 | * option) any later version. 15 | * 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19 | * for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with the SPL. If not, see . 23 | * 24 | * 25 | * z_compress_level/z_uncompress are nearly identical copies of the 26 | * compress2/uncompress functions provided by the official zlib package 27 | * available at http://zlib.net/. The only changes made we to slightly 28 | * adapt the functions called to match the linux kernel implementation 29 | * of zlib. The full zlib license follows: 30 | * 31 | * zlib.h -- interface of the 'zlib' general purpose compression library 32 | * version 1.2.5, April 19th, 2010 33 | * 34 | * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 35 | * 36 | * This software is provided 'as-is', without any express or implied 37 | * warranty. In no event will the authors be held liable for any damages 38 | * arising from the use of this software. 39 | * 40 | * Permission is granted to anyone to use this software for any purpose, 41 | * including commercial applications, and to alter it and redistribute it 42 | * freely, subject to the following restrictions: 43 | * 44 | * 1. The origin of this software must not be misrepresented; you must not 45 | * claim that you wrote the original software. If you use this software 46 | * in a product, an acknowledgment in the product documentation would be 47 | * appreciated but is not required. 48 | * 2. Altered source versions must be plainly marked as such, and must not be 49 | * misrepresented as being the original software. 50 | * 3. This notice may not be removed or altered from any source distribution. 51 | * 52 | * Jean-loup Gailly 53 | * Mark Adler 54 | */ 55 | 56 | 57 | #include 58 | #include 59 | #include 60 | 61 | static spl_kmem_cache_t *zlib_workspace_cache; 62 | 63 | /* 64 | * A kmem_cache is used for the zlib workspaces to avoid having to vmalloc 65 | * and vfree for every call. Using a kmem_cache also has the advantage 66 | * that improves the odds that the memory used will be local to this cpu. 67 | * To further improve things it might be wise to create a dedicated per-cpu 68 | * workspace for use. This would take some additional care because we then 69 | * must disable preemption around the critical section, and verify that 70 | * zlib_deflate* and zlib_inflate* never internally call schedule(). 71 | */ 72 | static void * 73 | zlib_workspace_alloc(int flags) 74 | { 75 | return (kmem_cache_alloc(zlib_workspace_cache, flags & ~(__GFP_FS))); 76 | } 77 | 78 | static void 79 | zlib_workspace_free(void *workspace) 80 | { 81 | kmem_cache_free(zlib_workspace_cache, workspace); 82 | } 83 | 84 | /* 85 | * Compresses the source buffer into the destination buffer. The level 86 | * parameter has the same meaning as in deflateInit. sourceLen is the byte 87 | * length of the source buffer. Upon entry, destLen is the total size of the 88 | * destination buffer, which must be at least 0.1% larger than sourceLen plus 89 | * 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 90 | * 91 | * compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 92 | * memory, Z_BUF_ERROR if there was not enough room in the output buffer, 93 | * Z_STREAM_ERROR if the level parameter is invalid. 94 | */ 95 | int 96 | z_compress_level(void *dest, size_t *destLen, const void *source, 97 | size_t sourceLen, int level) 98 | { 99 | z_stream stream; 100 | int err; 101 | 102 | stream.next_in = (Byte *)source; 103 | stream.avail_in = (uInt)sourceLen; 104 | stream.next_out = dest; 105 | stream.avail_out = (uInt)*destLen; 106 | 107 | if ((size_t)stream.avail_out != *destLen) 108 | return (Z_BUF_ERROR); 109 | 110 | stream.workspace = zlib_workspace_alloc(KM_SLEEP); 111 | if (!stream.workspace) 112 | return (Z_MEM_ERROR); 113 | 114 | err = zlib_deflateInit(&stream, level); 115 | if (err != Z_OK) { 116 | zlib_workspace_free(stream.workspace); 117 | return (err); 118 | } 119 | 120 | err = zlib_deflate(&stream, Z_FINISH); 121 | if (err != Z_STREAM_END) { 122 | zlib_deflateEnd(&stream); 123 | zlib_workspace_free(stream.workspace); 124 | return (err == Z_OK ? Z_BUF_ERROR : err); 125 | } 126 | *destLen = stream.total_out; 127 | 128 | err = zlib_deflateEnd(&stream); 129 | zlib_workspace_free(stream.workspace); 130 | 131 | return (err); 132 | } 133 | EXPORT_SYMBOL(z_compress_level); 134 | 135 | /* 136 | * Decompresses the source buffer into the destination buffer. sourceLen is 137 | * the byte length of the source buffer. Upon entry, destLen is the total 138 | * size of the destination buffer, which must be large enough to hold the 139 | * entire uncompressed data. (The size of the uncompressed data must have 140 | * been saved previously by the compressor and transmitted to the decompressor 141 | * by some mechanism outside the scope of this compression library.) 142 | * Upon exit, destLen is the actual size of the compressed buffer. 143 | * This function can be used to decompress a whole file at once if the 144 | * input file is mmap'ed. 145 | * 146 | * uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 147 | * enough memory, Z_BUF_ERROR if there was not enough room in the output 148 | * buffer, or Z_DATA_ERROR if the input data was corrupted. 149 | */ 150 | int 151 | z_uncompress(void *dest, size_t *destLen, const void *source, size_t sourceLen) 152 | { 153 | z_stream stream; 154 | int err; 155 | 156 | stream.next_in = (Byte *)source; 157 | stream.avail_in = (uInt)sourceLen; 158 | stream.next_out = dest; 159 | stream.avail_out = (uInt)*destLen; 160 | 161 | if ((size_t)stream.avail_out != *destLen) 162 | return (Z_BUF_ERROR); 163 | 164 | stream.workspace = zlib_workspace_alloc(KM_SLEEP); 165 | if (!stream.workspace) 166 | return (Z_MEM_ERROR); 167 | 168 | err = zlib_inflateInit(&stream); 169 | if (err != Z_OK) { 170 | zlib_workspace_free(stream.workspace); 171 | return (err); 172 | } 173 | 174 | err = zlib_inflate(&stream, Z_FINISH); 175 | if (err != Z_STREAM_END) { 176 | zlib_inflateEnd(&stream); 177 | zlib_workspace_free(stream.workspace); 178 | 179 | if (err == Z_NEED_DICT || 180 | (err == Z_BUF_ERROR && stream.avail_in == 0)) 181 | return (Z_DATA_ERROR); 182 | 183 | return (err); 184 | } 185 | *destLen = stream.total_out; 186 | 187 | err = zlib_inflateEnd(&stream); 188 | zlib_workspace_free(stream.workspace); 189 | 190 | return (err); 191 | } 192 | EXPORT_SYMBOL(z_uncompress); 193 | 194 | int 195 | spl_zlib_init(void) 196 | { 197 | int size; 198 | 199 | size = MAX(spl_zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL), 200 | zlib_inflate_workspacesize()); 201 | 202 | zlib_workspace_cache = kmem_cache_create( 203 | "spl_zlib_workspace_cache", 204 | size, 0, NULL, NULL, NULL, NULL, NULL, 205 | KMC_VMEM | KMC_NOEMERGENCY); 206 | if (!zlib_workspace_cache) 207 | return (1); 208 | 209 | return (0); 210 | } 211 | 212 | void 213 | spl_zlib_fini(void) 214 | { 215 | kmem_cache_destroy(zlib_workspace_cache); 216 | zlib_workspace_cache = NULL; 217 | } 218 | --------------------------------------------------------------------------------