├── module ├── Makefile.am ├── spl │ ├── .gitignore │ ├── InfoPlist.strings │ ├── KernelExports │ │ ├── .gitignore │ │ ├── README.txt │ │ ├── version.plist │ │ ├── zfs.exports │ │ ├── Makefile.am │ │ └── Info.plist │ ├── spl-proc.c │ ├── spl-debug.c │ ├── load_zfs │ ├── spl-processor.c │ ├── spl-atomic.c │ ├── spl-err.c │ ├── Info.plist │ ├── Makefile.am │ ├── spl-cred.c │ ├── spl-time.c │ ├── spl-kobj.c │ ├── spl-thread.c │ ├── spl-list.c │ └── spl-condvar.c └── .gitignore ├── spl.release.in ├── scripts ├── splwatch ├── Makefile.am ├── dolog ├── doarcstat ├── splwatch2 ├── ziowatch ├── splstat └── check.sh ├── autogen.sh ├── include ├── sys │ ├── ddi.h │ ├── sdt.h │ ├── sysdc.h │ ├── crc32.h │ ├── disp.h │ ├── mkdev.h │ ├── mode.h │ ├── note.h │ ├── open.h │ ├── bitmap.h │ ├── cpuvar.h │ ├── dumphdr.h │ ├── mntent.h │ ├── modctl.h │ ├── refstr.h │ ├── vfs_opreg.h │ ├── console.h │ ├── cpupart.h │ ├── dklabel.h │ ├── fm │ │ ├── util.h │ │ └── protocol.h │ ├── va_list.h │ ├── acl_impl.h │ ├── bootconf.h │ ├── compress.h │ ├── fs │ │ └── swapnode.h │ ├── inttypes.h │ ├── sysevent.h │ ├── bootprops.h │ ├── int_limits.h │ ├── priv_impl.h │ ├── u8_textprep.h │ ├── pool.h │ ├── stat.h │ ├── attr.h │ ├── conf.h │ ├── efi_partition.h │ ├── ctype.h │ ├── errno.h │ ├── kidmap.h │ ├── vmsystm.h │ ├── dirent.h │ ├── unistd.h │ ├── int_types.h │ ├── resource.h │ ├── sysevent │ │ └── eventdefs.h │ ├── extdirent.h │ ├── idmap.h │ ├── mutex.h │ ├── varargs.h │ ├── buf.h │ ├── ubc.h │ ├── mount.h │ ├── systm.h │ ├── fcntl.h │ ├── t_lock.h │ ├── processor.h │ ├── condvar.h │ ├── zone.h │ ├── proc.h │ ├── types32.h │ ├── param.h │ ├── pathname.h │ ├── pset.h │ ├── systeminfo.h │ ├── dnlc.h │ ├── file.h │ ├── sunldi.h │ ├── dkio.h │ ├── random.h │ ├── utsname.h │ ├── kobj.h │ ├── tsd.h │ ├── cmn_err.h │ ├── byteorder.h │ ├── cred.h │ ├── callb.h │ ├── timer.h │ ├── rwlock.h │ ├── signal.h │ ├── sid.h │ ├── vfs.h │ ├── time.h │ ├── thread.h │ ├── isa_defs.h │ ├── taskq.h │ ├── zmod.h │ ├── types.h │ ├── uio.h │ ├── list.h │ ├── avl_impl.h │ └── kmem.h ├── unistd.h ├── strings.h ├── vm │ ├── pvn.h │ ├── anon.h │ └── seg_kmem.h ├── sharefs │ └── share.h ├── fs │ └── fs_subr.h ├── util │ ├── sscanf.h │ └── qsort.h ├── rpc │ ├── types.h │ └── xdr.h ├── osx │ ├── atomic.h │ ├── sched.h │ ├── condvar.h │ └── mutex.h ├── Makefile.am ├── spl-ctl.h ├── spl-debug.h ├── spl-device.h └── spl-trace.h ├── META ├── config ├── .gitignore ├── config.awk ├── spl-boot.m4 ├── Rules.am ├── arch.am ├── tgz.am ├── deb.am ├── rpm.am └── spl-meta.m4 ├── AUTHORS ├── COPYING ├── README.markdown ├── spl.xcodeproj └── xcuserdata │ └── zfs-tests.xcuserdatad │ └── xcschemes │ ├── xcschememanagement.plist │ └── spl.xcscheme ├── dkms.postinst ├── PKGBUILD-spl.in ├── PKGBUILD-spl-modules.in ├── dkms.conf.in ├── spl.spec.in ├── .gitignore ├── DISCLAIMER ├── Makefile.am ├── configure.ac ├── copy-builtin └── patches ├── rhel5-spl-export-symbols.patch └── fc11-spl-export-symbols.patch /module/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS=spl 3 | 4 | -------------------------------------------------------------------------------- /spl.release.in: -------------------------------------------------------------------------------- 1 | @SPL_META_VERSION@-@SPL_META_RELEASE@ 2 | -------------------------------------------------------------------------------- /module/spl/.gitignore: -------------------------------------------------------------------------------- 1 | /spl 2 | /spl.kext 3 | /KernelExports.kext 4 | -------------------------------------------------------------------------------- /module/.gitignore: -------------------------------------------------------------------------------- 1 | /.tmp_versions 2 | /Module.markers 3 | /Module.symvers 4 | -------------------------------------------------------------------------------- /scripts/splwatch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /opt/local/bin/watch -d /usr/local/bin/splstat 3 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | autoreconf -fiv 5 | rm -Rf autom4te.cache 6 | -------------------------------------------------------------------------------- /scripts/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = check.sh 2 | 3 | check: 4 | $(top_srcdir)/scripts/check.sh 5 | -------------------------------------------------------------------------------- /include/sys/ddi.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_DDI_H 3 | #define _SPL_DDI_H 4 | 5 | #endif /* SPL_DDI_H */ 6 | -------------------------------------------------------------------------------- /include/sys/sdt.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SDT_H 3 | #define _SPL_SDT_H 4 | 5 | #endif /* SPL_SDT_H */ 6 | -------------------------------------------------------------------------------- /include/sys/sysdc.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPL_SYSDC_H 2 | #define _SPL_SYSDC_H 3 | 4 | #endif /* SPL_SYSDC_H */ 5 | -------------------------------------------------------------------------------- /include/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPL_UNISTD_H 2 | #define _SPL_UNISTD_H 3 | 4 | #endif /* SPL_UNISTD_H */ 5 | -------------------------------------------------------------------------------- /include/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPL_STRINGS_H 2 | #define _SPL_STRINGS_H 3 | 4 | #endif /* SPL_STRINGS_H */ 5 | -------------------------------------------------------------------------------- /include/sys/crc32.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_CRC32_H 3 | #define _SPL_CRC32_H 4 | 5 | #endif /* SPL_CRC32_H */ 6 | -------------------------------------------------------------------------------- /include/sys/disp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_DISP_H 3 | #define _SPL_DISP_H 4 | 5 | #endif /* SPL_DISP_H */ 6 | -------------------------------------------------------------------------------- /include/sys/mkdev.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_MKDEV_H 3 | #define _SPL_MKDEV_H 4 | 5 | #endif /* SPL_MKDEV_H */ 6 | -------------------------------------------------------------------------------- /include/sys/mode.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_MODE_H 3 | #define _SPL_MODE_H 4 | 5 | #endif /* SPL_MODE_H */ 6 | -------------------------------------------------------------------------------- /include/sys/note.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_NOTE_H 3 | #define _SPL_NOTE_H 4 | 5 | #endif /* SPL_NOTE_H */ 6 | -------------------------------------------------------------------------------- /include/sys/open.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_OPEN_H 3 | #define _SPL_OPEN_H 4 | 5 | #endif /* SPL_OPEN_H */ 6 | -------------------------------------------------------------------------------- /include/vm/pvn.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_VM_PVN_H 3 | #define _SPL_VM_PVN_H 4 | 5 | #endif /* SPL_VM_PVN_H */ 6 | -------------------------------------------------------------------------------- /module/spl/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openzfsonosx/spl/HEAD/module/spl/InfoPlist.strings -------------------------------------------------------------------------------- /include/sharefs/share.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SHARE_H 3 | #define _SPL_SHARE_H 4 | 5 | #endif /* SPL_SHARE_H */ 6 | -------------------------------------------------------------------------------- /include/sys/bitmap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_BITMAP_H 3 | #define _SPL_BITMAP_H 4 | 5 | #endif /* SPL_BITMAP_H */ 6 | -------------------------------------------------------------------------------- /include/sys/cpuvar.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_CPUVAR_H 3 | #define _SPL_CPUVAR_H 4 | 5 | #endif /* SPL_CPUVAR_H */ 6 | -------------------------------------------------------------------------------- /include/sys/dumphdr.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPL_DUMPHDR_H 2 | #define _SPL_DUMPHDR_H 3 | 4 | #endif /* SPL_DUMPHDR_H */ 5 | -------------------------------------------------------------------------------- /include/sys/mntent.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_MNTENT_H 3 | #define _SPL_MNTENT_H 4 | 5 | #endif /* SPL_MNTENT_H */ 6 | -------------------------------------------------------------------------------- /include/sys/modctl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_MODCTL_H 3 | #define _SPL_MODCTL_H 4 | 5 | #endif /* SPL_MODCTL_H */ 6 | -------------------------------------------------------------------------------- /include/sys/refstr.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_REFSTR_H 3 | #define _SPL_REFSTR_H 4 | 5 | #endif /* SPL_REFSTR_H */ 6 | -------------------------------------------------------------------------------- /include/sys/vfs_opreg.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_OPREG_H 3 | #define _SPL_OPREG_H 4 | 5 | #endif /* SPL_OPREG_H */ 6 | -------------------------------------------------------------------------------- /include/vm/anon.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_VM_ANON_H 3 | #define _SPL_VM_ANON_H 4 | 5 | #endif /* SPL_VM_ANON_H */ 6 | -------------------------------------------------------------------------------- /include/sys/console.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_CONSOLE_H 3 | #define _SPL_CONSOLE_H 4 | 5 | #endif /* _SPL_CONSOLE_H */ 6 | -------------------------------------------------------------------------------- /include/sys/cpupart.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_CPUPART_H 3 | #define _SPL_CPUPART_H 4 | 5 | #endif /* SPL_CPUPART_H */ 6 | -------------------------------------------------------------------------------- /include/sys/dklabel.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_DKLABEL_H 3 | #define _SPL_DKLABEL_H 4 | 5 | #endif /* _SPL_DKLABEL_H */ 6 | -------------------------------------------------------------------------------- /include/sys/fm/util.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_FM_UTIL_H 3 | #define _SPL_FM_UTIL_H 4 | 5 | #endif /* _SPL_FM_UTIL_H */ 6 | -------------------------------------------------------------------------------- /include/sys/va_list.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_VA_LIST_H 3 | #define _SPL_VA_LIST_H 4 | 5 | #endif /* SPL_VA_LIST_H */ 6 | -------------------------------------------------------------------------------- /include/sys/acl_impl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_ACL_IMPL_H 3 | #define _SPL_ACL_IMPL_H 4 | 5 | #endif /* _SPL_ACL_IMPL_H */ 6 | -------------------------------------------------------------------------------- /include/sys/bootconf.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_BOOTCONF_H 3 | #define _SPL_BOOTCONF_H 4 | 5 | #endif /* SPL_BOOTCONF_H */ 6 | -------------------------------------------------------------------------------- /include/sys/compress.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_COMPRESS_H 3 | #define _SPL_COMPRESS_H 4 | 5 | #endif /* SPL_COMPRESS_H */ 6 | -------------------------------------------------------------------------------- /include/sys/fs/swapnode.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SWAPNODE_H 3 | #define _SPL_SWAPNODE_H 4 | 5 | #endif /* SPL_SWAPNODE_H */ 6 | -------------------------------------------------------------------------------- /include/sys/inttypes.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_INTTYPES_H 3 | #define _SPL_INTTYPES_H 4 | 5 | #endif /* SPL_INTTYPES_H */ 6 | -------------------------------------------------------------------------------- /include/sys/sysevent.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SYSEVENT_H 3 | #define _SPL_SYSEVENT_H 4 | 5 | #endif /* _SPL_SYSEVENT_H */ 6 | -------------------------------------------------------------------------------- /include/fs/fs_subr.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_FS_FS_SUBR_H 3 | #define _SPL_FS_FS_SUBR_H 4 | 5 | #endif /* SPL_FS_FS_SUBR_H */ 6 | -------------------------------------------------------------------------------- /include/sys/bootprops.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_BOOTPROPS_H 3 | #define _SPL_BOOTPROPS_H 4 | 5 | #endif /* SPL_BOOTPROPS_H */ 6 | -------------------------------------------------------------------------------- /include/sys/int_limits.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_INT_LIMITS_H 3 | #define _SPL_INT_LIMITS_H 4 | 5 | #endif /* SPL_INT_LIMITS_H */ 6 | -------------------------------------------------------------------------------- /include/sys/priv_impl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_PRIV_IMPL_H 3 | #define _SPL_PRIV_IMPL_H 4 | 5 | #endif /* _SPL_PRIV_IMPL_H */ 6 | -------------------------------------------------------------------------------- /include/util/sscanf.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_UTIL_SSCANF_H 3 | #define _SPL_UTIL_SSCANF_H 4 | 5 | #endif /* SPL_UTIL_SSCAN_H */ 6 | -------------------------------------------------------------------------------- /include/sys/fm/protocol.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_FM_PROTOCOL_H 3 | #define _SPL_FM_PROTOCOL_H 4 | 5 | #endif /* _SPL_FM_PROTOCOL_H */ 6 | -------------------------------------------------------------------------------- /include/sys/u8_textprep.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_U8_TEXTPREP_H 3 | #define _SPL_U8_TEXTPREP_H 4 | 5 | #endif /* SPL_U8_TEXTPREP_H */ 6 | -------------------------------------------------------------------------------- /META: -------------------------------------------------------------------------------- 1 | Meta: 1 2 | Name: spl 3 | Branch: 1.0 4 | Version: 1.9.4 5 | Release: 0 6 | Release-Tags: relext 7 | -------------------------------------------------------------------------------- /config/.gitignore: -------------------------------------------------------------------------------- 1 | /config.guess 2 | /config.sub 3 | /depcomp 4 | /install-sh 5 | /ltmain.sh 6 | /missing 7 | /libtool.m4 8 | /lt*.m4 9 | -------------------------------------------------------------------------------- /include/sys/pool.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_POOL_H 3 | #define _SPL_POOL_H 4 | 5 | #include 6 | 7 | #endif /* SPL_POOL_H */ 8 | -------------------------------------------------------------------------------- /include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPL_STAT_H 2 | #define _SPL_STAT_H 3 | 4 | #include_next 5 | 6 | #endif /* SPL_STAT_H */ 7 | -------------------------------------------------------------------------------- /module/spl/KernelExports/.gitignore: -------------------------------------------------------------------------------- 1 | /KernelExports 2 | /KernelExports_32 3 | /KernelExports_64 4 | /allsymbols 5 | /kextsymboltool 6 | -------------------------------------------------------------------------------- /include/sys/attr.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_ATTR_H 3 | #define _SPL_ATTR_H 4 | 5 | #include_next 6 | 7 | #endif /* SPL_ATTR_H */ 8 | -------------------------------------------------------------------------------- /include/sys/conf.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_CONF_H 3 | #define _SPL_CONF_H 4 | 5 | #include_next 6 | 7 | #endif /* SPL_CONF_H */ 8 | -------------------------------------------------------------------------------- /include/sys/efi_partition.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_EFI_PARTITION_H 3 | #define _SPL_EFI_PARTITION_H 4 | 5 | #endif /* SPL_EFI_PARTITION_H */ 6 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | MacZFS Developers 2 | - Original Implementation 3 | 4 | Jorgen Lundman 5 | - Additional Implementation. 6 | 7 | 8 | -------------------------------------------------------------------------------- /include/sys/ctype.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_CTYPE_H 3 | #define _SPL_CTYPE_H 4 | 5 | //#include_next 6 | 7 | #endif /* SPL_CTYPE_H */ 8 | -------------------------------------------------------------------------------- /include/sys/errno.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_ERRNO_H 3 | #define _SPL_ERRNO_H 4 | 5 | #include_next 6 | 7 | #endif /* SPL_ERRNO_H */ 8 | -------------------------------------------------------------------------------- /include/sys/kidmap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_KIDMAP_H 3 | #define _SPL_KIDMAP_H 4 | 5 | #include 6 | 7 | #endif /* SPL_KIDMAP_H */ 8 | -------------------------------------------------------------------------------- /include/sys/vmsystm.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_VMSYSTM_H 3 | #define _SPL_VMSYSTM_H 4 | 5 | #include 6 | 7 | #endif /* SPL_VMSYSTM_H */ 8 | -------------------------------------------------------------------------------- /include/rpc/types.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_RPC_TYPES_H 3 | #define _SPL_RPC_TYPES_H 4 | 5 | typedef int bool_t; 6 | 7 | #endif /* SPL_RPC_TYPES_H */ 8 | -------------------------------------------------------------------------------- /include/sys/dirent.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_DIRENT_H 3 | #define _SPL_DIRENT_H 4 | 5 | #include_next 6 | 7 | #endif /* SPL_DIRENT_H */ 8 | -------------------------------------------------------------------------------- /include/sys/unistd.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_UNISTD_H 3 | #define _SPL_UNISTD_H 4 | 5 | #include_next 6 | 7 | #endif /* SPL_UNISTD_H */ 8 | -------------------------------------------------------------------------------- /include/vm/seg_kmem.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SEG_KMEM_H 3 | #define _SPL_SEG_KMEM_H 4 | 5 | #include 6 | 7 | #endif /* SPL_SEG_KMEM_H */ 8 | -------------------------------------------------------------------------------- /include/sys/int_types.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_INT_TYPES_H 3 | #define _SPL_INT_TYPES_H 4 | 5 | #include 6 | 7 | #endif /* SPL_INT_TYPES_H */ 8 | -------------------------------------------------------------------------------- /include/sys/resource.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_RESOURCE_H 3 | #define _SPL_RESOURCE_H 4 | 5 | #include_next 6 | 7 | #endif /* SPL_RESOURCE_H */ 8 | -------------------------------------------------------------------------------- /include/sys/sysevent/eventdefs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SYSEVENT_EVENTDEFS_H 3 | #define _SPL_SYSEVENT_EVENTDEFS_H 4 | 5 | #endif /* _SPL_SYSEVENT_EVENTDEFS_H */ 6 | -------------------------------------------------------------------------------- /include/sys/extdirent.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_EXTDIRENT_H 3 | #define _SPL_EXTDIRENT_H 4 | 5 | #define ED_CASE_CONFLICT 0x10 6 | 7 | #endif /* _SPL_EXTDIRENT_H */ 8 | -------------------------------------------------------------------------------- /include/sys/idmap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_IDMAP_H 3 | #define _SPL_IDMAP_H 4 | 5 | #define IDMAP_WK_CREATOR_OWNER_UID 2147483648U 6 | 7 | #endif /* SPL_IDMAP_H */ 8 | -------------------------------------------------------------------------------- /include/sys/mutex.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_MUTEX_H 3 | #define _SPL_MUTEX_H 4 | 5 | #include 6 | #include 7 | 8 | #endif /* _SPL_MUTEX_H */ 9 | -------------------------------------------------------------------------------- /include/sys/varargs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_VARARGS_H 3 | #define _SPL_VARARGS_H 4 | 5 | #define __va_list va_list 6 | 7 | #endif /* SPL_VARARGS_H */ 8 | -------------------------------------------------------------------------------- /module/spl/spl-proc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | struct proc *p0 = { 0 }; /* process 0 */ 7 | -------------------------------------------------------------------------------- /scripts/dolog: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | nice tail -900F /var/log/system.log|egrep --line-buffered 'USB|kex|SPL|ZFS|zfs| zed' | egrep --line-buffered -v 'zfs_vfs_(uuid_gen|getattr)' 3 | -------------------------------------------------------------------------------- /scripts/doarcstat: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /usr/local/bin/arcstat.pl -f Time,read,miss,miss%,redirt,l2hits,l2miss,l2write,dmis,dm%,pmis,pm%,mmis,mm%,size,tsize,ovrhd,comprs,uncomp,rat% 3 | -------------------------------------------------------------------------------- /include/sys/buf.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_BUF_H 3 | #define _SPL_BUF_H 4 | 5 | #undef vnode_t 6 | #include_next 7 | #include 8 | 9 | #endif /* SPL_BUF_H */ 10 | -------------------------------------------------------------------------------- /include/sys/ubc.h: -------------------------------------------------------------------------------- 1 | #ifndef UBC_H_INCLUDED 2 | #define UBC_H_INCLUDED 3 | 4 | #undef vnode_t 5 | #include_next 6 | #define vnode_t struct vnode 7 | 8 | 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /include/sys/mount.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_MOUNT_H 3 | #define _SPL_MOUNT_H 4 | 5 | #undef vnode_t 6 | #include_next 7 | #define vnode_t struct vnode 8 | 9 | #endif /* SPL_MOUNT_H */ 10 | -------------------------------------------------------------------------------- /include/sys/systm.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SYSTM_H 3 | #define _SPL_SYSTM_H 4 | 5 | #include_next 6 | #include 7 | 8 | typedef uintptr_t pc_t; 9 | 10 | #endif /* SPL_SYSTM_H */ 11 | -------------------------------------------------------------------------------- /include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_FCNTL_H 3 | #define _SPL_FCNTL_H 4 | 5 | #include 6 | #include_next 7 | 8 | #define F_FREESP 11 9 | 10 | 11 | #endif /* _SPL_FCNTL_H */ 12 | -------------------------------------------------------------------------------- /include/osx/atomic.h: -------------------------------------------------------------------------------- 1 | #ifndef OSX_ATOMIC_H 2 | #define OSX_ATOMIC_H 3 | 4 | #include 5 | //#include 6 | #include 7 | #include 8 | 9 | 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /include/sys/t_lock.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_T_LOCK_H 3 | #define _SPL_T_LOCK_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #endif /* SPL_T_LOCK_H */ 11 | -------------------------------------------------------------------------------- /include/sys/processor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_PROCESSOR_H 3 | #define _SPL_PROCESSOR_H 4 | 5 | #include 6 | 7 | extern uint32_t getcpuid(void); 8 | 9 | typedef int processorid_t; 10 | 11 | #endif /* _SPL_PROCESSOR_H */ 12 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Unless otherwise noted, all files in this distribution are released 2 | under the Common Development and Distribution License (CDDL). 3 | Exceptions are noted within the associated source files. See the file 4 | OPENSOLARIS.LICENSE for more information. 5 | -------------------------------------------------------------------------------- /include/sys/condvar.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_CONDVAR_H 3 | #define _SPL_CONDVAR_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #endif /* _SPL_CONDVAR_H */ 12 | -------------------------------------------------------------------------------- /include/sys/zone.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_ZONE_H 3 | #define _SPL_ZONE_H 4 | 5 | #include 6 | 7 | #define zone_dataset_visible(x, y) (1) 8 | #define INGLOBALZONE(z) (1) 9 | 10 | #endif /* SPL_ZONE_H */ 11 | -------------------------------------------------------------------------------- /include/sys/proc.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_PROC_H 3 | #define _SPL_PROC_H 4 | 5 | #include 6 | #include 7 | #include_next 8 | #include 9 | 10 | extern proc_t p0; /* process 0 */ 11 | 12 | #endif /* SPL_PROC_H */ 13 | -------------------------------------------------------------------------------- /include/sys/types32.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_TYPES32_H 3 | #define _SPL_TYPES32_H 4 | 5 | #include 6 | #include 7 | 8 | typedef uint32_t caddr32_t; 9 | typedef int32_t daddr32_t; 10 | typedef int32_t time32_t; 11 | typedef uint32_t size32_t; 12 | 13 | #endif /* _SPL_TYPES32_H */ 14 | -------------------------------------------------------------------------------- /include/util/qsort.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_QSORT_H 3 | #define _SPL_QSORT_H 4 | 5 | //#include 6 | //extern void qsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *)); 7 | 8 | //#define qsort(base, num, size, cmp) sort(base, num, size, cmp, NULL) 9 | 10 | #endif /* SPL_QSORT_H */ 11 | -------------------------------------------------------------------------------- /module/spl/spl-debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | 6 | /* Debug log support enabled */ 7 | __attribute__((noinline)) int assfail(const char *str, const char *file, 8 | unsigned int line) __attribute__((optnone)) 9 | { 10 | return 1; // Must return true for ASSERT macro 11 | } 12 | -------------------------------------------------------------------------------- /include/sys/param.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_PARAM_H 3 | #define _SPL_PARAM_H 4 | 5 | #include_next 6 | #include 7 | 8 | /* Pages to bytes and back */ 9 | #define ptob(pages) (pages << PAGE_SHIFT) 10 | #define btop(bytes) (bytes >> PAGE_SHIFT) 11 | 12 | #define MAXUID UINT32_MAX 13 | 14 | #endif /* SPL_PARAM_H */ 15 | -------------------------------------------------------------------------------- /module/spl/load_zfs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #tail -f /var/log/system.log & 3 | #sleep 1 4 | rsync -ar --delete spl.kext/ /tmp/spl.kext/ 5 | chown -R root:wheel /tmp/spl.kext 6 | kextload -v /tmp/spl.kext/ 7 | 8 | rsync -ar --delete ../splat/splat.kext/ /tmp/splat.kext/ 9 | chown -R root:wheel /tmp/splat.kext 10 | echo kextload -r /tmp/ -v /tmp/splat.kext/ 11 | 12 | -------------------------------------------------------------------------------- /include/sys/pathname.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_PATHNAME_H 3 | #define _SPL_PATHNAME_H 4 | 5 | typedef struct pathname { 6 | char *pn_buf; /* underlying storage */ 7 | char *pn_path; /* remaining pathname */ 8 | size_t pn_pathlen; /* remaining length */ 9 | size_t pn_bufsize; /* total size of pn_buf */ 10 | } pathname_t; 11 | 12 | #endif /* SPL_PATHNAME_H */ 13 | -------------------------------------------------------------------------------- /include/sys/pset.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_PSET_H 3 | #define _SPL_PSET_H 4 | 5 | typedef int psetid_t; 6 | 7 | /* special processor set id's */ 8 | #define PS_NONE -1 9 | #define PS_QUERY -2 10 | #define PS_MYID -3 11 | #define PS_SOFT -4 12 | #define PS_HARD -5 13 | #define PS_QUERY_TYPE -6 14 | 15 | #endif /* SPL_PSET_H */ 16 | -------------------------------------------------------------------------------- /module/spl/KernelExports/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Not all symbols are exported by default in OS X, and we have to do 3 | a little magic to get around that. 4 | 5 | This uses the OpenSource kextsymbol.c utility, and a dump of all the 6 | symbols in the kernel, to produce a link helper kext. 7 | 8 | We most likely need to make it better to handle kernel versions 9 | a little more flexibly. 10 | 11 | -------------------------------------------------------------------------------- /config/config.awk: -------------------------------------------------------------------------------- 1 | # Remove default preprocessor define's from config.h 2 | # PACKAGE 3 | # PACKAGE_BUGREPORT 4 | # PACKAGE_NAME 5 | # PACKAGE_STRING 6 | # PACKAGE_TARNAME 7 | # PACKAGE_VERSION 8 | # STDC_HEADERS 9 | # VERSION 10 | 11 | BEGIN { RS = "" ; FS = "\n" } \ 12 | !/.#define PACKAGE./ && \ 13 | !/.#define VERSION./ && \ 14 | !/.#define STDC_HEADERS./ \ 15 | { print $0"\n" } 16 | -------------------------------------------------------------------------------- /include/sys/systeminfo.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_SYSTEMINFO_H 3 | #define _SPL_SYSTEMINFO_H 4 | 5 | #define HW_INVALID_HOSTID 0xFFFFFFFF /* an invalid hostid */ 6 | #define HW_HOSTID_LEN 11 /* minimum buffer size needed */ 7 | /* to hold a decimal or hex */ 8 | /* hostid string */ 9 | 10 | const char *spl_panicstr(void); 11 | int spl_system_inshutdown(void); 12 | 13 | 14 | #endif /* SPL_SYSTEMINFO_H */ 15 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | OpenZFS on OS X (O3X) brings OpenZFS features to Apple's OS X. 2 | 3 | This is spl.kext, the Solaris Portability Layer (SPL). 4 | 5 | ** spl.kext is a dependency of zfs.kext, so start with this repository. 6 | 7 | It is tested primarily on MacOS Mojave. 8 | 9 | See http://openzfsonosx.org/ for more information. 10 | 11 | Detailed compiling instructions can be found in the wiki: 12 | 13 | https://openzfsonosx.org/wiki/Install 14 | 15 | - lundman 16 | -------------------------------------------------------------------------------- /module/spl/KernelExports/version.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildVersion 6 | 1 7 | CFBundleShortVersionString 8 | 12.0.0 9 | CFBundleVersion 10 | 12.0.0 11 | ProjectName 12 | xnu 13 | SourceVersion 14 | 2050007009000000 15 | 16 | 17 | -------------------------------------------------------------------------------- /spl.xcodeproj/xcuserdata/zfs-tests.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | spl.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 49C6A9121D164B68007A7AA2 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /scripts/splwatch2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/local/bin 3 | export PATH 4 | export LC_ALL=en_GB.UTF-8 5 | 6 | watch -d sh -c 'echo; sysctl -h kstat.spl.misc.spl_misc.active_threads kstat.spl.misc.spl_misc.vmem_conditional_allocs kstat.spl.misc.spl_misc.spl_osif_malloc_success kstat.spl.misc.spl_misc.spl_osif_free kstat.spl.misc.spl_misc.spl_osif_malloc_bytes kstat.spl.misc.spl_misc.spl_osif_free_bytes kstat.vmem.vmem| egrep -v "(: 0$)|\.(lookup|search|mem_total|vmem_source):|(vmem\.vmem\.[^b])"; sysctl -h kstat.vmem.vmem.bucket_heap.mem_total kstat.spl.misc.spl_misc.spl_bucket_non_pow2_allocs' 'kstat.unix.kmem_cache.kmem_slab_cache.reap' 7 | -------------------------------------------------------------------------------- /dkms.postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROG=$0 4 | 5 | while getopts "a:k:n:t:v:" opt; do 6 | case $opt in 7 | a) arch=$OPTARG ;; 8 | k) kver=$OPTARG ;; 9 | n) pkgname=$OPTARG ;; 10 | t) tree=$OPTARG ;; 11 | v) pkgver=$OPTARG ;; 12 | esac 13 | done 14 | 15 | if [ -z "${arch}" -o -z "${kver}" -o -z "${pkgname}" -o \ 16 | -z "${tree}" -o -z "${pkgver}" ]; then 17 | echo "Usage: $PROG -a -k -n " \ 18 | "-t -v " 19 | exit 1 20 | fi 21 | 22 | cp ${tree}/${pkgname}/${pkgver}/build/spl_config.h \ 23 | ${tree}/${pkgname}/${pkgver}/build/module/Module.symvers \ 24 | ${tree}/${pkgname}/${pkgver}/${kver}/${arch}/ 25 | -------------------------------------------------------------------------------- /scripts/ziowatch: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/local/bin 3 | export PATH 4 | export LC_ALL=en_GB.UTF-8 5 | 6 | watch -d sysctl -h kstat.vmem.vmem.zfs_file_data kstat.vmem.vmem.zfs_metadata kstat.vmem.vmem.bucket_heap.mem_inuse kstat.vmem.vmem.bucket_heap.mem_total kstat.vmem.vmem.bucket_heap.alloc kstat.vmem.vmem.bucket_heap.free kstat.vmem.vmem.bucket_heap.lookup kstat.vmem.vmem.bucket_heap.search kstat.vmem.vmem.bucket_heap.parent_alloc kstat.vmem.vmem.bucket_heap.parent_free kstat.spl.misc.spl_misc.spl_osif_malloc_success kstat.spl.misc.spl_misc.spl_osif_free kstat.spl.misc.spl_misc.os_mem_alloc kstat.spl.misc.spl_misc.spl_spl_free kstat.unix.kmem_cache.kmem_slab_cache.reap 7 | -------------------------------------------------------------------------------- /PKGBUILD-spl.in: -------------------------------------------------------------------------------- 1 | # Maintainer: Prakash Surya 2 | pkgname=@SPL_META_NAME@ 3 | pkgver=@SPL_META_VERSION@ 4 | pkgrel=@SPL_META_RELEASE@ 5 | pkgdesc="Contains the support utilities for the spl." 6 | arch=(x86_64) 7 | url="git://github.com/zfsonlinux/spl.git" 8 | license=(@LICENSE@) 9 | source=(@SPL_META_NAME@-@SPL_META_VERSION@.tar.gz) 10 | 11 | build() { 12 | cd $srcdir/@SPL_META_NAME@-@SPL_META_VERSION@ 13 | ./configure --with-config=user \ 14 | --prefix=/usr \ 15 | --sysconfdir=/etc \ 16 | --libexecdir=/usr/lib 17 | make 18 | } 19 | 20 | package() { 21 | cd $srcdir/@SPL_META_NAME@-@SPL_META_VERSION@ 22 | make DESTDIR=$pkgdir install 23 | } 24 | -------------------------------------------------------------------------------- /config/spl-boot.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([ZFS_AC_BOOT], [ 2 | AC_ARG_ENABLE([boot], 3 | [AS_HELP_STRING([--enable-boot], 4 | [Enable boot @<:@default=no@:>@])], 5 | [], 6 | [enable_boot=no]) 7 | 8 | AS_IF([test "x$enable_boot" != xno], 9 | [ 10 | enable_boot=yes 11 | ZFS_BOOT=1 12 | AM_CONDITIONAL(ZFS_BOOT, true) 13 | KERNELCPPFLAGS="${KERNELCPPFLAGS} -DZFS_BOOT" 14 | CFLAGS_KMOD="${CFLAGS_KMOD} -DZFS_BOOT" 15 | AC_DEFINE(ZFS_BOOT, 1, 16 | [Define ZFS_BOOT to enable kext load at boot]) 17 | AC_SUBST([ZFS_BOOT]) 18 | ], 19 | [ 20 | AM_CONDITIONAL(ZFS_BOOT, false) 21 | ]) 22 | 23 | AC_MSG_CHECKING([whether kext load at boot is enabled]) 24 | AC_MSG_RESULT([$enable_boot]) 25 | ]) 26 | -------------------------------------------------------------------------------- /config/Rules.am: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | # Copyright (C) 2007 The Regents of the University of California. 4 | # Written by Brian Behlendorf . 5 | ############################################################################### 6 | # Common rules for user space components. 7 | ############################################################################### 8 | 9 | DEFAULT_INCLUDES = -include ${top_builddir}/spl_config.h 10 | 11 | AM_LIBTOOLFLAGS = --silent 12 | AM_CFLAGS = -Wall -Wshadow -Wstrict-prototypes -fno-strict-aliasing 13 | AM_CFLAGS += ${DEBUG_CFLAGS} 14 | -------------------------------------------------------------------------------- /PKGBUILD-spl-modules.in: -------------------------------------------------------------------------------- 1 | # Maintainer: Prakash Surya 2 | pkgname=@SPL_META_NAME@-modules 3 | pkgver=@SPL_META_VERSION@ 4 | pkgrel=@SPL_META_RELEASE@ 5 | pkgdesc="Contains kernel modules for emulating Solaris style primatives in the linux kernel." 6 | arch=(x86_64) 7 | url="git://github.com/zfsonlinux/spl.git" 8 | license=(@LICENSE@) 9 | source=(@SPL_META_NAME@-@SPL_META_VERSION@.tar.gz) 10 | 11 | build() { 12 | cd $srcdir/@SPL_META_NAME@-@SPL_META_VERSION@ 13 | ./configure --with-config=kernel \ 14 | --prefix=/usr \ 15 | --sysconfdir=/etc \ 16 | --libexecdir=/usr/lib 17 | make 18 | } 19 | 20 | package() { 21 | cd $srcdir/@SPL_META_NAME@-@SPL_META_VERSION@ 22 | make DESTDIR=$pkgdir install 23 | } 24 | -------------------------------------------------------------------------------- /include/sys/dnlc.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_DNLC_H 3 | #define _SPL_DNLC_H 4 | 5 | /* 6 | * Reduce the dcache and icache then reap the free'd slabs. Note the 7 | * interface takes a reclaim percentage but we don't have easy access to 8 | * the total number of entries to calculate the reclaim count. However, 9 | * in practice this doesn't need to be even close to correct. We simply 10 | * need to reclaim some useful fraction of the cache. The caller can 11 | * determine if more needs to be done. 12 | */ 13 | static inline void 14 | dnlc_reduce_cache(void *reduce_percent) 15 | { 16 | #if 0 17 | int nr = (uintptr_t)reduce_percent * 10000; 18 | shrink_dcache_memory(nr, GFP_KERNEL); 19 | shrink_icache_memory(nr, GFP_KERNEL); 20 | kmem_reap(); 21 | #endif 22 | } 23 | 24 | #endif /* SPL_DNLC_H */ 25 | -------------------------------------------------------------------------------- /module/spl/KernelExports/zfs.exports: -------------------------------------------------------------------------------- 1 | _cpu_number 2 | _fp_lookup 3 | _fd_rdwr 4 | _hostname 5 | _kernel_memory_allocate 6 | _virtual_space_start 7 | _virtual_space_end 8 | _vm_page_free_wanted 9 | _vm_page_free_count 10 | _vm_page_free_min 11 | _vm_page_speculative_count 12 | _VFS_ROOT 13 | _vm_pool_low 14 | _fp_drop 15 | _fp_drop_written 16 | _fo_read 17 | _fo_write 18 | _system_inshutdown 19 | _cache_purgevfs 20 | _vfs_context_kernel 21 | _build_path 22 | _kvtophys 23 | __mh_execute_header 24 | _gLoadedKextSummaries 25 | _VNOP_LOOKUP 26 | _vnode_notify 27 | _vfs_get_notify_attributes 28 | _kauth_cred_getgroups 29 | _rootvnode 30 | _decmpfs_decompress_file 31 | _decmpfs_file_is_compressed 32 | _decmpfs_cnode_alloc 33 | _decmpfs_cnode_free 34 | _decmpfs_cnode_init 35 | _decmpfs_cnode_destroy 36 | _cpuid_info 37 | -------------------------------------------------------------------------------- /include/sys/file.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_FILE_H 3 | #define _SPL_FILE_H 4 | 5 | #define FIGNORECASE 0x00080000 6 | #define FKIOCTL 0x80000000 7 | 8 | #include 9 | 10 | struct spl_fileproc { 11 | void *f_vnode; // this points to the "fd" so we can look it up. 12 | list_node_t f_next; /* next zfsdev_state_t link */ 13 | int f_fd; 14 | uint64_t f_offset; 15 | void *f_proc; 16 | void *f_fp; 17 | int f_writes; 18 | minor_t f_file; // Minor of the file 19 | }; 20 | 21 | //typedef struct spl_fileproc file_t; 22 | #define file_t struct spl_fileproc 23 | 24 | void *getf(int fd); 25 | void releasef(int fd); 26 | /* O3X extended - get vnode from previos getf() */ 27 | struct vnode *getf_vnode(void *fp); 28 | 29 | #endif /* SPL_FILE_H */ 30 | -------------------------------------------------------------------------------- /module/spl/KernelExports/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/config/Rules.am 2 | 3 | AUTOMAKE_OPTIONS = subdir-objects 4 | 5 | 6 | noinst_PROGRAMS = kextsymboltool 7 | 8 | kextsymboltool_SOURCES = \ 9 | kextsymboltool.c 10 | 11 | kextsymboltool_LDFLAGS = -lstdc++ 12 | 13 | KernelExports: zfs.exports | kextsymboltool 14 | ./kextsymboltool -arch x86_64 -import allsymbols -export zfs.exports -output KernelExports_64 15 | ./kextsymboltool -arch i386 -import allsymbols -export zfs.exports -output KernelExports_32 16 | lipo -create KernelExports_32 KernelExports_64 -output KernelExports 17 | 18 | clean: 19 | rm -f KernelExports KernelExports_32 KernelExports_64 allsymbols 20 | rm -f kextsymboltool.o kextsymboltool 21 | 22 | allsymbols: 23 | $(NM) -gj $(MACH_KERNEL) > allsymbols 24 | 25 | all:kextsymboltool allsymbols KernelExports 26 | -------------------------------------------------------------------------------- /dkms.conf.in: -------------------------------------------------------------------------------- 1 | AUTOINSTALL="yes" 2 | PACKAGE_NAME="@PACKAGE@" 3 | PACKAGE_VERSION="@VERSION@" 4 | PRE_BUILD="configure 5 | --prefix=/usr 6 | --with-config=kernel 7 | --with-linux=$(case `lsb_release -is` in 8 | (Debian) echo ${kernel_source_dir/%build/source} ;; 9 | (*) echo ${kernel_source_dir} ;; 10 | esac) 11 | --with-linux-obj=${kernel_source_dir} 12 | " 13 | POST_INSTALL="dkms.postinst -a ${arch} -k ${kernelver} -t ${dkms_tree} 14 | -n ${PACKAGE_NAME} -v ${PACKAGE_VERSION} 15 | " 16 | REMAKE_INITRD="no" 17 | MAKE[0]="make" 18 | BUILT_MODULE_NAME[0]="spl" 19 | BUILT_MODULE_LOCATION[0]="module/spl/" 20 | DEST_MODULE_LOCATION[0]="/extra/spl/spl" 21 | BUILT_MODULE_NAME[1]="splat" 22 | BUILT_MODULE_LOCATION[1]="module/splat/" 23 | DEST_MODULE_LOCATION[1]="/extra/splat/splat" 24 | -------------------------------------------------------------------------------- /include/osx/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef OSX_SCHED_H 2 | #define OSX_SCHED_H 3 | 4 | #include 5 | 6 | 7 | #if 0 8 | typedef void (task_func_t)(void *); 9 | 10 | typedef struct task { 11 | struct task *task_next; 12 | struct task *task_prev; 13 | task_func_t *task_func; 14 | void *task_arg; 15 | } task_t; 16 | 17 | #define TASKQ_ACTIVE 0x00010000 18 | 19 | struct taskq { 20 | kmutex_t tq_lock; 21 | krwlock_t tq_threadlock; 22 | kcondvar_t tq_dispatch_cv; 23 | kcondvar_t tq_wait_cv; 24 | thread_t *tq_threadlist; 25 | int tq_flags; 26 | int tq_active; 27 | int tq_nthreads; 28 | int tq_nalloc; 29 | int tq_minalloc; 30 | int tq_maxalloc; 31 | task_t *tq_freelist; 32 | task_t tq_task; 33 | }; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /spl.spec.in: -------------------------------------------------------------------------------- 1 | %define name @PACKAGE@ 2 | %define version @VERSION@ 3 | %define release @SPL_META_RELEASE@ 4 | %define debug_package %{nil} 5 | 6 | Summary: SPL Utils 7 | Group: Utilities/System 8 | Name: %{name} 9 | Version: %{version} 10 | Release: %{release}%{?dist} 11 | License: @LICENSE@ 12 | URL: git://github.com/zfsonlinux/spl.git 13 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id} -un) 14 | Source: %{name}-%{version}.tar.gz 15 | Requires: spl-modules 16 | 17 | %description 18 | The %{name} package contains the support utilities for the spl. 19 | 20 | %prep 21 | %setup 22 | %build 23 | %configure --with-config=user 24 | make 25 | 26 | %install 27 | rm -rf $RPM_BUILD_ROOT 28 | make DESTDIR=$RPM_BUILD_ROOT install 29 | 30 | %clean 31 | rm -rf $RPM_BUILD_ROOT 32 | 33 | %files 34 | %defattr(-, root, root) 35 | %doc AUTHORS ChangeLog COPYING DISCLAIMER INSTALL 36 | %{_sbindir}/* 37 | 38 | %post 39 | %postun 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # N.B. 3 | # This is the toplevel .gitignore file. 4 | # This is not the place for entries that are specific to 5 | # a subdirectory. Instead add those files to the 6 | # .gitignore file in that subdirectory. 7 | # 8 | # N.B. 9 | # Please use 'git ls-files -i --exclude-standard' 10 | # command after changing this file, to see if there are 11 | # any tracked files which get ignored after the change. 12 | 13 | # 14 | # Normal rules 15 | # 16 | *.[oa] 17 | *.ko 18 | *.ko.unsigned 19 | *.ko.out 20 | *.ko.out.sig 21 | *.lo 22 | *.la 23 | *.mod.c 24 | *~ 25 | *.swp 26 | .*.cmd 27 | .deps 28 | .dirstamp 29 | .libs 30 | .DS_Store 31 | modules.order 32 | Makefile 33 | Makefile.in 34 | 35 | # 36 | # Top level generated files specific to this top level dir 37 | # 38 | /configure 39 | /config.log 40 | /config.status 41 | /libtool 42 | /spl_config.h 43 | /spl_config.h.in 44 | /spl.spec 45 | /spl-modules.spec 46 | /spl.release 47 | /dkms.conf 48 | /PKGBUILD-spl 49 | /PKGBUILD-spl-modules 50 | /stamp-h1 51 | /aclocal.m4 52 | /autom4te.cache 53 | /config/compile 54 | 55 | # 56 | # Top level generic files 57 | # 58 | !.gitignore 59 | tags 60 | TAGS 61 | cscope.* 62 | -------------------------------------------------------------------------------- /module/spl/KernelExports/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | KernelExports 9 | CFBundleGetInfoString 10 | Mach Kernel Pseudoextension, Apple Computer Inc, 12.5.0 11 | CFBundleIdentifier 12 | net.lundman.kernel.dependencies 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | Mach Kernel Pseudoextension 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleShortVersionString 20 | 12.5.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 12.5.0 25 | OSBundleCompatibleVersion 26 | 8.0.0d0 27 | OSKernelResource 28 | 29 | OSBundleAllowUserLoad 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /include/sys/sunldi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. 23 | */ 24 | 25 | 26 | 27 | #ifndef _SPL_SUNLDI_H 28 | #define _SPL_SUNLDI_H 29 | 30 | #include 31 | 32 | #define SECTOR_SIZE 512 33 | 34 | #endif /* SPL_SUNLDI_H */ 35 | -------------------------------------------------------------------------------- /include/sys/dkio.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SPL_DKIO_H 3 | #define _SPL_DKIO_H 4 | 5 | struct dk_callback { 6 | void (*dkc_callback)(void *dkc_cookie, int error); 7 | void *dkc_cookie; 8 | int dkc_flag; 9 | }; 10 | 11 | #define DKIOC (0x04 << 8) 12 | #define DKIOCFLUSHWRITECACHE (DKIOC | 34) 13 | #define DKIOCTRIM (DKIOC | 35) 14 | 15 | /* 16 | * ioctl to free space (e.g. SCSI UNMAP) off a disk. 17 | * Pass a dkioc_free_list_t containing a list of extents to be freed. 18 | */ 19 | #define DKIOCFREE (DKIOC|50) 20 | 21 | #define DF_WAIT_SYNC 0x00000001 /* Wait for full write-out of free. */ 22 | typedef struct dkioc_free_list_ext_s { 23 | uint64_t dfle_start; 24 | uint64_t dfle_length; 25 | } dkioc_free_list_ext_t; 26 | 27 | typedef struct dkioc_free_list_s { 28 | uint64_t dfl_flags; 29 | uint64_t dfl_num_exts; 30 | uint64_t dfl_offset; 31 | dkioc_free_list_ext_t dfl_exts[1]; 32 | } dkioc_free_list_t; 33 | #define DFL_SZ(num_exts) \ 34 | (sizeof (dkioc_free_list_t) + \ 35 | (num_exts - 1) * sizeof (dkioc_free_list_ext_t)) 36 | 37 | /* Frees a variable-length dkioc_free_list_t structure. */ 38 | static inline void 39 | dfl_free(dkioc_free_list_t *dfl) 40 | { 41 | kmem_free(dfl, DFL_SZ(dfl->dfl_num_exts)); 42 | } 43 | 44 | #endif /* _SPL_DKIO_H */ 45 | -------------------------------------------------------------------------------- /include/sys/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2013 Jorgen Lundman 25 | * 26 | */ 27 | 28 | #ifndef _SPL_RANDOM_H 29 | #define _SPL_RANDOM_H 30 | 31 | #include_next 32 | 33 | 34 | static inline int 35 | random_get_bytes(uint8_t *ptr, size_t len) 36 | { 37 | read_random(ptr, len); 38 | return 0; 39 | } 40 | 41 | static inline int 42 | random_get_pseudo_bytes(uint8_t *ptr, size_t len) 43 | { 44 | read_random(ptr, len); 45 | return 0; 46 | } 47 | 48 | #endif /* _SPL_RANDOM_H */ 49 | -------------------------------------------------------------------------------- /DISCLAIMER: -------------------------------------------------------------------------------- 1 | This work was produced at the Lawrence Livermore National Laboratory 2 | (LLNL) under Contract No. DE-AC52-07NA27344 (Contract 44) between 3 | the U.S. Department of Energy (DOE) and Lawrence Livermore National 4 | Security, LLC (LLNS) for the operation of LLNL. 5 | 6 | This work was prepared as an account of work sponsored by an agency of 7 | the United States Government. Neither the United States Government nor 8 | Lawrence Livermore National Security, LLC nor any of their employees, 9 | makes any warranty, express or implied, or assumes any liability or 10 | responsibility for the accuracy, completeness, or usefulness of any 11 | information, apparatus, product, or process disclosed, or represents 12 | that its use would not infringe privately-owned rights. 13 | 14 | Reference herein to any specific commercial products, process, or 15 | services by trade name, trademark, manufacturer or otherwise does 16 | not necessarily constitute or imply its endorsement, recommendation, 17 | or favoring by the United States Government or Lawrence Livermore 18 | National Security, LLC. The views and opinions of authors expressed 19 | herein do not necessarily state or reflect those of the Untied States 20 | Government or Lawrence Livermore National Security, LLC, and shall 21 | not be used for advertising or product endorsement purposes. 22 | 23 | The precise terms and conditions for copying, distribution, and 24 | modification are specified in the file "COPYING". 25 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | # All headers are referenced by this top level Makefile.am are 2 | # noinst_HEADERS because they are not installed in the usual include 3 | # location. We do not want to be using $includedir for this. 4 | # Installation is handled by the custom install-data-local rule. 5 | noinst_HEADERS = $(top_srcdir)/include/*.h 6 | noinst_HEADERS += $(top_srcdir)/include/fs/*.h 7 | noinst_HEADERS += $(top_srcdir)/include/osx/*.h 8 | noinst_HEADERS += $(top_srcdir)/include/rpc/*.h 9 | noinst_HEADERS += $(top_srcdir)/include/sharefs/*.h 10 | noinst_HEADERS += $(top_srcdir)/include/sys/fm/*.h 11 | noinst_HEADERS += $(top_srcdir)/include/sys/fs/*.h 12 | noinst_HEADERS += $(top_srcdir)/include/sys/sysevent/*.h 13 | noinst_HEADERS += $(top_srcdir)/include/sys/*.h 14 | noinst_HEADERS += $(top_srcdir)/include/util/*.h 15 | noinst_HEADERS += $(top_srcdir)/include/vm/*.h 16 | 17 | install-data-local: 18 | 19 | # O3X - installation of these is not required. 20 | # release=$(SPL_META_VERSION)-$(SPL_META_RELEASE); \ 21 | # instdest=$(DESTDIR)/usr/src/spl-$$release/$(KERNEL_VERSION); \ 22 | # instfiles=`find . -name '*.h'`; \ 23 | # for instfile in $$instfiles; do \ 24 | # parentdir=`dirname $$instdest/$$instfile`; \ 25 | # mkdir -p $$parentdir; \ 26 | # $(INSTALL) $$instfile $$instdest/$$instfile; \ 27 | # done 28 | 29 | uninstall-local: 30 | release=$(SPL_META_VERSION)-$(SPL_META_RELEASE); \ 31 | instdest=$(DESTDIR)/usr/src/spl-$$release/$(KERNEL_VERSION); \ 32 | $(RM) -R $$instdest 33 | -------------------------------------------------------------------------------- /config/arch.am: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Written by Prakash Surya 3 | ############################################################################### 4 | # Build targets for RPM packages. 5 | ############################################################################### 6 | 7 | sarch-modules: 8 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}-modules" sarch-common 9 | 10 | sarch-utils: 11 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}" sarch-common 12 | 13 | sarch: sarch-modules sarch-utils 14 | 15 | arch-modules: 16 | if CONFIG_KERNEL 17 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}-modules" arch-common 18 | endif 19 | 20 | arch-utils: 21 | if CONFIG_USER 22 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}" arch-common 23 | endif 24 | 25 | arch: arch-modules arch-utils 26 | 27 | arch-local: 28 | @(if test "${HAVE_MAKEPKG}" = "no"; then \ 29 | echo -e "\n" \ 30 | "*** Required util ${MAKEPKG} missing. Please install the\n" \ 31 | "*** package for your distribution which provides ${MAKEPKG},\n" \ 32 | "*** re-run configure, and try again.\n"; \ 33 | exit 1; \ 34 | fi;) 35 | 36 | sarch-common: dist 37 | pkgbuild=PKGBUILD-$(pkg); \ 38 | $(MAKE) $(AM_MAKEFLAGS) arch-local || exit 1; \ 39 | $(MAKEPKG) --allsource --skipinteg --nodeps -p $$pkgbuild || exit 1; 40 | 41 | arch-common: dist 42 | pkgbuild=PKGBUILD-$(pkg); \ 43 | $(MAKE) $(AM_MAKEFLAGS) arch-local || exit 1; \ 44 | $(MAKEPKG) --skipinteg -p $$pkgbuild || exit 1; 45 | -------------------------------------------------------------------------------- /module/spl/spl-processor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2013 Jorgen Lundman 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | extern int cpu_number(void); 32 | 33 | uint32_t 34 | getcpuid() 35 | { 36 | return ((uint32_t)cpu_number()); 37 | } 38 | 39 | uint64_t spl_cpuid_features(void) 40 | { 41 | i386_cpu_info_t *info; 42 | 43 | info = cpuid_info(); 44 | return info->cpuid_features; 45 | } 46 | 47 | uint64_t spl_cpuid_leaf7_features(void) 48 | { 49 | i386_cpu_info_t *info; 50 | 51 | info = cpuid_info(); 52 | return info->cpuid_leaf7_features; 53 | } 54 | -------------------------------------------------------------------------------- /include/sys/utsname.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23 | /* All Rights Reserved */ 24 | 25 | 26 | /* 27 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | 32 | #ifndef _SPL_UTSNAME_H 33 | #define _SPL_UTSNAME_H 34 | 35 | #define _SYS_NMLN 257 36 | struct utsname { 37 | char sysname[_SYS_NMLN]; 38 | char nodename[_SYS_NMLN]; 39 | char release[_SYS_NMLN]; 40 | char version[_SYS_NMLN]; 41 | char machine[_SYS_NMLN]; 42 | }; 43 | 44 | extern struct utsname utsname; 45 | 46 | #endif /* SPL_UTSNAME_H */ 47 | -------------------------------------------------------------------------------- /scripts/splstat: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/local/bin 3 | export PATH 4 | export LC_ALL=en_GB.UTF-8 5 | 6 | #sysctl vm | egrep '^vm.page_(free_(wanted|count)|speculative|purgeable_count)' 7 | #sysctl kstat.zfs.misc.arcstats.l2_hdr_size kstat.spl | gawk 'sqrt($2*$2) < 1024 { print $1, $2 } \ 8 | # sqrt($2*$2) > 1024 && sqrt($2*$2) < 1024^2 { print $1, $2/1024, "K" } \ 9 | # sqrt($2*$2) > 1024^2 && sqrt($2*$2) < 1024^3 { print $1, $2/1024^2, "M" } \ 10 | # sqrt($2*$2) > 1024^3 { print $1, $2/1024^3, "G" }' 11 | 12 | sysctl vm | egrep '^vm.page_(free_(wanted|count)|speculative|purgable_count)' | gnumfmt --field=2 --grouping 13 | 14 | sysctl -h kstat.zfs.misc.arcstats.l2_hdr_size kstat.zfs.misc.arcstats.arc_no_grow kstat.spl | egrep -v 'spl.reap_timeout|spl_misc.reap_thread|spl_free_(manual|fast)_pressure|spl.*wake_count|spl_spl_minimal_uses_spl_free|vm_page_free_multiplier|vm_page_free_min_min|active_(threads|mutex|rwlock|tsd|reap_thread|reap_timeout_seconds)|spl_osif_.*_calls:.0$|pushpage_waitlimit' #| gnumfmt --field=2 --to=iec-i # --grouping 15 | 16 | sysctl kstat.vmem.vmem.kmem_va.mem_inuse kstat.vmem.vmem.kmem_default.mem_inuse kstat.vmem.vmem.heap.mem_inuse kstat.unix.kmem_cache.zio_cache.buf_inuse kstat.vmem.vmem.heap.mem_total kstat.vmem.vmem.zfs_file_data.mem_total kstat.vmem.vmem.zfs_metadata.mem_total kstat.vmem.vmem.bucket_heap.mem_inuse kstat.vmem.vmem.bucket_heap.mem_total kstat.vmem.vmem.bucket_heap.mem_import kstat.vmem.vmem.bucket_heap.parent_alloc kstat.vmem.vmem.bucket_heap.parent_free | gnumfmt --field=2 --to=iec-i 17 | -------------------------------------------------------------------------------- /include/sys/kobj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | #ifndef _SPL_KOBJ_H 27 | #define _SPL_KOBJ_H 28 | 29 | #include 30 | 31 | 32 | struct _buf { 33 | intptr_t _fd; 34 | }; 35 | 36 | struct bootstat { 37 | uint64_t st_size; 38 | }; 39 | 40 | //typedef struct _buf buf_t; 41 | 42 | extern struct _buf *kobj_open_file(char *name); 43 | extern void kobj_close_file(struct _buf *file); 44 | extern int kobj_read_file(struct _buf *file, char *buf, 45 | ssize_t size, offset_t off); 46 | extern int kobj_get_filesize(struct _buf *file, uint64_t *size); 47 | 48 | #endif /* SPL_KOBJ_H */ 49 | -------------------------------------------------------------------------------- /include/sys/tsd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | 30 | #ifndef _SPL_TSD_H 31 | #define _SPL_TSD_H 32 | 33 | #include 34 | 35 | #define TSD_HASH_TABLE_BITS_DEFAULT 9 36 | #define TSD_KEYS_MAX 32768 37 | #define DTOR_PID (PID_MAX_LIMIT+1) 38 | #define PID_KEY (TSD_KEYS_MAX+1) 39 | 40 | typedef void (*dtor_func_t)(void *); 41 | 42 | extern int tsd_set(uint_t, void *); 43 | extern void *tsd_get(uint_t); 44 | extern void tsd_create(uint_t *, dtor_func_t); 45 | extern void tsd_destroy(uint_t *); 46 | extern void tsd_exit(void); 47 | 48 | uint64_t spl_tsd_size(void); 49 | void tsd_thread_exit(void); 50 | int spl_tsd_init(void); 51 | void spl_tsd_fini(void); 52 | 53 | #endif /* _SPL_TSD_H */ 54 | -------------------------------------------------------------------------------- /module/spl/spl-atomic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | * 21 | ***************************************************************************** 22 | * Solaris Porting Layer (SPL) Atomic Implementation. 23 | ***************************************************************************** 24 | */ 25 | 26 | /* 27 | * 28 | * Copyright (C) 2013 Jorgen Lundman 29 | * 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | 43 | #ifdef _KERNEL 44 | 45 | /* nothing */ 46 | 47 | 48 | void *atomic_cas_ptr(volatile void *target, void *cmp, void *new) 49 | { 50 | #ifdef __LP64__ 51 | return (void *)__sync_val_compare_and_swap((uint64_t *)target, (uint64_t)cmp, (uint64_t)new); 52 | #else 53 | return (void *)__sync_val_compare_and_swap((uint32_t *)target, cmp, new); 54 | #endif 55 | } 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/spl-ctl.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 _DEBUG_CTL_H 26 | #define _DEBUG_CTL_H 27 | 28 | /* 29 | * Contains shared definitions which both the user space 30 | * and kernel space portions of splat must agree on. 31 | */ 32 | typedef struct spl_debug_header { 33 | int ph_len; 34 | int ph_flags; 35 | int ph_subsys; 36 | int ph_mask; 37 | int ph_cpu_id; 38 | int ph_sec; 39 | long ph_usec; 40 | int ph_stack; 41 | int ph_pid; 42 | int ph_line_num; 43 | } spl_debug_header_t; 44 | 45 | #endif /* _DEBUG_CTL_H */ 46 | -------------------------------------------------------------------------------- /module/spl/spl-err.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2013 Jorgen Lundman 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | void 34 | vcmn_err(int ce, const char *fmt, va_list ap) 35 | { 36 | char msg[MAXMSGLEN]; 37 | 38 | vsnprintf(msg, MAXMSGLEN - 1, fmt, ap); 39 | 40 | switch (ce) { 41 | case CE_IGNORE: 42 | break; 43 | case CE_CONT: 44 | printf("%s", msg); 45 | break; 46 | case CE_NOTE: 47 | printf("SPL: Notice: %s\n", msg); 48 | break; 49 | case CE_WARN: 50 | printf("SPL: Warning: %s\n", msg); 51 | break; 52 | case CE_PANIC: 53 | PANIC("%s", msg); 54 | break; 55 | } 56 | } /* vcmn_err() */ 57 | 58 | void 59 | cmn_err(int ce, const char *fmt, ...) 60 | { 61 | va_list ap; 62 | 63 | va_start(ap, fmt); 64 | vcmn_err(ce, fmt, ap); 65 | va_end(ap); 66 | } /* cmn_err() */ 67 | -------------------------------------------------------------------------------- /include/sys/cmn_err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23 | /* All Rights Reserved */ 24 | 25 | 26 | /* 27 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | * 30 | * Copyright 2012 Nexenta Systems, Inc. All rights reserved. 31 | */ 32 | 33 | #ifndef _SPL_CMN_ERR_H 34 | #define _SPL_CMN_ERR_H 35 | 36 | #include 37 | #include 38 | 39 | #define CE_CONT 0 /* continuation */ 40 | #define CE_NOTE 1 /* notice */ 41 | #define CE_WARN 2 /* warning */ 42 | #define CE_PANIC 3 /* panic */ 43 | #define CE_IGNORE 4 /* print nothing */ 44 | 45 | #ifdef _KERNEL 46 | 47 | extern void vcmn_err(int, const char *, __va_list); 48 | extern void cmn_err(int, const char *, ...); 49 | 50 | #endif /* _KERNEL */ 51 | 52 | #define fm_panic panic 53 | 54 | #endif /* SPL_CMN_ERR_H */ 55 | -------------------------------------------------------------------------------- /module/spl/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 14C1514 7 | CFBundleDevelopmentRegion 8 | English 9 | CFBundleExecutable 10 | spl 11 | CFBundleIdentifier 12 | net.lundman.spl 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | spl 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0.0 25 | DTCompiler 26 | com.apple.compilers.llvm.clang.1_0 27 | DTPlatformBuild 28 | 6C131e 29 | DTPlatformVersion 30 | GM 31 | DTSDKBuild 32 | 12F37 33 | DTSDKName 34 | macosx10.8 35 | DTXcode 36 | 0620 37 | DTXcodeBuild 38 | 6C131e 39 | NSHumanReadableCopyright 40 | CDDL (SPL), BSD (FreeBSD), Copyright © 2012-2016 OpenZFS on OS X. All rights reserved. 41 | OSBundleCompatibleVersion 42 | 1.0.0 43 | OSBundleLibraries 44 | 45 | com.apple.kpi.bsd 46 | 8.0.0 47 | com.apple.kpi.iokit 48 | 8.0.0 49 | com.apple.kpi.libkern 50 | 10.0 51 | com.apple.kpi.mach 52 | 8.0.0 53 | com.apple.kpi.unsupported 54 | 8.0.0 55 | net.lundman.kernel.dependencies 56 | 12.5.0 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /config/tgz.am: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2010 Lawrence Livermore National Security, LLC. 3 | # Written by Brian Behlendorf . 4 | ############################################################################### 5 | # Build targets for TGZ packages. 6 | # 7 | # Long term native distro specific Slackware style packaging should be added. 8 | # In the short term RPM packages are built and converted to TGZ packages 9 | # using alien. If someone familiar with Slackware style packaging were to 10 | # update the build system to correctly build Slackware style packages I would 11 | # happily take it. Until then we will have to make due with alien. 12 | # 13 | ############################################################################### 14 | 15 | tgz-local: 16 | @(if test "${HAVE_ALIEN}" = "no"; then \ 17 | echo -e "\n" \ 18 | "*** Required util ${ALIEN} missing. Please install the\n" \ 19 | "*** package for your distribution which provides ${ALIEN},\n" \ 20 | "*** re-run configure, and try again.\n"; \ 21 | exit 1; \ 22 | fi) 23 | 24 | tgz-modules: tgz-local rpm-modules 25 | if CONFIG_KERNEL 26 | name=${PACKAGE}-modules; \ 27 | version=${SPL_META_VERSION}-${SPL_META_RELEASE}; \ 28 | release=`echo ${LINUX_VERSION} | $(SED) -e "s/-/_/g"`; \ 29 | arch=`$(RPM) -qp $${name}-$${version}.src.rpm --qf %{arch} | tail -1`; \ 30 | pkg1=$${name}-$${version}_$${release}.$${arch}.rpm; \ 31 | pkg2=$${name}-devel-$${version}_$${release}.$${arch}.rpm; \ 32 | fakeroot $(ALIEN) --scripts --to-tgz $$pkg1 $$pkg2; \ 33 | $(RM) $$pkg1 $$pkg2 34 | endif 35 | 36 | tgz-utils: tgz-local rpm-utils 37 | if CONFIG_USER 38 | name=${PACKAGE}; \ 39 | version=${SPL_META_VERSION}-${SPL_META_RELEASE}; \ 40 | arch=`$(RPM) -qp $${name}-$${version}.src.rpm --qf %{arch} | tail -1`; \ 41 | pkg1=$${name}-$${version}.$${arch}.rpm; \ 42 | fakeroot $(ALIEN) --scripts --to-tgz $$pkg1; \ 43 | $(RM) $$pkg1 44 | endif 45 | 46 | tgz: tgz-modules tgz-utils 47 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | ACLOCAL_AMFLAGS = -I config 3 | 4 | include $(top_srcdir)/config/rpm.am 5 | include $(top_srcdir)/config/deb.am 6 | include $(top_srcdir)/config/tgz.am 7 | include $(top_srcdir)/config/arch.am 8 | 9 | if CONFIG_USER 10 | USER_DIR = scripts 11 | endif 12 | if CONFIG_KERNEL 13 | KERNEL_DIR = module include 14 | endif 15 | SUBDIRS = $(USER_DIR) $(KERNEL_DIR) 16 | 17 | AUTOMAKE_OPTIONS = foreign 18 | EXTRA_DIST = autogen.sh spl.spec.in spl-modules.spec.in META DISCLAIMER 19 | EXTRA_DIST += config/config.awk config/rpm.am config/deb.am config/tgz.am 20 | EXTRA_DIST += dkms.postinst copy-builtin 21 | noinst_HEADERS = spl_config.h spl.release 22 | 23 | distclean-local:: 24 | -$(RM) -R autom4te*.cache 25 | -find . \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \ 26 | -o -name .pc -o -name .hg -o -name .git \) -prune -o \ 27 | \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 28 | -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ 29 | -o -name '.*.rej' -o -name 'aclocal.m4' -o -size 0 \ 30 | -o -name '*%' -o -name '.*.cmd' -o -name 'core' \ 31 | -o -name 'Makefile' \ 32 | -o -name '*.order' -o -name '*.markers' \) \ 33 | -type f -print | xargs $(RM) 34 | 35 | if CONFIG_KERNEL 36 | install-data-local: 37 | 38 | # O3X - installation of these is not desirable 39 | # release=$(SPL_META_VERSION)-$(SPL_META_RELEASE); \ 40 | # instdest=$(DESTDIR)/usr/src/spl-$$release/$(KERNEL_VERSION); \ 41 | # for instfile in $(noinst_HEADERS); do \ 42 | # parentdir=`dirname $$instdest/$$instfile`; \ 43 | # mkdir -p $$parentdir; \ 44 | # $(INSTALL) $$instfile $$instdest/$$instfile; \ 45 | # done 46 | 47 | endif 48 | 49 | dist-hook: 50 | sed -i 's/Release:[[:print:]]*/Release: $(RELEASE)/' \ 51 | $(distdir)/META 52 | 53 | ctags: 54 | $(RM) $(top_srcdir)/tags 55 | find $(top_srcdir) -name .git -prune -o -name '*.[hc]' | xargs ctags 56 | 57 | etags: 58 | $(RM) $(top_srcdir)/TAGS 59 | find $(top_srcdir) -name .pc -prune -o -name '*.[hc]' | xargs etags -a 60 | 61 | tags: ctags etags 62 | 63 | pkg: @DEFAULT_PACKAGE@ 64 | pkg-modules: @DEFAULT_PACKAGE@-modules 65 | pkg-utils: @DEFAULT_PACKAGE@-utils 66 | -------------------------------------------------------------------------------- /include/sys/byteorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2013 Jorgen Lundman 25 | * 26 | */ 27 | 28 | #ifndef _SPL_BYTEORDER_H 29 | #define _SPL_BYTEORDER_H 30 | 31 | #include 32 | #include 33 | 34 | 35 | #define LE_16(x) OSSwapHostToLittleInt16(x) 36 | #define LE_32(x) OSSwapHostToLittleInt32(x) 37 | #define LE_64(x) OSSwapHostToLittleInt64(x) 38 | #define BE_16(x) OSSwapHostToBigInt16(x) 39 | #define BE_32(x) OSSwapHostToBigInt32(x) 40 | #define BE_64(x) OSSwapHostToBigInt64(x) 41 | 42 | #define BE_IN8(xa) \ 43 | *((uint8_t *)(xa)) 44 | 45 | #define BE_IN16(xa) \ 46 | (((uint16_t)BE_IN8(xa) << 8) | BE_IN8((uint8_t *)(xa)+1)) 47 | 48 | #define BE_IN32(xa) \ 49 | (((uint32_t)BE_IN16(xa) << 16) | BE_IN16((uint8_t *)(xa)+2)) 50 | 51 | 52 | /* 10.8 is lacking in htonll */ 53 | #if !defined(htonll) 54 | #define htonll(x) __DARWIN_OSSwapInt64(x) 55 | #endif 56 | #if !defined(ntohll) 57 | #define ntohll(x) __DARWIN_OSSwapInt64(x) 58 | #endif 59 | 60 | 61 | 62 | #ifdef __LITTLE_ENDIAN__ 63 | #define _LITTLE_ENDIAN 64 | #endif 65 | 66 | #ifdef __BIG_ENDIAN__ 67 | #define _BIG_ENDIAN 68 | #endif 69 | 70 | #endif /* SPL_BYTEORDER_H */ 71 | -------------------------------------------------------------------------------- /config/deb.am: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2010 Lawrence Livermore National Security, LLC. 3 | # Written by Brian Behlendorf . 4 | ############################################################################### 5 | # Build targets for DEB packages. 6 | # 7 | # Long term native distro specific Debian style packaging should be added. 8 | # In the short term RPM packages are built and converted to DEB packages 9 | # using alien. If someone familiar with Debian style packaging were to 10 | # update the build system to correctly build Debian style packages I would 11 | # happily take it. Until then we will have to make due with alien. 12 | # 13 | ############################################################################### 14 | 15 | deb-local: 16 | @(if test "${HAVE_DPKGBUILD}" = "no"; then \ 17 | echo -e "\n" \ 18 | "*** Required util ${DPKGBUILD} missing. Please install the\n" \ 19 | "*** package for your distribution which provides ${DPKGBUILD},\n" \ 20 | "*** re-run configure, and try again.\n"; \ 21 | exit 1; \ 22 | fi; \ 23 | if test "${HAVE_ALIEN}" = "no"; then \ 24 | echo -e "\n" \ 25 | "*** Required util ${ALIEN} missing. Please install the\n" \ 26 | "*** package for your distribution which provides ${ALIEN},\n" \ 27 | "*** re-run configure, and try again.\n"; \ 28 | exit 1; \ 29 | fi) 30 | 31 | deb-modules: deb-local rpm-modules 32 | if CONFIG_KERNEL 33 | name=${PACKAGE}-modules; \ 34 | version=${SPL_META_VERSION}-${SPL_META_RELEASE}; \ 35 | release=`echo ${LINUX_VERSION} | $(SED) -e "s/-/_/g"`; \ 36 | arch=`$(RPM) -qp $${name}-$${version}.src.rpm --qf %{arch} | tail -1`; \ 37 | pkg1=$${name}-$${version}_$${release}.$${arch}.rpm; \ 38 | pkg2=$${name}-devel-$${version}_$${release}.$${arch}.rpm; \ 39 | fakeroot $(ALIEN) --scripts --to-deb $$pkg1 $$pkg2; \ 40 | $(RM) $$pkg1 $$pkg2 41 | endif 42 | 43 | deb-utils: deb-local rpm-utils 44 | if CONFIG_USER 45 | name=${PACKAGE}; \ 46 | version=${SPL_META_VERSION}-${SPL_META_RELEASE}; \ 47 | arch=`$(RPM) -qp $${name}-$${version}.src.rpm --qf %{arch} | tail -1`; \ 48 | pkg1=$${name}-$${version}.$${arch}.rpm; \ 49 | fakeroot $(ALIEN) --scripts --to-deb $$pkg1; \ 50 | $(RM) $$pkg1 51 | endif 52 | 53 | deb: deb-modules deb-utils 54 | -------------------------------------------------------------------------------- /include/sys/cred.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2013 Jorgen Lundman 25 | * 26 | */ 27 | 28 | #ifndef _SPL_CRED_H 29 | #define _SPL_CRED_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | typedef struct ucred cred_t; 36 | 37 | #define kcred (cred_t *)NOCRED 38 | #define CRED() (cred_t *)kauth_cred_get() 39 | 40 | #include 41 | 42 | // Older OSX API 43 | #if !(MAC_OS_X_VERSION_MIN_REQUIRED >= 1070) 44 | #define kauth_cred_getruid(x) (x)->cr_ruid 45 | #define kauth_cred_getrgid(x) (x)->cr_rgid 46 | #define kauth_cred_getsvuid(x) (x)->cr_svuid 47 | #define kauth_cred_getsvgid(x) (x)->cr_svgid 48 | #endif 49 | 50 | 51 | extern void crhold(cred_t *cr); 52 | extern void crfree(cred_t *cr); 53 | extern uid_t crgetuid(const cred_t *cr); 54 | extern uid_t crgetruid(const cred_t *cr); 55 | extern uid_t crgetsuid(const cred_t *cr); 56 | extern uid_t crgetfsuid(const cred_t *cr); 57 | extern gid_t crgetgid(const cred_t *cr); 58 | extern gid_t crgetrgid(const cred_t *cr); 59 | extern gid_t crgetsgid(const cred_t *cr); 60 | extern gid_t crgetfsgid(const cred_t *cr); 61 | extern int crgetngroups(const cred_t *cr); 62 | extern gid_t * crgetgroups(const cred_t *cr); 63 | extern void crgetgroupsfree(gid_t *gids); 64 | extern int spl_cred_ismember_gid(cred_t *cr, gid_t gid); 65 | 66 | #define crgetsid(cred, i) (NULL) 67 | 68 | #endif /* _SPL_CRED_H */ 69 | -------------------------------------------------------------------------------- /include/sys/callb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | #ifndef _SPL_CALLB_H 27 | #define _SPL_CALLB_H 28 | 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 | 55 | #define CALLOUT_FLAG_ROUNDUP 0x1 56 | #define CALLOUT_FLAG_ABSOLUTE 0x2 57 | #define CALLOUT_FLAG_HRESTIME 0x4 58 | #define CALLOUT_FLAG_32BIT 0x8 59 | 60 | /* Move me to more correct "sys/callo.h" file when convenient. */ 61 | #define CALLOUT_NORMAL 1 62 | typedef uint64_t callout_id_t; 63 | callout_id_t timeout_generic(int, void (*)(void *), void *, hrtime_t, hrtime_t, 64 | int); 65 | 66 | 67 | #endif /* _SPL_CALLB_H */ 68 | -------------------------------------------------------------------------------- /include/osx/condvar.h: -------------------------------------------------------------------------------- 1 | #ifndef OSX_CONDVAR_H 2 | #define OSX_CONDVAR_H 3 | 4 | #include 5 | 6 | #define hz 10 /* frequency when using gethrtime() >> 23 for lbolt */ 7 | 8 | typedef enum { 9 | CV_DEFAULT, 10 | CV_DRIVER 11 | } kcv_type_t; 12 | 13 | 14 | struct cv { 15 | uint64_t pad; 16 | }; 17 | 18 | typedef struct cv kcondvar_t; 19 | 20 | 21 | 22 | 23 | void spl_cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg); 24 | void spl_cv_destroy(kcondvar_t *cvp); 25 | void spl_cv_signal(kcondvar_t *cvp); 26 | void spl_cv_broadcast(kcondvar_t *cvp); 27 | void spl_cv_wait(kcondvar_t *cvp, kmutex_t *mp, int flags, const char *msg); 28 | int spl_cv_timedwait(kcondvar_t *cvp,kmutex_t *mp, clock_t tim, int flags, 29 | const char *msg); 30 | clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, 31 | hrtime_t tim, hrtime_t res, int flag); 32 | 33 | 34 | /* 35 | * Use these wrapper macros to obtain the CV variable 36 | * name to make ZFS more gdb debugging friendly! 37 | * This name shows up as a thread's wait_event string. 38 | */ 39 | #define cv_wait(cvp, mp) \ 40 | spl_cv_wait((cvp), (mp), PRIBIO, #cvp) 41 | 42 | /* Linux provides a cv_wait_io so the schedular will know why we block. 43 | * find OSX equivalent? 44 | */ 45 | #define cv_wait_io(cvp, mp) \ 46 | spl_cv_wait((cvp), (mp), PRIBIO, #cvp) 47 | 48 | #define cv_timedwait(cvp, mp, tim) \ 49 | spl_cv_timedwait((cvp), (mp), (tim), PRIBIO, #cvp) 50 | 51 | #define cv_wait_interruptible(cvp, mp) \ 52 | spl_cv_wait((cvp), (mp), PRIBIO|PCATCH, #cvp) 53 | 54 | #define cv_timedwait_interruptible(cvp, mp, tim) \ 55 | spl_cv_timedwait((cvp), (mp), (tim), PRIBIO|PCATCH, #cvp) 56 | 57 | /* cv_wait_sig is the correct name for cv_wait_interruptible */ 58 | #define cv_wait_sig(cvp, mp) \ 59 | spl_cv_wait((cvp), (mp), PRIBIO|PCATCH, #cvp) 60 | 61 | #define cv_timedwait_sig(cvp, mp, tim) \ 62 | spl_cv_timedwait((cvp), (mp), (tim), PRIBIO|PCATCH, #cvp) 63 | 64 | 65 | #define TICK_TO_NSEC(tick) ((hrtime_t)(tick) * 1000000000 / hz) 66 | #define cv_reltimedwait(cvp, mp, tim, type) \ 67 | cv_timedwait_hires((cvp), (mp), TICK_TO_NSEC((tim)), 0, 0) 68 | 69 | #define cv_init spl_cv_init 70 | #define cv_destroy spl_cv_destroy 71 | #define cv_broadcast spl_cv_broadcast 72 | #define cv_signal spl_cv_signal 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # SPL AutoConf Configuration 3 | ############################################################################### 4 | # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 5 | # Copyright (C) 2007 The Regents of the University of California. 6 | # Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 7 | # Written by Brian Behlendorf . 8 | # UCRL-CODE-235197 9 | # 10 | # This file is part of the SPL, Solaris Porting Layer. 11 | # For details, see . 12 | # 13 | # The SPL is free software; you can redistribute it and/or modify it 14 | # under the terms of the GNU General Public License as published by the 15 | # Free Software Foundation; either version 2 of the License, or (at your 16 | # option) any later version. 17 | # 18 | # The SPL is distributed in the hope that it will be useful, but WITHOUT 19 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21 | # for more details. 22 | # 23 | # You should have received a copy of the GNU General Public License along 24 | # with the SPL. If not, see . 25 | ############################################################################### 26 | 27 | AC_INIT(m4_esyscmd([awk '/^Name:/ {print $2}' META | tr -d '\n']), 28 | m4_esyscmd([awk '/^Version:/ {print $2}' META | tr -d '\n'])) 29 | AC_LANG(C) 30 | SPL_AC_META 31 | AC_CONFIG_AUX_DIR([config]) 32 | AC_CONFIG_MACRO_DIR([config]) 33 | AC_CANONICAL_SYSTEM 34 | AM_MAINTAINER_MODE 35 | AM_SILENT_RULES 36 | #AC_INIT([$SPL_META_NAME], [$SPL_META_VERSION]) 37 | AM_INIT_AUTOMAKE 38 | AC_CONFIG_HEADERS([spl_config.h], [ 39 | (mv spl_config.h spl_config.h.tmp && 40 | awk -f ${ac_srcdir}/config/config.awk spl_config.h.tmp >spl_config.h && 41 | rm spl_config.h.tmp) || exit 1]) 42 | 43 | AC_PROG_INSTALL 44 | 45 | AC_PROG_CC(clang) 46 | AC_PROG_LIBTOOL 47 | AM_PROG_CC_C_O 48 | 49 | SPL_AC_CONFIG 50 | 51 | AM_CONDITIONAL([CONFIG_KERNEL], [ true ]) 52 | AM_CONDITIONAL([CONFIG_USER], [ true ]) 53 | 54 | ZFS_AC_BOOT 55 | 56 | AC_CONFIG_FILES([ 57 | Makefile 58 | module/Makefile 59 | module/spl/KernelExports/Makefile 60 | module/spl/Makefile 61 | include/Makefile 62 | scripts/Makefile 63 | spl.spec 64 | spl-modules.spec 65 | PKGBUILD-spl 66 | PKGBUILD-spl-modules 67 | spl.release 68 | dkms.conf 69 | ]) 70 | 71 | AC_OUTPUT 72 | -------------------------------------------------------------------------------- /include/sys/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #ifndef _SPL_TIMER_H 30 | #define _SPL_TIMER_H 31 | 32 | #include 33 | 34 | 35 | //#define USEC_PER_SEC 1000000 /* microseconds per second */ 36 | 37 | /* Open Solaris lbolt is in hz */ 38 | static inline uint64_t 39 | zfs_lbolt(void) 40 | { 41 | struct timeval tv; 42 | uint64_t lbolt_hz; 43 | microuptime(&tv); 44 | lbolt_hz = ((uint64_t)tv.tv_sec * USEC_PER_SEC + tv.tv_usec) / 10000; 45 | return (lbolt_hz); 46 | } 47 | 48 | 49 | #define lbolt zfs_lbolt() 50 | #define lbolt64 zfs_lbolt() 51 | 52 | #define ddi_get_lbolt() (zfs_lbolt()) 53 | #define ddi_get_lbolt64() (zfs_lbolt()) 54 | 55 | #define typecheck(type,x) \ 56 | ({ type __dummy; \ 57 | typeof(x) __dummy2; \ 58 | (void)(&__dummy == &__dummy2); \ 59 | 1; \ 60 | }) 61 | 62 | 63 | 64 | #define ddi_time_before(a, b) (typecheck(clock_t, a) && \ 65 | typecheck(clock_t, b) && \ 66 | ((a) - (b) < 0)) 67 | #define ddi_time_after(a, b) ddi_time_before(b, a) 68 | 69 | #define ddi_time_before64(a, b) (typecheck(int64_t, a) && \ 70 | typecheck(int64_t, b) && \ 71 | ((a) - (b) < 0)) 72 | #define ddi_time_after64(a, b) ddi_time_before64(b, a) 73 | 74 | 75 | 76 | extern void delay(clock_t ticks); 77 | 78 | 79 | #endif /* _SPL_TIMER_H */ 80 | -------------------------------------------------------------------------------- /include/spl-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 debug functions. These function should be used by any 27 | * package which needs to integrate with the SPL log infrastructure. 28 | * 29 | * SDEBUG() - Log debug message with specified mask. 30 | * SDEBUG_LIMIT() - Log just 1 debug message with specified mask. 31 | * SWARN() - Log a warning message. 32 | * SERROR() - Log an error message. 33 | * SEMERG() - Log an emergency error message. 34 | * SCONSOLE() - Log a generic message to the console. 35 | * 36 | * SENTRY - Log entry point to a function. 37 | * SEXIT - Log exit point from a function. 38 | * SRETURN(x) - Log return from a function. 39 | * SGOTO(x, y) - Log goto within a function. 40 | */ 41 | 42 | #ifndef _SPL_DEBUG_INTERNAL_H 43 | #define _SPL_DEBUG_INTERNAL_H 44 | 45 | //#include 46 | #include 47 | //#include 48 | #include 49 | #ifdef __cplusplus 50 | // To make C++ happier about strnlen in kcdata.h 51 | extern "C" { 52 | #endif 53 | #include 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | 59 | 60 | void spl_backtrace(char *thesignal); 61 | int getpcstack(uintptr_t *pcstack, int pcstack_limit); 62 | void print_symbol(uintptr_t symbol); 63 | 64 | #endif /* SPL_DEBUG_INTERNAL_H */ 65 | -------------------------------------------------------------------------------- /include/sys/rwlock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | #ifndef _SPL_RWLOCK_H 27 | #define _SPL_RWLOCK_H 28 | 29 | #include 30 | #include 31 | 32 | 33 | /* 34 | * Define to track the allocs looking for leaks. It is expensive 35 | * so use it when unloading SPL reports leaks. 36 | */ 37 | //#define SPL_DEBUG_RWLOCK 38 | 39 | typedef enum { 40 | RW_DRIVER = 2, 41 | RW_DEFAULT = 4 42 | } krw_type_t; 43 | 44 | typedef enum { 45 | RW_NONE = 0, 46 | RW_WRITER = 1, 47 | RW_READER = 2 48 | } krw_t; 49 | 50 | struct krwlock { 51 | uint32_t rw_lock[4]; /* opaque lck_rw_t data */ 52 | void *rw_owner; /* writer (exclusive) lock only */ 53 | int rw_readers; /* reader lock only */ 54 | int rw_pad; /* */ 55 | #ifdef SPL_DEBUG_RWLOCK 56 | void *leak; 57 | #endif 58 | }; 59 | typedef struct krwlock krwlock_t; 60 | 61 | #define RW_WRITE_HELD(x) (rw_write_held((x))) 62 | #define RW_LOCK_HELD(x) (rw_lock_held((x))) 63 | 64 | #ifdef SPL_DEBUG_RWLOCK 65 | #define rw_init(A, B, C, D) rw_initx(A,B,C,D,__FILE__,__FUNCTION__,__LINE__) 66 | extern void rw_initx(krwlock_t *, char *, krw_type_t, void *, 67 | const char *, const char *, int); 68 | #else 69 | extern void rw_init(krwlock_t *, char *, krw_type_t, void *); 70 | #endif 71 | extern void rw_destroy(krwlock_t *); 72 | extern void rw_enter(krwlock_t *, krw_t); 73 | extern int rw_tryenter(krwlock_t *, krw_t); 74 | extern void rw_exit(krwlock_t *); 75 | extern void rw_downgrade(krwlock_t *); 76 | extern int rw_tryupgrade(krwlock_t *); 77 | extern int rw_write_held(krwlock_t *); 78 | extern int rw_lock_held(krwlock_t *); 79 | extern int rw_isinit(krwlock_t *); 80 | 81 | int spl_rwlock_init(void); 82 | void spl_rwlock_fini(void); 83 | 84 | #endif /* _SPL_RWLOCK_H */ 85 | -------------------------------------------------------------------------------- /include/sys/signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 | /* All Rights Reserved */ 29 | 30 | /* 31 | * University Copyright- Copyright (c) 1982, 1986, 1988 32 | * The Regents of the University of California 33 | * All Rights Reserved 34 | * 35 | * University Acknowledgment- Portions of this document are derived from 36 | * software developed by the University of California, Berkeley, and its 37 | * contributors. 38 | */ 39 | 40 | 41 | #ifndef _SPL_SIGNAL_H 42 | #define _SPL_SIGNAL_H 43 | 44 | #include 45 | #include 46 | #include 47 | #include_next 48 | #include 49 | 50 | #define FORREAL 0 /* Usual side-effects */ 51 | #define JUSTLOOKING 1 /* Don't stop the process */ 52 | 53 | struct proc; 54 | 55 | extern int 56 | thread_issignal(struct proc *, thread_t, sigset_t); 57 | 58 | /* The "why" argument indicates the allowable side-effects of the call: 59 | * 60 | * FORREAL: Extract the next pending signal from p_sig into p_cursig; 61 | * stop the process if a stop has been requested or if a traced signal 62 | * is pending. 63 | * 64 | * JUSTLOOKING: Don't stop the process, just indicate whether or not 65 | * a signal might be pending (FORREAL is needed to tell for sure). 66 | */ 67 | #define threadmask (sigmask(SIGILL)|sigmask(SIGTRAP)|\ 68 | sigmask(SIGIOT)|sigmask(SIGEMT)|\ 69 | sigmask(SIGFPE)|sigmask(SIGBUS)|\ 70 | sigmask(SIGSEGV)|sigmask(SIGSYS)|\ 71 | sigmask(SIGPIPE)|sigmask(SIGKILL)|\ 72 | sigmask(SIGTERM)|sigmask(SIGINT)) 73 | 74 | static __inline__ int 75 | issig(int why) 76 | { 77 | return (thread_issignal(current_proc(), current_thread(), 78 | threadmask)); 79 | } 80 | 81 | #endif /* SPL_SIGNAL_H */ 82 | -------------------------------------------------------------------------------- /include/sys/sid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | 28 | #ifndef _SPL_SID_H 29 | #define _SPL_SID_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | typedef struct ksiddomain { 37 | char *kd_name; 38 | } ksiddomain_t; 39 | 40 | typedef enum ksid_index { 41 | KSID_USER, 42 | KSID_GROUP, 43 | KSID_OWNER, 44 | KSID_COUNT 45 | } ksid_index_t; 46 | 47 | typedef int ksid_t; 48 | 49 | /* Should be in kidmap.h */ 50 | typedef int32_t idmap_stat; 51 | 52 | static inline ksiddomain_t * 53 | ksid_lookupdomain(const char *dom) 54 | { 55 | ksiddomain_t *kd; 56 | int len = strlen(dom); 57 | 58 | kd = (ksiddomain_t *)kmem_zalloc(sizeof(ksiddomain_t), KM_SLEEP); 59 | kd->kd_name = (char *)kmem_zalloc(len + 1, KM_SLEEP); 60 | memcpy(kd->kd_name, dom, len); 61 | 62 | return (kd); 63 | } 64 | 65 | static inline void 66 | ksiddomain_rele(ksiddomain_t *ksid) 67 | { 68 | kmem_free(ksid->kd_name, strlen(ksid->kd_name) + 1); 69 | kmem_free(ksid, sizeof(ksiddomain_t)); 70 | } 71 | 72 | #define UID_NOBODY 65534 73 | #define GID_NOBODY 65534 74 | 75 | static __inline uint_t 76 | ksid_getid(ksid_t *ks) 77 | { 78 | panic("%s has been unexpectedly called", __func__); 79 | return 0; 80 | } 81 | 82 | static __inline const char * 83 | ksid_getdomain(ksid_t *ks) 84 | { 85 | panic("%s has been unexpectedly called", __func__); 86 | return 0; 87 | } 88 | 89 | static __inline uint_t 90 | ksid_getrid(ksid_t *ks) 91 | { 92 | panic("%s has been unexpectedly called", __func__); 93 | return 0; 94 | } 95 | 96 | #define kidmap_getsidbyuid(zone, uid, sid_prefix, rid) (1) 97 | #define kidmap_getsidbygid(zone, gid, sid_prefix, rid) (1) 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* _SPL_SID_H */ 104 | -------------------------------------------------------------------------------- /include/sys/vfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. 23 | */ 24 | 25 | /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 26 | /* All Rights Reserved */ 27 | 28 | /* 29 | * Portions of this source code were derived from Berkeley 4.3 BSD 30 | * under license from the Regents of the University of California. 31 | */ 32 | 33 | #ifndef _SPL_ZFS_H 34 | #define _SPL_ZFS_H 35 | 36 | #include 37 | #include 38 | 39 | #define MAXFIDSZ 64 40 | 41 | typedef struct mount vfs_t; 42 | 43 | //#define LK_NOWAIT 0x00000010 /* do not sleep to await lock */ 44 | #define vn_vfswlock(vp) (0) 45 | #define vn_vfsunlock(vp) 46 | #define VFS_HOLD(vfsp) 47 | #define VFS_RELE(vfsp) 48 | 49 | 50 | 51 | /* 52 | * File identifier. Should be unique per filesystem on a single 53 | * machine. This is typically called by a stateless file server 54 | * in order to generate "file handles". 55 | * 56 | * Do not change the definition of struct fid ... fid_t without 57 | * letting the CacheFS group know about it! They will have to do at 58 | * least two things, in the same change that changes this structure: 59 | * 1. change CFSVERSION in usr/src/uts/common/sys/fs/cachefs_fs.h 60 | * 2. put the old version # in the canupgrade array 61 | * in cachfs_upgrade() in usr/src/cmd/fs.d/cachefs/fsck/fsck.c 62 | * This is necessary because CacheFS stores FIDs on disk. 63 | * 64 | * Many underlying file systems cast a struct fid into other 65 | * file system dependent structures which may require 4 byte alignment. 66 | * Because a fid starts with a short it may not be 4 byte aligned, the 67 | * fid_pad will force the alignment. 68 | */ 69 | #define MAXFIDSZ 64 70 | #define OLD_MAXFIDSZ 16 71 | 72 | typedef struct fid { 73 | union { 74 | long fid_pad; 75 | struct { 76 | ushort_t len; /* length of data in bytes */ 77 | char data[MAXFIDSZ]; /* data (variable len) */ 78 | } _fid; 79 | } un; 80 | } fid_t; 81 | 82 | 83 | extern void (*mountroot_post_hook)(void); 84 | 85 | #endif /* SPL_ZFS_H */ 86 | -------------------------------------------------------------------------------- /copy-builtin: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | usage() 6 | { 7 | echo "usage: $0 " >&2 8 | exit 1 9 | } 10 | 11 | [ "$#" -eq 1 ] || usage 12 | KERNEL_DIR="$(readlink --canonicalize-existing "$1")" 13 | 14 | MODULES=() 15 | for MODULE_DIR in module/* 16 | do 17 | [ -d "$MODULE_DIR" ] || continue 18 | MODULES+=("${MODULE_DIR##*/}") 19 | done 20 | 21 | if ! [ -e 'spl_config.h' ] 22 | then 23 | echo >&2 24 | echo " $0: you did not run configure, or you're not in the SPL source directory." >&2 25 | echo " $0: run configure with --with-linux=$KERNEL_DIR and --enable-linux-builtin." >&2 26 | echo >&2 27 | exit 1 28 | fi 29 | 30 | make clean || true 31 | 32 | rm -rf "$KERNEL_DIR/include/spl" "$KERNEL_DIR/spl" 33 | cp --recursive include "$KERNEL_DIR/include/spl" 34 | cp --recursive module "$KERNEL_DIR/spl" 35 | cp spl_config.h "$KERNEL_DIR/" 36 | 37 | adjust_obj_paths() 38 | { 39 | local FILE="$1" 40 | local LINE OBJPATH 41 | 42 | while IFS='' read -r LINE 43 | do 44 | OBJPATH="${LINE#\$(MODULE)-objs += }" 45 | if [ "$OBJPATH" = "$LINE" ] 46 | then 47 | echo "$LINE" 48 | else 49 | echo "\$(MODULE)-objs += ${OBJPATH##*/}" 50 | fi 51 | done < "$FILE" > "$FILE.new" 52 | mv "$FILE.new" "$FILE" 53 | } 54 | 55 | for MODULE in "${MODULES[@]}" 56 | do 57 | adjust_obj_paths "$KERNEL_DIR/spl/$MODULE/Makefile" 58 | done 59 | 60 | cat > "$KERNEL_DIR/spl/Kconfig" <<"EOF" 61 | config SPL 62 | tristate "Solaris Porting Layer (SPL)" 63 | help 64 | This is the SPL library from the ZFS On Linux project. 65 | 66 | See http://zfsonlinux.org/ 67 | 68 | To compile this library as a module, choose M here. 69 | 70 | If unsure, say N. 71 | EOF 72 | 73 | { 74 | cat <<-"EOF" 75 | SPL_MODULE_CFLAGS = -I$(srctree)/include/spl 76 | SPL_MODULE_CFLAGS += -include $(srctree)/spl_config.h 77 | export SPL_MODULE_CFLAGS 78 | 79 | obj-$(CONFIG_SPL) := 80 | EOF 81 | 82 | for MODULE in "${MODULES[@]}" 83 | do 84 | echo 'obj-$(CONFIG_SPL) += ' "$MODULE/" 85 | done 86 | } > "$KERNEL_DIR/spl/Kbuild" 87 | 88 | add_after() 89 | { 90 | local FILE="$1" 91 | local MARKER="$2" 92 | local NEW="$3" 93 | local LINE 94 | 95 | while IFS='' read -r LINE 96 | do 97 | echo "$LINE" 98 | 99 | if [ -n "$MARKER" -a "$LINE" = "$MARKER" ] 100 | then 101 | echo "$NEW" 102 | MARKER='' 103 | if IFS='' read -r LINE 104 | then 105 | [ "$LINE" != "$NEW" ] && echo "$LINE" 106 | fi 107 | fi 108 | done < "$FILE" > "$FILE.new" 109 | 110 | mv "$FILE.new" "$FILE" 111 | } 112 | 113 | add_after "$KERNEL_DIR/Kconfig" 'source "arch/$SRCARCH/Kconfig"' 'source "spl/Kconfig"' 114 | # We must take care to build SPL before ZFS, else module initialization order will be wrong 115 | sed -i 's#kernel/ mm/ fs/#kernel/ mm/ spl/ fs/#' "$KERNEL_DIR/Makefile" 116 | 117 | echo >&2 118 | echo " $0: done." >&2 119 | echo " $0: now you can build the kernel with SPL support." >&2 120 | echo " $0: make sure you enable SPL support (CONFIG_SPL) before building." >&2 121 | echo >&2 122 | 123 | -------------------------------------------------------------------------------- /include/sys/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #ifndef _SPL_TIME_H 30 | #define _SPL_TIME_H 31 | 32 | #include 33 | #include_next 34 | #include 35 | #include 36 | 37 | #if defined(CONFIG_64BIT) 38 | #define TIME_MAX INT64_MAX 39 | #define TIME_MIN INT64_MIN 40 | #else 41 | #define TIME_MAX INT32_MAX 42 | #define TIME_MIN INT32_MIN 43 | #endif 44 | 45 | #define SEC 1 46 | #define MILLISEC 1000 47 | #define MICROSEC 1000000 48 | #define NANOSEC 1000000000 49 | 50 | #define NSEC2SEC(n) ((n) / (NANOSEC / SEC)) 51 | #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC)) 52 | 53 | /* Already defined in include/linux/time.h */ 54 | #undef CLOCK_THREAD_CPUTIME_ID 55 | #undef CLOCK_REALTIME 56 | #undef CLOCK_MONOTONIC 57 | #undef CLOCK_PROCESS_CPUTIME_ID 58 | 59 | typedef enum clock_type { 60 | __CLOCK_REALTIME0 = 0, /* obsolete; same as CLOCK_REALTIME */ 61 | CLOCK_VIRTUAL = 1, /* thread's user-level CPU clock */ 62 | CLOCK_THREAD_CPUTIME_ID = 2, /* thread's user+system CPU clock */ 63 | CLOCK_REALTIME = 3, /* wall clock */ 64 | CLOCK_MONOTONIC = 4, /* high resolution monotonic clock */ 65 | CLOCK_PROCESS_CPUTIME_ID = 5, /* process's user+system CPU clock */ 66 | CLOCK_HIGHRES = CLOCK_MONOTONIC, /* alternate name */ 67 | CLOCK_PROF = CLOCK_THREAD_CPUTIME_ID,/* alternate name */ 68 | } clock_type_t; 69 | 70 | #if 0 71 | #define hz \ 72 | ({ \ 73 | ASSERT(HZ >= 100 && HZ <= MICROSEC); \ 74 | HZ; \ 75 | }) 76 | #endif 77 | 78 | #define TIMESPEC_OVERFLOW(ts) \ 79 | ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX) 80 | 81 | typedef long long hrtime_t; 82 | 83 | extern hrtime_t gethrtime(void); 84 | extern void gethrestime(struct timespec *); 85 | extern time_t gethrestime_sec(void); 86 | extern void hrt2ts(hrtime_t hrt, struct timespec *tsp); 87 | 88 | #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC)) 89 | #define USEC2NSEC(u) ((hrtime_t)(u) * (NANOSEC / MICROSEC)) 90 | #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC)) 91 | 92 | #endif /* _SPL_TIME_H */ 93 | -------------------------------------------------------------------------------- /scripts/check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############################################################################### 3 | # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 4 | # Copyright (C) 2007 The Regents of the University of California. 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 | # This script runs the full set of regression tests. 26 | ############################################################################### 27 | 28 | prog=check.sh 29 | spl_module=../module/spl/spl.ko 30 | splat_module=../module/splat/splat.ko 31 | splat_cmd=../cmd/splat 32 | verbose= 33 | 34 | die() { 35 | echo "${prog}: $1" >&2 36 | exit 1 37 | } 38 | 39 | warn() { 40 | echo "${prog}: $1" >&2 41 | } 42 | 43 | if [ -n "$V" ]; then 44 | verbose="-v" 45 | fi 46 | 47 | if [ -n "$TESTS" ]; then 48 | tests="$TESTS" 49 | else 50 | tests="-a" 51 | fi 52 | 53 | if [ $(id -u) != 0 ]; then 54 | die "Must run as root" 55 | fi 56 | 57 | if /sbin/lsmod | egrep -q "^spl|^splat"; then 58 | die "Must start with spl modules unloaded" 59 | fi 60 | 61 | if [ ! -f ${spl_module} ] || [ ! -f ${splat_module} ]; then 62 | die "Source tree must be built, run 'make'" 63 | fi 64 | 65 | /sbin/modprobe zlib_inflate &>/dev/null 66 | /sbin/modprobe zlib_deflate &>/dev/null 67 | 68 | echo "Loading ${spl_module}" 69 | /sbin/insmod ${spl_module} || die "Failed to load ${spl_module}" 70 | 71 | echo "Loading ${splat_module}" 72 | /sbin/insmod ${splat_module} || die "Unable to load ${splat_module}" 73 | 74 | # Wait a maximum of 3 seconds for udev to detect the new splatctl 75 | # device, if we do not see the character device file created assume 76 | # udev is not running and manually create the character device. 77 | for i in `seq 1 50`; do 78 | sleep 0.1 79 | 80 | if [ -c /dev/splatctl ]; then 81 | break 82 | fi 83 | 84 | if [ $i -eq 50 ]; then 85 | mknod /dev/splatctl c 229 0 86 | fi 87 | done 88 | 89 | $splat_cmd $tests $verbose 90 | 91 | echo "Unloading ${splat_module}" 92 | /sbin/rmmod ${splat_module} || die "Failed to unload ${splat_module}" 93 | 94 | echo "Unloading ${spl_module}" 95 | /sbin/rmmod ${spl_module} || die "Unable to unload ${spl_module}" 96 | 97 | exit 0 98 | -------------------------------------------------------------------------------- /spl.xcodeproj/xcuserdata/zfs-tests.xcuserdatad/xcschemes/spl.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /include/sys/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #ifndef _SPL_THREAD_H 30 | #define _SPL_THREAD_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | typedef struct kthread kthread_t; 39 | 40 | /* 41 | * Thread interfaces 42 | */ 43 | #define TP_MAGIC 0x53535353 44 | 45 | #define TS_FREE 0x00 /* Thread at loose ends */ 46 | #define TS_SLEEP 0x01 /* Awaiting an event */ 47 | #define TS_RUN 0x02 /* Runnable, but not yet on a processor */ 48 | #define TS_ONPROC 0x04 /* Thread is being run on a processor */ 49 | #define TS_ZOMB 0x08 /* Thread has died but hasn't been reaped */ 50 | #define TS_STOPPED 0x10 /* Stopped, initial state */ 51 | #define TS_WAIT 0x20 /* Waiting to become runnable */ 52 | 53 | 54 | typedef void (*thread_func_t)(void *); 55 | 56 | 57 | #define curthread ((struct kthread *)current_thread()) /* current thread pointer */ 58 | #define curproj (ttoproj(curthread)) /* current project pointer */ 59 | 60 | #define thread_join(t) VERIFY(0) 61 | 62 | // Drop the p0 argument, not used. 63 | 64 | #ifdef SPL_DEBUG_THREAD 65 | 66 | #define thread_create(A,B,C,D,E,F,G,H) spl_thread_create(A,B,C,D,E,G,__FILE__, __LINE__, H) 67 | extern kthread_t *spl_thread_create(caddr_t stk, size_t stksize, 68 | void (*proc)(void *), void *arg, size_t len, /*proc_t *pp,*/ int state, 69 | char *, int, pri_t pri); 70 | 71 | #else 72 | 73 | #define thread_create(A,B,C,D,E,F,G,H) spl_thread_create(A,B,C,D,E,G,H) 74 | extern kthread_t *spl_thread_create(caddr_t stk, size_t stksize, 75 | void (*proc)(void *), void *arg, size_t len, /*proc_t *pp,*/ int state, 76 | pri_t pri); 77 | 78 | #endif 79 | 80 | #define thread_exit spl_thread_exit 81 | extern void spl_thread_exit(void); 82 | 83 | extern kthread_t *spl_current_thread(void); 84 | 85 | #define delay osx_delay 86 | extern void osx_delay(int); 87 | 88 | #define KPREEMPT_SYNC 0 89 | static inline void kpreempt(int flags) 90 | { 91 | (void)thread_block(THREAD_CONTINUE_NULL); 92 | } 93 | 94 | #endif /* _SPL_THREAD_H */ 95 | -------------------------------------------------------------------------------- /include/sys/isa_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | 23 | /* 24 | * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25 | * Use is subject to license terms. 26 | */ 27 | 28 | 29 | 30 | #ifndef _SPL_ISA_DEFS_H 31 | #define _SPL_ISA_DEFS_H 32 | 33 | /* x86_64 arch specific defines */ 34 | #if defined(__x86_64) || defined(__x86_64__) 35 | 36 | #if !defined(__x86_64) 37 | #define __x86_64 38 | #endif 39 | 40 | #if !defined(__amd64) 41 | #define __amd64 42 | #endif 43 | 44 | #if !defined(__x86) 45 | #define __x86 46 | #endif 47 | 48 | #if !defined(_LP64) 49 | #define _LP64 50 | #endif 51 | 52 | /* i386 arch specific defines */ 53 | #elif defined(__i386) || defined(__i386__) 54 | 55 | #if !defined(__i386) 56 | #define __i386 57 | #endif 58 | 59 | #if !defined(__x86) 60 | #define __x86 61 | #endif 62 | 63 | #if !defined(_ILP32) 64 | #define _ILP32 65 | #endif 66 | 67 | /* powerpc (ppc64) arch specific defines */ 68 | #elif defined(__powerpc) || defined(__powerpc__) 69 | 70 | #if !defined(__powerpc) 71 | #define __powerpc 72 | #endif 73 | 74 | #if !defined(__powerpc__) 75 | #define __powerpc__ 76 | #endif 77 | 78 | #if !defined(_LP64) 79 | #define _LP64 80 | #endif 81 | 82 | /* arm arch specific defines */ 83 | #elif defined(__arm) || defined(__arm__) 84 | 85 | #if !defined(__arm) 86 | #define __arm 87 | #endif 88 | 89 | #if !defined(__arm__) 90 | #define __arm__ 91 | #endif 92 | 93 | #if defined(__ARMEL__) 94 | #define _LITTLE_ENDIAN 95 | #else 96 | #define _BIG_ENDIAN 97 | #endif 98 | 99 | #else /* Currently only x86_64, i386, arm, and powerpc arches supported */ 100 | #error "Unsupported ISA type" 101 | #endif 102 | 103 | #if defined(_ILP32) && defined(_LP64) 104 | #error "Both _ILP32 and _LP64 are defined" 105 | #endif 106 | 107 | #include 108 | 109 | #if defined(__LITTLE_ENDIAN) && !defined(_LITTLE_ENDIAN) 110 | #define _LITTLE_ENDIAN __LITTLE_ENDIAN 111 | #endif 112 | 113 | #if defined(__BIG_ENDIAN) && !defined(_BIG_ENDIAN) 114 | #define _BIG_ENDIAN __BIG_ENDIAN 115 | #endif 116 | 117 | #if defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) 118 | #error "Both _LITTLE_ENDIAN and _BIG_ENDIAN are defined" 119 | #endif 120 | 121 | #if !defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) 122 | #error "Neither _LITTLE_ENDIAN or _BIG_ENDIAN are defined" 123 | #endif 124 | 125 | #endif /* _SPL_ISA_DEFS_H */ 126 | -------------------------------------------------------------------------------- /include/osx/mutex.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef OSX_MUTEX_H 4 | #define OSX_MUTEX_H 5 | 6 | #include <../spl_config.h> // For SPL_DEBUG_MUTEX 7 | 8 | #ifdef _KERNEL 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef enum { 21 | MUTEX_ADAPTIVE = 0, /* spin if owner is running, otherwise block */ 22 | MUTEX_SPIN = 1, /* block interrupts and spin */ 23 | MUTEX_DRIVER = 4, /* driver (DDI) mutex */ 24 | MUTEX_DEFAULT = 6 /* kernel default mutex */ 25 | } kmutex_type_t; 26 | 27 | // Does anyone know where lck_mtx_t; is actually defined? Not just the opaque 28 | // typedef in i386/locks.h ? 29 | typedef struct { 30 | uint32_t opaque[4]; 31 | } mutex_t; 32 | 33 | /* To enable watchdog to keep an eye on mutex being held for too long 34 | * define this debug variable. 35 | */ 36 | //#define SPL_DEBUG_MUTEX // smd - uncomment for lundman testing 37 | 38 | #ifdef SPL_DEBUG_MUTEX 39 | #define SPL_MUTEX_WATCHDOG_SLEEP 10 /* How long to sleep between checking */ 40 | #define SPL_MUTEX_WATCHDOG_TIMEOUT 60 /* When is a mutex held too long? */ 41 | #endif 42 | 43 | /* 44 | * Solaris kmutex defined. 45 | * 46 | * and is embedded into ZFS structures (see dbuf) so we need to match the 47 | * size carefully. It appears to be 32 bytes. Or rather, it needs to be 48 | * aligned. 49 | */ 50 | 51 | typedef struct kmutex { 52 | void *m_owner; 53 | mutex_t m_lock; 54 | 55 | #ifdef SPL_DEBUG_MUTEX 56 | void *leak; 57 | #endif 58 | 59 | } kmutex_t; 60 | 61 | 62 | #define MUTEX_HELD(x) (mutex_owned(x)) 63 | #define MUTEX_NOT_HELD(x) (!mutex_owned(x)) 64 | 65 | /* 66 | * On OS X, CoreStorage provides these symbols, so we have to redefine them, 67 | * preferably without having to modify SPL users. 68 | */ 69 | #ifdef SPL_DEBUG_MUTEX 70 | 71 | #define mutex_init(A,B,C,D) spl_mutex_init(A,B,C,D,__FILE__,__FUNCTION__,__LINE__) 72 | void spl_mutex_init(kmutex_t *mp, char *name, kmutex_type_t type, void *ibc, const char *f, const char *fn, int l); 73 | 74 | #else 75 | 76 | #define mutex_init spl_mutex_init 77 | void spl_mutex_init(kmutex_t *mp, char *name, kmutex_type_t type, void *ibc); 78 | 79 | #endif 80 | 81 | #ifdef SPL_DEBUG_MUTEX 82 | #define mutex_enter(X) spl_mutex_enter((X), __FILE__, __LINE__) 83 | void spl_mutex_enter(kmutex_t *mp, char *file, int line); 84 | #else 85 | #define mutex_enter spl_mutex_enter 86 | void spl_mutex_enter(kmutex_t *mp); 87 | #endif 88 | 89 | #define mutex_destroy spl_mutex_destroy 90 | #define mutex_exit spl_mutex_exit 91 | #define mutex_tryenter spl_mutex_tryenter 92 | #define mutex_owned spl_mutex_owned 93 | #define mutex_owner spl_mutex_owner 94 | 95 | void spl_mutex_destroy(kmutex_t *mp); 96 | void spl_mutex_exit(kmutex_t *mp); 97 | int spl_mutex_tryenter(kmutex_t *mp); 98 | int spl_mutex_owned(kmutex_t *mp); 99 | struct kthread *spl_mutex_owner(kmutex_t *mp); 100 | 101 | int spl_mutex_subsystem_init(void); 102 | void spl_mutex_subsystem_fini(void); 103 | 104 | #endif 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /patches/rhel5-spl-export-symbols.patch: -------------------------------------------------------------------------------- 1 | Index: linux+rh+chaos/kernel/sched.c 2 | =================================================================== 3 | --- linux+rh+chaos.orig/kernel/sched.c 4 | +++ linux+rh+chaos/kernel/sched.c 5 | @@ -1034,10 +1034,11 @@ static inline void resched_task(struct t 6 | * task_curr - is this task currently executing on a CPU? 7 | * @p: the task in question. 8 | */ 9 | -inline int task_curr(const struct task_struct *p) 10 | +int task_curr(const struct task_struct *p) 11 | { 12 | return cpu_curr(task_cpu(p)) == p; 13 | } 14 | +EXPORT_SYMBOL(task_curr); /* Request export upstream */ 15 | 16 | /* Used instead of source_load when we know the type == 0 */ 17 | unsigned long weighted_cpuload(const int cpu) 18 | Index: linux+rh+chaos/kernel/time.c 19 | =================================================================== 20 | --- linux+rh+chaos.orig/kernel/time.c 21 | +++ linux+rh+chaos/kernel/time.c 22 | @@ -605,6 +605,7 @@ void set_normalized_timespec(struct time 23 | ts->tv_sec = sec; 24 | ts->tv_nsec = nsec; 25 | } 26 | +EXPORT_SYMBOL(set_normalized_timespec); /* Exported as of 2.6.26 */ 27 | 28 | /** 29 | * ns_to_timespec - Convert nanoseconds to timespec 30 | Index: linux+rh+chaos/kernel/kallsyms.c 31 | =================================================================== 32 | --- linux+rh+chaos.orig/kernel/kallsyms.c 33 | +++ linux+rh+chaos/kernel/kallsyms.c 34 | @@ -154,6 +154,7 @@ unsigned long kallsyms_lookup_name(const 35 | } 36 | return module_kallsyms_lookup_name(name); 37 | } 38 | +EXPORT_SYMBOL(kallsyms_lookup_name); /* Exported prior to 2.6.19 */ 39 | 40 | /* 41 | * Lookup an address 42 | Index: linux+rh+chaos/fs/proc/mmu.c 43 | =================================================================== 44 | --- linux+rh+chaos.orig/fs/proc/mmu.c 45 | +++ linux+rh+chaos/fs/proc/mmu.c 46 | @@ -75,3 +75,4 @@ void get_vmalloc_info(struct vmalloc_inf 47 | read_unlock(&vmlist_lock); 48 | } 49 | } 50 | +EXPORT_SYMBOL(get_vmalloc_info); /* Request clean upstream API for this */ 51 | Index: linux+rh+chaos/mm/mmzone.c 52 | =================================================================== 53 | --- linux+rh+chaos.orig/mm/mmzone.c 54 | +++ linux+rh+chaos/mm/mmzone.c 55 | @@ -14,7 +14,7 @@ struct pglist_data *first_online_pgdat(v 56 | return NODE_DATA(first_online_node); 57 | } 58 | 59 | -EXPORT_UNUSED_SYMBOL(first_online_pgdat); /* June 2006 */ 60 | +EXPORT_SYMBOL(first_online_pgdat); /* Exported prior to 2.6.18 */ 61 | 62 | struct pglist_data *next_online_pgdat(struct pglist_data *pgdat) 63 | { 64 | @@ -24,7 +24,7 @@ struct pglist_data *next_online_pgdat(st 65 | return NULL; 66 | return NODE_DATA(nid); 67 | } 68 | -EXPORT_UNUSED_SYMBOL(next_online_pgdat); /* June 2006 */ 69 | +EXPORT_SYMBOL(next_online_pgdat); /* Exported prior to 2.6.18 */ 70 | 71 | 72 | /* 73 | @@ -45,5 +45,5 @@ struct zone *next_zone(struct zone *zone 74 | } 75 | return zone; 76 | } 77 | -EXPORT_UNUSED_SYMBOL(next_zone); /* June 2006 */ 78 | +EXPORT_SYMBOL(next_zone); /* Exported prior to 2.6.18 */ 79 | 80 | Index: linux+rh+chaos/mm/vmstat.c 81 | =================================================================== 82 | --- linux+rh+chaos.orig/mm/vmstat.c 83 | +++ linux+rh+chaos/mm/vmstat.c 84 | @@ -45,6 +45,7 @@ void get_zone_counts(unsigned long *acti 85 | *free += n; 86 | } 87 | } 88 | +EXPORT_SYMBOL(get_zone_counts); /* Request clean upstream API for this */ 89 | 90 | #ifdef CONFIG_VM_EVENT_COUNTERS 91 | DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}}; 92 | -------------------------------------------------------------------------------- /include/spl-device.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_DEVICE_H 26 | #define _SPL_DEVICE_H 27 | 28 | //#include 29 | 30 | /* 31 | * Preferred API from 2.6.18 to 2.6.26+ 32 | */ 33 | #ifdef HAVE_DEVICE_CREATE 34 | 35 | typedef struct class spl_class; 36 | typedef struct device spl_device; 37 | 38 | #define spl_class_create(mod, name) class_create(mod, name) 39 | #define spl_class_destroy(cls) class_destroy(cls) 40 | 41 | # ifdef HAVE_5ARGS_DEVICE_CREATE 42 | # define spl_device_create(cls, parent, devt, drvdata, fmt, args...) \ 43 | device_create(cls, parent, devt, drvdata, fmt, ## args) 44 | # else 45 | # define spl_device_create(cls, parent, devt, drvdata, fmt, args...) \ 46 | device_create(cls, parent, devt, fmt, ## args) 47 | # endif 48 | 49 | #define spl_device_destroy(cls, cls_dev, devt) \ 50 | device_destroy(cls, devt) 51 | 52 | /* 53 | * Preferred API from 2.6.13 to 2.6.17 54 | * Depricated in 2.6.18 55 | * Removed in 2.6.26 56 | */ 57 | #else 58 | #ifdef HAVE_CLASS_DEVICE_CREATE 59 | 60 | typedef struct class spl_class; 61 | typedef struct class_device spl_device; 62 | 63 | #define spl_class_create(mod, name) class_create(mod, name) 64 | #define spl_class_destroy(cls) class_destroy(cls) 65 | #define spl_device_create(cls, parent, devt, device, fmt, args...) \ 66 | class_device_create(cls, parent, devt, device, fmt, ## args) 67 | #define spl_device_destroy(cls, cls_dev, devt) \ 68 | class_device_unregister(cls_dev) 69 | 70 | /* 71 | * Prefered API from 2.6.0 to 2.6.12 72 | * Depricated in 2.6.13 73 | * Removed in 2.6.13 74 | */ 75 | #else /* Legacy API */ 76 | 77 | typedef struct class_simple spl_class; 78 | typedef struct class_device spl_class_device; 79 | 80 | #define spl_class_create(mod, name) class_simple_create(mod, name) 81 | #define spl_class_destroy(cls) class_simple_destroy(cls) 82 | #define spl_device_create(cls, parent, devt, device, fmt, args...) \ 83 | class_simple_device_add(cls, devt, device, fmt, ## args) 84 | #define spl_device_destroy(cls, cls_dev, devt) \ 85 | class_simple_device_remove(devt) 86 | 87 | #endif /* HAVE_CLASS_DEVICE_CREATE */ 88 | #endif /* HAVE_DEVICE_CREATE */ 89 | 90 | #endif /* _SPL_DEVICE_H */ 91 | -------------------------------------------------------------------------------- /include/sys/taskq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | /* 26 | * Copyright (C) 2015 Jorgen Lundman 27 | */ 28 | 29 | #ifndef _SYS_TASKQ_H 30 | #define _SYS_TASKQ_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #define TASKQ_NAMELEN 31 41 | 42 | typedef struct taskq taskq_t; 43 | typedef uintptr_t taskqid_t; 44 | typedef void (task_func_t)(void *); 45 | 46 | struct proc; 47 | 48 | /* 49 | * Public flags for taskq_create(): bit range 0-15 50 | */ 51 | #define TASKQ_PREPOPULATE 0x0001 /* Prepopulate with threads and data */ 52 | #define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ 53 | #define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ 54 | #define TASKQ_THREADS_CPU_PCT 0x0008 /* number of threads as % of ncpu */ 55 | #define TASKQ_DC_BATCH 0x0010 /* Taskq uses SDC in batch mode */ 56 | 57 | /* 58 | * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as 59 | * KM_SLEEP/KM_NOSLEEP. 60 | */ 61 | #define TQ_SLEEP 0x00 /* Can block for memory */ 62 | #define TQ_NOSLEEP 0x01 /* cannot block for memory; may fail */ 63 | #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ 64 | #define TQ_NOALLOC 0x04 /* cannot allocate memory; may fail */ 65 | #define TQ_FRONT 0x08 /* Put task at the front of the queue */ 66 | 67 | #define TASKQID_INVALID ((taskqid_t)0) 68 | 69 | #ifdef _KERNEL 70 | 71 | extern taskq_t *system_taskq; 72 | 73 | extern int spl_taskq_init(void); 74 | extern void spl_taskq_fini(void); 75 | extern void taskq_mp_init(void); 76 | 77 | extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); 78 | extern taskq_t *taskq_create_instance(const char *, int, int, pri_t, int, 79 | int, uint_t); 80 | extern taskq_t *taskq_create_proc(const char *, int, pri_t, int, int, 81 | proc_t *, uint_t); 82 | extern taskq_t *taskq_create_sysdc(const char *, int, int, int, 83 | proc_t *, uint_t, uint_t); 84 | extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); 85 | extern void nulltask(void *); 86 | extern void taskq_destroy(taskq_t *); 87 | extern void taskq_wait(taskq_t *); 88 | #define HAVE_TASKQ_WAIT_ID 89 | extern void taskq_wait_id(taskq_t *, taskqid_t); 90 | extern void taskq_suspend(taskq_t *); 91 | extern int taskq_suspended(taskq_t *); 92 | extern void taskq_resume(taskq_t *); 93 | extern int taskq_member(taskq_t *, struct kthread *); 94 | 95 | #define taskq_wait_outstanding(T, D) taskq_wait((T)) 96 | 97 | extern void system_taskq_init(void); 98 | extern void system_taskq_fini(void); 99 | 100 | #endif /* _KERNEL */ 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* _SYS_TASKQ_H */ 107 | -------------------------------------------------------------------------------- /module/spl/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/config/Rules.am 2 | 3 | INFO_PLIST = Info.plist 4 | PLIST_STRING = InfoPlist.strings 5 | 6 | SUBDIRS = KernelExports 7 | 8 | CFLAGS_KMOD = \ 9 | ${AM_CFLAGS} \ 10 | -Wall \ 11 | -nostdinc \ 12 | -mkernel \ 13 | -fno-builtin-printf \ 14 | -D_KERNEL \ 15 | -DKERNEL \ 16 | -DKERNEL_PRIVATE \ 17 | -DDRIVER_PRIVATE \ 18 | -DAPPLE \ 19 | -DNeXT \ 20 | -I$(top_srcdir)/include \ 21 | -I@KERNEL_HEADERS@/Headers \ 22 | -I@KERNEL_HEADERS@/PrivateHeaders 23 | 24 | LINKFLAGS_KMOD = \ 25 | -Xlinker \ 26 | -kext \ 27 | -nostdlib \ 28 | -lkmodc++ \ 29 | -lkmod \ 30 | -lcc_kext 31 | 32 | bin_PROGRAMS = spl.kext 33 | noinst_PROGRAMS = spl 34 | 35 | spl_kext_SOURCE = 36 | 37 | spl_SOURCES = \ 38 | spl-atomic.c \ 39 | spl-avl.c \ 40 | spl-condvar.c \ 41 | spl-cred.c \ 42 | spl-ddi.c \ 43 | spl-debug.c \ 44 | spl-err.c \ 45 | spl-kmem.c \ 46 | spl-kobj.c \ 47 | spl-kstat.c \ 48 | spl-list.c \ 49 | spl-mutex.c \ 50 | spl-osx.c \ 51 | spl-policy.c \ 52 | spl-proc.c \ 53 | spl-processor.c \ 54 | spl-rwlock.c \ 55 | spl-seg_kmem.c \ 56 | spl-taskq.c \ 57 | spl-thread.c \ 58 | spl-time.c \ 59 | spl-tsd.c \ 60 | spl-vmem.c \ 61 | spl-vnode.c \ 62 | spl-xdr.c 63 | 64 | spl_CPPFLAGS=$(CFLAGS_KMOD) 65 | spl_LDFLAGS=$(LINKFLAGS_KMOD) 66 | 67 | KERNEL_MODDIR= $(DESTDIR)@KERNEL_MODPREFIX@/spl.kext 68 | 69 | dist_noinst_DATA = $(PLIST_STRING) $(INFO_PLIST) 70 | 71 | spl.kext$(EXEEXT): spl $(PLIST_STRING) $(INFO_PLIST) 72 | @echo "" 73 | @mkdir -p spl.kext/Contents/Resources/English.lproj spl.kext/Contents/MacOS 74 | @cp -f $(INFO_PLIST) spl.kext/Contents/ 75 | /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $(SPL_META_VERSION)" spl.kext/Contents/Info.plist 76 | /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $(SPL_META_VERSION)" spl.kext/Contents/Info.plist 77 | /usr/libexec/PlistBuddy -c "Delete :OSBundleLibraries:net.lundman.kernel.dependencies" spl.kext/Contents/Info.plist 78 | /usr/libexec/PlistBuddy -c "Add :OSBundleLibraries:net.lundman.kernel.dependencies.$(SPL_KERNEL_DEPENDENCIES) string 12.5.0" spl.kext/Contents/Info.plist 79 | @cp -f $(PLIST_STRING) spl.kext/Contents/Resources/English.lproj/ 80 | @cp -f spl spl.kext/Contents/MacOS/ 81 | @mkdir -p spl.kext/Contents/PlugIns/KernelExports.kext/ 82 | @cd KernelExports && $(MAKE) 83 | @cp -f KernelExports/KernelExports spl.kext/Contents/PlugIns/KernelExports.kext/ 84 | cp -f KernelExports/Info.plist spl.kext/Contents/PlugIns/KernelExports.kext/ 85 | /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier net.lundman.kernel.dependencies.$(SPL_KERNEL_DEPENDENCIES)" spl.kext/Contents/PlugIns/KernelExports.kext/Info.plist 86 | if [ "0$(ZFS_BOOT)" -eq 1 ]; then /usr/libexec/PlistBuddy -c "Add :OSBundleRequired string Root" spl.kext/Contents/Info.plist; fi 87 | cp -f KernelExports/version.plist spl.kext/Contents/PlugIns/KernelExports.kext/ 88 | mkdir -p KernelExports.kext 89 | cp -f spl.kext/Contents/PlugIns/KernelExports.kext/KernelExports KernelExports.kext/ 90 | cp -f spl.kext/Contents/PlugIns/KernelExports.kext/Info.plist KernelExports.kext/ 91 | if [ "0$(ZFS_BOOT)" -eq 1 ]; then /usr/libexec/PlistBuddy -c "Add :OSBundleRequired string Root" spl.kext/Contents/PlugIns/KernelExports.kext/Info.plist; fi 92 | @kextlibs -undef-symbols -xml spl.kext/ || echo "Ignoring errors.." 93 | 94 | install-exec-local: spl.kext 95 | rm -rf $(KERNEL_MODDIR) 96 | mkdir -p $(KERNEL_MODDIR) 97 | rsync -r spl.kext/ $(KERNEL_MODDIR) 98 | chown -R root:wheel $(KERNEL_MODDIR) || echo "Unable to chown root:wheel $(KERNEL_MODDIR)" 99 | @echo 100 | @echo "To load module: kextload -v $(KERNEL_MODDIR)" 101 | @echo "To uninstall module: rm -rf $(KERNEL_MODDIR)" 102 | @echo 103 | 104 | uninstall-am: 105 | rm -rf $(KERNEL_MODDIR) 106 | 107 | clean: 108 | rm -rf spl.kext/ 109 | rm -f *.o *.lo spl 110 | @cd KernelExports && $(MAKE) clean 111 | -------------------------------------------------------------------------------- /patches/fc11-spl-export-symbols.patch: -------------------------------------------------------------------------------- 1 | Required missing symbols for FC11 kernels (2.6.29.4-167.fc11.x86_64) 2 | 3 | * get_vmalloc_info() 4 | There is no clean API in the kernel for modules to check the virtual 5 | memory state of the system. This information is available in user 6 | space under /proc/meminfo and the details for every virtual memory 7 | node are available under /proc/vmallocinfo. 8 | 9 | * groups_search() 10 | This support is easily replicated if the symbol is not provided by the 11 | kernel. However exporting the symbol from the kernel is preferable. 12 | This is required by the solaris credential API. 13 | 14 | * task_curr() 15 | This symbol is used by the solaris adaptive mutex implementation. If 16 | unavailable then all solaris mutexs behave strictly like linux style 17 | semaphones. If available then the mutex may spin for a short while, 18 | rather than sleep, if the holder of the lock is currently executing. 19 | 20 | * first_online_pgdat() 21 | * next_online_pgdat() 22 | * next_zone() 23 | Required helper functions for the zone iterators for_each_zone() and 24 | for_each_populated_zone(). These symbols were previously available 25 | in 2.6.17 kernels, marked unused in 2.6.18 kernels, and removed as 26 | of the 2.6.19 kernel series. The information is available in user 27 | space under /proc/zoneinfo. 28 | 29 | diff --git a/fs/proc/mmu.c b/fs/proc/mmu.c 30 | index 8ae221d..081c7b5 100644 31 | --- a/fs/proc/mmu.c 32 | +++ b/fs/proc/mmu.c 33 | @@ -58,3 +58,4 @@ void get_vmalloc_info(struct vmalloc_info *vmi) 34 | read_unlock(&vmlist_lock); 35 | } 36 | } 37 | +EXPORT_SYMBOL(get_vmalloc_info); 38 | diff --git a/kernel/groups.c b/kernel/groups.c 39 | index 2b45b2e..24b62f8 100644 40 | --- a/kernel/groups.c 41 | +++ b/kernel/groups.c 42 | @@ -153,6 +153,7 @@ int groups_search(const struct group_info *group_info, gid_t grp) 43 | } 44 | return 0; 45 | } 46 | +EXPORT_SYMBOL(groups_search); 47 | 48 | /** 49 | * set_groups - Change a group subscription in a set of credentials 50 | diff --git a/kernel/sched.c b/kernel/sched.c 51 | index 1b59e26..8728c52 100644 52 | --- a/kernel/sched.c 53 | +++ b/kernel/sched.c 54 | @@ -1883,10 +1883,11 @@ static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep) 55 | * task_curr - is this task currently executing on a CPU? 56 | * @p: the task in question. 57 | */ 58 | -inline int task_curr(const struct task_struct *p) 59 | +task_curr(const struct task_struct *p) 60 | { 61 | return cpu_curr(task_cpu(p)) == p; 62 | } 63 | +EXPORT_SYMBOL(task_curr); 64 | 65 | static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu) 66 | { 67 | diff --git a/mm/mmzone.c b/mm/mmzone.c 68 | index f5b7d17..1468a22 100644 69 | --- a/mm/mmzone.c 70 | +++ b/mm/mmzone.c 71 | @@ -14,6 +14,7 @@ struct pglist_data *first_online_pgdat(void) 72 | { 73 | return NODE_DATA(first_online_node); 74 | } 75 | +EXPORT_SYMBOL(first_online_pgdat); 76 | 77 | struct pglist_data *next_online_pgdat(struct pglist_data *pgdat) 78 | { 79 | @@ -23,6 +24,7 @@ struct pglist_data *next_online_pgdat(struct pglist_data *pgdat) 80 | return NULL; 81 | return NODE_DATA(nid); 82 | } 83 | +EXPORT_SYMBOL(next_online_pgdat); 84 | 85 | /* 86 | * next_zone - helper magic for for_each_zone() 87 | @@ -42,6 +44,7 @@ struct zone *next_zone(struct zone *zone) 88 | } 89 | return zone; 90 | } 91 | +EXPORT_SYMBOL(next_zone); 92 | 93 | static inline int zref_in_nodemask(struct zoneref *zref, nodemask_t *nodes) 94 | { 95 | diff --git a/kernel/fork.c b/kernel/fork.c 96 | index 9b42695..852499e 100644 97 | --- a/kernel/fork.c 98 | +++ b/kernel/fork.c 99 | @@ -159,6 +159,7 @@ void __put_task_struct(struct task_struct *tsk) 100 | if (!profile_handoff_task(tsk)) 101 | free_task(tsk); 102 | } 103 | +EXPORT_SYMBOL(__put_task_struct); 104 | 105 | /* 106 | * macro override instead of weak attribute alias, to workaround 107 | -------------------------------------------------------------------------------- /module/spl/spl-cred.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /* Return the effective user id */ 34 | uid_t 35 | crgetuid(const cred_t *cr) 36 | { 37 | if (!cr) return 0; 38 | return kauth_cred_getuid((kauth_cred_t)cr); 39 | } 40 | 41 | 42 | /* Return the real user id */ 43 | uid_t 44 | crgetruid(const cred_t *cr) 45 | { 46 | if (!cr) return 0; 47 | return kauth_cred_getruid((kauth_cred_t)cr); 48 | } 49 | 50 | /* Return the saved user id */ 51 | uid_t 52 | crgetsuid(const cred_t *cr) 53 | { 54 | if (!cr) return 0; 55 | return kauth_cred_getsvuid((kauth_cred_t)cr); 56 | } 57 | 58 | /* Return the filesystem user id */ 59 | uid_t 60 | crgetfsuid(const cred_t *cr) 61 | { 62 | if (!cr) return 0; 63 | return -1; 64 | } 65 | 66 | /* Return the effective group id */ 67 | gid_t 68 | crgetgid(const cred_t *cr) 69 | { 70 | if (!cr) return 0; 71 | return kauth_cred_getgid((kauth_cred_t)cr); 72 | } 73 | 74 | /* Return the real group id */ 75 | gid_t 76 | crgetrgid(const cred_t *cr) 77 | { 78 | if (!cr) return 0; 79 | return kauth_cred_getrgid((kauth_cred_t)cr); 80 | } 81 | 82 | /* Return the saved group id */ 83 | gid_t 84 | crgetsgid(const cred_t *cr) 85 | { 86 | if (!cr) return 0; 87 | return kauth_cred_getsvgid((kauth_cred_t)cr); 88 | } 89 | 90 | /* Return the filesystem group id */ 91 | gid_t 92 | crgetfsgid(const cred_t *cr) 93 | { 94 | return -1; 95 | } 96 | 97 | 98 | extern int kauth_cred_getgroups(kauth_cred_t _cred, gid_t *_groups, int *_groupcount); 99 | /* 100 | * Unfortunately, to get the count of groups, we have to call XNU which 101 | * memcpy's them over. No real clean way to get around that, but at least 102 | * these calls are done sparingly. 103 | */ 104 | int crgetngroups(const cred_t *cr) 105 | { 106 | gid_t gids[NGROUPS]; 107 | int count = NGROUPS; 108 | int ret; 109 | 110 | ret = kauth_cred_getgroups((kauth_cred_t) cr, gids, &count); 111 | 112 | if (!ret) return count; 113 | 114 | return 0; 115 | } 116 | 117 | 118 | /* 119 | * We always allocate NGROUPs here, since we don't know how many there will 120 | * be until after the call. Unlike IllumOS, the ptr returned is allocated 121 | * and must be returned by a call to crgetgroupsfree(). 122 | */ 123 | gid_t *crgetgroups(const cred_t *cr) 124 | { 125 | gid_t *gids; 126 | int count = NGROUPS; 127 | 128 | gids = kmem_zalloc(sizeof(gid_t) * count, KM_SLEEP); 129 | if (!gids) return NULL; 130 | 131 | kauth_cred_getgroups((kauth_cred_t) cr, gids, &count); 132 | 133 | return gids; 134 | } 135 | 136 | void crgetgroupsfree(gid_t *gids) 137 | { 138 | if (!gids) return; 139 | kmem_free(gids, sizeof(gid_t) * NGROUPS); 140 | } 141 | 142 | /* 143 | * Return true if "cr" belongs in group "gid". 144 | */ 145 | int spl_cred_ismember_gid(cred_t *cr, gid_t gid) 146 | { 147 | int ret = 0; // Is not member. 148 | kauth_cred_ismember_gid((kauth_cred_t)cr, gid, &ret); 149 | if (ret == 1) 150 | return TRUE; 151 | return FALSE; 152 | } 153 | -------------------------------------------------------------------------------- /config/rpm.am: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3 | # Copyright (C) 2007 The Regents of the University of California. 4 | # Written by Brian Behlendorf . 5 | ############################################################################### 6 | # Build targets for RPM packages. 7 | ############################################################################### 8 | 9 | srpm-modules: 10 | if CONFIG_KERNEL 11 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}-modules" srpm-common 12 | endif 13 | 14 | srpm-utils: 15 | if CONFIG_USER 16 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}" srpm-common 17 | endif 18 | 19 | srpm: srpm-modules srpm-utils 20 | 21 | rpm-dkms: srpm-modules 22 | if CONFIG_KERNEL 23 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}-modules" dkms-common 24 | endif 25 | 26 | rpm-modules: srpm-modules 27 | if CONFIG_KERNEL 28 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}-modules" rpm-common 29 | endif 30 | 31 | rpm-utils: srpm-utils 32 | if CONFIG_USER 33 | $(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}" rpm-common 34 | endif 35 | 36 | rpm: rpm-modules rpm-utils rpm-dkms 37 | 38 | rpm-local: 39 | @(if test "${HAVE_RPMBUILD}" = "no"; then \ 40 | echo -e "\n" \ 41 | "*** Required util ${RPMBUILD} missing. Please install the\n" \ 42 | "*** package for your distribution which provides ${RPMBUILD},\n" \ 43 | "*** re-run configure, and try again.\n"; \ 44 | exit 1; \ 45 | fi; \ 46 | mkdir -p $(rpmbuild)/TMP && \ 47 | mkdir -p $(rpmbuild)/BUILD && \ 48 | mkdir -p $(rpmbuild)/RPMS && \ 49 | mkdir -p $(rpmbuild)/SRPMS && \ 50 | mkdir -p $(rpmbuild)/SPECS && \ 51 | cp $(rpmspec) $(rpmbuild)/SPECS && \ 52 | mkdir -p $(rpmbuild)/SOURCES && \ 53 | cp $(distdir).tar.gz $(rpmbuild)/SOURCES) 54 | 55 | dkms-common: 56 | rpmpkg=$(pkg)-$(SPL_META_VERSION)-$(SPL_META_RELEASE).src.rpm; \ 57 | rpmspec=$(pkg).spec; \ 58 | rpmdkms=$(pkg)-dkms-$(SPL_META_VERSION)-$(SPL_META_RELEASE).noarch.rpm;\ 59 | rpmbuild=`mktemp -t -d $(PACKAGE)-build-$$USER-XXXXXXXX`; \ 60 | $(MAKE) $(AM_MAKEFLAGS) \ 61 | rpmbuild="$$rpmbuild" \ 62 | rpmspec="$$rpmspec" \ 63 | rpm-local || exit 1; \ 64 | $(RPMBUILD) \ 65 | --define "_tmppath $$rpmbuild/TMP" \ 66 | --define "_topdir $$rpmbuild" \ 67 | --define "dist %{nil}" \ 68 | --define "_without_kernel 1" \ 69 | --define "_without_kernel_debug 1" \ 70 | --define "_with_kernel_dkms 1" \ 71 | --nodeps --rebuild $$rpmpkg || exit 1; \ 72 | cp $$rpmbuild/RPMS/noarch/$$rpmdkms . || exit 1; \ 73 | $(RM) -R $$rpmbuild 74 | 75 | srpm-common: dist 76 | rpmpkg=$(pkg)-$(SPL_META_VERSION)-$(SPL_META_RELEASE).src.rpm; \ 77 | rpmspec=$(pkg).spec; \ 78 | rpmbuild=`mktemp -t -d $(PACKAGE)-build-$$USER-XXXXXXXX`; \ 79 | $(MAKE) $(AM_MAKEFLAGS) \ 80 | rpmbuild="$$rpmbuild" \ 81 | rpmspec="$$rpmspec" \ 82 | rpm-local || exit 1; \ 83 | $(RPMBUILD) \ 84 | --define "_tmppath $$rpmbuild/TMP" \ 85 | --define "_topdir $$rpmbuild" \ 86 | --define "build_src_rpm 1" \ 87 | --define "dist %{nil}" \ 88 | --nodeps -bs $$rpmbuild/SPECS/$$rpmspec || exit 1; \ 89 | cp $$rpmbuild/SRPMS/$$rpmpkg . || exit 1; \ 90 | $(RM) -R $$rpmbuild 91 | 92 | rpm-common: 93 | rpmpkg=$(pkg)-$(SPL_META_VERSION)-$(SPL_META_RELEASE).src.rpm; \ 94 | rpmspec=$(pkg).spec; \ 95 | rpmbuild=`mktemp -t -d $(PACKAGE)-build-$$USER-XXXXXXXX`; \ 96 | $(MAKE) $(AM_MAKEFLAGS) \ 97 | rpmbuild="$$rpmbuild" \ 98 | rpmspec="$$rpmspec" \ 99 | rpm-local || exit 1; \ 100 | ${RPMBUILD} \ 101 | --define "_tmppath $$rpmbuild/TMP" \ 102 | --define "_topdir $$rpmbuild" \ 103 | --define "dist %{nil}" \ 104 | --define "require_kdir $(LINUX)" \ 105 | --define "require_kobj $(LINUX_OBJ)" \ 106 | --define "require_kver $(LINUX_VERSION)" \ 107 | --define "$(DEBUG_SPL) 1" \ 108 | --define "$(DEBUG_LOG) 1" \ 109 | --define "$(DEBUG_KMEM) 1" \ 110 | --define "$(DEBUG_KMEM_TRACKING) 1" \ 111 | --nodeps --rebuild $$rpmpkg || exit 1; \ 112 | cp $$rpmbuild/RPMS/*/* . || exit 1; \ 113 | $(RM) -R $$rpmbuild 114 | -------------------------------------------------------------------------------- /include/sys/zmod.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************************\ 2 | * zlib.h -- interface of the 'zlib' general purpose compression library 3 | * version 1.2.5, April 19th, 2010 4 | * 5 | * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * 11 | * Permission is granted to anyone to use this software for any purpose, 12 | * including commercial applications, and to alter it and redistribute it 13 | * freely, subject to the following restrictions: 14 | * 15 | * 1. The origin of this software must not be misrepresented; you must not 16 | * claim that you wrote the original software. If you use this software 17 | * in a product, an acknowledgment in the product documentation would be 18 | * appreciated but is not required. 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 3. This notice may not be removed or altered from any source distribution. 22 | * 23 | * Jean-loup Gailly 24 | * Mark Adler 25 | \*****************************************************************************/ 26 | 27 | #ifndef _SPL_ZMOD_H 28 | #define _SPL_ZMOD_H 29 | 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | struct _zmemheader { 36 | uint64_t length; 37 | char data[0]; 38 | }; 39 | 40 | static inline void * 41 | zfs_zalloc(void* opaque, uInt items, uInt size) 42 | { 43 | struct _zmemheader *hdr; 44 | size_t alloc_size = (items * size) + sizeof (uint64_t); 45 | hdr = kmem_zalloc(alloc_size, KM_SLEEP); 46 | hdr->length = alloc_size; 47 | return (&hdr->data); 48 | } 49 | 50 | static inline void 51 | zfs_zfree(void *opaque, void *addr) 52 | { 53 | struct _zmemheader *hdr; 54 | hdr = addr; 55 | hdr--; 56 | kmem_free(hdr, hdr->length); 57 | } 58 | 59 | /* 60 | * Uncompress the buffer 'src' into the buffer 'dst'. The caller must store 61 | * the expected decompressed data size externally so it can be passed in. 62 | * The resulting decompressed size is then returned through dstlen. This 63 | * function return Z_OK on success, or another error code on failure. 64 | */ 65 | static inline int 66 | z_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen) 67 | { 68 | z_stream zs; 69 | int err; 70 | 71 | bzero(&zs, sizeof (zs)); 72 | zs.next_in = (uchar_t *)src; 73 | zs.avail_in = srclen; 74 | zs.next_out = dst; 75 | zs.avail_out = *dstlen; 76 | zs.zalloc = zfs_zalloc; 77 | zs.zfree = zfs_zfree; 78 | if ((err = inflateInit(&zs)) != Z_OK) 79 | return (err); 80 | if ((err = inflate(&zs, Z_FINISH)) != Z_STREAM_END) { 81 | (void) inflateEnd(&zs); 82 | return (err == Z_OK ? Z_BUF_ERROR : err); 83 | } 84 | *dstlen = zs.total_out; 85 | return (inflateEnd(&zs)); 86 | } 87 | 88 | static inline int 89 | z_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen, 90 | int level) 91 | { 92 | z_stream zs; 93 | int err; 94 | bzero(&zs, sizeof (zs)); 95 | zs.next_in = (uchar_t *)src; 96 | zs.avail_in = srclen; 97 | zs.next_out = dst; 98 | zs.avail_out = *dstlen; 99 | zs.zalloc = zfs_zalloc; 100 | zs.zfree = zfs_zfree; 101 | if ((err = deflateInit(&zs, level)) != Z_OK) 102 | return (err); 103 | if ((err = deflate(&zs, Z_FINISH)) != Z_STREAM_END) { 104 | (void) deflateEnd(&zs); 105 | return (err == Z_OK ? Z_BUF_ERROR : err); 106 | } 107 | *dstlen = zs.total_out; 108 | return (deflateEnd(&zs)); 109 | } 110 | 111 | static inline int 112 | z_compress(void *dst, size_t *dstlen, const void *src, size_t srclen) 113 | { 114 | return (z_compress_level(dst, dstlen, src, srclen, 115 | Z_DEFAULT_COMPRESSION)); 116 | } 117 | 118 | 119 | int spl_zlib_init(void); 120 | void spl_zlib_fini(void); 121 | 122 | #endif /* SPL_ZMOD_H */ 123 | -------------------------------------------------------------------------------- /module/spl/spl-time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | 35 | /* 36 | * gethrtime() provides high-resolution timestamps with machine-dependent origin 37 | . 38 | * Hence its primary use is to specify intervals. 39 | */ 40 | 41 | static hrtime_t 42 | zfs_abs_to_nano(uint64_t elapsed) 43 | { 44 | static mach_timebase_info_data_t sTimebaseInfo = { 0, 0 }; 45 | 46 | /* 47 | * If this is the first time we've run, get the timebase. 48 | * We can use denom == 0 to indicate that sTimebaseInfo is 49 | * uninitialised because it makes no sense to have a zero 50 | * denominator in a fraction. 51 | */ 52 | 53 | if ( sTimebaseInfo.denom == 0 ) { 54 | (void) clock_timebase_info(&sTimebaseInfo); 55 | } 56 | 57 | /* 58 | * Convert to nanoseconds. 59 | * return (elapsed * (uint64_t)sTimebaseInfo.numer)/(uint64_t)sTimebaseInfo.denom; 60 | * 61 | * Provided the final result is representable in 64 bits the following maneuver will 62 | * deliver that result without intermediate overflow. 63 | */ 64 | if (sTimebaseInfo.denom == sTimebaseInfo.numer) 65 | return elapsed; 66 | else if (sTimebaseInfo.denom == 1) 67 | return elapsed * (uint64_t)sTimebaseInfo.numer; 68 | else { 69 | /* Decompose elapsed = eta32 * 2^32 + eps32: */ 70 | uint64_t eta32 = elapsed >> 32; 71 | uint64_t eps32 = elapsed & 0x00000000ffffffffLL; 72 | 73 | uint32_t numer = sTimebaseInfo.numer, denom = sTimebaseInfo.denom; 74 | 75 | /* Form product of elapsed64 (decomposed) and numer: */ 76 | uint64_t mu64 = numer * eta32; 77 | uint64_t lambda64 = numer * eps32; 78 | 79 | /* Divide the constituents by denom: */ 80 | uint64_t q32 = mu64/denom; 81 | uint64_t r32 = mu64 - (q32 * denom); /* mu64 % denom */ 82 | 83 | return (q32 << 32) + ((r32 << 32) + lambda64)/denom; 84 | } 85 | } 86 | 87 | 88 | hrtime_t gethrtime(void) 89 | { 90 | static uint64_t start = 0; 91 | if (start == 0) 92 | start = mach_absolute_time(); 93 | return zfs_abs_to_nano(mach_absolute_time() - start); 94 | } 95 | 96 | 97 | void 98 | gethrestime(struct timespec *ts) 99 | { 100 | nanotime(ts); 101 | } 102 | 103 | time_t 104 | gethrestime_sec(void) 105 | { 106 | struct timeval tv; 107 | 108 | microtime(&tv); 109 | return (tv.tv_sec); 110 | } 111 | 112 | void 113 | hrt2ts(hrtime_t hrt, struct timespec *tsp) 114 | { 115 | uint32_t sec, nsec, tmp; 116 | 117 | tmp = (uint32_t)(hrt >> 30); 118 | sec = tmp - (tmp >> 2); 119 | sec = tmp - (sec >> 5); 120 | sec = tmp + (sec >> 1); 121 | sec = tmp - (sec >> 6) + 7; 122 | sec = tmp - (sec >> 3); 123 | sec = tmp + (sec >> 1); 124 | sec = tmp + (sec >> 3); 125 | sec = tmp + (sec >> 4); 126 | tmp = (sec << 7) - sec - sec - sec; 127 | tmp = (tmp << 7) - tmp - tmp - tmp; 128 | tmp = (tmp << 7) - tmp - tmp - tmp; 129 | nsec = (uint32_t)hrt - (tmp << 9); 130 | while (nsec >= NANOSEC) { 131 | nsec -= NANOSEC; 132 | sec++; 133 | } 134 | tsp->tv_sec = (time_t)sec; 135 | tsp->tv_nsec = nsec; 136 | } 137 | -------------------------------------------------------------------------------- /module/spl/spl-kobj.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | struct _buf * 36 | kobj_open_file(char *name) 37 | { 38 | struct vnode *vp; 39 | vfs_context_t vctx; 40 | struct _buf *file; 41 | int error; 42 | 43 | vctx = vfs_context_create((vfs_context_t)0); 44 | error = vnode_open(name, 0, 0, 0, &vp, vctx); 45 | (void) vfs_context_rele(vctx); 46 | 47 | if (error) { 48 | printf("kobj_open_file: \"%s\", err %d from vnode_open\n", name ? name : "", error); 49 | 50 | return ((struct _buf *)-1); 51 | } 52 | file = (struct _buf *)kmem_alloc(sizeof (struct _buf *), KM_SLEEP); 53 | file->_fd = (intptr_t)vp; 54 | 55 | return (file); 56 | } 57 | 58 | void 59 | kobj_close_file(struct _buf *file) 60 | { 61 | vfs_context_t vctx; 62 | 63 | vctx = vfs_context_create((vfs_context_t)0); 64 | (void) vnode_close((struct vnode *)file->_fd, 0, vctx); 65 | (void) vfs_context_rele(vctx); 66 | 67 | kmem_free(file, sizeof (struct _buf)); 68 | } 69 | 70 | int 71 | kobj_fstat(struct vnode *vp, struct bootstat *buf) 72 | { 73 | struct vnode_attr vattr; 74 | vfs_context_t vctx; 75 | int error; 76 | 77 | if (buf == NULL) 78 | return (-1); 79 | 80 | VATTR_INIT(&vattr); 81 | VATTR_WANTED(&vattr, va_mode); 82 | VATTR_WANTED(&vattr, va_data_size); 83 | vattr.va_mode = 0; 84 | vattr.va_data_size = 0; 85 | 86 | vctx = vfs_context_create((vfs_context_t)0); 87 | error = vnode_getattr(vp, &vattr, vctx); 88 | (void) vfs_context_rele(vctx); 89 | 90 | if (error == 0) { 91 | //buf->st_mode = (uint32_t)vattr.va_mode; 92 | buf->st_size = vattr.va_data_size; 93 | } 94 | return (error); 95 | } 96 | 97 | int 98 | kobj_read_file(struct _buf *file, char *buf, ssize_t size, offset_t off) 99 | { 100 | struct vnode *vp = (struct vnode *)file->_fd; 101 | vfs_context_t vctx; 102 | uio_t *auio; 103 | int count; 104 | int error; 105 | 106 | vctx = vfs_context_create((vfs_context_t)0); 107 | auio = uio_create(1, 0, UIO_SYSSPACE32, UIO_READ); 108 | uio_reset(auio, off, UIO_SYSSPACE32, UIO_READ); 109 | uio_addiov(auio, (uintptr_t)buf, size); 110 | 111 | error = VNOP_READ(vp, auio, 0, vctx); 112 | 113 | if (error) 114 | count = -1; 115 | else 116 | count = size - uio_resid(auio); 117 | 118 | uio_free(auio); 119 | (void) vfs_context_rele(vctx); 120 | 121 | return (count); 122 | } 123 | 124 | /* 125 | * Get the file size. 126 | * 127 | * Before root is mounted, files are compressed in the boot_archive ramdisk 128 | * (in the memory). kobj_fstat would return the compressed file size. 129 | * In order to get the uncompressed file size, read the file to the end and 130 | * count its size. 131 | */ 132 | int 133 | kobj_get_filesize(struct _buf *file, uint64_t *size) 134 | { 135 | /* 136 | * In OSX, the root will always be mounted, so we can 137 | * just use kobj_fstat to stat the file 138 | */ 139 | struct bootstat bst; 140 | 141 | if (kobj_fstat((struct vnode *)file->_fd, &bst) != 0) 142 | return (EIO); 143 | *size = bst.st_size; 144 | return (0); 145 | } 146 | -------------------------------------------------------------------------------- /module/spl/spl-thread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | uint64_t zfs_threads = 0; 39 | 40 | kthread_t * 41 | spl_thread_create( 42 | caddr_t stk, 43 | size_t stksize, 44 | void (*proc)(void *), 45 | void *arg, 46 | size_t len, 47 | /*struct proc *pp,*/ 48 | int state, 49 | #ifdef SPL_DEBUG_THREAD 50 | char *filename, 51 | int line, 52 | #endif 53 | pri_t pri) 54 | { 55 | kern_return_t result; 56 | thread_t thread; 57 | 58 | #ifdef SPL_DEBUG_THREAD 59 | printf("Start thread pri %d by '%s':%d\n", pri, 60 | filename, line); 61 | #endif 62 | 63 | result= kernel_thread_start((thread_continue_t)proc, arg, &thread); 64 | 65 | if (result != KERN_SUCCESS) 66 | return (NULL); 67 | 68 | /* Improve the priority when asked to do so */ 69 | if (pri > minclsyspri) { 70 | thread_precedence_policy_data_t policy; 71 | 72 | /* kernel priorities (osfmk/kern/sched.h) 73 | * 74 | * 96 Reserved (real-time) 75 | * 95 Kernel mode only 76 | * A 77 | * + 78 | * (16 levels) 79 | * + 80 | * V 81 | * 80 Kernel mode only 82 | * 79 System high priority 83 | * 84 | * spl/include/sys/sysmacros.h 85 | * #define maxclsyspri 89 86 | * #define minclsyspri 81 BASEPRI_KERNEL 87 | * #define defclsyspri 81 BASEPRI_KERNEL 88 | * 89 | * Calling policy.importance = 10 will create 90 | * a default pri (81) at pri (91). 91 | * 92 | * So asking for pri (85) we do 85-81 = 4. 93 | * 94 | q * IllumOS priorities are: 95 | * #define MAXCLSYSPRI 99 96 | * #define MINCLSYSPRI 60 97 | */ 98 | 99 | policy.importance = (pri - minclsyspri); 100 | 101 | thread_policy_set(thread, 102 | THREAD_PRECEDENCE_POLICY, 103 | (thread_policy_t)&policy, 104 | THREAD_PRECEDENCE_POLICY_COUNT); 105 | } 106 | 107 | thread_deallocate(thread); 108 | 109 | atomic_inc_64(&zfs_threads); 110 | 111 | return ((kthread_t *)thread); 112 | } 113 | 114 | kthread_t * 115 | spl_current_thread(void) 116 | { 117 | thread_t cur_thread = current_thread(); 118 | return ((kthread_t *)cur_thread); 119 | } 120 | 121 | void spl_thread_exit(void) 122 | { 123 | atomic_dec_64(&zfs_threads); 124 | 125 | tsd_thread_exit(); 126 | (void) thread_terminate(current_thread()); 127 | } 128 | 129 | 130 | /* 131 | * IllumOS has callout.c - place it here until we find a better place 132 | */ 133 | callout_id_t 134 | timeout_generic(int type, void (*func)(void *), void *arg, 135 | hrtime_t expiration, hrtime_t resolution, int flags) 136 | { 137 | struct timespec ts; 138 | hrt2ts(expiration, &ts); 139 | bsd_timeout(func, arg, &ts); 140 | /* bsd_untimeout() requires func and arg to cancel the timeout, so 141 | * pass it back as the callout_id. If we one day were to implement 142 | * untimeout_generic() they would pass it back to us 143 | */ 144 | return (callout_id_t)arg; 145 | } 146 | -------------------------------------------------------------------------------- /config/spl-meta.m4: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Written by Chris Dunlap . 3 | # Modified by Brian Behlendorf . 4 | ############################################################################### 5 | # SPL_AC_META: Read metadata from the META file. When building from a 6 | # git repository the SPL_META_RELEASE field will be overwritten if there 7 | # is an annotated tag matching the form SPL_META_NAME-SPL_META_VERSION-*. 8 | # This allows for working builds to be uniquely identified using the git 9 | # commit hash. 10 | ############################################################################### 11 | 12 | AC_DEFUN([SPL_AC_META], [ 13 | AC_PROG_AWK 14 | AC_MSG_CHECKING([metadata]) 15 | 16 | META="$srcdir/META" 17 | _spl_ac_meta_type="none" 18 | if test -f "$META"; then 19 | _spl_ac_meta_type="META file" 20 | 21 | SPL_META_NAME=_SPL_AC_META_GETVAL([(?:NAME|PROJECT|PACKAGE)]); 22 | if test -n "$SPL_META_NAME"; then 23 | AC_DEFINE_UNQUOTED([SPL_META_NAME], ["$SPL_META_NAME"], 24 | [Define the project name.] 25 | ) 26 | AC_SUBST([SPL_META_NAME]) 27 | fi 28 | 29 | SPL_META_VERSION=_SPL_AC_META_GETVAL([VERSION]); 30 | if test -n "$SPL_META_VERSION"; then 31 | AC_DEFINE_UNQUOTED([SPL_META_VERSION], ["$SPL_META_VERSION"], 32 | [Define the project version.] 33 | ) 34 | AC_SUBST([SPL_META_VERSION]) 35 | fi 36 | 37 | SPL_META_RELEASE=_SPL_AC_META_GETVAL([RELEASE]); 38 | if git rev-parse --git-dir > /dev/null 2>&1; then 39 | _match="${SPL_META_NAME}-${SPL_META_VERSION}*" 40 | _alias=$(git describe --tags --match=${_match} 2>/dev/null) 41 | _release=$(echo ${_alias}|cut -f3- -d'-') 42 | if test -n "${_release}"; then 43 | SPL_META_RELEASE=${_release} 44 | _spl_ac_meta_type="git describe" 45 | fi 46 | fi 47 | 48 | if test -n "$SPL_META_RELEASE"; then 49 | AC_DEFINE_UNQUOTED([SPL_META_RELEASE], ["$SPL_META_RELEASE"], 50 | [Define the project release.] 51 | ) 52 | AC_SUBST([SPL_META_RELEASE]) 53 | fi 54 | 55 | if test -n "$SPL_META_NAME" -a -n "$SPL_META_VERSION"; then 56 | SPL_META_ALIAS="$SPL_META_NAME-$SPL_META_VERSION" 57 | test -n "$SPL_META_RELEASE" && 58 | SPL_META_ALIAS="$SPL_META_ALIAS-$SPL_META_RELEASE" 59 | AC_DEFINE_UNQUOTED([SPL_META_ALIAS], 60 | ["$SPL_META_ALIAS"], 61 | [Define the project alias string.] 62 | ) 63 | AC_SUBST([SPL_META_ALIAS]) 64 | fi 65 | 66 | SPL_META_DATA=_SPL_AC_META_GETVAL([DATE]); 67 | if test -n "$SPL_META_DATA"; then 68 | AC_DEFINE_UNQUOTED([SPL_META_DATA], ["$SPL_META_DATA"], 69 | [Define the project release date.] 70 | ) 71 | AC_SUBST([SPL_META_DATA]) 72 | fi 73 | 74 | SPL_META_AUTHOR=_SPL_AC_META_GETVAL([AUTHOR]); 75 | if test -n "$SPL_META_AUTHOR"; then 76 | AC_DEFINE_UNQUOTED([SPL_META_AUTHOR], ["$SPL_META_AUTHOR"], 77 | [Define the project author.] 78 | ) 79 | AC_SUBST([SPL_META_AUTHOR]) 80 | fi 81 | 82 | m4_pattern_allow([^LT_(CURRENT|REVISION|AGE)$]) 83 | SPL_META_LT_CURRENT=_SPL_AC_META_GETVAL([LT_CURRENT]); 84 | SPL_META_LT_REVISION=_SPL_AC_META_GETVAL([LT_REVISION]); 85 | SPL_META_LT_AGE=_SPL_AC_META_GETVAL([LT_AGE]); 86 | if test -n "$SPL_META_LT_CURRENT" \ 87 | -o -n "$SPL_META_LT_REVISION" \ 88 | -o -n "$SPL_META_LT_AGE"; then 89 | test -n "$SPL_META_LT_CURRENT" || SPL_META_LT_CURRENT="0" 90 | test -n "$SPL_META_LT_REVISION" || SPL_META_LT_REVISION="0" 91 | test -n "$SPL_META_LT_AGE" || SPL_META_LT_AGE="0" 92 | AC_DEFINE_UNQUOTED([SPL_META_LT_CURRENT], 93 | ["$SPL_META_LT_CURRENT"], 94 | [Define the libtool library 'current' 95 | version information.] 96 | ) 97 | AC_DEFINE_UNQUOTED([SPL_META_LT_REVISION], 98 | ["$SPL_META_LT_REVISION"], 99 | [Define the libtool library 'revision' 100 | version information.] 101 | ) 102 | AC_DEFINE_UNQUOTED([SPL_META_LT_AGE], ["$SPL_META_LT_AGE"], 103 | [Define the libtool library 'age' 104 | version information.] 105 | ) 106 | AC_SUBST([SPL_META_LT_CURRENT]) 107 | AC_SUBST([SPL_META_LT_REVISION]) 108 | AC_SUBST([SPL_META_LT_AGE]) 109 | fi 110 | fi 111 | 112 | AC_MSG_RESULT([$_spl_ac_meta_type]) 113 | ] 114 | ) 115 | 116 | AC_DEFUN([_SPL_AC_META_GETVAL], 117 | [`perl -n\ 118 | -e "BEGIN { \\$key=shift @ARGV; }"\ 119 | -e "next unless s/^\s*\\$key@<:@:=@:>@//i;"\ 120 | -e "s/^((?:@<:@^'\"#@:>@*(?:(@<:@'\"@:>@)@<:@^\2@:>@*\2)*)*)#.*/\\@S|@1/;"\ 121 | -e "s/^\s+//;"\ 122 | -e "s/\s+$//;"\ 123 | -e "s/^(@<:@'\"@:>@)(.*)\1/\\@S|@2/;"\ 124 | -e "\\$val=\\$_;"\ 125 | -e "END { print \\$val if defined \\$val; }"\ 126 | '$1' $META`]dnl 127 | ) 128 | -------------------------------------------------------------------------------- /include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * 27 | */ 28 | 29 | #ifndef _SPL_TYPES_H 30 | #define _SPL_TYPES_H 31 | 32 | #define likely(x) __builtin_expect(!!(x), 1) 33 | #define unlikely(x) __builtin_expect(!!(x), 0) 34 | 35 | #include_next 36 | #include 37 | #include 38 | 39 | /* Avoid kcdata.h header error */ 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | extern unsigned long strnlen(const char *, unsigned long); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #include 51 | 52 | 53 | #include 54 | 55 | 56 | 57 | #if 0 58 | #ifndef HAVE_UINTPTR_T 59 | typedef unsigned long uintptr_t; 60 | #endif 61 | #endif 62 | 63 | #ifndef ULLONG_MAX 64 | #define ULLONG_MAX (~0ULL) 65 | #endif 66 | 67 | #ifndef LLONG_MAX 68 | #define LLONG_MAX ((long long)(~0ULL>>1)) 69 | #endif 70 | 71 | #if 0 72 | typedef unsigned long intptr_t; 73 | typedef unsigned long long u_offset_t; 74 | typedef struct task_struct kthread_t; 75 | typedef struct task_struct proc_t; 76 | typedef struct vmem { } vmem_t; 77 | typedef struct timespec timestruc_t; /* definition per SVr4 */ 78 | typedef struct timespec timespec_t; 79 | typedef u_longlong_t len_t; 80 | typedef longlong_t diskaddr_t; 81 | typedef ushort_t o_mode_t; 82 | typedef uint_t major_t; 83 | typedef ulong_t pfn_t; 84 | typedef long spgcnt_t; 85 | typedef short index_t; 86 | typedef int id_t; 87 | 88 | extern proc_t p0; 89 | typedef enum { B_FALSE=0, B_TRUE=1 } boolean_t; 90 | #endif 91 | 92 | enum { B_FALSE=0, B_TRUE=1 }; 93 | typedef short pri_t; 94 | typedef unsigned long ulong_t; 95 | typedef unsigned long long u_longlong_t; 96 | typedef unsigned long long rlim64_t; 97 | typedef unsigned long long loff_t; 98 | typedef long long longlong_t; 99 | typedef unsigned char uchar_t; 100 | typedef unsigned int uint_t; 101 | typedef unsigned short ushort_t; 102 | typedef void *spinlock_t; 103 | typedef long long offset_t; 104 | typedef struct timespec timestruc_t; /* definition per SVr4 */ 105 | typedef struct timespec timespec_t; 106 | typedef ulong_t pgcnt_t; 107 | typedef unsigned int umode_t ; 108 | #define NODEV32 (dev32_t)(-1) 109 | typedef uint32_t dev32_t; 110 | typedef uint_t minor_t; 111 | 112 | #define EBADE EBADMACHO 113 | 114 | #include 115 | #define FCREAT O_CREAT 116 | #define FTRUNC O_TRUNC 117 | #define FEXCL O_EXCL 118 | #define FNOCTTY O_NOCTTY 119 | //#define FASYNC O_SYNC 120 | #define FNOFOLLOW O_NOFOLLOW 121 | 122 | #ifdef __APPLE__ 123 | #define FSYNC O_SYNC /* file (data+inode) integrity while writing */ 124 | #define FDSYNC O_DSYNC /* file data only integrity while writing */ 125 | #define FOFFMAX 0x0000 /* not used */ 126 | #define FRSYNC 0x0000 /* not used */ 127 | #else 128 | #define FRSYNC 0x8000 /* sync read operations at same level of */ 129 | /* integrity as specified for writes by */ 130 | /* FSYNC and FDSYNC flags */ 131 | #define FOFFMAX 0x2000 /* large file */ 132 | #endif 133 | 134 | #define EXPORT_SYMBOL(X) 135 | #define module_param(X,Y,Z) 136 | #define MODULE_PARM_DESC(X,Y) 137 | 138 | #ifdef __GNUC__ 139 | #define member_type(type, member) __typeof__ (((type *)0)->member) 140 | #else 141 | #define member_type(type, member) void 142 | #endif 143 | 144 | #define container_of(ptr, type, member) ((type *)( \ 145 | (char *)(member_type(type, member) *){ ptr } - offsetof(type, member))) 146 | 147 | #endif /* _SPL_TYPES_H */ 148 | -------------------------------------------------------------------------------- /include/sys/uio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 | /* All Rights Reserved */ 28 | 29 | /* 30 | * University Copyright- Copyright (c) 1982, 1986, 1988 31 | * The Regents of the University of California 32 | * All Rights Reserved 33 | * 34 | * University Acknowledgment- Portions of this document are derived from 35 | * software developed by the University of California, Berkeley, and its 36 | * contributors. 37 | */ 38 | 39 | 40 | #ifndef _SPL_UIO_H 41 | #define _SPL_UIO_H 42 | 43 | 44 | // OSX defines "uio_t" as "struct uio *" 45 | // ZFS defines "uio_t" as "struct uio" 46 | #undef uio_t 47 | #include_next 48 | #define uio_t struct uio 49 | 50 | #include 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | typedef struct iovec iovec_t; 57 | 58 | typedef enum uio_seg uio_seg_t; 59 | typedef enum uio_rw uio_rw_t; 60 | 61 | 62 | 63 | #if 0 64 | typedef enum uio_rw { 65 | UIO_READ = 0, 66 | UIO_WRITE = 1, 67 | } uio_rw_t; 68 | 69 | typedef enum uio_seg { 70 | UIO_USERSPACE = 0, 71 | UIO_SYSSPACE = 1, 72 | UIO_USERISPACE= 2, 73 | } uio_seg_t; 74 | 75 | 76 | 77 | typedef struct uio { 78 | //struct uio { 79 | struct iovec *uio_iov; 80 | int uio_iovcnt; 81 | offset_t uio_loffset; 82 | uio_seg_t uio_segflg; 83 | uint16_t uio_fmode; 84 | uint16_t uio_extflg; 85 | offset_t uio_limit; 86 | ssize_t uio_resid; 87 | } uio_t; 88 | //} ; 89 | 90 | #endif 91 | 92 | typedef struct aio_req { 93 | uio_t *aio_uio; 94 | void *aio_private; 95 | } aio_req_t; 96 | 97 | typedef enum xuio_type { 98 | UIOTYPE_ASYNCIO, 99 | UIOTYPE_ZEROCOPY, 100 | } xuio_type_t; 101 | 102 | 103 | #define UIOA_IOV_MAX 16 104 | 105 | typedef struct uioa_page_s { 106 | int uioa_pfncnt; 107 | void **uioa_ppp; 108 | caddr_t uioa_base; 109 | size_t uioa_len; 110 | } uioa_page_t; 111 | 112 | typedef struct xuio { 113 | uio_t *xu_uio; 114 | enum xuio_type xu_type; 115 | union { 116 | struct { 117 | uint32_t xu_a_state; 118 | ssize_t xu_a_mbytes; 119 | uioa_page_t *xu_a_lcur; 120 | void **xu_a_lppp; 121 | void *xu_a_hwst[4]; 122 | uioa_page_t xu_a_locked[UIOA_IOV_MAX]; 123 | } xu_aio; 124 | 125 | struct { 126 | int xu_zc_rw; 127 | void *xu_zc_priv; 128 | } xu_zc; 129 | } xu_ext; 130 | } xuio_t; 131 | 132 | #define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv 133 | #define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw 134 | 135 | 136 | /* 137 | * same as uiomove() but doesn't modify uio structure. 138 | * return in cbytes how many bytes were copied. 139 | */ 140 | static inline int uiocopy(const char *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes) \ 141 | { \ 142 | int result; \ 143 | struct uio *nuio = uio_duplicate(uio); \ 144 | unsigned long long x = uio_resid(uio); \ 145 | if (!nuio) return ENOMEM; \ 146 | uio_setrw(nuio, rw); \ 147 | result = uiomove(p,n,nuio); \ 148 | *cbytes = x-uio_resid(nuio); \ 149 | uio_free(nuio); \ 150 | return result; \ 151 | } 152 | 153 | 154 | // Apple's uiomove puts the uio_rw in uio_create 155 | #define uiomove(A,B,C,D) uiomove((A),(B),(D)) 156 | #define uioskip(A,B) uio_update((A), (B)) 157 | 158 | 159 | #ifdef __cplusplus 160 | } 161 | #endif 162 | #endif /* SPL_UIO_H */ 163 | -------------------------------------------------------------------------------- /include/sys/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | 27 | #ifndef _SPL_LIST_H 28 | #define _SPL_LIST_H 29 | 30 | #include 31 | 32 | /* 33 | * NOTE: I have implemented the Solaris list API in terms of the native 34 | * linux API. This has certain advantages in terms of leveraging the linux 35 | * list debugging infrastructure, but it also means that the internals of a 36 | * list differ slightly than on Solaris. This is not a problem as long as 37 | * all callers stick to the published API. The two major differences are: 38 | * 39 | * 1) A list_node_t is mapped to a linux list_head struct which changes 40 | * the name of the list_next/list_prev pointers to next/prev respectively. 41 | * 42 | * 2) A list_node_t which is not attached to a list on Solaris is denoted 43 | * by having its list_next/list_prev pointers set to NULL. Under linux 44 | * the next/prev pointers are set to LIST_POISON1 and LIST_POISON2 45 | * respectively. At this moment this only impacts the implementation 46 | * of the list_link_init() and list_link_active() functions. 47 | */ 48 | 49 | //typedef struct list_head list_node_t; 50 | 51 | typedef struct list_node { 52 | struct list_node *list_next; 53 | struct list_node *list_prev; 54 | } list_node_t; 55 | 56 | 57 | 58 | typedef struct list { 59 | size_t list_size; 60 | size_t list_offset; 61 | list_node_t list_head; 62 | } list_t; 63 | 64 | void list_create(list_t *, size_t, size_t); 65 | void list_destroy(list_t *); 66 | 67 | void list_insert_after(list_t *, void *, void *); 68 | void list_insert_before(list_t *, void *, void *); 69 | void list_insert_head(list_t *, void *); 70 | void list_insert_tail(list_t *, void *); 71 | void list_remove(list_t *, void *); 72 | void list_move_tail(list_t *, list_t *); 73 | 74 | void *list_head(list_t *); 75 | void *list_tail(list_t *); 76 | void *list_next(list_t *, void *); 77 | void *list_prev(list_t *, void *); 78 | 79 | int list_link_active(list_node_t *); 80 | int list_is_empty(list_t *); 81 | 82 | #define LIST_POISON1 NULL 83 | #define LIST_POISON2 NULL 84 | 85 | #define list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset)) 86 | #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset)) 87 | #define list_empty(a) ((a)->list_head.list_next == &(a)->list_head) 88 | 89 | 90 | static inline void 91 | list_link_init(list_node_t *node) 92 | { 93 | node->list_next = LIST_POISON1; 94 | node->list_prev = LIST_POISON2; 95 | } 96 | 97 | static inline void 98 | __list_del(list_node_t * prev, list_node_t * next) 99 | { 100 | next->list_prev = prev; 101 | prev->list_next = next; 102 | } 103 | 104 | static inline void list_del(list_node_t *entry) 105 | { 106 | __list_del(entry->list_prev, entry->list_next); 107 | entry->list_next = LIST_POISON1; 108 | entry->list_prev = LIST_POISON2; 109 | } 110 | 111 | static inline void * 112 | list_remove_head(list_t *list) 113 | { 114 | list_node_t *head = list->list_head.list_next; 115 | if (head == &list->list_head) 116 | return NULL; 117 | 118 | list_del(head); 119 | return list_object(list, head); 120 | } 121 | 122 | static inline void * 123 | list_remove_tail(list_t *list) 124 | { 125 | list_node_t *tail = list->list_head.list_prev; 126 | if (tail == &list->list_head) 127 | return NULL; 128 | 129 | list_del(tail); 130 | return list_object(list, tail); 131 | } 132 | 133 | static inline void 134 | list_link_replace(list_node_t *old_node, list_node_t *new_node) 135 | { 136 | ASSERT(list_link_active(old_node)); 137 | ASSERT(!list_link_active(new_node)); 138 | 139 | new_node->list_next = old_node->list_next; 140 | new_node->list_prev = old_node->list_prev; 141 | old_node->list_prev->list_next = new_node; 142 | old_node->list_next->list_prev = new_node; 143 | list_link_init(old_node); 144 | } 145 | 146 | #endif /* SPL_LIST_H */ 147 | -------------------------------------------------------------------------------- /include/spl-trace.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_TRACE_H 26 | #define _SPL_TRACE_H 27 | 28 | #define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT)) 29 | #define TCD_STOCK_PAGES (TCD_MAX_PAGES) 30 | #define TRACE_CONSOLE_BUFFER_SIZE 1024 31 | 32 | #define SPL_DEFAULT_MAX_DELAY (600 * HZ) 33 | #define SPL_DEFAULT_MIN_DELAY ((HZ + 1) / 2) 34 | #define SPL_DEFAULT_BACKOFF 2 35 | 36 | #define DL_NOTHREAD 0x0001 /* Do not create a new thread */ 37 | #define DL_SINGLE_CPU 0x0002 /* Collect pages from this CPU*/ 38 | 39 | typedef struct dumplog_priv { 40 | wait_queue_head_t dp_waitq; 41 | pid_t dp_pid; 42 | int dp_flags; 43 | atomic_t dp_done; 44 | } dumplog_priv_t; 45 | 46 | /* Three trace data types */ 47 | typedef enum { 48 | TCD_TYPE_PROC, 49 | TCD_TYPE_SOFTIRQ, 50 | TCD_TYPE_IRQ, 51 | TCD_TYPE_MAX 52 | } tcd_type_t; 53 | 54 | union trace_data_union { 55 | struct trace_cpu_data { 56 | /* pages with trace records not yet processed by tracefiled */ 57 | struct list_head tcd_pages; 58 | /* number of pages on ->tcd_pages */ 59 | unsigned long tcd_cur_pages; 60 | /* Max number of pages allowed on ->tcd_pages */ 61 | unsigned long tcd_max_pages; 62 | 63 | /* 64 | * preallocated pages to write trace records into. Pages from 65 | * ->tcd_stock_pages are moved to ->tcd_pages by spl_debug_msg(). 66 | * 67 | * This list is necessary, because on some platforms it's 68 | * impossible to perform efficient atomic page allocation in a 69 | * non-blockable context. 70 | * 71 | * Such platforms fill ->tcd_stock_pages "on occasion", when 72 | * tracing code is entered in blockable context. 73 | * 74 | * trace_get_tage_try() tries to get a page from 75 | * ->tcd_stock_pages first and resorts to atomic page 76 | * allocation only if this queue is empty. ->tcd_stock_pages 77 | * is replenished when tracing code is entered in blocking 78 | * context (darwin-tracefile.c:trace_get_tcd()). We try to 79 | * maintain TCD_STOCK_PAGES (40 by default) pages in this 80 | * queue. Atomic allocation is only required if more than 81 | * TCD_STOCK_PAGES pagesful are consumed by trace records all 82 | * emitted in non-blocking contexts. Which is quite unlikely. 83 | */ 84 | struct list_head tcd_stock_pages; 85 | /* number of pages on ->tcd_stock_pages */ 86 | unsigned long tcd_cur_stock_pages; 87 | 88 | unsigned short tcd_shutting_down; 89 | unsigned short tcd_cpu; 90 | unsigned short tcd_type; 91 | /* The factors to share debug memory. */ 92 | unsigned short tcd_pages_factor; 93 | 94 | /* 95 | * This spinlock is needed to workaround the problem of 96 | * set_cpus_allowed() being GPL-only. Since we cannot 97 | * schedule a thread on a specific CPU when dumping the 98 | * pages, we must use the spinlock for mutual exclusion. 99 | */ 100 | spinlock_t tcd_lock; 101 | unsigned long tcd_lock_flags; 102 | } tcd; 103 | char __pad[L1_CACHE_ALIGN(sizeof(struct trace_cpu_data))]; 104 | }; 105 | 106 | extern union trace_data_union (*trace_data[TCD_TYPE_MAX])[NR_CPUS]; 107 | 108 | #define tcd_for_each(tcd, i, j) \ 109 | for (i = 0; i < TCD_TYPE_MAX && trace_data[i]; i++) \ 110 | for (j = 0, ((tcd) = &(*trace_data[i])[j].tcd); \ 111 | j < max_ncpus; j++, (tcd) = &(*trace_data[i])[j].tcd) 112 | 113 | #define tcd_for_each_type_lock(tcd, i, cpu) \ 114 | for (i = 0; i < TCD_TYPE_MAX && trace_data[i] && \ 115 | (tcd = &(*trace_data[i])[cpu].tcd) && \ 116 | trace_lock_tcd(tcd); trace_unlock_tcd(tcd), i++) 117 | 118 | struct trace_page { 119 | struct page *page; /* page itself */ 120 | struct list_head linkage; /* Used by trace_data_union */ 121 | unsigned int used; /* number of bytes used within this page */ 122 | unsigned short cpu; /* cpu that owns this page */ 123 | unsigned short type; /* type(context) of this page */ 124 | }; 125 | 126 | struct page_collection { 127 | struct list_head pc_pages; 128 | spinlock_t pc_lock; 129 | int pc_want_daemon_pages; 130 | }; 131 | 132 | #endif /* SPL_TRACE_H */ 133 | -------------------------------------------------------------------------------- /include/rpc/xdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | * 21 | * Copyright (c) 1989, 2011, Oracle and/or its affiliates. All rights reserved. 22 | */ 23 | /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 24 | /* All Rights Reserved */ 25 | /* 26 | * Portions of this source code were derived from Berkeley 27 | * 4.3 BSD under license from the Regents of the University of 28 | * California. 29 | */ 30 | 31 | /* 32 | * xdr.h, External Data Representation Serialization Routines. 33 | * 34 | */ 35 | 36 | #ifndef _SPL_RPC_XDR_H 37 | #define _SPL_RPC_XDR_H 38 | 39 | 40 | #include 41 | #include 42 | 43 | /* 44 | * XDR enums and types. 45 | */ 46 | enum xdr_op { 47 | XDR_ENCODE, 48 | XDR_DECODE 49 | }; 50 | 51 | struct xdr_ops; 52 | 53 | typedef struct { 54 | struct xdr_ops *x_ops; /* Also used to let caller know if 55 | xdrmem_create() succeeds (sigh..) */ 56 | caddr_t x_addr; /* Current buffer addr */ 57 | caddr_t x_addr_end; /* End of the buffer */ 58 | enum xdr_op x_op; /* Stream direction */ 59 | } XDR; 60 | 61 | typedef bool_t (*xdrproc_t)(XDR *xdrs, void *ptr); 62 | 63 | struct xdr_ops { 64 | bool_t (*xdr_control)(XDR *, int, void *); 65 | 66 | bool_t (*xdr_char)(XDR *, char *); 67 | bool_t (*xdr_u_short)(XDR *, unsigned short *); 68 | bool_t (*xdr_u_int)(XDR *, unsigned *); 69 | bool_t (*xdr_u_longlong_t)(XDR *, u_longlong_t *); 70 | 71 | bool_t (*xdr_opaque)(XDR *, caddr_t, const uint_t); 72 | bool_t (*xdr_string)(XDR *, char **, const uint_t); 73 | bool_t (*xdr_array)(XDR *, caddr_t *, uint_t *, const uint_t, 74 | const uint_t, const xdrproc_t); 75 | }; 76 | 77 | /* 78 | * XDR control operator. 79 | */ 80 | #define XDR_GET_BYTES_AVAIL 1 81 | 82 | struct xdr_bytesrec { 83 | bool_t xc_is_last_record; 84 | size_t xc_num_avail; 85 | }; 86 | 87 | /* 88 | * XDR functions. 89 | */ 90 | void xdrmem_create(XDR *xdrs, const caddr_t addr, const uint_t size, 91 | const enum xdr_op op); 92 | #define xdr_destroy(xdrs) ((void) 0) /* Currently not needed. If needed later, 93 | we'll add it to struct xdr_ops */ 94 | 95 | #define xdr_control(xdrs, req, info) (xdrs)->x_ops->xdr_control((xdrs), \ 96 | (req), (info)) 97 | 98 | /* 99 | * For precaution, the following are defined as static inlines instead of macros 100 | * to get some amount of type safety. 101 | * 102 | * Also, macros wouldn't work in the case where typecasting is done, because it 103 | * must be possible to reference the functions' addresses by these names. 104 | */ 105 | static inline bool_t xdr_char(XDR *xdrs, char *cp) 106 | { 107 | return xdrs->x_ops->xdr_char(xdrs, cp); 108 | } 109 | 110 | static inline bool_t xdr_u_short(XDR *xdrs, unsigned short *usp) 111 | { 112 | return xdrs->x_ops->xdr_u_short(xdrs, usp); 113 | } 114 | 115 | static inline bool_t xdr_short(XDR *xdrs, short *sp) 116 | { 117 | //BUILD_BUG_ON(sizeof(short) != 2); 118 | return xdrs->x_ops->xdr_u_short(xdrs, (unsigned short *) sp); 119 | } 120 | 121 | static inline bool_t xdr_u_int(XDR *xdrs, unsigned *up) 122 | { 123 | return xdrs->x_ops->xdr_u_int(xdrs, up); 124 | } 125 | 126 | static inline bool_t xdr_int(XDR *xdrs, int *ip) 127 | { 128 | //BUILD_BUG_ON(sizeof(int) != 4); 129 | return xdrs->x_ops->xdr_u_int(xdrs, (unsigned *) ip); 130 | } 131 | 132 | static inline bool_t xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp) 133 | { 134 | return xdrs->x_ops->xdr_u_longlong_t(xdrs, ullp); 135 | } 136 | 137 | static inline bool_t xdr_longlong_t(XDR *xdrs, longlong_t *llp) 138 | { 139 | //BUILD_BUG_ON(sizeof(longlong_t) != 8); 140 | return xdrs->x_ops->xdr_u_longlong_t(xdrs, (u_longlong_t *) llp); 141 | } 142 | 143 | /* 144 | * Fixed-length opaque data. 145 | */ 146 | static inline bool_t xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt) 147 | { 148 | return xdrs->x_ops->xdr_opaque(xdrs, cp, cnt); 149 | } 150 | 151 | /* 152 | * Variable-length string. 153 | * The *sp buffer must have (maxsize + 1) bytes. 154 | */ 155 | static inline bool_t xdr_string(XDR *xdrs, char **sp, const uint_t maxsize) 156 | { 157 | return xdrs->x_ops->xdr_string(xdrs, sp, maxsize); 158 | } 159 | 160 | /* 161 | * Variable-length arrays. 162 | */ 163 | static inline bool_t xdr_array(XDR *xdrs, caddr_t *arrp, uint_t *sizep, 164 | const uint_t maxsize, const uint_t elsize, const xdrproc_t elproc) 165 | { 166 | return xdrs->x_ops->xdr_array(xdrs, arrp, sizep, maxsize, elsize, 167 | elproc); 168 | } 169 | 170 | #endif /* SPL_RPC_XDR_H */ 171 | -------------------------------------------------------------------------------- /module/spl/spl-list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | /* 22 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 | * Use is subject to license terms. 24 | */ 25 | 26 | /* 27 | * Generic doubly-linked list implementation 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | #define list_insert_after_node(list, node, object) { \ 37 | list_node_t *lnew = list_d2l(list, object); \ 38 | lnew->list_prev = node; \ 39 | lnew->list_next = node->list_next; \ 40 | node->list_next->list_prev = lnew; \ 41 | node->list_next = lnew; \ 42 | } 43 | 44 | #define list_insert_before_node(list, node, object) { \ 45 | list_node_t *lnew = list_d2l(list, object); \ 46 | lnew->list_next = node; \ 47 | lnew->list_prev = node->list_prev; \ 48 | node->list_prev->list_next = lnew; \ 49 | node->list_prev = lnew; \ 50 | } 51 | 52 | void 53 | list_create(list_t *list, size_t size, size_t offset) 54 | { 55 | ASSERT(list); 56 | ASSERT(size > 0); 57 | ASSERT(size >= offset + sizeof (list_node_t)); 58 | 59 | list->list_size = size; 60 | list->list_offset = offset; 61 | list->list_head.list_next = list->list_head.list_prev = 62 | &list->list_head; 63 | } 64 | 65 | void 66 | list_destroy(list_t *list) 67 | { 68 | list_node_t *node = &list->list_head; 69 | 70 | ASSERT(list); 71 | ASSERT(list->list_head.list_next == node); 72 | ASSERT(list->list_head.list_prev == node); 73 | 74 | node->list_next = node->list_prev = NULL; 75 | } 76 | 77 | void 78 | list_insert_after(list_t *list, void *object, void *nobject) 79 | { 80 | if (object == NULL) { 81 | list_insert_head(list, nobject); 82 | } else { 83 | list_node_t *lold = list_d2l(list, object); 84 | list_insert_after_node(list, lold, nobject); 85 | } 86 | } 87 | 88 | void 89 | list_insert_before(list_t *list, void *object, void *nobject) 90 | { 91 | if (object == NULL) { 92 | list_insert_tail(list, nobject); 93 | } else { 94 | list_node_t *lold = list_d2l(list, object); 95 | list_insert_before_node(list, lold, nobject); 96 | } 97 | } 98 | 99 | void 100 | list_insert_head(list_t *list, void *object) 101 | { 102 | list_node_t *lold = &list->list_head; 103 | list_insert_after_node(list, lold, object); 104 | } 105 | 106 | void 107 | list_insert_tail(list_t *list, void *object) 108 | { 109 | list_node_t *lold = &list->list_head; 110 | list_insert_before_node(list, lold, object); 111 | } 112 | 113 | void 114 | list_remove(list_t *list, void *object) 115 | { 116 | list_node_t *lold = list_d2l(list, object); 117 | ASSERT(!list_empty(list)); 118 | ASSERT(lold->list_next != NULL); 119 | lold->list_prev->list_next = lold->list_next; 120 | lold->list_next->list_prev = lold->list_prev; 121 | lold->list_next = lold->list_prev = NULL; 122 | } 123 | 124 | 125 | void * 126 | list_head(list_t *list) 127 | { 128 | if (list_empty(list)) 129 | return (NULL); 130 | return (list_object(list, list->list_head.list_next)); 131 | } 132 | 133 | void * 134 | list_tail(list_t *list) 135 | { 136 | if (list_empty(list)) 137 | return (NULL); 138 | return (list_object(list, list->list_head.list_prev)); 139 | } 140 | 141 | void * 142 | list_next(list_t *list, void *object) 143 | { 144 | list_node_t *node = list_d2l(list, object); 145 | 146 | if (node->list_next != &list->list_head) 147 | return (list_object(list, node->list_next)); 148 | 149 | return (NULL); 150 | } 151 | 152 | void * 153 | list_prev(list_t *list, void *object) 154 | { 155 | list_node_t *node = list_d2l(list, object); 156 | 157 | if (node->list_prev != &list->list_head) 158 | return (list_object(list, node->list_prev)); 159 | 160 | return (NULL); 161 | } 162 | 163 | /* 164 | * Insert src list after dst list. Empty src list thereafter. 165 | */ 166 | void 167 | list_move_tail(list_t *dst, list_t *src) 168 | { 169 | list_node_t *dstnode = &dst->list_head; 170 | list_node_t *srcnode = &src->list_head; 171 | 172 | ASSERT(dst->list_size == src->list_size); 173 | ASSERT(dst->list_offset == src->list_offset); 174 | 175 | if (list_empty(src)) 176 | return; 177 | 178 | dstnode->list_prev->list_next = srcnode->list_next; 179 | srcnode->list_next->list_prev = dstnode->list_prev; 180 | dstnode->list_prev = srcnode->list_prev; 181 | srcnode->list_prev->list_next = dstnode; 182 | 183 | /* empty src list */ 184 | srcnode->list_next = srcnode->list_prev = srcnode; 185 | } 186 | 187 | int 188 | list_link_active(list_node_t *link) 189 | { 190 | return (link->list_next != NULL); 191 | } 192 | 193 | int 194 | list_is_empty(list_t *list) 195 | { 196 | return (list_empty(list)); 197 | } 198 | -------------------------------------------------------------------------------- /module/spl/spl-condvar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2013 Jorgen Lundman 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef SPL_DEBUG_MUTEX 34 | void spl_wdlist_settime(void *mpleak, uint64_t value); 35 | #endif 36 | 37 | void 38 | spl_cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg) 39 | { 40 | } 41 | 42 | void 43 | spl_cv_destroy(kcondvar_t *cvp) 44 | { 45 | } 46 | 47 | void 48 | spl_cv_signal(kcondvar_t *cvp) 49 | { 50 | wakeup_one((caddr_t)cvp); 51 | } 52 | 53 | void 54 | spl_cv_broadcast(kcondvar_t *cvp) 55 | { 56 | wakeup((caddr_t)cvp); 57 | } 58 | 59 | 60 | /* 61 | * Block on the indicated condition variable and 62 | * release the associated mutex while blocked. 63 | */ 64 | void 65 | spl_cv_wait(kcondvar_t *cvp, kmutex_t *mp, int flags, const char *msg) 66 | { 67 | if (msg != NULL && msg[0] == '&') 68 | ++msg; /* skip over '&' prefixes */ 69 | 70 | #ifdef SPL_DEBUG_MUTEX 71 | spl_wdlist_settime(mp->leak, 0); 72 | #endif 73 | mp->m_owner = NULL; 74 | (void) msleep(cvp, (lck_mtx_t *)&mp->m_lock, flags, msg, 0); 75 | mp->m_owner = current_thread(); 76 | #ifdef SPL_DEBUG_MUTEX 77 | spl_wdlist_settime(mp->leak, gethrestime_sec()); 78 | #endif 79 | } 80 | 81 | /* 82 | * Same as cv_wait except the thread will unblock at 'tim' 83 | * (an absolute time) if it hasn't already unblocked. 84 | * 85 | * Returns the amount of time left from the original 'tim' value 86 | * when it was unblocked. 87 | */ 88 | int 89 | spl_cv_timedwait(kcondvar_t *cvp, kmutex_t *mp, clock_t tim, int flags, 90 | const char *msg) 91 | { 92 | struct timespec ts; 93 | int result; 94 | uint64_t timenow; 95 | 96 | if (msg != NULL && msg[0] == '&') 97 | ++msg; /* skip over '&' prefixes */ 98 | 99 | timenow = zfs_lbolt(); 100 | 101 | // Check for events already in the past 102 | if (tim < timenow) 103 | return -1; // timedout 104 | 105 | // Compute the delta 106 | tim = tim - timenow; 107 | 108 | // figure out sec and nsec 109 | ts.tv_sec = (tim / hz); 110 | ts.tv_nsec = (tim % hz) * NSEC_PER_SEC / hz; 111 | 112 | // Both sec and nsec zero is a blocking call. (Not poll) 113 | if (ts.tv_sec == 0 && 114 | ts.tv_nsec == 0) 115 | ts.tv_nsec = 1000; 116 | 117 | // Sanity check 118 | if (ts.tv_sec > 400) { 119 | printf("cv_timedwait: would have waited %lds\n", ts.tv_sec); 120 | ts.tv_sec = 5; 121 | } 122 | #ifdef SPL_DEBUG_MUTEX 123 | spl_wdlist_settime(mp->leak, 0); 124 | #endif 125 | mp->m_owner = NULL; 126 | result = msleep(cvp, (lck_mtx_t *)&mp->m_lock, flags, msg, &ts); 127 | 128 | // msleep grabs the mutex, even if timeout/signal 129 | mp->m_owner = current_thread(); 130 | 131 | #ifdef SPL_DEBUG_MUTEX 132 | spl_wdlist_settime(mp->leak, gethrestime_sec()); 133 | #endif 134 | return (result == EWOULDBLOCK ? -1 : 0); 135 | } 136 | 137 | 138 | /* 139 | * Compatibility wrapper for the cv_timedwait_hires() Illumos interface. 140 | */ 141 | clock_t 142 | cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, 143 | hrtime_t res, int flag) 144 | { 145 | struct timespec ts; 146 | int result; 147 | hrtime_t time_left; 148 | 149 | if (res > 1) { 150 | /* 151 | * Align expiration to the specified resolution. 152 | */ 153 | if (flag & CALLOUT_FLAG_ROUNDUP) 154 | tim += res - 1; 155 | tim = (tim / res) * res; 156 | } 157 | 158 | if ((flag & CALLOUT_FLAG_ABSOLUTE)) { 159 | time_left = tim - gethrtime(); 160 | if (time_left <= 0) 161 | return (-1); 162 | tim = time_left; 163 | } 164 | 165 | ts.tv_sec = 0; 166 | ts.tv_nsec = tim; 167 | 168 | if (ts.tv_nsec <= 100) { 169 | printf("cv_timedwait_hires: warning, sleep is less that 100nsec %lds\n", 170 | ts.tv_nsec); 171 | ts.tv_nsec = 1000; // At least one microsecond 172 | } 173 | 174 | if (ts.tv_nsec > 400L * NSEC_PER_SEC) { 175 | printf("cv_timedwait_hires: will wait %llus -> forced to 5s\n", 176 | (uint64_t)ts.tv_nsec/NSEC_PER_SEC); 177 | ts.tv_nsec = 5 * NSEC_PER_SEC; 178 | } 179 | 180 | #ifdef SPL_DEBUG_MUTEX 181 | spl_wdlist_settime(mp->leak, 0); 182 | #endif 183 | mp->m_owner = NULL; 184 | result = msleep(cvp, (lck_mtx_t *)&mp->m_lock, PRIBIO, "cv_timedwait_hires", &ts); 185 | mp->m_owner = current_thread(); 186 | #ifdef SPL_DEBUG_MUTEX 187 | spl_wdlist_settime(mp->leak, gethrestime_sec()); 188 | #endif 189 | 190 | return (result == EWOULDBLOCK ? -1 : 0); 191 | 192 | } 193 | -------------------------------------------------------------------------------- /include/sys/avl_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #ifndef _AVL_IMPL_H 28 | #define _AVL_IMPL_H 29 | 30 | 31 | 32 | /* 33 | * This is a private header file. Applications should not directly include 34 | * this file. 35 | */ 36 | 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | 44 | /* 45 | * generic AVL tree implementation for kernel use 46 | * 47 | * There are 5 pieces of information stored for each node in an AVL tree 48 | * 49 | * pointer to less than child 50 | * pointer to greater than child 51 | * a pointer to the parent of this node 52 | * an indication [0/1] of which child I am of my parent 53 | * a "balance" (-1, 0, +1) indicating which child tree is taller 54 | * 55 | * Since they only need 3 bits, the last two fields are packed into the 56 | * bottom bits of the parent pointer on 64 bit machines to save on space. 57 | */ 58 | 59 | #ifndef _LP64 60 | 61 | struct avl_node { 62 | struct avl_node *avl_child[2]; /* left/right children */ 63 | struct avl_node *avl_parent; /* this node's parent */ 64 | unsigned short avl_child_index; /* my index in parent's avl_child[] */ 65 | short avl_balance; /* balance value: -1, 0, +1 */ 66 | }; 67 | 68 | #define AVL_XPARENT(n) ((n)->avl_parent) 69 | #define AVL_SETPARENT(n, p) ((n)->avl_parent = (p)) 70 | 71 | #define AVL_XCHILD(n) ((n)->avl_child_index) 72 | #define AVL_SETCHILD(n, c) ((n)->avl_child_index = (unsigned short)(c)) 73 | 74 | #define AVL_XBALANCE(n) ((n)->avl_balance) 75 | #define AVL_SETBALANCE(n, b) ((n)->avl_balance = (short)(b)) 76 | 77 | #else /* _LP64 */ 78 | 79 | /* 80 | * for 64 bit machines, avl_pcb contains parent pointer, balance and child_index 81 | * values packed in the following manner: 82 | * 83 | * |63 3| 2 |1 0 | 84 | * |-------------------------------------|-----------------|-------------| 85 | * | avl_parent hi order bits | avl_child_index | avl_balance | 86 | * | | | + 1 | 87 | * |-------------------------------------|-----------------|-------------| 88 | * 89 | */ 90 | struct avl_node { 91 | struct avl_node *avl_child[2]; /* left/right children nodes */ 92 | uintptr_t avl_pcb; /* parent, child_index, balance */ 93 | }; 94 | 95 | /* 96 | * macros to extract/set fields in avl_pcb 97 | * 98 | * pointer to the parent of the current node is the high order bits 99 | */ 100 | #define AVL_XPARENT(n) ((struct avl_node *)((n)->avl_pcb & ~7)) 101 | #define AVL_SETPARENT(n, p) \ 102 | ((n)->avl_pcb = (((n)->avl_pcb & 7) | (uintptr_t)(p))) 103 | 104 | /* 105 | * index of this node in its parent's avl_child[]: bit #2 106 | */ 107 | #define AVL_XCHILD(n) (((n)->avl_pcb >> 2) & 1) 108 | #define AVL_SETCHILD(n, c) \ 109 | ((n)->avl_pcb = (uintptr_t)(((n)->avl_pcb & ~4) | ((c) << 2))) 110 | 111 | /* 112 | * balance indication for a node, lowest 2 bits. A valid balance is 113 | * -1, 0, or +1, and is encoded by adding 1 to the value to get the 114 | * unsigned values of 0, 1, 2. 115 | */ 116 | #define AVL_XBALANCE(n) ((int)(((n)->avl_pcb & 3) - 1)) 117 | #define AVL_SETBALANCE(n, b) \ 118 | ((n)->avl_pcb = (uintptr_t)((((n)->avl_pcb & ~3) | ((b) + 1)))) 119 | 120 | #endif /* _LP64 */ 121 | 122 | 123 | 124 | /* 125 | * switch between a node and data pointer for a given tree 126 | * the value of "o" is tree->avl_offset 127 | */ 128 | #define AVL_NODE2DATA(n, o) ((void *)((uintptr_t)(n) - (o))) 129 | #define AVL_DATA2NODE(d, o) ((struct avl_node *)((uintptr_t)(d) + (o))) 130 | 131 | 132 | 133 | /* 134 | * macros used to create/access an avl_index_t 135 | */ 136 | #define AVL_INDEX2NODE(x) ((avl_node_t *)((x) & ~1)) 137 | #define AVL_INDEX2CHILD(x) ((x) & 1) 138 | #define AVL_MKINDEX(n, c) ((avl_index_t)(n) | (c)) 139 | 140 | 141 | /* 142 | * The tree structure. The fields avl_root, avl_compar, and avl_offset come 143 | * first since they are needed for avl_find(). We want them to fit into 144 | * a single 64 byte cache line to make avl_find() as fast as possible. 145 | */ 146 | struct avl_tree { 147 | struct avl_node *avl_root; /* root node in tree */ 148 | int (*avl_compar)(const void *, const void *); 149 | size_t avl_offset; /* offsetof(type, avl_link_t field) */ 150 | ulong_t avl_numnodes; /* number of nodes in the tree */ 151 | size_t avl_size; /* sizeof user type struct */ 152 | }; 153 | 154 | 155 | /* 156 | * This will only by used via AVL_NEXT() or AVL_PREV() 157 | */ 158 | extern void *avl_walk(struct avl_tree *, void *, int); 159 | 160 | #ifdef __cplusplus 161 | } 162 | #endif 163 | 164 | #endif /* _AVL_IMPL_H */ 165 | -------------------------------------------------------------------------------- /include/sys/kmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * 8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 | * or http://www.opensolaris.org/os/licensing. 10 | * See the License for the specific language governing permissions 11 | * and limitations under the License. 12 | * 13 | * When distributing Covered Code, include this CDDL HEADER in each 14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 | * If applicable, add the following below this CDDL HEADER, with the 16 | * fields enclosed by brackets "[]" replaced with your own identifying 17 | * information: Portions Copyright [yyyy] [name of copyright owner] 18 | * 19 | * CDDL HEADER END 20 | */ 21 | 22 | /* 23 | * 24 | * Copyright (C) 2008 MacZFS Project 25 | * Copyright (C) 2013 Jorgen Lundman 26 | * Copyright (C) 2017 Sean Doran 27 | * 28 | */ 29 | 30 | #ifndef _SPL_KMEM_H 31 | #define _SPL_KMEM_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | // XNU total amount of memory 46 | extern uint64_t physmem; 47 | 48 | #define KM_SLEEP 0x0000 /* can block for memory; success guaranteed */ 49 | #define KM_NOSLEEP 0x0001 /* cannot block for memory; may fail */ 50 | #define KM_PANIC 0x0002 /* if memory cannot be allocated, panic */ 51 | #define KM_PUSHPAGE 0x0004 /* can block for memory; may use reserve */ 52 | #define KM_NORMALPRI 0x0008 /* with KM_NOSLEEP, lower priority allocation */ 53 | #define KM_NODEBUG 0x0010 /* NOT IMPLEMENTED ON OSX */ 54 | #define KM_NO_VBA 0x0020 /* OSX: don't descend to the bucket layer */ 55 | #define KM_VMFLAGS 0x00ff /* flags that must match VM_* flags */ 56 | 57 | #define KM_FLAGS 0xffff /* all settable kmem flags */ 58 | 59 | /* 60 | * Kernel memory allocator: DDI interfaces. 61 | * See kmem_alloc(9F) for details. 62 | */ 63 | 64 | // Work around symbol collisions in XNU 65 | #define kmem_alloc(size, kmflags) zfs_kmem_alloc((size), (kmflags)) 66 | #define kmem_zalloc(size, kmflags) zfs_kmem_zalloc((size), (kmflags)) 67 | #define kmem_free(buf, size) zfs_kmem_free((buf), (size)) 68 | 69 | void* zfs_kmem_alloc(size_t size, int kmflags); 70 | void* zfs_kmem_zalloc(size_t size, int kmflags); 71 | void zfs_kmem_free(void *buf, size_t size); 72 | 73 | void spl_kmem_init(uint64_t); 74 | void spl_kmem_thread_init(void); 75 | void spl_kmem_mp_init(void); 76 | void spl_kmem_thread_fini(void); 77 | void spl_kmem_fini(void); 78 | 79 | size_t kmem_size(void); 80 | size_t kmem_used(void); 81 | int64_t kmem_avail(void); 82 | size_t kmem_num_pages_wanted(void); 83 | int spl_vm_pool_low(void); 84 | int32_t spl_minimal_physmem_p(void); 85 | int64_t spl_adjust_pressure(int64_t); 86 | int64_t spl_free_wrapper(void); 87 | int64_t spl_free_manual_pressure_wrapper(void); 88 | boolean_t spl_free_fast_pressure_wrapper(void); 89 | void spl_free_set_pressure(int64_t); 90 | void spl_free_set_fast_pressure(boolean_t); 91 | uint64_t spl_free_last_pressure_wrapper(void); 92 | 93 | #define KMC_NOTOUCH 0x00010000 94 | #define KMC_NODEBUG 0x00020000 95 | #define KMC_NOMAGAZINE 0x00040000 96 | #define KMC_NOHASH 0x00080000 97 | #define KMC_QCACHE 0x00100000 98 | #define KMC_KMEM_ALLOC 0x00200000 /* internal use only */ 99 | #define KMC_IDENTIFIER 0x00400000 /* internal use only */ 100 | #define KMC_PREFILL 0x00800000 101 | #define KMC_ARENA_SLAB 0x01000000 /* use a bigger kmem cache */ 102 | 103 | struct kmem_cache; 104 | 105 | typedef struct kmem_cache kmem_cache_t; 106 | 107 | /* Client response to kmem move callback */ 108 | typedef enum kmem_cbrc { 109 | KMEM_CBRC_YES, 110 | KMEM_CBRC_NO, 111 | KMEM_CBRC_LATER, 112 | KMEM_CBRC_DONT_NEED, 113 | KMEM_CBRC_DONT_KNOW 114 | } kmem_cbrc_t; 115 | 116 | #define POINTER_IS_VALID(p) (!((uintptr_t)(p) & 0x3)) 117 | #define POINTER_INVALIDATE(pp) (*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1)) 118 | 119 | kmem_cache_t *kmem_cache_create(char *name, size_t bufsize, size_t align, 120 | int (*constructor)(void *, void *, int), 121 | void (*destructor)(void *, void *), 122 | void (*reclaim)(void *), 123 | void *_private, vmem_t *vmp, int cflags); 124 | void kmem_cache_destroy(kmem_cache_t *cache); 125 | void *kmem_cache_alloc(kmem_cache_t *cache, int flags); 126 | void kmem_cache_free(kmem_cache_t *cache, void *buf); 127 | void kmem_cache_free_to_slab(kmem_cache_t *cache, void *buf); 128 | void kmem_cache_reap_now(kmem_cache_t *cache); 129 | void kmem_depot_ws_zero(kmem_cache_t *cache); 130 | void kmem_reap(void); 131 | void kmem_reap_idspace(void); 132 | kmem_cache_t *kmem_cache_buf_in_cache(kmem_cache_t *, void *); 133 | 134 | int kmem_debugging(void); 135 | void kmem_cache_set_move(kmem_cache_t *, 136 | kmem_cbrc_t (*)(void *, void *, size_t, void *)); 137 | 138 | void *calloc(size_t n, size_t s); 139 | char *kmem_asprintf(const char *fmt, ...); 140 | void strfree(char *str); 141 | char *kmem_vasprintf(const char *fmt, va_list ap); 142 | char *kmem_strstr(const char *in, const char *str); 143 | void strident_canon(char *s, size_t n); 144 | 145 | boolean_t spl_arc_no_grow(size_t, boolean_t, kmem_cache_t **); 146 | 147 | #ifdef __cplusplus 148 | } 149 | #endif 150 | 151 | #endif /* _SPL_KMEM_H */ 152 | --------------------------------------------------------------------------------