aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMatt Macy <mmacy@FreeBSD.org>2020-08-25 02:21:27 +0000
committerMatt Macy <mmacy@FreeBSD.org>2020-08-25 02:21:27 +0000
commit9e5787d2284e187abb5b654d924394a65772e004 (patch)
tree2ebf833af6b1953d4a683e2da830fe87bf3435e1 /sys
parent22df1ffd812f0395cdb7c0b1edae1f67b991562a (diff)
downloadsrc-9e5787d2284e187abb5b654d924394a65772e004.tar.gz
src-9e5787d2284e187abb5b654d924394a65772e004.zip
Merge OpenZFS support in to HEAD.
The primary benefit is maintaining a completely shared code base with the community allowing FreeBSD to receive new features sooner and with less effort. I would advise against doing 'zpool upgrade' or creating indispensable pools using new features until this change has had a month+ to soak. Work on merging FreeBSD support in to what was at the time "ZFS on Linux" began in August 2018. I first publicly proposed transitioning FreeBSD to (new) OpenZFS on December 18th, 2018. FreeBSD support in OpenZFS was finally completed in December 2019. A CFT for downstreaming OpenZFS support in to FreeBSD was first issued on July 8th. All issues that were reported have been addressed or, for a couple of less critical matters there are pull requests in progress with OpenZFS. iXsystems has tested and dogfooded extensively internally. The TrueNAS 12 release is based on OpenZFS with some additional features that have not yet made it upstream. Improvements include: project quotas, encrypted datasets, allocation classes, vectorized raidz, vectorized checksums, various command line improvements, zstd compression. Thanks to those who have helped along the way: Ryan Moeller, Allan Jude, Zack Welch, and many others. Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D25872
Notes
Notes: svn path=/head/; revision=364746
Diffstat (limited to 'sys')
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris.c3
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c296
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c210
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c148
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c64
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_misc.c54
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_policy.c429
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_sunddi.c194
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_sysevent.c338
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c252
-rw-r--r--sys/cddl/compat/opensolaris/kern/opensolaris_zone.c256
-rw-r--r--sys/cddl/compat/opensolaris/sys/acl.h39
-rw-r--r--sys/cddl/compat/opensolaris/sys/file.h64
-rw-r--r--sys/cddl/compat/opensolaris/sys/kobj.h60
-rw-r--r--sys/cddl/compat/opensolaris/sys/lock.h45
-rw-r--r--sys/cddl/compat/opensolaris/sys/misc.h1
-rw-r--r--sys/cddl/compat/opensolaris/sys/mman.h37
-rw-r--r--sys/cddl/compat/opensolaris/sys/modctl.h1
-rw-r--r--sys/cddl/compat/opensolaris/sys/mount.h41
-rw-r--r--sys/cddl/compat/opensolaris/sys/mutex.h77
-rw-r--r--sys/cddl/compat/opensolaris/sys/nvpair.h230
-rw-r--r--sys/cddl/compat/opensolaris/sys/param.h41
-rw-r--r--sys/cddl/compat/opensolaris/sys/proc.h105
-rw-r--r--sys/cddl/compat/opensolaris/sys/stat.h65
-rw-r--r--sys/cddl/compat/opensolaris/sys/systm.h47
-rw-r--r--sys/cddl/compat/opensolaris/sys/time.h95
-rw-r--r--sys/cddl/compat/opensolaris/sys/types.h101
-rw-r--r--sys/cddl/compat/opensolaris/sys/uio.h89
-rw-r--r--sys/cddl/compat/opensolaris/sys/vnode.h287
-rw-r--r--sys/cddl/contrib/opensolaris/common/acl/acl_common.c1765
-rw-r--r--sys/cddl/contrib/opensolaris/common/acl/acl_common.h69
-rw-r--r--sys/cddl/contrib/opensolaris/common/atomic/i386/opensolaris_atomic.S133
-rw-r--r--sys/cddl/contrib/opensolaris/common/avl/avl.c1063
-rw-r--r--sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c512
-rw-r--r--sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c3600
-rw-r--r--sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c118
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c310
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h111
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.c206
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.h52
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.c235
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.h90
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.c279
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.h58
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.c1380
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.h543
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.c399
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.h66
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c718
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.h131
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zpool_prop.c250
-rw-r--r--sys/cddl/contrib/opensolaris/common/zfs/zprop_common.c430
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c19
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c3
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/vnode.c94
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash19
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash.descrip1
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz430
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz4.descrip1
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/abd.c960
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/aggsum.c234
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c8569
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/blkptr.c152
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/bplist.c77
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/bpobj.c606
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/bptree.c301
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/bqueue.c111
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/cityhash.c63
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c4248
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf_stats.c242
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt.c1189
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt_zap.c165
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c2748
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_diff.c251
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_object.c444
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c2484
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_send.c3550
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_traverse.c712
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_tx.c1345
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_zfetch.c374
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dnode.c2418
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dnode_sync.c779
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_bookmark.c566
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dataset.c4252
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_deadlist.c561
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_deleg.c760
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_destroy.c1097
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_dir.c2184
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_pool.c1372
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_prop.c1211
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_scan.c4001
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_synctask.c256
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dsl_userhold.c667
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/edonr_zfs.c114
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/gzip.c69
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/README.zfs80
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lapi.c1283
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lapi.h24
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lauxlib.c791
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lauxlib.h176
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c296
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbitlib.c212
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lcode.c885
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lcode.h83
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lcompat.c102
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lcorolib.c154
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lctype.c52
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lctype.h93
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ldebug.c607
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ldebug.h34
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ldo.c691
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ldo.h46
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ldump.c173
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lfunc.c161
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lfunc.h33
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lgc.c1220
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lgc.h157
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/llex.c529
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/llex.h78
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/llimits.h308
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lmem.c99
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lmem.h57
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lobject.c283
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lobject.h606
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lopcodes.c107
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lopcodes.h288
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lparser.c1637
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lparser.h119
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstate.c321
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstate.h228
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstring.c185
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstring.h46
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c1050
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ltable.c589
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ltable.h45
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ltablib.c284
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ltm.c77
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/ltm.h57
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lua.h443
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/luaconf.h555
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lualib.h55
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lundump.c258
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lundump.h28
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lvm.c930
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lvm.h44
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lzio.c76
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lzio.h65
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lzjb.c129
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/metaslab.c4624
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/mmp.c750
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/multilist.c423
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/range_tree.c670
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/refcount.c321
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/rrwlock.c396
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sa.c2012
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sha256.c105
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/skein_zfs.c105
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c8972
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_checkpoint.c623
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c594
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_errlog.c406
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_history.c628
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c2523
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/space_map.c1073
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/space_reftree.c149
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/abd.h154
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/aggsum.h58
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/arc.h290
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/blkptr.h39
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/bplist.h57
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/bpobj.h95
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/bptree.h65
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/bqueue.h54
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/cityhash.h41
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dbuf.h417
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/ddt.h248
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h1028
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_impl.h315
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_objset.h221
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_send.h93
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_traverse.h69
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_tx.h152
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu_zfetch.h76
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dnode.h599
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_bookmark.h52
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_dataset.h457
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_deadlist.h89
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_deleg.h81
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_destroy.h68
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_dir.h209
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_pool.h191
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_prop.h115
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_scan.h188
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_synctask.h127
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dsl_userhold.h57
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/metaslab.h127
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/metaslab_impl.h501
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/mmp.h74
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/multilist.h107
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/range_tree.h124
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/refcount.h125
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/rrwlock.h112
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/sa.h170
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/sa_impl.h291
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa.h969
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_boot.h48
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_checkpoint.h44
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/spa_impl.h435
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/space_map.h230
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/space_reftree.h57
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/trim_map.h51
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/txg.h136
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/txg_impl.h125
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/uberblock.h50
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/uberblock_impl.h145
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/unique.h57
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev.h196
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_disk.h67
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_file.h49
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_impl.h571
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_indirect_births.h80
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_indirect_mapping.h141
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_initialize.h46
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_raidz.h50
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/vdev_removal.h96
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zap.h514
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zap_impl.h242
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zap_leaf.h248
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zcp.h185
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zcp_global.h35
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zcp_iter.h41
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zcp_prop.h34
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfeature.h73
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_acl.h248
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_context.h146
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_ctldir.h65
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_debug.h99
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_dir.h74
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_fuid.h132
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_ioctl.h466
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_onexit.h66
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_rlock.h90
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_sa.h142
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_stat.h55
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_vfsops.h192
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_znode.h374
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h464
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil_impl.h229
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h675
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_checksum.h119
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_compress.h128
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_impl.h256
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_priority.h43
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zrlock.h63
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zthr.h39
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zvol.h85
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c634
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/txg.c977
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/uberblock.c74
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/unique.c112
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c4520
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_cache.c434
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_disk.c971
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_file.c307
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c1193
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_indirect.c1849
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_indirect_births.c212
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_indirect_mapping.c593
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_initialize.c782
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_label.c1701
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_mirror.c779
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_missing.c113
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_queue.c1047
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_raidz.c2707
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_removal.c2156
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_root.c157
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zap.c1378
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zap_leaf.c849
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zap_micro.c1609
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp.c1432
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_get.c865
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_global.c89
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_iter.c531
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zcp_synctask.c360
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfeature.c505
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs.conf28
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_acl.c2778
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_byteswap.c199
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c1364
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_debug.c112
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c968
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_fm.c871
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_fuid.c762
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c7692
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_log.c688
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_onexit.c254
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_replay.c1069
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_rlock.c641
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_sa.c326
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c2813
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c6124
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c2388
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c3499
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c4386
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_checksum.c475
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_compress.c215
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_inject.c755
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zle.c86
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zrlock.c187
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zthr.c431
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c3347
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/os/callb.c438
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/os/fm.c1399
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/os/nvpair_alloc_system.c63
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/acl.h313
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/ccompile.h1
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/cpuvar.h830
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/dtrace.h15
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/dtrace_impl.h1
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/fm/fs/zfs.h97
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/fm/protocol.h369
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/fm/util.h102
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/fs/zfs.h1248
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/fs/zut.h93
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/nvpair.h351
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/nvpair_impl.h90
-rw-r--r--sys/cddl/contrib/opensolaris/uts/common/sys/vnode.h427
-rw-r--r--sys/cddl/dev/dtrace/amd64/dtrace_subr.c1
-rw-r--r--sys/cddl/dev/fbt/fbt.c1
-rw-r--r--sys/cddl/dev/profile/profile.c1
-rw-r--r--sys/cddl/dev/sdt/sdt.c1
-rw-r--r--sys/cddl/dev/systrace/systrace.c2
-rw-r--r--sys/conf/files395
-rw-r--r--sys/conf/files.amd6410
-rw-r--r--sys/conf/kern.pre.mk68
-rw-r--r--sys/conf/kmod.mk16
-rw-r--r--sys/modules/Makefile2
-rw-r--r--sys/modules/dtrace/dtaudit/Makefile4
-rw-r--r--sys/modules/dtrace/dtmalloc/Makefile4
-rw-r--r--sys/modules/dtrace/dtnfscl/Makefile4
-rw-r--r--sys/modules/dtrace/dtrace/Makefile8
-rw-r--r--sys/modules/dtrace/fasttrap/Makefile8
-rw-r--r--sys/modules/dtrace/fbt/Makefile7
-rw-r--r--sys/modules/dtrace/profile/Makefile4
-rw-r--r--sys/modules/dtrace/prototype/Makefile4
-rw-r--r--sys/modules/dtrace/sdt/Makefile5
-rw-r--r--sys/modules/dtrace/systrace/Makefile5
-rw-r--r--sys/modules/dtrace/systrace_freebsd32/Makefile5
-rw-r--r--sys/modules/dtrace/systrace_linux/Makefile5
-rw-r--r--sys/modules/dtrace/systrace_linux32/Makefile5
-rw-r--r--sys/modules/opensolaris/Makefile16
-rw-r--r--sys/modules/zfs/Makefile430
-rw-r--r--sys/modules/zfs/static_ccompile.h29
-rw-r--r--sys/modules/zfs/zfs_config.h711
-rw-r--r--sys/modules/zfs/zfs_gitrev.h5
-rw-r--r--sys/vm/vm.h2
356 files changed, 1445 insertions, 200934 deletions
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris.c b/sys/cddl/compat/opensolaris/kern/opensolaris.c
index f804a1b561d1..bed1f21235d5 100644
--- a/sys/cddl/compat/opensolaris/kern/opensolaris.c
+++ b/sys/cddl/compat/opensolaris/kern/opensolaris.c
@@ -37,6 +37,8 @@
#include <sys/module.h>
#include <sys/mutex.h>
+extern struct opensolaris_utsname utsname;
+
cpu_core_t cpu_core[MAXCPU];
kmutex_t cpu_lock;
solaris_cpu_t solaris_cpu[MAXCPU];
@@ -82,7 +84,6 @@ opensolaris_modevent(module_t mod __unused, int type, void *data __unused)
switch (type) {
case MOD_LOAD:
- utsname.nodename = prison0.pr_hostname;
break;
case MOD_UNLOAD:
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c b/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c
deleted file mode 100644
index fa23233833bb..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*-
- * Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kmem.h>
-#include <sys/debug.h>
-#include <sys/mutex.h>
-#include <sys/vmmeter.h>
-
-#include <vm/vm_page.h>
-#include <vm/vm_object.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_map.h>
-
-#ifdef KMEM_DEBUG
-#include <sys/queue.h>
-#include <sys/stack.h>
-#endif
-
-#ifdef _KERNEL
-MALLOC_DEFINE(M_SOLARIS, "solaris", "Solaris");
-#else
-#define malloc(size, type, flags) malloc(size)
-#define free(addr, type) free(addr)
-#endif
-
-#ifdef KMEM_DEBUG
-struct kmem_item {
- struct stack stack;
- LIST_ENTRY(kmem_item) next;
-};
-static LIST_HEAD(, kmem_item) kmem_items;
-static struct mtx kmem_items_mtx;
-MTX_SYSINIT(kmem_items_mtx, &kmem_items_mtx, "kmem_items", MTX_DEF);
-#endif /* KMEM_DEBUG */
-
-#include <sys/vmem.h>
-
-void *
-zfs_kmem_alloc(size_t size, int kmflags)
-{
- void *p;
-#ifdef KMEM_DEBUG
- struct kmem_item *i;
-
- size += sizeof(struct kmem_item);
-#endif
- p = malloc(size, M_SOLARIS, kmflags);
-#ifndef _KERNEL
- if (kmflags & KM_SLEEP)
- assert(p != NULL);
-#endif
-#ifdef KMEM_DEBUG
- if (p != NULL) {
- i = p;
- p = (u_char *)p + sizeof(struct kmem_item);
- stack_save(&i->stack);
- mtx_lock(&kmem_items_mtx);
- LIST_INSERT_HEAD(&kmem_items, i, next);
- mtx_unlock(&kmem_items_mtx);
- }
-#endif
- return (p);
-}
-
-void
-zfs_kmem_free(void *buf, size_t size __unused)
-{
-#ifdef KMEM_DEBUG
- if (buf == NULL) {
- printf("%s: attempt to free NULL\n", __func__);
- return;
- }
- struct kmem_item *i;
-
- buf = (u_char *)buf - sizeof(struct kmem_item);
- mtx_lock(&kmem_items_mtx);
- LIST_FOREACH(i, &kmem_items, next) {
- if (i == buf)
- break;
- }
- ASSERT(i != NULL);
- LIST_REMOVE(i, next);
- mtx_unlock(&kmem_items_mtx);
-#endif
- free(buf, M_SOLARIS);
-}
-
-static uint64_t kmem_size_val;
-
-static void
-kmem_size_init(void *unused __unused)
-{
-
- kmem_size_val = (uint64_t)vm_cnt.v_page_count * PAGE_SIZE;
- if (kmem_size_val > vm_kmem_size)
- kmem_size_val = vm_kmem_size;
-}
-SYSINIT(kmem_size_init, SI_SUB_KMEM, SI_ORDER_ANY, kmem_size_init, NULL);
-
-uint64_t
-kmem_size(void)
-{
-
- return (kmem_size_val);
-}
-
-static int
-kmem_std_constructor(void *mem, int size __unused, void *private, int flags)
-{
- struct kmem_cache *cache = private;
-
- return (cache->kc_constructor(mem, cache->kc_private, flags));
-}
-
-static void
-kmem_std_destructor(void *mem, int size __unused, void *private)
-{
- struct kmem_cache *cache = private;
-
- cache->kc_destructor(mem, cache->kc_private);
-}
-
-kmem_cache_t *
-kmem_cache_create(char *name, size_t bufsize, size_t align,
- int (*constructor)(void *, void *, int), void (*destructor)(void *, void *),
- void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int cflags)
-{
- kmem_cache_t *cache;
-
- ASSERT(vmp == NULL);
-
- cache = kmem_alloc(sizeof(*cache), KM_SLEEP);
- strlcpy(cache->kc_name, name, sizeof(cache->kc_name));
- cache->kc_constructor = constructor;
- cache->kc_destructor = destructor;
- cache->kc_private = private;
-#if defined(_KERNEL) && !defined(KMEM_DEBUG)
- cache->kc_zone = uma_zcreate(cache->kc_name, bufsize,
- constructor != NULL ? kmem_std_constructor : NULL,
- destructor != NULL ? kmem_std_destructor : NULL,
- NULL, NULL, align > 0 ? align - 1 : 0, cflags);
-#else
- cache->kc_size = bufsize;
-#endif
-
- return (cache);
-}
-
-void
-kmem_cache_destroy(kmem_cache_t *cache)
-{
-#if defined(_KERNEL) && !defined(KMEM_DEBUG)
- uma_zdestroy(cache->kc_zone);
-#endif
- kmem_free(cache, sizeof(*cache));
-}
-
-void *
-kmem_cache_alloc(kmem_cache_t *cache, int flags)
-{
-#if defined(_KERNEL) && !defined(KMEM_DEBUG)
- return (uma_zalloc_arg(cache->kc_zone, cache, flags));
-#else
- void *p;
-
- p = kmem_alloc(cache->kc_size, flags);
- if (p != NULL && cache->kc_constructor != NULL)
- kmem_std_constructor(p, cache->kc_size, cache, flags);
- return (p);
-#endif
-}
-
-void
-kmem_cache_free(kmem_cache_t *cache, void *buf)
-{
-#if defined(_KERNEL) && !defined(KMEM_DEBUG)
- uma_zfree_arg(cache->kc_zone, buf, cache);
-#else
- if (cache->kc_destructor != NULL)
- kmem_std_destructor(buf, cache->kc_size, cache);
- kmem_free(buf, cache->kc_size);
-#endif
-}
-
-/*
- * Allow our caller to determine if there are running reaps.
- *
- * This call is very conservative and may return B_TRUE even when
- * reaping activity isn't active. If it returns B_FALSE, then reaping
- * activity is definitely inactive.
- */
-boolean_t
-kmem_cache_reap_active(void)
-{
-
- return (B_FALSE);
-}
-
-/*
- * Reap (almost) everything soon.
- *
- * Note: this does not wait for the reap-tasks to complete. Caller
- * should use kmem_cache_reap_active() (above) and/or moderation to
- * avoid scheduling too many reap-tasks.
- */
-#ifdef _KERNEL
-void
-kmem_cache_reap_soon(kmem_cache_t *cache)
-{
-#ifndef KMEM_DEBUG
- uma_zone_reclaim(cache->kc_zone, UMA_RECLAIM_DRAIN);
-#endif
-}
-
-void
-kmem_reap(void)
-{
- uma_reclaim(UMA_RECLAIM_TRIM);
-}
-#else
-void
-kmem_cache_reap_soon(kmem_cache_t *cache __unused)
-{
-}
-
-void
-kmem_reap(void)
-{
-}
-#endif
-
-int
-kmem_debugging(void)
-{
- return (0);
-}
-
-void *
-calloc(size_t n, size_t s)
-{
- return (kmem_zalloc(n * s, KM_NOSLEEP));
-}
-
-#ifdef KMEM_DEBUG
-void kmem_show(void *);
-void
-kmem_show(void *dummy __unused)
-{
- struct kmem_item *i;
-
- mtx_lock(&kmem_items_mtx);
- if (LIST_EMPTY(&kmem_items))
- printf("KMEM_DEBUG: No leaked elements.\n");
- else {
- printf("KMEM_DEBUG: Leaked elements:\n\n");
- LIST_FOREACH(i, &kmem_items, next) {
- printf("address=%p\n", i);
- stack_print_ddb(&i->stack);
- printf("\n");
- }
- }
- mtx_unlock(&kmem_items_mtx);
-}
-
-SYSUNINIT(sol_kmem, SI_SUB_CPU, SI_ORDER_FIRST, kmem_show, NULL);
-#endif /* KMEM_DEBUG */
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c b/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c
deleted file mode 100644
index 14d48da82ac0..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/kthread.h>
-#include <sys/namei.h>
-#include <sys/proc.h>
-#include <sys/filedesc.h>
-#include <sys/fcntl.h>
-#include <sys/linker.h>
-#include <sys/kobj.h>
-
-void
-kobj_free(void *address, size_t size)
-{
-
- kmem_free(address, size);
-}
-
-void *
-kobj_alloc(size_t size, int flag)
-{
-
- return (kmem_alloc(size, (flag & KM_NOWAIT) ? KM_NOSLEEP : KM_SLEEP));
-}
-
-void *
-kobj_zalloc(size_t size, int flag)
-{
- void *p;
-
- if ((p = kobj_alloc(size, flag)) != NULL)
- bzero(p, size);
- return (p);
-}
-
-static void *
-kobj_open_file_vnode(const char *file)
-{
- struct thread *td = curthread;
- struct nameidata nd;
- int error, flags;
-
- pwd_ensure_dirs();
-
- flags = FREAD | O_NOFOLLOW;
- NDINIT(&nd, LOOKUP, 0, UIO_SYSSPACE, file, td);
- error = vn_open_cred(&nd, &flags, 0, 0, curthread->td_ucred, NULL);
- if (error != 0)
- return (NULL);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- /* We just unlock so we hold a reference. */
- VOP_UNLOCK(nd.ni_vp);
- return (nd.ni_vp);
-}
-
-static void *
-kobj_open_file_loader(const char *file)
-{
-
- return (preload_search_by_name(file));
-}
-
-struct _buf *
-kobj_open_file(const char *file)
-{
- struct _buf *out;
-
- out = kmem_alloc(sizeof(*out), KM_SLEEP);
- out->mounted = root_mounted();
- /*
- * If root is already mounted we read file using file system,
- * if not, we use loader.
- */
- if (out->mounted)
- out->ptr = kobj_open_file_vnode(file);
- else
- out->ptr = kobj_open_file_loader(file);
- if (out->ptr == NULL) {
- kmem_free(out, sizeof(*out));
- return ((struct _buf *)-1);
- }
- return (out);
-}
-
-static int
-kobj_get_filesize_vnode(struct _buf *file, uint64_t *size)
-{
- struct vnode *vp = file->ptr;
- struct vattr va;
- int error;
-
- vn_lock(vp, LK_SHARED | LK_RETRY);
- error = VOP_GETATTR(vp, &va, curthread->td_ucred);
- VOP_UNLOCK(vp);
- if (error == 0)
- *size = (uint64_t)va.va_size;
- return (error);
-}
-
-static int
-kobj_get_filesize_loader(struct _buf *file, uint64_t *size)
-{
- void *ptr;
-
- ptr = preload_search_info(file->ptr, MODINFO_SIZE);
- if (ptr == NULL)
- return (ENOENT);
- *size = (uint64_t)*(size_t *)ptr;
- return (0);
-}
-
-int
-kobj_get_filesize(struct _buf *file, uint64_t *size)
-{
-
- if (file->mounted)
- return (kobj_get_filesize_vnode(file, size));
- else
- return (kobj_get_filesize_loader(file, size));
-}
-
-int
-kobj_read_file_vnode(struct _buf *file, char *buf, unsigned size, unsigned off)
-{
- struct vnode *vp = file->ptr;
- struct thread *td = curthread;
- struct uio auio;
- struct iovec aiov;
- int error;
-
- bzero(&aiov, sizeof(aiov));
- bzero(&auio, sizeof(auio));
-
- aiov.iov_base = buf;
- aiov.iov_len = size;
-
- auio.uio_iov = &aiov;
- auio.uio_offset = (off_t)off;
- auio.uio_segflg = UIO_SYSSPACE;
- auio.uio_rw = UIO_READ;
- auio.uio_iovcnt = 1;
- auio.uio_resid = size;
- auio.uio_td = td;
-
- vn_lock(vp, LK_SHARED | LK_RETRY);
- error = VOP_READ(vp, &auio, IO_UNIT | IO_SYNC, td->td_ucred);
- VOP_UNLOCK(vp);
- return (error != 0 ? -1 : size - auio.uio_resid);
-}
-
-int
-kobj_read_file_loader(struct _buf *file, char *buf, unsigned size, unsigned off)
-{
- char *ptr;
-
- ptr = preload_fetch_addr(file->ptr);
- if (ptr == NULL)
- return (ENOENT);
- bcopy(ptr + off, buf, size);
- return (0);
-}
-
-int
-kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off)
-{
-
- if (file->mounted)
- return (kobj_read_file_vnode(file, buf, size, off));
- else
- return (kobj_read_file_loader(file, buf, size, off));
-}
-
-void
-kobj_close_file(struct _buf *file)
-{
-
- if (file->mounted)
- vn_close(file->ptr, FREAD, curthread->td_ucred, curthread);
- kmem_free(file, sizeof(*file));
-}
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c b/sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c
deleted file mode 100644
index 51fe07497f98..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/sysctl.h>
-#include <sys/kstat.h>
-
-static MALLOC_DEFINE(M_KSTAT, "kstat_data", "Kernel statistics");
-
-SYSCTL_ROOT_NODE(OID_AUTO, kstat, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
- "Kernel statistics");
-
-kstat_t *
-kstat_create(char *module, int instance, char *name, char *class, uchar_t type,
- ulong_t ndata, uchar_t flags)
-{
- struct sysctl_oid *root;
- kstat_t *ksp;
-
- KASSERT(instance == 0, ("instance=%d", instance));
- KASSERT(type == KSTAT_TYPE_NAMED, ("type=%hhu", type));
- KASSERT(flags == KSTAT_FLAG_VIRTUAL, ("flags=%02hhx", flags));
-
- /*
- * Allocate the main structure. We don't need to copy module/class/name
- * stuff in here, because it is only used for sysctl node creation
- * done in this function.
- */
- ksp = malloc(sizeof(*ksp), M_KSTAT, M_WAITOK);
- ksp->ks_ndata = ndata;
-
- /*
- * Create sysctl tree for those statistics:
- *
- * kstat.<module>.<class>.<name>.
- */
- sysctl_ctx_init(&ksp->ks_sysctl_ctx);
- root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx,
- SYSCTL_STATIC_CHILDREN(_kstat), OID_AUTO, module,
- CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "");
- if (root == NULL) {
- printf("%s: Cannot create kstat.%s tree!\n", __func__, module);
- sysctl_ctx_free(&ksp->ks_sysctl_ctx);
- free(ksp, M_KSTAT);
- return (NULL);
- }
- root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx, SYSCTL_CHILDREN(root),
- OID_AUTO, class, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "");
- if (root == NULL) {
- printf("%s: Cannot create kstat.%s.%s tree!\n", __func__,
- module, class);
- sysctl_ctx_free(&ksp->ks_sysctl_ctx);
- free(ksp, M_KSTAT);
- return (NULL);
- }
- root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx, SYSCTL_CHILDREN(root),
- OID_AUTO, name, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "");
- if (root == NULL) {
- printf("%s: Cannot create kstat.%s.%s.%s tree!\n", __func__,
- module, class, name);
- sysctl_ctx_free(&ksp->ks_sysctl_ctx);
- free(ksp, M_KSTAT);
- return (NULL);
- }
- ksp->ks_sysctl_root = root;
-
- return (ksp);
-}
-
-static int
-kstat_sysctl(SYSCTL_HANDLER_ARGS)
-{
- kstat_named_t *ksent = arg1;
- uint64_t val;
-
- val = ksent->value.ui64;
- return sysctl_handle_64(oidp, &val, 0, req);
-}
-
-void
-kstat_install(kstat_t *ksp)
-{
- kstat_named_t *ksent;
- u_int i;
-
- ksent = ksp->ks_data;
- for (i = 0; i < ksp->ks_ndata; i++, ksent++) {
- KASSERT(ksent->data_type == KSTAT_DATA_UINT64,
- ("data_type=%d", ksent->data_type));
- SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
- SYSCTL_CHILDREN(ksp->ks_sysctl_root), OID_AUTO, ksent->name,
- CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_RD, ksent,
- sizeof(*ksent), kstat_sysctl, "QU", ksent->desc);
- }
-}
-
-void
-kstat_delete(kstat_t *ksp)
-{
-
- sysctl_ctx_free(&ksp->ks_sysctl_ctx);
- free(ksp, M_KSTAT);
-}
-
-void
-kstat_set_string(char *dst, const char *src)
-{
-
- bzero(dst, KSTAT_STRLEN);
- (void) strncpy(dst, src, KSTAT_STRLEN - 1);
-}
-
-void
-kstat_named_init(kstat_named_t *knp, const char *name, uchar_t data_type)
-{
-
- kstat_set_string(knp->name, name);
- knp->data_type = data_type;
-}
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c b/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c
deleted file mode 100644
index e025e10b240f..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/pathname.h>
-#include <sys/vfs.h>
-#include <sys/vnode.h>
-
-int
-lookupname(char *dirname, enum uio_seg seg, enum symfollow follow,
- vnode_t **dirvpp, vnode_t **compvpp)
-{
-
- return (lookupnameat(dirname, seg, follow, dirvpp, compvpp, NULL));
-}
-
-int
-lookupnameat(char *dirname, enum uio_seg seg, enum symfollow follow,
- vnode_t **dirvpp, vnode_t **compvpp, vnode_t *startvp)
-{
- struct nameidata nd;
- int error, ltype;
-
- ASSERT(dirvpp == NULL);
-
- vref(startvp);
- ltype = VOP_ISLOCKED(startvp);
- VOP_UNLOCK(startvp);
- NDINIT_ATVP(&nd, LOOKUP, LOCKLEAF | follow, seg, dirname,
- startvp, curthread);
- error = namei(&nd);
- *compvpp = nd.ni_vp;
- NDFREE(&nd, NDF_ONLY_PNBUF);
- vn_lock(startvp, ltype | LK_RETRY);
- return (error);
-}
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c b/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c
deleted file mode 100644
index 595f3c0b3c55..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_misc.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/jail.h>
-#include <sys/kernel.h>
-#include <sys/libkern.h>
-#include <sys/limits.h>
-#include <sys/misc.h>
-#include <sys/sysctl.h>
-
-char hw_serial[11] = "0";
-
-struct opensolaris_utsname utsname = {
- .machine = MACHINE
-};
-
-static void
-opensolaris_utsname_init(void *arg)
-{
-
- utsname.sysname = ostype;
- utsname.nodename = prison0.pr_hostname;
- utsname.release = osrelease;
- snprintf(utsname.version, sizeof(utsname.version), "%d", osreldate);
-}
-SYSINIT(opensolaris_utsname_init, SI_SUB_TUNABLES, SI_ORDER_ANY,
- opensolaris_utsname_init, NULL);
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c b/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c
deleted file mode 100644
index e49cee11a101..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_policy.c
+++ /dev/null
@@ -1,429 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/priv.h>
-#include <sys/vnode.h>
-#include <sys/mntent.h>
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/jail.h>
-#include <sys/policy.h>
-#include <sys/zfs_vfsops.h>
-
-int
-secpolicy_nfs(cred_t *cr)
-{
-
- return (priv_check_cred(cr, PRIV_NFS_DAEMON));
-}
-
-int
-secpolicy_zfs(cred_t *cr)
-{
-
- return (priv_check_cred(cr, PRIV_VFS_MOUNT));
-}
-
-int
-secpolicy_sys_config(cred_t *cr, int checkonly __unused)
-{
-
- return (priv_check_cred(cr, PRIV_ZFS_POOL_CONFIG));
-}
-
-int
-secpolicy_zinject(cred_t *cr)
-{
-
- return (priv_check_cred(cr, PRIV_ZFS_INJECT));
-}
-
-int
-secpolicy_fs_unmount(cred_t *cr, struct mount *vfsp __unused)
-{
-
- return (priv_check_cred(cr, PRIV_VFS_UNMOUNT));
-}
-
-int
-secpolicy_fs_owner(struct mount *mp, cred_t *cr)
-{
-
- if (zfs_super_owner) {
- if (cr->cr_uid == mp->mnt_cred->cr_uid &&
- cr->cr_prison == mp->mnt_cred->cr_prison) {
- return (0);
- }
- }
- return (EPERM);
-}
-
-/*
- * This check is done in kern_link(), so we could just return 0 here.
- */
-extern int hardlink_check_uid;
-int
-secpolicy_basic_link(vnode_t *vp, cred_t *cr)
-{
-
- if (!hardlink_check_uid)
- return (0);
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
- return (priv_check_cred(cr, PRIV_VFS_LINK));
-}
-
-int
-secpolicy_vnode_stky_modify(cred_t *cr)
-{
-
- return (EPERM);
-}
-
-int
-secpolicy_vnode_remove(vnode_t *vp, cred_t *cr)
-{
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
- return (priv_check_cred(cr, PRIV_VFS_ADMIN));
-}
-
-int
-secpolicy_vnode_access(cred_t *cr, vnode_t *vp, uid_t owner, accmode_t accmode)
-{
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
-
- if ((accmode & VREAD) && priv_check_cred(cr, PRIV_VFS_READ) != 0)
- return (EACCES);
- if ((accmode & VWRITE) &&
- priv_check_cred(cr, PRIV_VFS_WRITE) != 0) {
- return (EACCES);
- }
- if (accmode & VEXEC) {
- if (vp->v_type == VDIR) {
- if (priv_check_cred(cr, PRIV_VFS_LOOKUP) != 0)
- return (EACCES);
- } else {
- if (priv_check_cred(cr, PRIV_VFS_EXEC) != 0)
- return (EACCES);
- }
- }
- return (0);
-}
-
-/*
- * Like secpolicy_vnode_access() but we get the actual wanted mode and the
- * current mode of the file, not the missing bits.
- */
-int
-secpolicy_vnode_access2(cred_t *cr, vnode_t *vp, uid_t owner,
- accmode_t curmode, accmode_t wantmode)
-{
- accmode_t mode;
-
- mode = ~curmode & wantmode;
-
- if (mode == 0)
- return (0);
-
- return (secpolicy_vnode_access(cr, vp, owner, mode));
-}
-
-int
-secpolicy_vnode_any_access(cred_t *cr, vnode_t *vp, uid_t owner)
-{
- static int privs[] = {
- PRIV_VFS_ADMIN,
- PRIV_VFS_READ,
- PRIV_VFS_WRITE,
- PRIV_VFS_EXEC,
- PRIV_VFS_LOOKUP
- };
- int i;
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
-
- /* Same as secpolicy_vnode_setdac */
- if (owner == cr->cr_uid)
- return (0);
-
- for (i = 0; i < sizeof (privs)/sizeof (int); i++) {
- boolean_t allzone = B_FALSE;
- int priv;
-
- switch (priv = privs[i]) {
- case PRIV_VFS_EXEC:
- if (vp->v_type == VDIR)
- continue;
- break;
- case PRIV_VFS_LOOKUP:
- if (vp->v_type != VDIR)
- continue;
- break;
- }
- if (priv_check_cred(cr, priv) == 0)
- return (0);
- }
- return (EPERM);
-}
-
-int
-secpolicy_vnode_setdac(vnode_t *vp, cred_t *cr, uid_t owner)
-{
-
- if (owner == cr->cr_uid)
- return (0);
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
- return (priv_check_cred(cr, PRIV_VFS_ADMIN));
-}
-
-int
-secpolicy_vnode_setattr(cred_t *cr, vnode_t *vp, struct vattr *vap,
- const struct vattr *ovap, int flags,
- int unlocked_access(void *, int, cred_t *), void *node)
-{
- int mask = vap->va_mask;
- int error;
-
- if (mask & AT_SIZE) {
- if (vp->v_type == VDIR)
- return (EISDIR);
- error = unlocked_access(node, VWRITE, cr);
- if (error)
- return (error);
- }
- if (mask & AT_MODE) {
- /*
- * If not the owner of the file then check privilege
- * for two things: the privilege to set the mode at all
- * and, if we're setting setuid, we also need permissions
- * to add the set-uid bit, if we're not the owner.
- * In the specific case of creating a set-uid root
- * file, we need even more permissions.
- */
- error = secpolicy_vnode_setdac(vp, cr, ovap->va_uid);
- if (error)
- return (error);
- error = secpolicy_setid_setsticky_clear(vp, vap, ovap, cr);
- if (error)
- return (error);
- } else {
- vap->va_mode = ovap->va_mode;
- }
- if (mask & (AT_UID | AT_GID)) {
- error = secpolicy_vnode_setdac(vp, cr, ovap->va_uid);
- if (error)
- return (error);
-
- /*
- * To change the owner of a file, or change the group of a file to a
- * group of which we are not a member, the caller must have
- * privilege.
- */
- if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) ||
- ((mask & AT_GID) && vap->va_gid != ovap->va_gid &&
- !groupmember(vap->va_gid, cr))) {
- if (secpolicy_fs_owner(vp->v_mount, cr) != 0) {
- error = priv_check_cred(cr, PRIV_VFS_CHOWN);
- if (error)
- return (error);
- }
- }
-
- if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) ||
- ((mask & AT_GID) && vap->va_gid != ovap->va_gid)) {
- secpolicy_setid_clear(vap, vp, cr);
- }
- }
- if (mask & (AT_ATIME | AT_MTIME)) {
- /*
- * From utimes(2):
- * If times is NULL, ... The caller must be the owner of
- * the file, have permission to write the file, or be the
- * super-user.
- * If times is non-NULL, ... The caller must be the owner of
- * the file or be the super-user.
- */
- error = secpolicy_vnode_setdac(vp, cr, ovap->va_uid);
- if (error && (vap->va_vaflags & VA_UTIMES_NULL))
- error = unlocked_access(node, VWRITE, cr);
- if (error)
- return (error);
- }
- return (0);
-}
-
-int
-secpolicy_vnode_create_gid(cred_t *cr)
-{
-
- return (EPERM);
-}
-
-int
-secpolicy_vnode_setids_setgids(vnode_t *vp, cred_t *cr, gid_t gid)
-{
-
- if (groupmember(gid, cr))
- return (0);
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
- return (priv_check_cred(cr, PRIV_VFS_SETGID));
-}
-
-int
-secpolicy_vnode_setid_retain(vnode_t *vp, cred_t *cr,
- boolean_t issuidroot __unused)
-{
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
- return (priv_check_cred(cr, PRIV_VFS_RETAINSUGID));
-}
-
-void
-secpolicy_setid_clear(struct vattr *vap, vnode_t *vp, cred_t *cr)
-{
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return;
-
- if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0) {
- if (priv_check_cred(cr, PRIV_VFS_RETAINSUGID)) {
- vap->va_mask |= AT_MODE;
- vap->va_mode &= ~(S_ISUID|S_ISGID);
- }
- }
-}
-
-int
-secpolicy_setid_setsticky_clear(vnode_t *vp, struct vattr *vap,
- const struct vattr *ovap, cred_t *cr)
-{
- int error;
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
-
- /*
- * Privileged processes may set the sticky bit on non-directories,
- * as well as set the setgid bit on a file with a group that the process
- * is not a member of. Both of these are allowed in jail(8).
- */
- if (vp->v_type != VDIR && (vap->va_mode & S_ISTXT)) {
- if (priv_check_cred(cr, PRIV_VFS_STICKYFILE))
- return (EFTYPE);
- }
- /*
- * Check for privilege if attempting to set the
- * group-id bit.
- */
- if ((vap->va_mode & S_ISGID) != 0) {
- error = secpolicy_vnode_setids_setgids(vp, cr, ovap->va_gid);
- if (error)
- return (error);
- }
- /*
- * Deny setting setuid if we are not the file owner.
- */
- if ((vap->va_mode & S_ISUID) && ovap->va_uid != cr->cr_uid) {
- error = priv_check_cred(cr, PRIV_VFS_ADMIN);
- if (error)
- return (error);
- }
- return (0);
-}
-
-int
-secpolicy_fs_mount(cred_t *cr, vnode_t *mvp, struct mount *vfsp)
-{
-
- return (priv_check_cred(cr, PRIV_VFS_MOUNT));
-}
-
-int
-secpolicy_vnode_owner(vnode_t *vp, cred_t *cr, uid_t owner)
-{
-
- if (owner == cr->cr_uid)
- return (0);
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
-
- /* XXX: vfs_suser()? */
- return (priv_check_cred(cr, PRIV_VFS_MOUNT_OWNER));
-}
-
-int
-secpolicy_vnode_chown(vnode_t *vp, cred_t *cr, uid_t owner)
-{
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
- return (priv_check_cred(cr, PRIV_VFS_CHOWN));
-}
-
-void
-secpolicy_fs_mount_clearopts(cred_t *cr, struct mount *vfsp)
-{
-
- if (priv_check_cred(cr, PRIV_VFS_MOUNT_NONUSER) != 0) {
- MNT_ILOCK(vfsp);
- vfsp->vfs_flag |= VFS_NOSETUID | MNT_USER;
- vfs_clearmntopt(vfsp, MNTOPT_SETUID);
- vfs_setmntopt(vfsp, MNTOPT_NOSETUID, NULL, 0);
- MNT_IUNLOCK(vfsp);
- }
-}
-
-/*
- * Check privileges for setting xvattr attributes
- */
-int
-secpolicy_xvattr(vnode_t *vp, xvattr_t *xvap, uid_t owner, cred_t *cr,
- vtype_t vtype)
-{
-
- if (secpolicy_fs_owner(vp->v_mount, cr) == 0)
- return (0);
- return (priv_check_cred(cr, PRIV_VFS_SYSFLAGS));
-}
-
-int
-secpolicy_smb(cred_t *cr)
-{
-
- return (priv_check_cred(cr, PRIV_NETSMB));
-}
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_sunddi.c b/sys/cddl/compat/opensolaris/kern/opensolaris_sunddi.c
deleted file mode 100644
index 4a13cd8956c0..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_sunddi.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*-
- * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/jail.h>
-#include <sys/kernel.h>
-#include <sys/libkern.h>
-#include <sys/limits.h>
-#include <sys/misc.h>
-#include <sys/sunddi.h>
-#include <sys/sysctl.h>
-
-int
-ddi_strtol(const char *str, char **nptr, int base, long *result)
-{
-
- *result = strtol(str, nptr, base);
- return (0);
-}
-
-int
-ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result)
-{
-
- if (str == hw_serial) {
- *result = prison0.pr_hostid;
- return (0);
- }
-
- *result = strtoul(str, nptr, base);
- return (0);
-}
-
-int
-ddi_strtoull(const char *str, char **nptr, int base, unsigned long long *result)
-{
-
- *result = (unsigned long long)strtouq(str, nptr, base);
- return (0);
-}
-
-int
-ddi_strtoll(const char *str, char **nptr, int base, long long *result)
-{
-
- *result = (long long)strtoq(str, nptr, base);
- return (0);
-}
-
-struct ddi_soft_state_item {
- int ssi_item;
- void *ssi_data;
- LIST_ENTRY(ddi_soft_state_item) ssi_next;
-};
-
-struct ddi_soft_state {
- size_t ss_size;
- kmutex_t ss_lock;
- LIST_HEAD(, ddi_soft_state_item) ss_list;
-};
-
-static void *
-ddi_get_soft_state_locked(struct ddi_soft_state *ss, int item)
-{
- struct ddi_soft_state_item *itemp;
-
- ASSERT(MUTEX_HELD(&ss->ss_lock));
-
- LIST_FOREACH(itemp, &ss->ss_list, ssi_next) {
- if (itemp->ssi_item == item)
- return (itemp->ssi_data);
- }
- return (NULL);
-}
-
-void *
-ddi_get_soft_state(void *state, int item)
-{
- struct ddi_soft_state *ss = state;
- void *data;
-
- mutex_enter(&ss->ss_lock);
- data = ddi_get_soft_state_locked(ss, item);
- mutex_exit(&ss->ss_lock);
- return (data);
-}
-
-int
-ddi_soft_state_zalloc(void *state, int item)
-{
- struct ddi_soft_state *ss = state;
- struct ddi_soft_state_item *itemp;
-
- itemp = kmem_alloc(sizeof(*itemp), KM_SLEEP);
- itemp->ssi_item = item;
- itemp->ssi_data = kmem_zalloc(ss->ss_size, KM_SLEEP);
-
- mutex_enter(&ss->ss_lock);
- if (ddi_get_soft_state_locked(ss, item) != NULL) {
- mutex_exit(&ss->ss_lock);
- kmem_free(itemp->ssi_data, ss->ss_size);
- kmem_free(itemp, sizeof(*itemp));
- return (DDI_FAILURE);
- }
- LIST_INSERT_HEAD(&ss->ss_list, itemp, ssi_next);
- mutex_exit(&ss->ss_lock);
- return (DDI_SUCCESS);
-}
-
-static void
-ddi_soft_state_free_locked(struct ddi_soft_state *ss, int item)
-{
- struct ddi_soft_state_item *itemp;
-
- ASSERT(MUTEX_HELD(&ss->ss_lock));
-
- LIST_FOREACH(itemp, &ss->ss_list, ssi_next) {
- if (itemp->ssi_item == item)
- break;
- }
- if (itemp != NULL) {
- LIST_REMOVE(itemp, ssi_next);
- kmem_free(itemp->ssi_data, ss->ss_size);
- kmem_free(itemp, sizeof(*itemp));
- }
-}
-
-void
-ddi_soft_state_free(void *state, int item)
-{
- struct ddi_soft_state *ss = state;
-
- mutex_enter(&ss->ss_lock);
- ddi_soft_state_free_locked(ss, item);
- mutex_exit(&ss->ss_lock);
-}
-
-int
-ddi_soft_state_init(void **statep, size_t size, size_t nitems __unused)
-{
- struct ddi_soft_state *ss;
-
- ss = kmem_alloc(sizeof(*ss), KM_SLEEP);
- mutex_init(&ss->ss_lock, NULL, MUTEX_DEFAULT, NULL);
- ss->ss_size = size;
- LIST_INIT(&ss->ss_list);
- *statep = ss;
- return (0);
-}
-
-void
-ddi_soft_state_fini(void **statep)
-{
- struct ddi_soft_state *ss = *statep;
- struct ddi_soft_state_item *itemp;
- int item;
-
- mutex_enter(&ss->ss_lock);
- while ((itemp = LIST_FIRST(&ss->ss_list)) != NULL) {
- item = itemp->ssi_item;
- ddi_soft_state_free_locked(ss, item);
- }
- mutex_exit(&ss->ss_lock);
- mutex_destroy(&ss->ss_lock);
- kmem_free(ss, sizeof(*ss));
-
- *statep = NULL;
-}
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_sysevent.c b/sys/cddl/compat/opensolaris/kern/opensolaris_sysevent.c
deleted file mode 100644
index e810ae458140..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_sysevent.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/*-
- * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kmem.h>
-#include <sys/sbuf.h>
-#include <sys/devctl.h>
-#include <sys/nvpair.h>
-#include <sys/sunddi.h>
-#include <sys/sysevent.h>
-#include <sys/fm/protocol.h>
-
-struct sysevent {
- nvlist_t *se_nvl;
- char se_class[128];
- char se_subclass[128];
- char se_pub[128];
-};
-
-sysevent_t *
-sysevent_alloc(char *class, char *subclass, char *pub, int flag)
-{
- struct sysevent *ev;
-
- ASSERT(class != NULL);
- ASSERT(subclass != NULL);
- ASSERT(pub != NULL);
- ASSERT(flag == SE_SLEEP);
-
- ev = kmem_alloc(sizeof(*ev), KM_SLEEP);
- ev->se_nvl = NULL;
- strlcpy(ev->se_class, class, sizeof(ev->se_class));
- strlcpy(ev->se_subclass, subclass, sizeof(ev->se_subclass));
- strlcpy(ev->se_pub, pub, sizeof(ev->se_pub));
-
- return ((sysevent_t *)ev);
-}
-
-void
-sysevent_free(sysevent_t *evp)
-{
- struct sysevent *ev = (struct sysevent *)evp;
-
- ASSERT(evp != NULL);
-
- if (ev->se_nvl != NULL)
- sysevent_free_attr(ev->se_nvl);
- kmem_free(ev, sizeof(*ev));
-}
-
-int
-sysevent_add_attr(sysevent_attr_list_t **ev_attr_list, char *name,
- sysevent_value_t *se_value, int flag)
-{
- nvlist_t *nvl;
- int error;
-
- ASSERT(ev_attr_list != NULL);
- ASSERT(name != NULL);
- ASSERT(se_value != NULL);
- ASSERT(flag == SE_SLEEP);
-
- if (strlen(name) >= MAX_ATTR_NAME)
- return (SE_EINVAL);
-
- nvl = *ev_attr_list;
- if (nvl == NULL) {
- if (nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, KM_SLEEP) != 0)
- return (SE_ENOMEM);
- }
-
- error = 0;
-
- switch (se_value->value_type) {
- case SE_DATA_TYPE_UINT64:
- error = nvlist_add_uint64(nvl, name, se_value->value.sv_uint64);
- break;
- case SE_DATA_TYPE_STRING:
- if (strlen(se_value->value.sv_string) >= MAX_STRING_SZ)
- error = SE_EINVAL;
- if (error == 0) {
- error = nvlist_add_string(nvl, name,
- se_value->value.sv_string);
- }
- break;
- default:
-#if 0
- printf("%s: type %d is not implemented\n", __func__,
- se_value->value_type);
-#endif
- break;
- }
-
- if (error != 0) {
- nvlist_free(nvl);
- return (error);
- }
-
- *ev_attr_list = nvl;
-
- return (0);
-}
-
-void
-sysevent_free_attr(sysevent_attr_list_t *ev_attr_list)
-{
-
- nvlist_free(ev_attr_list);
-}
-
-int
-sysevent_attach_attributes(sysevent_t *evp, sysevent_attr_list_t *ev_attr_list)
-{
- struct sysevent *ev = (struct sysevent *)evp;
-
- ASSERT(ev->se_nvl == NULL);
-
- ev->se_nvl = ev_attr_list;
-
- return (0);
-}
-
-void
-sysevent_detach_attributes(sysevent_t *evp)
-{
- struct sysevent *ev = (struct sysevent *)evp;
-
- ASSERT(ev->se_nvl != NULL);
-
- ev->se_nvl = NULL;
-}
-
-int
-log_sysevent(sysevent_t *evp, int flag, sysevent_id_t *eid)
-{
- struct sysevent *ev = (struct sysevent *)evp;
- struct sbuf *sb;
- const char *type;
- char typestr[128];
- nvpair_t *elem = NULL;
-
- ASSERT(evp != NULL);
- ASSERT(ev->se_nvl != NULL);
- ASSERT(flag == SE_SLEEP);
- ASSERT(eid != NULL);
-
- sb = sbuf_new_auto();
- if (sb == NULL)
- return (SE_ENOMEM);
- type = NULL;
-
- while ((elem = nvlist_next_nvpair(ev->se_nvl, elem)) != NULL) {
- switch (nvpair_type(elem)) {
- case DATA_TYPE_BOOLEAN:
- {
- boolean_t value;
-
- (void) nvpair_value_boolean_value(elem, &value);
- sbuf_printf(sb, " %s=%s", nvpair_name(elem),
- value ? "true" : "false");
- break;
- }
- case DATA_TYPE_UINT8:
- {
- uint8_t value;
-
- (void) nvpair_value_uint8(elem, &value);
- sbuf_printf(sb, " %s=%hhu", nvpair_name(elem), value);
- break;
- }
- case DATA_TYPE_INT32:
- {
- int32_t value;
-
- (void) nvpair_value_int32(elem, &value);
- sbuf_printf(sb, " %s=%jd", nvpair_name(elem),
- (intmax_t)value);
- break;
- }
- case DATA_TYPE_UINT32:
- {
- uint32_t value;
-
- (void) nvpair_value_uint32(elem, &value);
- sbuf_printf(sb, " %s=%ju", nvpair_name(elem),
- (uintmax_t)value);
- break;
- }
- case DATA_TYPE_INT64:
- {
- int64_t value;
-
- (void) nvpair_value_int64(elem, &value);
- sbuf_printf(sb, " %s=%jd", nvpair_name(elem),
- (intmax_t)value);
- break;
- }
- case DATA_TYPE_UINT64:
- {
- uint64_t value;
-
- (void) nvpair_value_uint64(elem, &value);
- sbuf_printf(sb, " %s=%ju", nvpair_name(elem),
- (uintmax_t)value);
- break;
- }
- case DATA_TYPE_STRING:
- {
- char *value;
-
- (void) nvpair_value_string(elem, &value);
- sbuf_printf(sb, " %s=%s", nvpair_name(elem), value);
- if (strcmp(FM_CLASS, nvpair_name(elem)) == 0)
- type = value;
- break;
- }
- case DATA_TYPE_UINT8_ARRAY:
- {
- uint8_t *value;
- uint_t ii, nelem;
-
- (void) nvpair_value_uint8_array(elem, &value, &nelem);
- sbuf_printf(sb, " %s=", nvpair_name(elem));
- for (ii = 0; ii < nelem; ii++)
- sbuf_printf(sb, "%02hhx", value[ii]);
- break;
- }
- case DATA_TYPE_UINT16_ARRAY:
- {
- uint16_t *value;
- uint_t ii, nelem;
-
- (void) nvpair_value_uint16_array(elem, &value, &nelem);
- sbuf_printf(sb, " %s=", nvpair_name(elem));
- for (ii = 0; ii < nelem; ii++)
- sbuf_printf(sb, "%04hx", value[ii]);
- break;
- }
- case DATA_TYPE_UINT32_ARRAY:
- {
- uint32_t *value;
- uint_t ii, nelem;
-
- (void) nvpair_value_uint32_array(elem, &value, &nelem);
- sbuf_printf(sb, " %s=", nvpair_name(elem));
- for (ii = 0; ii < nelem; ii++)
- sbuf_printf(sb, "%08jx", (uintmax_t)value[ii]);
- break;
- }
- case DATA_TYPE_UINT64_ARRAY:
- {
- uint64_t *value;
- uint_t ii, nelem;
-
- (void) nvpair_value_uint64_array(elem, &value, &nelem);
- sbuf_printf(sb, " %s=", nvpair_name(elem));
- for (ii = 0; ii < nelem; ii++)
- sbuf_printf(sb, "%016jx", (uintmax_t)value[ii]);
- break;
- }
- default:
-#if 0
- printf("%s: type %d is not implemented\n", __func__,
- nvpair_type(elem));
-#endif
- break;
- }
- }
-
- if (sbuf_finish(sb) != 0) {
- sbuf_delete(sb);
- return (SE_ENOMEM);
- }
-
- if (type == NULL)
- type = ev->se_subclass;
- if (strncmp(type, "ESC_ZFS_", 8) == 0) {
- snprintf(typestr, sizeof(typestr), "misc.fs.zfs.%s", type + 8);
- type = typestr;
- }
- devctl_notify("ZFS", "ZFS", type, sbuf_data(sb));
- sbuf_delete(sb);
-
- return (0);
-}
-
-int
-_ddi_log_sysevent(char *vendor, char *class, char *subclass,
- nvlist_t *attr_list, sysevent_id_t *eidp, int flag)
-{
- sysevent_t *ev;
- int ret;
-
- ASSERT(vendor != NULL);
- ASSERT(class != NULL);
- ASSERT(subclass != NULL);
- ASSERT(attr_list != NULL);
- ASSERT(eidp != NULL);
- ASSERT(flag == DDI_SLEEP);
-
- ev = sysevent_alloc(class, subclass, vendor, SE_SLEEP);
- ASSERT(ev != NULL);
- (void)sysevent_attach_attributes(ev, attr_list);
- ret = log_sysevent(ev, SE_SLEEP, eidp);
- sysevent_detach_attributes(ev);
- sysevent_free(ev);
-
- return (ret);
-}
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c b/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
deleted file mode 100644
index 0ba0338a9848..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*-
- * Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/mount.h>
-#include <sys/cred.h>
-#include <sys/vfs.h>
-#include <sys/priv.h>
-#include <sys/libkern.h>
-
-MALLOC_DECLARE(M_MOUNT);
-
-void
-vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg,
- int flags __unused)
-{
- struct vfsopt *opt;
- size_t namesize;
- int locked;
-
- if (!(locked = mtx_owned(MNT_MTX(vfsp))))
- MNT_ILOCK(vfsp);
-
- if (vfsp->mnt_opt == NULL) {
- void *opts;
-
- MNT_IUNLOCK(vfsp);
- opts = malloc(sizeof(*vfsp->mnt_opt), M_MOUNT, M_WAITOK);
- MNT_ILOCK(vfsp);
- if (vfsp->mnt_opt == NULL) {
- vfsp->mnt_opt = opts;
- TAILQ_INIT(vfsp->mnt_opt);
- } else {
- free(opts, M_MOUNT);
- }
- }
-
- MNT_IUNLOCK(vfsp);
-
- opt = malloc(sizeof(*opt), M_MOUNT, M_WAITOK);
- namesize = strlen(name) + 1;
- opt->name = malloc(namesize, M_MOUNT, M_WAITOK);
- strlcpy(opt->name, name, namesize);
- opt->pos = -1;
- opt->seen = 1;
- if (arg == NULL) {
- opt->value = NULL;
- opt->len = 0;
- } else {
- opt->len = strlen(arg) + 1;
- opt->value = malloc(opt->len, M_MOUNT, M_WAITOK);
- bcopy(arg, opt->value, opt->len);
- }
-
- MNT_ILOCK(vfsp);
- TAILQ_INSERT_TAIL(vfsp->mnt_opt, opt, link);
- if (!locked)
- MNT_IUNLOCK(vfsp);
-}
-
-void
-vfs_clearmntopt(vfs_t *vfsp, const char *name)
-{
- int locked;
-
- if (!(locked = mtx_owned(MNT_MTX(vfsp))))
- MNT_ILOCK(vfsp);
- vfs_deleteopt(vfsp->mnt_opt, name);
- if (!locked)
- MNT_IUNLOCK(vfsp);
-}
-
-int
-vfs_optionisset(const vfs_t *vfsp, const char *opt, char **argp)
-{
- struct vfsoptlist *opts = vfsp->mnt_optnew;
- int error;
-
- if (opts == NULL)
- return (0);
- error = vfs_getopt(opts, opt, (void **)argp, NULL);
- return (error != 0 ? 0 : 1);
-}
-
-int
-mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath,
- char *fspec, int fsflags)
-{
- struct vfsconf *vfsp;
- struct mount *mp;
- vnode_t *vp, *mvp;
- struct ucred *cr;
- int error;
-
- ASSERT_VOP_ELOCKED(*vpp, "mount_snapshot");
-
- vp = *vpp;
- *vpp = NULL;
- error = 0;
-
- /*
- * Be ultra-paranoid about making sure the type and fspath
- * variables will fit in our mp buffers, including the
- * terminating NUL.
- */
- if (strlen(fstype) >= MFSNAMELEN || strlen(fspath) >= MNAMELEN)
- error = ENAMETOOLONG;
- if (error == 0 && (vfsp = vfs_byname_kld(fstype, td, &error)) == NULL)
- error = ENODEV;
- if (error == 0 && vp->v_type != VDIR)
- error = ENOTDIR;
- /*
- * We need vnode lock to protect v_mountedhere and vnode interlock
- * to protect v_iflag.
- */
- if (error == 0) {
- VI_LOCK(vp);
- if ((vp->v_iflag & VI_MOUNT) == 0 && vp->v_mountedhere == NULL)
- vp->v_iflag |= VI_MOUNT;
- else
- error = EBUSY;
- VI_UNLOCK(vp);
- }
- if (error != 0) {
- vput(vp);
- return (error);
- }
- vn_seqc_write_begin(vp);
- VOP_UNLOCK(vp);
-
- /*
- * Allocate and initialize the filesystem.
- * We don't want regular user that triggered snapshot mount to be able
- * to unmount it, so pass credentials of the parent mount.
- */
- mp = vfs_mount_alloc(vp, vfsp, fspath, vp->v_mount->mnt_cred);
-
- mp->mnt_optnew = NULL;
- vfs_setmntopt(mp, "from", fspec, 0);
- mp->mnt_optnew = mp->mnt_opt;
- mp->mnt_opt = NULL;
-
- /*
- * Set the mount level flags.
- */
- mp->mnt_flag = fsflags & MNT_UPDATEMASK;
- /*
- * Snapshots are always read-only.
- */
- mp->mnt_flag |= MNT_RDONLY;
- /*
- * We don't want snapshots to allow access to vulnerable setuid
- * programs, so we turn off setuid when mounting snapshots.
- */
- mp->mnt_flag |= MNT_NOSUID;
- /*
- * We don't want snapshots to be visible in regular
- * mount(8) and df(1) output.
- */
- mp->mnt_flag |= MNT_IGNORE;
- /*
- * XXX: This is evil, but we can't mount a snapshot as a regular user.
- * XXX: Is is safe when snapshot is mounted from within a jail?
- */
- cr = td->td_ucred;
- td->td_ucred = kcred;
- error = VFS_MOUNT(mp);
- td->td_ucred = cr;
-
- if (error != 0) {
- /*
- * Clear VI_MOUNT and decrement the use count "atomically",
- * under the vnode lock. This is not strictly required,
- * but makes it easier to reason about the life-cycle and
- * ownership of the covered vnode.
- */
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
- VI_LOCK(vp);
- vp->v_iflag &= ~VI_MOUNT;
- VI_UNLOCK(vp);
- vn_seqc_write_end(vp);
- vput(vp);
- vfs_unbusy(mp);
- vfs_freeopts(mp->mnt_optnew);
- mp->mnt_vnodecovered = NULL;
- vfs_mount_destroy(mp);
- return (error);
- }
-
- if (mp->mnt_opt != NULL)
- vfs_freeopts(mp->mnt_opt);
- mp->mnt_opt = mp->mnt_optnew;
- (void)VFS_STATFS(mp, &mp->mnt_stat);
-
- /*
- * Prevent external consumers of mount options from reading
- * mnt_optnew.
- */
- mp->mnt_optnew = NULL;
-
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-#ifdef FREEBSD_NAMECACHE
- cache_purge(vp);
-#endif
- VI_LOCK(vp);
- vp->v_iflag &= ~VI_MOUNT;
- VI_UNLOCK(vp);
-
- vp->v_mountedhere = mp;
- /* Put the new filesystem on the mount list. */
- mtx_lock(&mountlist_mtx);
- TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
- mtx_unlock(&mountlist_mtx);
- vfs_event_signal(NULL, VQ_MOUNT, 0);
- if (VFS_ROOT(mp, LK_EXCLUSIVE, &mvp))
- panic("mount: lost mount");
- vn_seqc_write_end(vp);
- VOP_UNLOCK(vp);
- vfs_op_exit(mp);
- vfs_unbusy(mp);
- *vpp = mvp;
- return (0);
-}
diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c b/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c
deleted file mode 100644
index f4a6042ffef2..000000000000
--- a/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/sx.h>
-#include <sys/malloc.h>
-#include <sys/queue.h>
-#include <sys/jail.h>
-#include <sys/osd.h>
-#include <sys/priv.h>
-#include <sys/zone.h>
-
-static MALLOC_DEFINE(M_ZONES, "zones_data", "Zones data");
-
-/*
- * Structure to record list of ZFS datasets exported to a zone.
- */
-typedef struct zone_dataset {
- LIST_ENTRY(zone_dataset) zd_next;
- char zd_dataset[0];
-} zone_dataset_t;
-
-LIST_HEAD(zone_dataset_head, zone_dataset);
-
-static int zone_slot;
-
-int
-zone_dataset_attach(struct ucred *cred, const char *dataset, int jailid)
-{
- struct zone_dataset_head *head;
- zone_dataset_t *zd, *zd2;
- struct prison *pr;
- int dofree, error;
-
- if ((error = priv_check_cred(cred, PRIV_ZFS_JAIL)) != 0)
- return (error);
-
- /* Allocate memory before we grab prison's mutex. */
- zd = malloc(sizeof(*zd) + strlen(dataset) + 1, M_ZONES, M_WAITOK);
-
- sx_slock(&allprison_lock);
- pr = prison_find(jailid); /* Locks &pr->pr_mtx. */
- sx_sunlock(&allprison_lock);
- if (pr == NULL) {
- free(zd, M_ZONES);
- return (ENOENT);
- }
-
- head = osd_jail_get(pr, zone_slot);
- if (head != NULL) {
- dofree = 0;
- LIST_FOREACH(zd2, head, zd_next) {
- if (strcmp(dataset, zd2->zd_dataset) == 0) {
- free(zd, M_ZONES);
- error = EEXIST;
- goto end;
- }
- }
- } else {
- dofree = 1;
- prison_hold_locked(pr);
- mtx_unlock(&pr->pr_mtx);
- head = malloc(sizeof(*head), M_ZONES, M_WAITOK);
- LIST_INIT(head);
- mtx_lock(&pr->pr_mtx);
- error = osd_jail_set(pr, zone_slot, head);
- KASSERT(error == 0, ("osd_jail_set() failed (error=%d)", error));
- }
- strcpy(zd->zd_dataset, dataset);
- LIST_INSERT_HEAD(head, zd, zd_next);
-end:
- if (dofree)
- prison_free_locked(pr);
- else
- mtx_unlock(&pr->pr_mtx);
- return (error);
-}
-
-int
-zone_dataset_detach(struct ucred *cred, const char *dataset, int jailid)
-{
- struct zone_dataset_head *head;
- zone_dataset_t *zd;
- struct prison *pr;
- int error;
-
- if ((error = priv_check_cred(cred, PRIV_ZFS_JAIL)) != 0)
- return (error);
-
- sx_slock(&allprison_lock);
- pr = prison_find(jailid);
- sx_sunlock(&allprison_lock);
- if (pr == NULL)
- return (ENOENT);
- head = osd_jail_get(pr, zone_slot);
- if (head == NULL) {
- error = ENOENT;
- goto end;
- }
- LIST_FOREACH(zd, head, zd_next) {
- if (strcmp(dataset, zd->zd_dataset) == 0)
- break;
- }
- if (zd == NULL)
- error = ENOENT;
- else {
- LIST_REMOVE(zd, zd_next);
- free(zd, M_ZONES);
- if (LIST_EMPTY(head))
- osd_jail_del(pr, zone_slot);
- error = 0;
- }
-end:
- mtx_unlock(&pr->pr_mtx);
- return (error);
-}
-
-/*
- * Returns true if the named dataset is visible in the current zone.
- * The 'write' parameter is set to 1 if the dataset is also writable.
- */
-int
-zone_dataset_visible(const char *dataset, int *write)
-{
- struct zone_dataset_head *head;
- zone_dataset_t *zd;
- struct prison *pr;
- size_t len;
- int ret = 0;
-
- if (dataset[0] == '\0')
- return (0);
- if (INGLOBALZONE(curthread)) {
- if (write != NULL)
- *write = 1;
- return (1);
- }
- pr = curthread->td_ucred->cr_prison;
- mtx_lock(&pr->pr_mtx);
- head = osd_jail_get(pr, zone_slot);
- if (head == NULL)
- goto end;
-
- /*
- * Walk the list once, looking for datasets which match exactly, or
- * specify a dataset underneath an exported dataset. If found, return
- * true and note that it is writable.
- */
- LIST_FOREACH(zd, head, zd_next) {
- len = strlen(zd->zd_dataset);
- if (strlen(dataset) >= len &&
- bcmp(dataset, zd->zd_dataset, len) == 0 &&
- (dataset[len] == '\0' || dataset[len] == '/' ||
- dataset[len] == '@')) {
- if (write)
- *write = 1;
- ret = 1;
- goto end;
- }
- }
-
- /*
- * Walk the list a second time, searching for datasets which are parents
- * of exported datasets. These should be visible, but read-only.
- *
- * Note that we also have to support forms such as 'pool/dataset/', with
- * a trailing slash.
- */
- LIST_FOREACH(zd, head, zd_next) {
- len = strlen(dataset);
- if (dataset[len - 1] == '/')
- len--; /* Ignore trailing slash */
- if (len < strlen(zd->zd_dataset) &&
- bcmp(dataset, zd->zd_dataset, len) == 0 &&
- zd->zd_dataset[len] == '/') {
- if (write)
- *write = 0;
- ret = 1;
- goto end;
- }
- }
-end:
- mtx_unlock(&pr->pr_mtx);
- return (ret);
-}
-
-static void
-zone_destroy(void *arg)
-{
- struct zone_dataset_head *head;
- zone_dataset_t *zd;
-
- head = arg;
- while ((zd = LIST_FIRST(head)) != NULL) {
- LIST_REMOVE(zd, zd_next);
- free(zd, M_ZONES);
- }
- free(head, M_ZONES);
-}
-
-uint32_t
-zone_get_hostid(void *ptr)
-{
-
- KASSERT(ptr == NULL, ("only NULL pointer supported in %s", __func__));
-
- return ((uint32_t)curthread->td_ucred->cr_prison->pr_hostid);
-}
-
-static void
-zone_sysinit(void *arg __unused)
-{
-
- zone_slot = osd_jail_register(zone_destroy, NULL);
-}
-
-static void
-zone_sysuninit(void *arg __unused)
-{
-
- osd_jail_deregister(zone_slot);
-}
-
-SYSINIT(zone_sysinit, SI_SUB_DRIVERS, SI_ORDER_ANY, zone_sysinit, NULL);
-SYSUNINIT(zone_sysuninit, SI_SUB_DRIVERS, SI_ORDER_ANY, zone_sysuninit, NULL);
diff --git a/sys/cddl/compat/opensolaris/sys/acl.h b/sys/cddl/compat/opensolaris/sys/acl.h
deleted file mode 100644
index 57fad6faa001..000000000000
--- a/sys/cddl/compat/opensolaris/sys/acl.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * Copyright (c) 2008, 2009 Edward Tomasz NapieraƂa <trasz@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef OPENSOLARIS_SYS_ACL_H
-#define OPENSOLARIS_SYS_ACL_H
-
-#include_next <sys/acl.h>
-
-struct acl;
-
-void aces_from_acl(ace_t *aces, int *nentries, const struct acl *aclp);
-int acl_from_aces(struct acl *aclp, const ace_t *aces, int nentries);
-
-#endif /* OPENSOLARIS_SYS_ACL_H */
diff --git a/sys/cddl/compat/opensolaris/sys/file.h b/sys/cddl/compat/opensolaris/sys/file.h
deleted file mode 100644
index 04851ee86d6d..000000000000
--- a/sys/cddl/compat/opensolaris/sys/file.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_FILE_H_
-#define _OPENSOLARIS_SYS_FILE_H_
-
-#include_next <sys/file.h>
-
-#define FKIOCTL 0x80000000 /* ioctl addresses are from kernel */
-
-#ifdef _KERNEL
-typedef struct file file_t;
-
-#include <sys/capsicum.h>
-
-static __inline file_t *
-getf(int fd, cap_rights_t *rightsp)
-{
- struct file *fp;
-
- if (fget(curthread, fd, rightsp, &fp) == 0)
- return (fp);
- return (NULL);
-}
-
-static __inline void
-releasef(int fd)
-{
- struct file *fp;
-
- /* No CAP_ rights required, as we're only releasing. */
- if (fget(curthread, fd, &cap_no_rights, &fp) == 0) {
- fdrop(fp, curthread);
- fdrop(fp, curthread);
- }
-}
-#endif /* _KERNEL */
-
-#endif /* !_OPENSOLARIS_SYS_FILE_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/kobj.h b/sys/cddl/compat/opensolaris/sys/kobj.h
deleted file mode 100644
index e060ff04ce2f..000000000000
--- a/sys/cddl/compat/opensolaris/sys/kobj.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_KOBJ_H_
-#define _OPENSOLARIS_SYS_KOBJ_H_
-
-#include <sys/types.h>
-#include <sys/kmem.h>
-#include_next <sys/kobj.h>
-#ifdef AT_UID
-#undef AT_UID
-#endif
-#ifdef AT_GID
-#undef AT_GID
-#endif
-#include <sys/vnode.h>
-
-#define KM_NOWAIT 0x01
-#define KM_TMP 0x02
-
-void kobj_free(void *address, size_t size);
-void *kobj_alloc(size_t size, int flag);
-void *kobj_zalloc(size_t size, int flag);
-
-struct _buf {
- void *ptr;
- int mounted;
-};
-
-struct _buf *kobj_open_file(const char *path);
-int kobj_get_filesize(struct _buf *file, uint64_t *size);
-int kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off);
-void kobj_close_file(struct _buf *file);
-
-#endif /* _OPENSOLARIS_SYS_KOBJ_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/lock.h b/sys/cddl/compat/opensolaris/sys/lock.h
deleted file mode 100644
index 27663f46e446..000000000000
--- a/sys/cddl/compat/opensolaris/sys/lock.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_LOCK_H_
-#define _OPENSOLARIS_SYS_LOCK_H_
-
-#include_next <sys/lock.h>
-
-#ifdef _KERNEL
-
-#define LO_ALLMASK (LO_INITIALIZED | LO_WITNESS | LO_QUIET | \
- LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE | \
- LO_DUPOK | LO_CLASSMASK | LO_NOPROFILE)
-#define LO_EXPECTED (LO_INITIALIZED | LO_WITNESS | LO_RECURSABLE | \
- LO_SLEEPABLE | LO_UPGRADABLE | LO_DUPOK | \
- /* sx lock class */(2 << LO_CLASSSHIFT))
-
-#endif /* defined(_KERNEL) */
-
-#endif /* _OPENSOLARIS_SYS_LOCK_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/misc.h b/sys/cddl/compat/opensolaris/sys/misc.h
index e128ce06d165..b2230da24e7a 100644
--- a/sys/cddl/compat/opensolaris/sys/misc.h
+++ b/sys/cddl/compat/opensolaris/sys/misc.h
@@ -55,7 +55,6 @@ struct opensolaris_utsname {
};
extern char hw_serial[11];
-extern struct opensolaris_utsname utsname;
#endif
#endif /* _OPENSOLARIS_SYS_MISC_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/mman.h b/sys/cddl/compat/opensolaris/sys/mman.h
deleted file mode 100644
index ca746898f65d..000000000000
--- a/sys/cddl/compat/opensolaris/sys/mman.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2007 John Birrell <jb@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- *
- */
-
-#ifndef _COMPAT_OPENSOLARIS_SYS_MMAN_H_
-#define _COMPAT_OPENSOLARIS_SYS_MMAN_H_
-
-#include_next <sys/mman.h>
-
-#define mmap64(_a,_b,_c,_d,_e,_f) mmap(_a,_b,_c,_d,_e,_f)
-
-#endif
diff --git a/sys/cddl/compat/opensolaris/sys/modctl.h b/sys/cddl/compat/opensolaris/sys/modctl.h
index 7af39b090f3b..af91036a31b4 100644
--- a/sys/cddl/compat/opensolaris/sys/modctl.h
+++ b/sys/cddl/compat/opensolaris/sys/modctl.h
@@ -31,6 +31,7 @@
#define _COMPAT_OPENSOLARIS_SYS_MODCTL_H
#include <sys/param.h>
+#include <sys/queue.h>
#include <sys/linker.h>
typedef struct linker_file modctl_t;
diff --git a/sys/cddl/compat/opensolaris/sys/mount.h b/sys/cddl/compat/opensolaris/sys/mount.h
deleted file mode 100644
index e012597a92e6..000000000000
--- a/sys/cddl/compat/opensolaris/sys/mount.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_MOUNT_H_
-#define _OPENSOLARIS_SYS_MOUNT_H_
-
-#include <sys/param.h>
-
-#include_next <sys/mount.h>
-
-#define MS_FORCE MNT_FORCE
-#define MS_REMOUNT MNT_UPDATE
-
-typedef struct fid fid_t;
-
-#endif /* !_OPENSOLARIS_SYS_MOUNT_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/mutex.h b/sys/cddl/compat/opensolaris/sys/mutex.h
deleted file mode 100644
index 45a33bd71cf6..000000000000
--- a/sys/cddl/compat/opensolaris/sys/mutex.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_MUTEX_H_
-#define _OPENSOLARIS_SYS_MUTEX_H_
-
-#ifdef _KERNEL
-
-#include <sys/param.h>
-#include <sys/lock.h>
-#include_next <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/sx.h>
-
-typedef enum {
- MUTEX_DEFAULT = 6 /* kernel default mutex */
-} kmutex_type_t;
-
-#define MUTEX_HELD(x) (mutex_owned(x))
-#define MUTEX_NOT_HELD(x) (!mutex_owned(x) || KERNEL_PANICKED())
-
-typedef struct sx kmutex_t;
-
-#ifndef OPENSOLARIS_WITNESS
-#define MUTEX_FLAGS (SX_DUPOK | SX_NEW | SX_NOWITNESS)
-#else
-#define MUTEX_FLAGS (SX_DUPOK | SX_NEW)
-#endif
-
-#define mutex_init(lock, desc, type, arg) do { \
- const char *_name; \
- ASSERT((type) == 0 || (type) == MUTEX_DEFAULT); \
- KASSERT(((lock)->lock_object.lo_flags & LO_ALLMASK) != \
- LO_EXPECTED, ("lock %s already initialized", #lock)); \
- for (_name = #lock; *_name != '\0'; _name++) { \
- if (*_name >= 'a' && *_name <= 'z') \
- break; \
- } \
- if (*_name == '\0') \
- _name = #lock; \
- sx_init_flags((lock), _name, MUTEX_FLAGS); \
-} while (0)
-#define mutex_destroy(lock) sx_destroy(lock)
-#define mutex_enter(lock) sx_xlock(lock)
-#define mutex_tryenter(lock) sx_try_xlock(lock)
-#define mutex_exit(lock) sx_xunlock(lock)
-#define mutex_owned(lock) sx_xlocked(lock)
-#define mutex_owner(lock) sx_xholder(lock)
-
-#endif /* _KERNEL */
-
-#endif /* _OPENSOLARIS_SYS_MUTEX_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/nvpair.h b/sys/cddl/compat/opensolaris/sys/nvpair.h
deleted file mode 100644
index 33b62cbe49c5..000000000000
--- a/sys/cddl/compat/opensolaris/sys/nvpair.h
+++ /dev/null
@@ -1,230 +0,0 @@
-/*-
- * Copyright (c) 2014 Sandvine Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_NVPAIR_H_
-#define _OPENSOLARIS_SYS_NVPAIR_H_
-
-#ifdef _KERNEL
-
-/*
- * Some of the symbols in the Illumos nvpair library conflict with symbols
- * provided by nv(9), so we use this preprocessor hack to avoid the conflict.
- *
- * This list was generated by:
- * cat nv.h nv_impl.h nvlist_* nvpair_impl.h | \
- * sed -nE 's/^[[:alnum:]_][[:alnum:]_ ]*[[:space:]]+[*]*([[:alnum:]_]+)\(.*$/#define \1 illumos_\1/p' | \
- * sort -u
- */
-#define nvlist_add_binary illumos_nvlist_add_binary
-#define nvlist_add_bool illumos_nvlist_add_bool
-#define nvlist_add_bool_array illumos_nvlist_add_bool_array
-#define nvlist_add_descriptor illumos_nvlist_add_descriptor
-#define nvlist_add_descriptor_array illumos_nvlist_add_descriptor_array
-#define nvlist_add_null illumos_nvlist_add_null
-#define nvlist_add_number illumos_nvlist_add_number
-#define nvlist_add_number_array illumos_nvlist_add_number_array
-#define nvlist_add_nvlist illumos_nvlist_add_nvlist
-#define nvlist_add_nvlist_array illumos_nvlist_add_nvlist_array
-#define nvlist_add_nvpair illumos_nvlist_add_nvpair
-#define nvlist_add_string illumos_nvlist_add_string
-#define nvlist_add_string_array illumos_nvlist_add_string_array
-#define nvlist_add_stringf illumos_nvlist_add_stringf
-#define nvlist_add_stringv illumos_nvlist_add_stringv
-#define nvlist_clone illumos_nvlist_clone
-#define nvlist_create illumos_nvlist_create
-#define nvlist_descriptors illumos_nvlist_descriptors
-#define nvlist_destroy illumos_nvlist_destroy
-#define nvlist_dump illumos_nvlist_dump
-#define nvlist_empty illumos_nvlist_empty
-#define nvlist_error illumos_nvlist_error
-#define nvlist_exists illumos_nvlist_exists
-#define nvlist_exists_binary illumos_nvlist_exists_binary
-#define nvlist_exists_bool illumos_nvlist_exists_bool
-#define nvlist_exists_bool_array illumos_nvlist_exists_bool_array
-#define nvlist_exists_descriptor illumos_nvlist_exists_descriptor
-#define nvlist_exists_descriptor_array illumos_nvlist_exists_descriptor_array
-#define nvlist_exists_null illumos_nvlist_exists_null
-#define nvlist_exists_number illumos_nvlist_exists_number
-#define nvlist_exists_number_array illumos_nvlist_exists_number_array
-#define nvlist_exists_nvlist illumos_nvlist_exists_nvlist
-#define nvlist_exists_nvlist_array illumos_nvlist_exists_nvlist_array
-#define nvlist_exists_string illumos_nvlist_exists_string
-#define nvlist_exists_string_array illumos_nvlist_exists_string_array
-#define nvlist_exists_type illumos_nvlist_exists_type
-#define nvlist_fdump illumos_nvlist_fdump
-#define nvlist_first_nvpair illumos_nvlist_first_nvpair
-#define nvlist_flags illumos_nvlist_flags
-#define nvlist_free illumos_nvlist_free
-#define nvlist_free_binary illumos_nvlist_free_binary
-#define nvlist_free_binary_array illumos_nvlist_free_binary_array
-#define nvlist_free_bool illumos_nvlist_free_bool
-#define nvlist_free_bool_array illumos_nvlist_free_bool_array
-#define nvlist_free_descriptor illumos_nvlist_free_descriptor
-#define nvlist_free_descriptor_array illumos_nvlist_free_descriptor_array
-#define nvlist_free_null illumos_nvlist_free_null
-#define nvlist_free_number illumos_nvlist_free_number
-#define nvlist_free_number_array illumos_nvlist_free_number_array
-#define nvlist_free_nvlist illumos_nvlist_free_nvlist
-#define nvlist_free_nvlist_array illumos_nvlist_free_nvlist_array
-#define nvlist_free_nvpair illumos_nvlist_free_nvpair
-#define nvlist_free_string illumos_nvlist_free_string
-#define nvlist_free_string_array illumos_nvlist_free_string_array
-#define nvlist_free_type illumos_nvlist_free_type
-#define nvlist_get_array_next illumos_nvlist_get_array_next
-#define nvlist_get_binary illumos_nvlist_get_binary
-#define nvlist_get_bool illumos_nvlist_get_bool
-#define nvlist_get_bool_array illumos_nvlist_get_bool_array
-#define nvlist_get_descriptor illumos_nvlist_get_descriptor
-#define nvlist_get_descriptor_array illumos_nvlist_get_descriptor_array
-#define nvlist_get_number illumos_nvlist_get_number
-#define nvlist_get_number_array illumos_nvlist_get_number_array
-#define nvlist_get_nvlist illumos_nvlist_get_nvlist
-#define nvlist_get_nvpair illumos_nvlist_get_nvpair
-#define nvlist_get_nvpair_parent illumos_nvlist_get_nvpair_parent
-#define nvlist_get_pararr illumos_nvlist_get_pararr
-#define nvlist_get_parent illumos_nvlist_get_parent
-#define nvlist_get_string illumos_nvlist_get_string
-#define nvlist_in_array illumos_nvlist_in_array
-#define nvlist_move_binary illumos_nvlist_move_binary
-#define nvlist_move_bool_array illumos_nvlist_move_bool_array
-#define nvlist_move_descriptor illumos_nvlist_move_descriptor
-#define nvlist_move_descriptor_array illumos_nvlist_move_descriptor_array
-#define nvlist_move_number_array illumos_nvlist_move_number_array
-#define nvlist_move_nvlist illumos_nvlist_move_nvlist
-#define nvlist_move_nvlist_array illumos_nvlist_move_nvlist_array
-#define nvlist_move_nvpair illumos_nvlist_move_nvpair
-#define nvlist_move_string illumos_nvlist_move_string
-#define nvlist_move_string_array illumos_nvlist_move_string_array
-#define nvlist_ndescriptors illumos_nvlist_ndescriptors
-#define nvlist_next illumos_nvlist_next
-#define nvlist_next_nvpair illumos_nvlist_next_nvpair
-#define nvlist_pack illumos_nvlist_pack
-#define nvlist_prev_nvpair illumos_nvlist_prev_nvpair
-#define nvlist_recv illumos_nvlist_recv
-#define nvlist_remove_nvpair illumos_nvlist_remove_nvpair
-#define nvlist_send illumos_nvlist_send
-#define nvlist_set_array_next illumos_nvlist_set_array_next
-#define nvlist_set_error illumos_nvlist_set_error
-#define nvlist_set_flags illumos_nvlist_set_flags
-#define nvlist_set_parent illumos_nvlist_set_parent
-#define nvlist_size illumos_nvlist_size
-#define nvlist_take_binary illumos_nvlist_take_binary
-#define nvlist_take_bool illumos_nvlist_take_bool
-#define nvlist_take_bool_array illumos_nvlist_take_bool_array
-#define nvlist_take_descriptor illumos_nvlist_take_descriptor
-#define nvlist_take_descriptor_array illumos_nvlist_take_descriptor_array
-#define nvlist_take_number illumos_nvlist_take_number
-#define nvlist_take_number_array illumos_nvlist_take_number_array
-#define nvlist_take_nvlist illumos_nvlist_take_nvlist
-#define nvlist_take_nvlist_array illumos_nvlist_take_nvlist_array
-#define nvlist_take_nvpair illumos_nvlist_take_nvpair
-#define nvlist_take_string illumos_nvlist_take_string
-#define nvlist_take_string_array illumos_nvlist_take_string_array
-#define nvlist_unpack illumos_nvlist_unpack
-#define nvlist_unpack_header illumos_nvlist_unpack_header
-#define nvlist_xfer illumos_nvlist_xfer
-#define nvpair_assert illumos_nvpair_assert
-#define nvpair_clone illumos_nvpair_clone
-#define nvpair_create_binary illumos_nvpair_create_binary
-#define nvpair_create_bool illumos_nvpair_create_bool
-#define nvpair_create_bool_array illumos_nvpair_create_bool_array
-#define nvpair_create_descriptor illumos_nvpair_create_descriptor
-#define nvpair_create_descriptor_array illumos_nvpair_create_descriptor_array
-#define nvpair_create_null illumos_nvpair_create_null
-#define nvpair_create_number illumos_nvpair_create_number
-#define nvpair_create_number_array illumos_nvpair_create_number_array
-#define nvpair_create_nvlist illumos_nvpair_create_nvlist
-#define nvpair_create_nvlist_array illumos_nvpair_create_nvlist_array
-#define nvpair_create_string illumos_nvpair_create_string
-#define nvpair_create_string_array illumos_nvpair_create_string_array
-#define nvpair_create_stringf illumos_nvpair_create_stringf
-#define nvpair_create_stringv illumos_nvpair_create_stringv
-#define nvpair_free illumos_nvpair_free
-#define nvpair_free_structure illumos_nvpair_free_structure
-#define nvpair_get_binary illumos_nvpair_get_binary
-#define nvpair_get_bool illumos_nvpair_get_bool
-#define nvpair_get_bool_array illumos_nvpair_get_bool_array
-#define nvpair_get_descriptor illumos_nvpair_get_descriptor
-#define nvpair_get_descriptor_array illumos_nvpair_get_descriptor_array
-#define nvpair_get_number illumos_nvpair_get_number
-#define nvpair_get_number_array illumos_nvpair_get_number_array
-#define nvpair_get_nvlist illumos_nvpair_get_nvlist
-#define nvpair_get_string illumos_nvpair_get_string
-#define nvpair_header_size illumos_nvpair_header_size
-#define nvpair_init_datasize illumos_nvpair_init_datasize
-#define nvpair_insert illumos_nvpair_insert
-#define nvpair_move_binary illumos_nvpair_move_binary
-#define nvpair_move_bool_array illumos_nvpair_move_bool_array
-#define nvpair_move_descriptor illumos_nvpair_move_descriptor
-#define nvpair_move_descriptor_array illumos_nvpair_move_descriptor_array
-#define nvpair_move_number_array illumos_nvpair_move_number_array
-#define nvpair_move_nvlist illumos_nvpair_move_nvlist
-#define nvpair_move_nvlist_array illumos_nvpair_move_nvlist_array
-#define nvpair_move_string illumos_nvpair_move_string
-#define nvpair_move_string_array illumos_nvpair_move_string_array
-#define nvpair_name illumos_nvpair_name
-#define nvpair_next illumos_nvpair_next
-#define nvpair_nvlist illumos_nvpair_nvlist
-#define nvpair_pack_binary illumos_nvpair_pack_binary
-#define nvpair_pack_bool illumos_nvpair_pack_bool
-#define nvpair_pack_bool_array illumos_nvpair_pack_bool_array
-#define nvpair_pack_descriptor illumos_nvpair_pack_descriptor
-#define nvpair_pack_descriptor_array illumos_nvpair_pack_descriptor_array
-#define nvpair_pack_header illumos_nvpair_pack_header
-#define nvpair_pack_null illumos_nvpair_pack_null
-#define nvpair_pack_number illumos_nvpair_pack_number
-#define nvpair_pack_number_array illumos_nvpair_pack_number_array
-#define nvpair_pack_nvlist_array_next illumos_nvpair_pack_nvlist_array_next
-#define nvpair_pack_nvlist_up illumos_nvpair_pack_nvlist_up
-#define nvpair_pack_string illumos_nvpair_pack_string
-#define nvpair_pack_string_array illumos_nvpair_pack_string_array
-#define nvpair_prev illumos_nvpair_prev
-#define nvpair_remove illumos_nvpair_remove
-#define nvpair_size illumos_nvpair_size
-#define nvpair_type illumos_nvpair_type
-#define nvpair_type_string illumos_nvpair_type_string
-#define nvpair_unpack illumos_nvpair_unpack
-#define nvpair_unpack_binary illumos_nvpair_unpack_binary
-#define nvpair_unpack_bool illumos_nvpair_unpack_bool
-#define nvpair_unpack_bool_array illumos_nvpair_unpack_bool_array
-#define nvpair_unpack_descriptor illumos_nvpair_unpack_descriptor
-#define nvpair_unpack_descriptor_array illumos_nvpair_unpack_descriptor_array
-#define nvpair_unpack_header illumos_nvpair_unpack_header
-#define nvpair_unpack_null illumos_nvpair_unpack_null
-#define nvpair_unpack_number illumos_nvpair_unpack_number
-#define nvpair_unpack_number_array illumos_nvpair_unpack_number_array
-#define nvpair_unpack_nvlist illumos_nvpair_unpack_nvlist
-#define nvpair_unpack_nvlist_array illumos_nvpair_unpack_nvlist_array
-#define nvpair_unpack_string illumos_nvpair_unpack_string
-#define nvpair_unpack_string_array illumos_nvpair_unpack_string_array
-
-#endif /* _KERNEL */
-
-#include_next <sys/nvpair.h>
-
-#endif
diff --git a/sys/cddl/compat/opensolaris/sys/param.h b/sys/cddl/compat/opensolaris/sys/param.h
deleted file mode 100644
index 609d22afe8c1..000000000000
--- a/sys/cddl/compat/opensolaris/sys/param.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2007 John Birrell <jb@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- *
- */
-
-#ifndef _COMPAT_OPENSOLARIS_SYS_PARAM_H_
-#define _COMPAT_OPENSOLARIS_SYS_PARAM_H_
-
-#include_next <sys/param.h>
-
-#define PAGESIZE PAGE_SIZE
-
-#ifdef _KERNEL
-#define ptob(x) ((uint64_t)(x) << PAGE_SHIFT)
-#endif
-
-#endif
diff --git a/sys/cddl/compat/opensolaris/sys/proc.h b/sys/cddl/compat/opensolaris/sys/proc.h
deleted file mode 100644
index d91833a58f8c..000000000000
--- a/sys/cddl/compat/opensolaris/sys/proc.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_PROC_H_
-#define _OPENSOLARIS_SYS_PROC_H_
-
-#include <sys/param.h>
-#include <sys/kthread.h>
-#include_next <sys/proc.h>
-#include <sys/stdint.h>
-#include <sys/smp.h>
-#include <sys/sched.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/unistd.h>
-#include <sys/debug.h>
-
-#ifdef _KERNEL
-
-#define CPU curcpu
-#define minclsyspri PRIBIO
-#define maxclsyspri PVM
-#define max_ncpus (mp_maxid + 1)
-#define boot_max_ncpus (mp_maxid + 1)
-#define syscid 1
-
-#define TS_RUN 0
-
-#define p0 proc0
-
-#define t_did td_tid
-
-typedef short pri_t;
-typedef struct thread _kthread;
-typedef struct thread kthread_t;
-typedef struct thread *kthread_id_t;
-typedef struct proc proc_t;
-
-extern struct proc *system_proc;
-
-static __inline kthread_t *
-do_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
- size_t len, proc_t *pp, int state, pri_t pri)
-{
- kthread_t *td = NULL;
- proc_t **ppp;
- int error;
-
- /*
- * Be sure there are no surprises.
- */
- ASSERT(stk == NULL);
- ASSERT(len == 0);
- ASSERT(state == TS_RUN);
- ASSERT(pp != NULL);
-
- if (pp == &p0)
- ppp = &system_proc;
- else
- ppp = &pp;
- error = kproc_kthread_add(proc, arg, ppp, &td, RFSTOPPED,
- stksize / PAGE_SIZE, "zfskern", "solthread %p", proc);
- if (error == 0) {
- thread_lock(td);
- sched_prio(td, pri);
- sched_add(td, SRQ_BORING);
- }
- return (td);
-}
-
-#define thread_create(stk, stksize, proc, arg, len, pp, state, pri) \
- do_thread_create(stk, stksize, proc, arg, len, pp, state, pri)
-#define thread_exit() kthread_exit()
-
-int uread(proc_t *, void *, size_t, uintptr_t);
-int uwrite(proc_t *, void *, size_t, uintptr_t);
-
-#endif /* _KERNEL */
-
-#endif /* _OPENSOLARIS_SYS_PROC_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/stat.h b/sys/cddl/compat/opensolaris/sys/stat.h
deleted file mode 100644
index 05b9671789dd..000000000000
--- a/sys/cddl/compat/opensolaris/sys/stat.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2007 John Birrell <jb@freebsd.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- *
- */
-
-#ifndef _COMPAT_OPENSOLARIS_SYS_STAT_H_
-#define _COMPAT_OPENSOLARIS_SYS_STAT_H_
-
-#include_next <sys/stat.h>
-
-/*
- * When bootstrapping on Linux a stat64/fstat64 functions exists in both
- * glibc and musl libc. To avoid compilation errors, use those functions instead
- * of redefining them to stat/fstat.
- * Similarly, macOS provides (deprecated) stat64 functions that we can use
- * for now.
- */
-#if !defined(__linux__) && !defined(__APPLE__)
-#define stat64 stat
-
-#define MAXOFFSET_T OFF_MAX
-
-#if !defined(_KERNEL)
-#include <sys/disk.h>
-
-static __inline int
-fstat64(int fd, struct stat *sb)
-{
- int ret;
-
- ret = fstat(fd, sb);
- if (ret == 0) {
- if (S_ISCHR(sb->st_mode))
- (void)ioctl(fd, DIOCGMEDIASIZE, &sb->st_size);
- }
- return (ret);
-}
-#endif /* !defined(_KERNEL) */
-#endif /* !defined(__linux__) && !defined(__APPLE__) */
-
-#endif /* !_COMPAT_OPENSOLARIS_SYS_STAT_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/systm.h b/sys/cddl/compat/opensolaris/sys/systm.h
deleted file mode 100644
index fe0e1998c2c4..000000000000
--- a/sys/cddl/compat/opensolaris/sys/systm.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_SYSTM_H_
-#define _OPENSOLARIS_SYS_SYSTM_H_
-
-#ifdef _KERNEL
-
-#include <sys/param.h>
-#include_next <sys/systm.h>
-
-#include <sys/string.h>
-
-#define PAGESIZE PAGE_SIZE
-#define PAGEOFFSET (PAGESIZE - 1)
-#define PAGEMASK (~PAGEOFFSET)
-
-#define delay(x) pause("soldelay", (x))
-
-#endif /* _KERNEL */
-
-#endif /* _OPENSOLARIS_SYS_SYSTM_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/time.h b/sys/cddl/compat/opensolaris/sys/time.h
deleted file mode 100644
index 5f51d08550f4..000000000000
--- a/sys/cddl/compat/opensolaris/sys/time.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_TIME_H_
-#define _OPENSOLARIS_SYS_TIME_H_
-
-#include <sys/types.h>
-#include_next <sys/time.h>
-
-#define SEC 1
-#define MILLISEC 1000
-#define MICROSEC 1000000
-#define NANOSEC 1000000000
-#define TIME_MAX LLONG_MAX
-
-#define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
-#define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
-
-#define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
-#define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
-
-#define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
-#define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
-
-typedef longlong_t hrtime_t;
-
-#if defined(__i386__) || defined(__powerpc__)
-#define TIMESPEC_OVERFLOW(ts) \
- ((ts)->tv_sec < INT32_MIN || (ts)->tv_sec > INT32_MAX)
-#else
-#define TIMESPEC_OVERFLOW(ts) \
- ((ts)->tv_sec < INT64_MIN || (ts)->tv_sec > INT64_MAX)
-#endif
-
-#define SEC_TO_TICK(sec) ((sec) * hz)
-#define NSEC_TO_TICK(nsec) ((nsec) / (NANOSEC / hz))
-
-#ifdef _KERNEL
-static __inline hrtime_t
-gethrtime(void) {
-
- struct timespec ts;
- hrtime_t nsec;
-
- getnanouptime(&ts);
- nsec = (hrtime_t)ts.tv_sec * NANOSEC + ts.tv_nsec;
- return (nsec);
-}
-
-#define gethrestime_sec() (time_second)
-#define gethrestime(ts) getnanotime(ts)
-#define gethrtime_waitfree() gethrtime()
-
-extern int nsec_per_tick; /* nanoseconds per clock tick */
-
-#define ddi_get_lbolt64() \
- (int64_t)(((getsbinuptime() >> 16) * hz) >> 16)
-#define ddi_get_lbolt() (clock_t)ddi_get_lbolt64()
-
-#else
-
-static __inline hrtime_t gethrtime(void) {
- struct timespec ts;
- clock_gettime(CLOCK_UPTIME,&ts);
- return (((u_int64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
-}
-
-#endif /* _KERNEL */
-
-#endif /* !_OPENSOLARIS_SYS_TIME_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/types.h b/sys/cddl/compat/opensolaris/sys/types.h
deleted file mode 100644
index ee065f023af0..000000000000
--- a/sys/cddl/compat/opensolaris/sys/types.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_TYPES_H_
-#define _OPENSOLARIS_SYS_TYPES_H_
-
-/*
- * This is a bag of dirty hacks to keep things compiling.
- */
-
-#include <sys/stdint.h>
-
-#ifdef _KERNEL
-typedef int64_t clock_t;
-#define _CLOCK_T_DECLARED
-#endif
-
-#include_next <sys/types.h>
-
-#define MAXNAMELEN 256
-
-typedef struct timespec timestruc_t;
-typedef struct timespec timespec_t;
-typedef u_int uint_t;
-typedef u_char uchar_t;
-typedef u_short ushort_t;
-typedef u_long ulong_t;
-typedef long long longlong_t;
-typedef unsigned long long u_longlong_t;
-#ifndef _OFF64_T_DECLARED
-#define _OFF64_T_DECLARED
-typedef off_t off64_t;
-#endif
-typedef id_t taskid_t;
-typedef id_t projid_t;
-typedef id_t poolid_t;
-typedef id_t zoneid_t;
-typedef id_t ctid_t;
-typedef mode_t o_mode_t;
-typedef uint64_t pgcnt_t;
-typedef u_int minor_t;
-
-#ifdef _KERNEL
-
-#define B_FALSE 0
-#define B_TRUE 1
-
-typedef short index_t;
-typedef off_t offset_t;
-#ifndef _PTRDIFF_T_DECLARED
-typedef __ptrdiff_t ptrdiff_t; /* pointer difference */
-#define _PTRDIFF_T_DECLARED
-#endif
-typedef int64_t rlim64_t;
-typedef int major_t;
-
-#else
-#ifdef NEED_SOLARIS_BOOLEAN
-#if defined(__XOPEN_OR_POSIX)
-typedef enum { _B_FALSE, _B_TRUE } boolean_t;
-#else
-typedef enum { B_FALSE, B_TRUE } boolean_t;
-#endif /* defined(__XOPEN_OR_POSIX) */
-#endif
-
-typedef longlong_t offset_t;
-typedef u_longlong_t u_offset_t;
-typedef uint64_t upad64_t;
-typedef short pri_t;
-typedef int32_t daddr32_t;
-typedef int32_t time32_t;
-typedef u_longlong_t diskaddr_t;
-
-#endif /* !_KERNEL */
-
-#endif /* !_OPENSOLARIS_SYS_TYPES_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/uio.h b/sys/cddl/compat/opensolaris/sys/uio.h
deleted file mode 100644
index f0edfb1c0541..000000000000
--- a/sys/cddl/compat/opensolaris/sys/uio.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-
- * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_UIO_H_
-#define _OPENSOLARIS_SYS_UIO_H_
-
-#include_next <sys/uio.h>
-#include <sys/debug.h>
-
-#ifndef _KERNEL
-#define FOF_OFFSET 1 /* Use the offset in uio argument */
-
-struct uio {
- struct iovec *uio_iov;
- int uio_iovcnt;
- off_t uio_offset;
- int uio_resid;
- enum uio_seg uio_segflg;
- enum uio_rw uio_rw;
- void *uio_td;
-};
-#endif
-
-#define uio_loffset uio_offset
-
-typedef struct uio uio_t;
-typedef struct iovec iovec_t;
-
-typedef enum xuio_type {
- UIOTYPE_ASYNCIO,
- UIOTYPE_ZEROCOPY
-} xuio_type_t;
-
-typedef struct xuio {
- uio_t xu_uio;
-
- /* Extended uio fields */
- enum xuio_type xu_type; /* What kind of uio structure? */
- union {
- struct {
- int xu_zc_rw;
- void *xu_zc_priv;
- } xu_zc;
- } xu_ext;
-} xuio_t;
-
-#define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv
-#define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw
-
-#ifdef BUILDING_ZFS
-static __inline int
-zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio)
-{
-
- ASSERT(uio->uio_rw == dir);
- return (uiomove(cp, (int)n, uio));
-}
-#define uiomove(cp, n, dir, uio) zfs_uiomove((cp), (n), (dir), (uio))
-
-int uiocopy(void *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes);
-void uioskip(uio_t *uiop, size_t n);
-#endif /* BUILDING_ZFS */
-
-#endif /* !_OPENSOLARIS_SYS_UIO_H_ */
diff --git a/sys/cddl/compat/opensolaris/sys/vnode.h b/sys/cddl/compat/opensolaris/sys/vnode.h
deleted file mode 100644
index 0d1646396538..000000000000
--- a/sys/cddl/compat/opensolaris/sys/vnode.h
+++ /dev/null
@@ -1,287 +0,0 @@
-/*-
- * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef _OPENSOLARIS_SYS_VNODE_H_
-#define _OPENSOLARIS_SYS_VNODE_H_
-
-#ifdef _KERNEL
-
-struct vnode;
-struct vattr;
-
-typedef struct vnode vnode_t;
-typedef struct vattr vattr_t;
-typedef enum vtype vtype_t;
-
-#include <sys/namei.h>
-enum symfollow { NO_FOLLOW = NOFOLLOW };
-
-#include <sys/proc.h>
-#include_next <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/cred.h>
-#include <sys/fcntl.h>
-#include <sys/file.h>
-#include <sys/filedesc.h>
-#include <sys/syscallsubr.h>
-
-typedef struct vop_vector vnodeops_t;
-#define VOP_FID VOP_VPTOFH
-#define vop_fid vop_vptofh
-#define vop_fid_args vop_vptofh_args
-#define a_fid a_fhp
-
-#define IS_XATTRDIR(dvp) (0)
-
-#define v_count v_usecount
-
-#define V_APPEND VAPPEND
-
-#define rootvfs (rootvnode == NULL ? NULL : rootvnode->v_mount)
-
-static __inline int
-vn_is_readonly(vnode_t *vp)
-{
- return (vp->v_mount->mnt_flag & MNT_RDONLY);
-}
-#define vn_vfswlock(vp) (0)
-#define vn_vfsunlock(vp) do { } while (0)
-#define vn_ismntpt(vp) ((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
-#define vn_mountedvfs(vp) ((vp)->v_mountedhere)
-#define vn_has_cached_data(vp) \
- ((vp)->v_object != NULL && \
- (vp)->v_object->resident_page_count > 0)
-#define vn_exists(vp) do { } while (0)
-#define vn_invalid(vp) do { } while (0)
-#define vn_renamepath(tdvp, svp, tnm, lentnm) do { } while (0)
-#define vn_free(vp) do { } while (0)
-#define vn_matchops(vp, vops) ((vp)->v_op == &(vops))
-
-#define VN_HOLD(v) vref(v)
-#define VN_RELE(v) vrele(v)
-#define VN_URELE(v) vput(v)
-
-#define vnevent_create(vp, ct) do { } while (0)
-#define vnevent_link(vp, ct) do { } while (0)
-#define vnevent_remove(vp, dvp, name, ct) do { } while (0)
-#define vnevent_rmdir(vp, dvp, name, ct) do { } while (0)
-#define vnevent_rename_src(vp, dvp, name, ct) do { } while (0)
-#define vnevent_rename_dest(vp, dvp, name, ct) do { } while (0)
-#define vnevent_rename_dest_dir(vp, ct) do { } while (0)
-
-#define specvp(vp, rdev, type, cr) (VN_HOLD(vp), (vp))
-#define MANDMODE(mode) (0)
-#define MANDLOCK(vp, mode) (0)
-#define chklock(vp, op, offset, size, mode, ct) (0)
-#define cleanlocks(vp, pid, foo) do { } while (0)
-#define cleanshares(vp, pid) do { } while (0)
-
-/*
- * We will use va_spare is place of Solaris' va_mask.
- * This field is initialized in zfs_setattr().
- */
-#define va_mask va_spare
-/* TODO: va_fileid is shorter than va_nodeid !!! */
-#define va_nodeid va_fileid
-/* TODO: This field needs conversion! */
-#define va_nblocks va_bytes
-#define va_blksize va_blocksize
-#define va_seq va_gen
-
-#define MAXOFFSET_T OFF_MAX
-#define EXCL 0
-
-#define ACCESSED (AT_ATIME)
-#define STATE_CHANGED (AT_CTIME)
-#define CONTENT_MODIFIED (AT_MTIME | AT_CTIME)
-
-static __inline void
-vattr_init_mask(vattr_t *vap)
-{
-
- vap->va_mask = 0;
-
- if (vap->va_type != VNON)
- vap->va_mask |= AT_TYPE;
- if (vap->va_uid != (uid_t)VNOVAL)
- vap->va_mask |= AT_UID;
- if (vap->va_gid != (gid_t)VNOVAL)
- vap->va_mask |= AT_GID;
- if (vap->va_size != (u_quad_t)VNOVAL)
- vap->va_mask |= AT_SIZE;
- if (vap->va_atime.tv_sec != VNOVAL)
- vap->va_mask |= AT_ATIME;
- if (vap->va_mtime.tv_sec != VNOVAL)
- vap->va_mask |= AT_MTIME;
- if (vap->va_mode != (u_short)VNOVAL)
- vap->va_mask |= AT_MODE;
- if (vap->va_flags != VNOVAL)
- vap->va_mask |= AT_XVATTR;
-}
-
-#define FCREAT O_CREAT
-#define FTRUNC O_TRUNC
-#define FEXCL O_EXCL
-#define FDSYNC FFSYNC
-#define FRSYNC FFSYNC
-#define FSYNC FFSYNC
-#define FOFFMAX 0x00
-#define FIGNORECASE 0x00
-
-static __inline int
-vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode,
- vnode_t **vpp, enum create crwhy, mode_t umask, struct vnode *startvp,
- int fd)
-{
- struct thread *td = curthread;
- struct nameidata nd;
- int error, operation;
-
- ASSERT(seg == UIO_SYSSPACE);
- if ((filemode & FCREAT) != 0) {
- ASSERT(filemode == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
- ASSERT(crwhy == CRCREAT);
- operation = CREATE;
- } else {
- ASSERT(filemode == (FREAD | FOFFMAX) ||
- filemode == (FREAD | FWRITE | FOFFMAX));
- ASSERT(crwhy == 0);
- operation = LOOKUP;
- }
- ASSERT(umask == 0);
-
- pwd_ensure_dirs();
-
- if (startvp != NULL)
- vref(startvp);
- NDINIT_ATVP(&nd, operation, 0, UIO_SYSSPACE, pnamep, startvp, td);
- filemode |= O_NOFOLLOW;
- error = vn_open_cred(&nd, &filemode, createmode, 0, td->td_ucred, NULL);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (error == 0) {
- /* We just unlock so we hold a reference. */
- VOP_UNLOCK(nd.ni_vp);
- *vpp = nd.ni_vp;
- }
- return (error);
-}
-
-static __inline int
-zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
- vnode_t **vpp, enum create crwhy, mode_t umask)
-{
-
- return (vn_openat(pnamep, seg, filemode, createmode, vpp, crwhy,
- umask, NULL, -1));
-}
-#define vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask) \
- zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
-
-#define RLIM64_INFINITY 0
-static __inline int
-zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
- offset_t offset, enum uio_seg seg, int ioflag, int ulimit, cred_t *cr,
- ssize_t *residp)
-{
- struct thread *td = curthread;
- int error;
- ssize_t resid;
-
- ASSERT(ioflag == 0);
- ASSERT(ulimit == RLIM64_INFINITY);
-
- if (rw == UIO_WRITE) {
- ioflag = IO_SYNC;
- } else {
- ioflag = IO_DIRECT;
- }
- error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr, NOCRED,
- &resid, td);
- if (residp != NULL)
- *residp = (ssize_t)resid;
- return (error);
-}
-#define vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
- zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
-
-static __inline int
-zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
-{
- struct mount *mp;
- int error;
-
- ASSERT(flag == FSYNC);
-
- if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
- goto drop;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
- error = VOP_FSYNC(vp, MNT_WAIT, curthread);
- VOP_UNLOCK(vp);
- vn_finished_write(mp);
-drop:
- return (error);
-}
-#define VOP_FSYNC(vp, flag, cr, ct) zfs_vop_fsync((vp), (flag), (cr))
-
-static __inline int
-zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
-{
- int error;
-
- ASSERT(count == 1);
- ASSERT(offset == 0);
-
- error = vn_close(vp, flag, cr, curthread);
- return (error);
-}
-#define VOP_CLOSE(vp, oflags, count, offset, cr, ct) \
- zfs_vop_close((vp), (oflags), (count), (offset), (cr))
-
-static __inline int
-vn_rename(char *from, char *to, enum uio_seg seg)
-{
-
- ASSERT(seg == UIO_SYSSPACE);
-
- return (kern_renameat(curthread, AT_FDCWD, from, AT_FDCWD, to, seg));
-}
-
-static __inline int
-vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
-{
-
- ASSERT(seg == UIO_SYSSPACE);
- ASSERT(dirflag == RMFILE);
-
- return (kern_funlinkat(curthread, AT_FDCWD, fnamep, FD_NONE, seg, 0,
- 0));
-}
-
-#endif /* _KERNEL */
-
-#endif /* _OPENSOLARIS_SYS_VNODE_H_ */
diff --git a/sys/cddl/contrib/opensolaris/common/acl/acl_common.c b/sys/cddl/contrib/opensolaris/common/acl/acl_common.c
deleted file mode 100644
index a681905579c6..000000000000
--- a/sys/cddl/contrib/opensolaris/common/acl/acl_common.c
+++ /dev/null
@@ -1,1765 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/avl.h>
-#include <sys/misc.h>
-#if defined(_KERNEL)
-#include <sys/kmem.h>
-#include <sys/systm.h>
-#include <sys/sysmacros.h>
-#include <acl/acl_common.h>
-#include <sys/debug.h>
-#else
-#include <errno.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <strings.h>
-#include <unistd.h>
-#include <assert.h>
-#include <grp.h>
-#include <pwd.h>
-#include <acl_common.h>
-#define ASSERT assert
-#endif
-
-#define ACE_POSIX_SUPPORTED_BITS (ACE_READ_DATA | \
- ACE_WRITE_DATA | ACE_APPEND_DATA | ACE_EXECUTE | \
- ACE_READ_ATTRIBUTES | ACE_READ_ACL | ACE_WRITE_ACL)
-
-
-#define ACL_SYNCHRONIZE_SET_DENY 0x0000001
-#define ACL_SYNCHRONIZE_SET_ALLOW 0x0000002
-#define ACL_SYNCHRONIZE_ERR_DENY 0x0000004
-#define ACL_SYNCHRONIZE_ERR_ALLOW 0x0000008
-
-#define ACL_WRITE_OWNER_SET_DENY 0x0000010
-#define ACL_WRITE_OWNER_SET_ALLOW 0x0000020
-#define ACL_WRITE_OWNER_ERR_DENY 0x0000040
-#define ACL_WRITE_OWNER_ERR_ALLOW 0x0000080
-
-#define ACL_DELETE_SET_DENY 0x0000100
-#define ACL_DELETE_SET_ALLOW 0x0000200
-#define ACL_DELETE_ERR_DENY 0x0000400
-#define ACL_DELETE_ERR_ALLOW 0x0000800
-
-#define ACL_WRITE_ATTRS_OWNER_SET_DENY 0x0001000
-#define ACL_WRITE_ATTRS_OWNER_SET_ALLOW 0x0002000
-#define ACL_WRITE_ATTRS_OWNER_ERR_DENY 0x0004000
-#define ACL_WRITE_ATTRS_OWNER_ERR_ALLOW 0x0008000
-
-#define ACL_WRITE_ATTRS_WRITER_SET_DENY 0x0010000
-#define ACL_WRITE_ATTRS_WRITER_SET_ALLOW 0x0020000
-#define ACL_WRITE_ATTRS_WRITER_ERR_DENY 0x0040000
-#define ACL_WRITE_ATTRS_WRITER_ERR_ALLOW 0x0080000
-
-#define ACL_WRITE_NAMED_WRITER_SET_DENY 0x0100000
-#define ACL_WRITE_NAMED_WRITER_SET_ALLOW 0x0200000
-#define ACL_WRITE_NAMED_WRITER_ERR_DENY 0x0400000
-#define ACL_WRITE_NAMED_WRITER_ERR_ALLOW 0x0800000
-
-#define ACL_READ_NAMED_READER_SET_DENY 0x1000000
-#define ACL_READ_NAMED_READER_SET_ALLOW 0x2000000
-#define ACL_READ_NAMED_READER_ERR_DENY 0x4000000
-#define ACL_READ_NAMED_READER_ERR_ALLOW 0x8000000
-
-
-#define ACE_VALID_MASK_BITS (\
- ACE_READ_DATA | \
- ACE_LIST_DIRECTORY | \
- ACE_WRITE_DATA | \
- ACE_ADD_FILE | \
- ACE_APPEND_DATA | \
- ACE_ADD_SUBDIRECTORY | \
- ACE_READ_NAMED_ATTRS | \
- ACE_WRITE_NAMED_ATTRS | \
- ACE_EXECUTE | \
- ACE_DELETE_CHILD | \
- ACE_READ_ATTRIBUTES | \
- ACE_WRITE_ATTRIBUTES | \
- ACE_DELETE | \
- ACE_READ_ACL | \
- ACE_WRITE_ACL | \
- ACE_WRITE_OWNER | \
- ACE_SYNCHRONIZE)
-
-#define ACE_MASK_UNDEFINED 0x80000000
-
-#define ACE_VALID_FLAG_BITS (ACE_FILE_INHERIT_ACE | \
- ACE_DIRECTORY_INHERIT_ACE | \
- ACE_NO_PROPAGATE_INHERIT_ACE | ACE_INHERIT_ONLY_ACE | \
- ACE_SUCCESSFUL_ACCESS_ACE_FLAG | ACE_FAILED_ACCESS_ACE_FLAG | \
- ACE_IDENTIFIER_GROUP | ACE_OWNER | ACE_GROUP | ACE_EVERYONE)
-
-/*
- * ACL conversion helpers
- */
-
-typedef enum {
- ace_unused,
- ace_user_obj,
- ace_user,
- ace_group, /* includes GROUP and GROUP_OBJ */
- ace_other_obj
-} ace_to_aent_state_t;
-
-typedef struct acevals {
- uid_t key;
- avl_node_t avl;
- uint32_t mask;
- uint32_t allowed;
- uint32_t denied;
- int aent_type;
-} acevals_t;
-
-typedef struct ace_list {
- acevals_t user_obj;
- avl_tree_t user;
- int numusers;
- acevals_t group_obj;
- avl_tree_t group;
- int numgroups;
- acevals_t other_obj;
- uint32_t acl_mask;
- int hasmask;
- int dfacl_flag;
- ace_to_aent_state_t state;
- int seen; /* bitmask of all aclent_t a_type values seen */
-} ace_list_t;
-
-/*
- * Generic shellsort, from K&R (1st ed, p 58.), somewhat modified.
- * v = Ptr to array/vector of objs
- * n = # objs in the array
- * s = size of each obj (must be multiples of a word size)
- * f = ptr to function to compare two objs
- * returns (-1 = less than, 0 = equal, 1 = greater than
- */
-void
-ksort(caddr_t v, int n, int s, int (*f)())
-{
- int g, i, j, ii;
- unsigned int *p1, *p2;
- unsigned int tmp;
-
- /* No work to do */
- if (v == NULL || n <= 1)
- return;
-
- /* Sanity check on arguments */
- ASSERT(((uintptr_t)v & 0x3) == 0 && (s & 0x3) == 0);
- ASSERT(s > 0);
- for (g = n / 2; g > 0; g /= 2) {
- for (i = g; i < n; i++) {
- for (j = i - g; j >= 0 &&
- (*f)(v + j * s, v + (j + g) * s) == 1;
- j -= g) {
- p1 = (void *)(v + j * s);
- p2 = (void *)(v + (j + g) * s);
- for (ii = 0; ii < s / 4; ii++) {
- tmp = *p1;
- *p1++ = *p2;
- *p2++ = tmp;
- }
- }
- }
- }
-}
-
-/*
- * Compare two acls, all fields. Returns:
- * -1 (less than)
- * 0 (equal)
- * +1 (greater than)
- */
-int
-cmp2acls(void *a, void *b)
-{
- aclent_t *x = (aclent_t *)a;
- aclent_t *y = (aclent_t *)b;
-
- /* Compare types */
- if (x->a_type < y->a_type)
- return (-1);
- if (x->a_type > y->a_type)
- return (1);
- /* Equal types; compare id's */
- if (x->a_id < y->a_id)
- return (-1);
- if (x->a_id > y->a_id)
- return (1);
- /* Equal ids; compare perms */
- if (x->a_perm < y->a_perm)
- return (-1);
- if (x->a_perm > y->a_perm)
- return (1);
- /* Totally equal */
- return (0);
-}
-
-/*ARGSUSED*/
-static void *
-cacl_realloc(void *ptr, size_t size, size_t new_size)
-{
-#if defined(_KERNEL)
- void *tmp;
-
- tmp = kmem_alloc(new_size, KM_SLEEP);
- (void) memcpy(tmp, ptr, (size < new_size) ? size : new_size);
- kmem_free(ptr, size);
- return (tmp);
-#else
- return (realloc(ptr, new_size));
-#endif
-}
-
-static int
-cacl_malloc(void **ptr, size_t size)
-{
-#if defined(_KERNEL)
- *ptr = kmem_zalloc(size, KM_SLEEP);
- return (0);
-#else
- *ptr = calloc(1, size);
- if (*ptr == NULL)
- return (errno);
-
- return (0);
-#endif
-}
-
-/*ARGSUSED*/
-static void
-cacl_free(void *ptr, size_t size)
-{
-#if defined(_KERNEL)
- kmem_free(ptr, size);
-#else
- free(ptr);
-#endif
-}
-
-#if !defined(_KERNEL)
-acl_t *
-acl_alloc(enum acl_type type)
-{
- acl_t *aclp;
-
- if (cacl_malloc((void **)&aclp, sizeof (acl_t)) != 0)
- return (NULL);
-
- aclp->acl_aclp = NULL;
- aclp->acl_cnt = 0;
-
- switch (type) {
- case ACE_T:
- aclp->acl_type = ACE_T;
- aclp->acl_entry_size = sizeof (ace_t);
- break;
- case ACLENT_T:
- aclp->acl_type = ACLENT_T;
- aclp->acl_entry_size = sizeof (aclent_t);
- break;
- default:
- acl_free(aclp);
- aclp = NULL;
- }
- return (aclp);
-}
-
-/*
- * Free acl_t structure
- */
-void
-acl_free(acl_t *aclp)
-{
- int acl_size;
-
- if (aclp == NULL)
- return;
-
- if (aclp->acl_aclp) {
- acl_size = aclp->acl_cnt * aclp->acl_entry_size;
- cacl_free(aclp->acl_aclp, acl_size);
- }
-
- cacl_free(aclp, sizeof (acl_t));
-}
-
-static uint32_t
-access_mask_set(int haswriteperm, int hasreadperm, int isowner, int isallow)
-{
- uint32_t access_mask = 0;
- int acl_produce;
- int synchronize_set = 0, write_owner_set = 0;
- int delete_set = 0, write_attrs_set = 0;
- int read_named_set = 0, write_named_set = 0;
-
- acl_produce = (ACL_SYNCHRONIZE_SET_ALLOW |
- ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
- ACL_WRITE_ATTRS_WRITER_SET_DENY);
-
- if (isallow) {
- synchronize_set = ACL_SYNCHRONIZE_SET_ALLOW;
- write_owner_set = ACL_WRITE_OWNER_SET_ALLOW;
- delete_set = ACL_DELETE_SET_ALLOW;
- if (hasreadperm)
- read_named_set = ACL_READ_NAMED_READER_SET_ALLOW;
- if (haswriteperm)
- write_named_set = ACL_WRITE_NAMED_WRITER_SET_ALLOW;
- if (isowner)
- write_attrs_set = ACL_WRITE_ATTRS_OWNER_SET_ALLOW;
- else if (haswriteperm)
- write_attrs_set = ACL_WRITE_ATTRS_WRITER_SET_ALLOW;
- } else {
-
- synchronize_set = ACL_SYNCHRONIZE_SET_DENY;
- write_owner_set = ACL_WRITE_OWNER_SET_DENY;
- delete_set = ACL_DELETE_SET_DENY;
- if (hasreadperm)
- read_named_set = ACL_READ_NAMED_READER_SET_DENY;
- if (haswriteperm)
- write_named_set = ACL_WRITE_NAMED_WRITER_SET_DENY;
- if (isowner)
- write_attrs_set = ACL_WRITE_ATTRS_OWNER_SET_DENY;
- else if (haswriteperm)
- write_attrs_set = ACL_WRITE_ATTRS_WRITER_SET_DENY;
- else
- /*
- * If the entity is not the owner and does not
- * have write permissions ACE_WRITE_ATTRIBUTES will
- * always go in the DENY ACE.
- */
- access_mask |= ACE_WRITE_ATTRIBUTES;
- }
-
- if (acl_produce & synchronize_set)
- access_mask |= ACE_SYNCHRONIZE;
- if (acl_produce & write_owner_set)
- access_mask |= ACE_WRITE_OWNER;
- if (acl_produce & delete_set)
- access_mask |= ACE_DELETE;
- if (acl_produce & write_attrs_set)
- access_mask |= ACE_WRITE_ATTRIBUTES;
- if (acl_produce & read_named_set)
- access_mask |= ACE_READ_NAMED_ATTRS;
- if (acl_produce & write_named_set)
- access_mask |= ACE_WRITE_NAMED_ATTRS;
-
- return (access_mask);
-}
-
-/*
- * Given an mode_t, convert it into an access_mask as used
- * by nfsace, assuming aclent_t -> nfsace semantics.
- */
-static uint32_t
-mode_to_ace_access(mode_t mode, boolean_t isdir, int isowner, int isallow)
-{
- uint32_t access = 0;
- int haswriteperm = 0;
- int hasreadperm = 0;
-
- if (isallow) {
- haswriteperm = (mode & S_IWOTH);
- hasreadperm = (mode & S_IROTH);
- } else {
- haswriteperm = !(mode & S_IWOTH);
- hasreadperm = !(mode & S_IROTH);
- }
-
- /*
- * The following call takes care of correctly setting the following
- * mask bits in the access_mask:
- * ACE_SYNCHRONIZE, ACE_WRITE_OWNER, ACE_DELETE,
- * ACE_WRITE_ATTRIBUTES, ACE_WRITE_NAMED_ATTRS, ACE_READ_NAMED_ATTRS
- */
- access = access_mask_set(haswriteperm, hasreadperm, isowner, isallow);
-
- if (isallow) {
- access |= ACE_READ_ACL | ACE_READ_ATTRIBUTES;
- if (isowner)
- access |= ACE_WRITE_ACL;
- } else {
- if (! isowner)
- access |= ACE_WRITE_ACL;
- }
-
- /* read */
- if (mode & S_IROTH) {
- access |= ACE_READ_DATA;
- }
- /* write */
- if (mode & S_IWOTH) {
- access |= ACE_WRITE_DATA |
- ACE_APPEND_DATA;
- if (isdir)
- access |= ACE_DELETE_CHILD;
- }
- /* exec */
- if (mode & S_IXOTH) {
- access |= ACE_EXECUTE;
- }
-
- return (access);
-}
-
-/*
- * Given an nfsace (presumably an ALLOW entry), make a
- * corresponding DENY entry at the address given.
- */
-static void
-ace_make_deny(ace_t *allow, ace_t *deny, int isdir, int isowner)
-{
- (void) memcpy(deny, allow, sizeof (ace_t));
-
- deny->a_who = allow->a_who;
-
- deny->a_type = ACE_ACCESS_DENIED_ACE_TYPE;
- deny->a_access_mask ^= ACE_POSIX_SUPPORTED_BITS;
- if (isdir)
- deny->a_access_mask ^= ACE_DELETE_CHILD;
-
- deny->a_access_mask &= ~(ACE_SYNCHRONIZE | ACE_WRITE_OWNER |
- ACE_DELETE | ACE_WRITE_ATTRIBUTES | ACE_READ_NAMED_ATTRS |
- ACE_WRITE_NAMED_ATTRS);
- deny->a_access_mask |= access_mask_set((allow->a_access_mask &
- ACE_WRITE_DATA), (allow->a_access_mask & ACE_READ_DATA), isowner,
- B_FALSE);
-}
-/*
- * Make an initial pass over an array of aclent_t's. Gather
- * information such as an ACL_MASK (if any), number of users,
- * number of groups, and whether the array needs to be sorted.
- */
-static int
-ln_aent_preprocess(aclent_t *aclent, int n,
- int *hasmask, mode_t *mask,
- int *numuser, int *numgroup, int *needsort)
-{
- int error = 0;
- int i;
- int curtype = 0;
-
- *hasmask = 0;
- *mask = 07;
- *needsort = 0;
- *numuser = 0;
- *numgroup = 0;
-
- for (i = 0; i < n; i++) {
- if (aclent[i].a_type < curtype)
- *needsort = 1;
- else if (aclent[i].a_type > curtype)
- curtype = aclent[i].a_type;
- if (aclent[i].a_type & USER)
- (*numuser)++;
- if (aclent[i].a_type & (GROUP | GROUP_OBJ))
- (*numgroup)++;
- if (aclent[i].a_type & CLASS_OBJ) {
- if (*hasmask) {
- error = EINVAL;
- goto out;
- } else {
- *hasmask = 1;
- *mask = aclent[i].a_perm;
- }
- }
- }
-
- if ((! *hasmask) && (*numuser + *numgroup > 1)) {
- error = EINVAL;
- goto out;
- }
-
-out:
- return (error);
-}
-
-/*
- * Convert an array of aclent_t into an array of nfsace entries,
- * following POSIX draft -> nfsv4 conversion semantics as outlined in
- * the IETF draft.
- */
-static int
-ln_aent_to_ace(aclent_t *aclent, int n, ace_t **acepp, int *rescount, int isdir)
-{
- int error = 0;
- mode_t mask;
- int numuser, numgroup, needsort;
- int resultsize = 0;
- int i, groupi = 0, skip;
- ace_t *acep, *result = NULL;
- int hasmask;
-
- error = ln_aent_preprocess(aclent, n, &hasmask, &mask,
- &numuser, &numgroup, &needsort);
- if (error != 0)
- goto out;
-
- /* allow + deny for each aclent */
- resultsize = n * 2;
- if (hasmask) {
- /*
- * stick extra deny on the group_obj and on each
- * user|group for the mask (the group_obj was added
- * into the count for numgroup)
- */
- resultsize += numuser + numgroup;
- /* ... and don't count the mask itself */
- resultsize -= 2;
- }
-
- /* sort the source if necessary */
- if (needsort)
- ksort((caddr_t)aclent, n, sizeof (aclent_t), cmp2acls);
-
- if (cacl_malloc((void **)&result, resultsize * sizeof (ace_t)) != 0)
- goto out;
-
- acep = result;
-
- for (i = 0; i < n; i++) {
- /*
- * don't process CLASS_OBJ (mask); mask was grabbed in
- * ln_aent_preprocess()
- */
- if (aclent[i].a_type & CLASS_OBJ)
- continue;
-
- /* If we need an ACL_MASK emulator, prepend it now */
- if ((hasmask) &&
- (aclent[i].a_type & (USER | GROUP | GROUP_OBJ))) {
- acep->a_type = ACE_ACCESS_DENIED_ACE_TYPE;
- acep->a_flags = 0;
- if (aclent[i].a_type & GROUP_OBJ) {
- acep->a_who = (uid_t)-1;
- acep->a_flags |=
- (ACE_IDENTIFIER_GROUP|ACE_GROUP);
- } else if (aclent[i].a_type & USER) {
- acep->a_who = aclent[i].a_id;
- } else {
- acep->a_who = aclent[i].a_id;
- acep->a_flags |= ACE_IDENTIFIER_GROUP;
- }
- if (aclent[i].a_type & ACL_DEFAULT) {
- acep->a_flags |= ACE_INHERIT_ONLY_ACE |
- ACE_FILE_INHERIT_ACE |
- ACE_DIRECTORY_INHERIT_ACE;
- }
- /*
- * Set the access mask for the prepended deny
- * ace. To do this, we invert the mask (found
- * in ln_aent_preprocess()) then convert it to an
- * DENY ace access_mask.
- */
- acep->a_access_mask = mode_to_ace_access((mask ^ 07),
- isdir, 0, 0);
- acep += 1;
- }
-
- /* handle a_perm -> access_mask */
- acep->a_access_mask = mode_to_ace_access(aclent[i].a_perm,
- isdir, aclent[i].a_type & USER_OBJ, 1);
-
- /* emulate a default aclent */
- if (aclent[i].a_type & ACL_DEFAULT) {
- acep->a_flags |= ACE_INHERIT_ONLY_ACE |
- ACE_FILE_INHERIT_ACE |
- ACE_DIRECTORY_INHERIT_ACE;
- }
-
- /*
- * handle a_perm and a_id
- *
- * this must be done last, since it involves the
- * corresponding deny aces, which are handled
- * differently for each different a_type.
- */
- if (aclent[i].a_type & USER_OBJ) {
- acep->a_who = (uid_t)-1;
- acep->a_flags |= ACE_OWNER;
- ace_make_deny(acep, acep + 1, isdir, B_TRUE);
- acep += 2;
- } else if (aclent[i].a_type & USER) {
- acep->a_who = aclent[i].a_id;
- ace_make_deny(acep, acep + 1, isdir, B_FALSE);
- acep += 2;
- } else if (aclent[i].a_type & (GROUP_OBJ | GROUP)) {
- if (aclent[i].a_type & GROUP_OBJ) {
- acep->a_who = (uid_t)-1;
- acep->a_flags |= ACE_GROUP;
- } else {
- acep->a_who = aclent[i].a_id;
- }
- acep->a_flags |= ACE_IDENTIFIER_GROUP;
- /*
- * Set the corresponding deny for the group ace.
- *
- * The deny aces go after all of the groups, unlike
- * everything else, where they immediately follow
- * the allow ace.
- *
- * We calculate "skip", the number of slots to
- * skip ahead for the deny ace, here.
- *
- * The pattern is:
- * MD1 A1 MD2 A2 MD3 A3 D1 D2 D3
- * thus, skip is
- * (2 * numgroup) - 1 - groupi
- * (2 * numgroup) to account for MD + A
- * - 1 to account for the fact that we're on the
- * access (A), not the mask (MD)
- * - groupi to account for the fact that we have
- * passed up groupi number of MD's.
- */
- skip = (2 * numgroup) - 1 - groupi;
- ace_make_deny(acep, acep + skip, isdir, B_FALSE);
- /*
- * If we just did the last group, skip acep past
- * all of the denies; else, just move ahead one.
- */
- if (++groupi >= numgroup)
- acep += numgroup + 1;
- else
- acep += 1;
- } else if (aclent[i].a_type & OTHER_OBJ) {
- acep->a_who = (uid_t)-1;
- acep->a_flags |= ACE_EVERYONE;
- ace_make_deny(acep, acep + 1, isdir, B_FALSE);
- acep += 2;
- } else {
- error = EINVAL;
- goto out;
- }
- }
-
- *acepp = result;
- *rescount = resultsize;
-
-out:
- if (error != 0) {
- if ((result != NULL) && (resultsize > 0)) {
- cacl_free(result, resultsize * sizeof (ace_t));
- }
- }
-
- return (error);
-}
-
-static int
-convert_aent_to_ace(aclent_t *aclentp, int aclcnt, boolean_t isdir,
- ace_t **retacep, int *retacecnt)
-{
- ace_t *acep;
- ace_t *dfacep;
- int acecnt = 0;
- int dfacecnt = 0;
- int dfaclstart = 0;
- int dfaclcnt = 0;
- aclent_t *aclp;
- int i;
- int error;
- int acesz, dfacesz;
-
- ksort((caddr_t)aclentp, aclcnt, sizeof (aclent_t), cmp2acls);
-
- for (i = 0, aclp = aclentp; i < aclcnt; aclp++, i++) {
- if (aclp->a_type & ACL_DEFAULT)
- break;
- }
-
- if (i < aclcnt) {
- dfaclstart = i;
- dfaclcnt = aclcnt - i;
- }
-
- if (dfaclcnt && !isdir) {
- return (EINVAL);
- }
-
- error = ln_aent_to_ace(aclentp, i, &acep, &acecnt, isdir);
- if (error)
- return (error);
-
- if (dfaclcnt) {
- error = ln_aent_to_ace(&aclentp[dfaclstart], dfaclcnt,
- &dfacep, &dfacecnt, isdir);
- if (error) {
- if (acep) {
- cacl_free(acep, acecnt * sizeof (ace_t));
- }
- return (error);
- }
- }
-
- if (dfacecnt != 0) {
- acesz = sizeof (ace_t) * acecnt;
- dfacesz = sizeof (ace_t) * dfacecnt;
- acep = cacl_realloc(acep, acesz, acesz + dfacesz);
- if (acep == NULL)
- return (ENOMEM);
- if (dfaclcnt) {
- (void) memcpy(acep + acecnt, dfacep, dfacesz);
- }
- }
- if (dfaclcnt)
- cacl_free(dfacep, dfacecnt * sizeof (ace_t));
-
- *retacecnt = acecnt + dfacecnt;
- *retacep = acep;
- return (0);
-}
-
-static int
-ace_mask_to_mode(uint32_t mask, o_mode_t *modep, boolean_t isdir)
-{
- int error = 0;
- o_mode_t mode = 0;
- uint32_t bits, wantbits;
-
- /* read */
- if (mask & ACE_READ_DATA)
- mode |= S_IROTH;
-
- /* write */
- wantbits = (ACE_WRITE_DATA | ACE_APPEND_DATA);
- if (isdir)
- wantbits |= ACE_DELETE_CHILD;
- bits = mask & wantbits;
- if (bits != 0) {
- if (bits != wantbits) {
- error = ENOTSUP;
- goto out;
- }
- mode |= S_IWOTH;
- }
-
- /* exec */
- if (mask & ACE_EXECUTE) {
- mode |= S_IXOTH;
- }
-
- *modep = mode;
-
-out:
- return (error);
-}
-
-static void
-acevals_init(acevals_t *vals, uid_t key)
-{
- bzero(vals, sizeof (*vals));
- vals->allowed = ACE_MASK_UNDEFINED;
- vals->denied = ACE_MASK_UNDEFINED;
- vals->mask = ACE_MASK_UNDEFINED;
- vals->key = key;
-}
-
-static void
-ace_list_init(ace_list_t *al, int dfacl_flag)
-{
- acevals_init(&al->user_obj, 0);
- acevals_init(&al->group_obj, 0);
- acevals_init(&al->other_obj, 0);
- al->numusers = 0;
- al->numgroups = 0;
- al->acl_mask = 0;
- al->hasmask = 0;
- al->state = ace_unused;
- al->seen = 0;
- al->dfacl_flag = dfacl_flag;
-}
-
-/*
- * Find or create an acevals holder for a given id and avl tree.
- *
- * Note that only one thread will ever touch these avl trees, so
- * there is no need for locking.
- */
-static acevals_t *
-acevals_find(ace_t *ace, avl_tree_t *avl, int *num)
-{
- acevals_t key, *rc;
- avl_index_t where;
-
- key.key = ace->a_who;
- rc = avl_find(avl, &key, &where);
- if (rc != NULL)
- return (rc);
-
- /* this memory is freed by ln_ace_to_aent()->ace_list_free() */
- if (cacl_malloc((void **)&rc, sizeof (acevals_t)) != 0)
- return (NULL);
-
- acevals_init(rc, ace->a_who);
- avl_insert(avl, rc, where);
- (*num)++;
-
- return (rc);
-}
-
-static int
-access_mask_check(ace_t *acep, int mask_bit, int isowner)
-{
- int set_deny, err_deny;
- int set_allow, err_allow;
- int acl_consume;
- int haswriteperm, hasreadperm;
-
- if (acep->a_type == ACE_ACCESS_DENIED_ACE_TYPE) {
- haswriteperm = (acep->a_access_mask & ACE_WRITE_DATA) ? 0 : 1;
- hasreadperm = (acep->a_access_mask & ACE_READ_DATA) ? 0 : 1;
- } else {
- haswriteperm = (acep->a_access_mask & ACE_WRITE_DATA) ? 1 : 0;
- hasreadperm = (acep->a_access_mask & ACE_READ_DATA) ? 1 : 0;
- }
-
- acl_consume = (ACL_SYNCHRONIZE_ERR_DENY |
- ACL_DELETE_ERR_DENY |
- ACL_WRITE_OWNER_ERR_DENY |
- ACL_WRITE_OWNER_ERR_ALLOW |
- ACL_WRITE_ATTRS_OWNER_SET_ALLOW |
- ACL_WRITE_ATTRS_OWNER_ERR_DENY |
- ACL_WRITE_ATTRS_WRITER_SET_DENY |
- ACL_WRITE_ATTRS_WRITER_ERR_ALLOW |
- ACL_WRITE_NAMED_WRITER_ERR_DENY |
- ACL_READ_NAMED_READER_ERR_DENY);
-
- if (mask_bit == ACE_SYNCHRONIZE) {
- set_deny = ACL_SYNCHRONIZE_SET_DENY;
- err_deny = ACL_SYNCHRONIZE_ERR_DENY;
- set_allow = ACL_SYNCHRONIZE_SET_ALLOW;
- err_allow = ACL_SYNCHRONIZE_ERR_ALLOW;
- } else if (mask_bit == ACE_WRITE_OWNER) {
- set_deny = ACL_WRITE_OWNER_SET_DENY;
- err_deny = ACL_WRITE_OWNER_ERR_DENY;
- set_allow = ACL_WRITE_OWNER_SET_ALLOW;
- err_allow = ACL_WRITE_OWNER_ERR_ALLOW;
- } else if (mask_bit == ACE_DELETE) {
- set_deny = ACL_DELETE_SET_DENY;
- err_deny = ACL_DELETE_ERR_DENY;
- set_allow = ACL_DELETE_SET_ALLOW;
- err_allow = ACL_DELETE_ERR_ALLOW;
- } else if (mask_bit == ACE_WRITE_ATTRIBUTES) {
- if (isowner) {
- set_deny = ACL_WRITE_ATTRS_OWNER_SET_DENY;
- err_deny = ACL_WRITE_ATTRS_OWNER_ERR_DENY;
- set_allow = ACL_WRITE_ATTRS_OWNER_SET_ALLOW;
- err_allow = ACL_WRITE_ATTRS_OWNER_ERR_ALLOW;
- } else if (haswriteperm) {
- set_deny = ACL_WRITE_ATTRS_WRITER_SET_DENY;
- err_deny = ACL_WRITE_ATTRS_WRITER_ERR_DENY;
- set_allow = ACL_WRITE_ATTRS_WRITER_SET_ALLOW;
- err_allow = ACL_WRITE_ATTRS_WRITER_ERR_ALLOW;
- } else {
- if ((acep->a_access_mask & mask_bit) &&
- (acep->a_type & ACE_ACCESS_ALLOWED_ACE_TYPE)) {
- return (ENOTSUP);
- }
- return (0);
- }
- } else if (mask_bit == ACE_READ_NAMED_ATTRS) {
- if (!hasreadperm)
- return (0);
-
- set_deny = ACL_READ_NAMED_READER_SET_DENY;
- err_deny = ACL_READ_NAMED_READER_ERR_DENY;
- set_allow = ACL_READ_NAMED_READER_SET_ALLOW;
- err_allow = ACL_READ_NAMED_READER_ERR_ALLOW;
- } else if (mask_bit == ACE_WRITE_NAMED_ATTRS) {
- if (!haswriteperm)
- return (0);
-
- set_deny = ACL_WRITE_NAMED_WRITER_SET_DENY;
- err_deny = ACL_WRITE_NAMED_WRITER_ERR_DENY;
- set_allow = ACL_WRITE_NAMED_WRITER_SET_ALLOW;
- err_allow = ACL_WRITE_NAMED_WRITER_ERR_ALLOW;
- } else {
- return (EINVAL);
- }
-
- if (acep->a_type == ACE_ACCESS_DENIED_ACE_TYPE) {
- if (acl_consume & set_deny) {
- if (!(acep->a_access_mask & mask_bit)) {
- return (ENOTSUP);
- }
- } else if (acl_consume & err_deny) {
- if (acep->a_access_mask & mask_bit) {
- return (ENOTSUP);
- }
- }
- } else {
- /* ACE_ACCESS_ALLOWED_ACE_TYPE */
- if (acl_consume & set_allow) {
- if (!(acep->a_access_mask & mask_bit)) {
- return (ENOTSUP);
- }
- } else if (acl_consume & err_allow) {
- if (acep->a_access_mask & mask_bit) {
- return (ENOTSUP);
- }
- }
- }
- return (0);
-}
-
-static int
-ace_to_aent_legal(ace_t *acep)
-{
- int error = 0;
- int isowner;
-
- /* only ALLOW or DENY */
- if ((acep->a_type != ACE_ACCESS_ALLOWED_ACE_TYPE) &&
- (acep->a_type != ACE_ACCESS_DENIED_ACE_TYPE)) {
- error = ENOTSUP;
- goto out;
- }
-
- /* check for invalid flags */
- if (acep->a_flags & ~(ACE_VALID_FLAG_BITS)) {
- error = EINVAL;
- goto out;
- }
-
- /* some flags are illegal */
- if (acep->a_flags & (ACE_SUCCESSFUL_ACCESS_ACE_FLAG |
- ACE_FAILED_ACCESS_ACE_FLAG |
- ACE_NO_PROPAGATE_INHERIT_ACE)) {
- error = ENOTSUP;
- goto out;
- }
-
- /* check for invalid masks */
- if (acep->a_access_mask & ~(ACE_VALID_MASK_BITS)) {
- error = EINVAL;
- goto out;
- }
-
- if ((acep->a_flags & ACE_OWNER)) {
- isowner = 1;
- } else {
- isowner = 0;
- }
-
- error = access_mask_check(acep, ACE_SYNCHRONIZE, isowner);
- if (error)
- goto out;
-
- error = access_mask_check(acep, ACE_WRITE_OWNER, isowner);
- if (error)
- goto out;
-
- error = access_mask_check(acep, ACE_DELETE, isowner);
- if (error)
- goto out;
-
- error = access_mask_check(acep, ACE_WRITE_ATTRIBUTES, isowner);
- if (error)
- goto out;
-
- error = access_mask_check(acep, ACE_READ_NAMED_ATTRS, isowner);
- if (error)
- goto out;
-
- error = access_mask_check(acep, ACE_WRITE_NAMED_ATTRS, isowner);
- if (error)
- goto out;
-
- /* more detailed checking of masks */
- if (acep->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE) {
- if (! (acep->a_access_mask & ACE_READ_ATTRIBUTES)) {
- error = ENOTSUP;
- goto out;
- }
- if ((acep->a_access_mask & ACE_WRITE_DATA) &&
- (! (acep->a_access_mask & ACE_APPEND_DATA))) {
- error = ENOTSUP;
- goto out;
- }
- if ((! (acep->a_access_mask & ACE_WRITE_DATA)) &&
- (acep->a_access_mask & ACE_APPEND_DATA)) {
- error = ENOTSUP;
- goto out;
- }
- }
-
- /* ACL enforcement */
- if ((acep->a_access_mask & ACE_READ_ACL) &&
- (acep->a_type != ACE_ACCESS_ALLOWED_ACE_TYPE)) {
- error = ENOTSUP;
- goto out;
- }
- if (acep->a_access_mask & ACE_WRITE_ACL) {
- if ((acep->a_type == ACE_ACCESS_DENIED_ACE_TYPE) &&
- (isowner)) {
- error = ENOTSUP;
- goto out;
- }
- if ((acep->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE) &&
- (! isowner)) {
- error = ENOTSUP;
- goto out;
- }
- }
-
-out:
- return (error);
-}
-
-static int
-ace_allow_to_mode(uint32_t mask, o_mode_t *modep, boolean_t isdir)
-{
- /* ACE_READ_ACL and ACE_READ_ATTRIBUTES must both be set */
- if ((mask & (ACE_READ_ACL | ACE_READ_ATTRIBUTES)) !=
- (ACE_READ_ACL | ACE_READ_ATTRIBUTES)) {
- return (ENOTSUP);
- }
-
- return (ace_mask_to_mode(mask, modep, isdir));
-}
-
-static int
-acevals_to_aent(acevals_t *vals, aclent_t *dest, ace_list_t *list,
- uid_t owner, gid_t group, boolean_t isdir)
-{
- int error;
- uint32_t flips = ACE_POSIX_SUPPORTED_BITS;
-
- if (isdir)
- flips |= ACE_DELETE_CHILD;
- if (vals->allowed != (vals->denied ^ flips)) {
- error = ENOTSUP;
- goto out;
- }
- if ((list->hasmask) && (list->acl_mask != vals->mask) &&
- (vals->aent_type & (USER | GROUP | GROUP_OBJ))) {
- error = ENOTSUP;
- goto out;
- }
- error = ace_allow_to_mode(vals->allowed, &dest->a_perm, isdir);
- if (error != 0)
- goto out;
- dest->a_type = vals->aent_type;
- if (dest->a_type & (USER | GROUP)) {
- dest->a_id = vals->key;
- } else if (dest->a_type & USER_OBJ) {
- dest->a_id = owner;
- } else if (dest->a_type & GROUP_OBJ) {
- dest->a_id = group;
- } else if (dest->a_type & OTHER_OBJ) {
- dest->a_id = 0;
- } else {
- error = EINVAL;
- goto out;
- }
-
-out:
- return (error);
-}
-
-
-static int
-ace_list_to_aent(ace_list_t *list, aclent_t **aclentp, int *aclcnt,
- uid_t owner, gid_t group, boolean_t isdir)
-{
- int error = 0;
- aclent_t *aent, *result = NULL;
- acevals_t *vals;
- int resultcount;
-
- if ((list->seen & (USER_OBJ | GROUP_OBJ | OTHER_OBJ)) !=
- (USER_OBJ | GROUP_OBJ | OTHER_OBJ)) {
- error = ENOTSUP;
- goto out;
- }
- if ((! list->hasmask) && (list->numusers + list->numgroups > 0)) {
- error = ENOTSUP;
- goto out;
- }
-
- resultcount = 3 + list->numusers + list->numgroups;
- /*
- * This must be the same condition as below, when we add the CLASS_OBJ
- * (aka ACL mask)
- */
- if ((list->hasmask) || (! list->dfacl_flag))
- resultcount += 1;
-
- if (cacl_malloc((void **)&result,
- resultcount * sizeof (aclent_t)) != 0) {
- error = ENOMEM;
- goto out;
- }
- aent = result;
-
- /* USER_OBJ */
- if (!(list->user_obj.aent_type & USER_OBJ)) {
- error = EINVAL;
- goto out;
- }
-
- error = acevals_to_aent(&list->user_obj, aent, list, owner, group,
- isdir);
-
- if (error != 0)
- goto out;
- ++aent;
- /* USER */
- vals = NULL;
- for (vals = avl_first(&list->user); vals != NULL;
- vals = AVL_NEXT(&list->user, vals)) {
- if (!(vals->aent_type & USER)) {
- error = EINVAL;
- goto out;
- }
- error = acevals_to_aent(vals, aent, list, owner, group,
- isdir);
- if (error != 0)
- goto out;
- ++aent;
- }
- /* GROUP_OBJ */
- if (!(list->group_obj.aent_type & GROUP_OBJ)) {
- error = EINVAL;
- goto out;
- }
- error = acevals_to_aent(&list->group_obj, aent, list, owner, group,
- isdir);
- if (error != 0)
- goto out;
- ++aent;
- /* GROUP */
- vals = NULL;
- for (vals = avl_first(&list->group); vals != NULL;
- vals = AVL_NEXT(&list->group, vals)) {
- if (!(vals->aent_type & GROUP)) {
- error = EINVAL;
- goto out;
- }
- error = acevals_to_aent(vals, aent, list, owner, group,
- isdir);
- if (error != 0)
- goto out;
- ++aent;
- }
- /*
- * CLASS_OBJ (aka ACL_MASK)
- *
- * An ACL_MASK is not fabricated if the ACL is a default ACL.
- * This is to follow UFS's behavior.
- */
- if ((list->hasmask) || (! list->dfacl_flag)) {
- if (list->hasmask) {
- uint32_t flips = ACE_POSIX_SUPPORTED_BITS;
- if (isdir)
- flips |= ACE_DELETE_CHILD;
- error = ace_mask_to_mode(list->acl_mask ^ flips,
- &aent->a_perm, isdir);
- if (error != 0)
- goto out;
- } else {
- /* fabricate the ACL_MASK from the group permissions */
- error = ace_mask_to_mode(list->group_obj.allowed,
- &aent->a_perm, isdir);
- if (error != 0)
- goto out;
- }
- aent->a_id = 0;
- aent->a_type = CLASS_OBJ | list->dfacl_flag;
- ++aent;
- }
- /* OTHER_OBJ */
- if (!(list->other_obj.aent_type & OTHER_OBJ)) {
- error = EINVAL;
- goto out;
- }
- error = acevals_to_aent(&list->other_obj, aent, list, owner, group,
- isdir);
- if (error != 0)
- goto out;
- ++aent;
-
- *aclentp = result;
- *aclcnt = resultcount;
-
-out:
- if (error != 0) {
- if (result != NULL)
- cacl_free(result, resultcount * sizeof (aclent_t));
- }
-
- return (error);
-}
-
-
-/*
- * free all data associated with an ace_list
- */
-static void
-ace_list_free(ace_list_t *al)
-{
- acevals_t *node;
- void *cookie;
-
- if (al == NULL)
- return;
-
- cookie = NULL;
- while ((node = avl_destroy_nodes(&al->user, &cookie)) != NULL)
- cacl_free(node, sizeof (acevals_t));
- cookie = NULL;
- while ((node = avl_destroy_nodes(&al->group, &cookie)) != NULL)
- cacl_free(node, sizeof (acevals_t));
-
- avl_destroy(&al->user);
- avl_destroy(&al->group);
-
- /* free the container itself */
- cacl_free(al, sizeof (ace_list_t));
-}
-
-static int
-acevals_compare(const void *va, const void *vb)
-{
- const acevals_t *a = va, *b = vb;
-
- if (a->key == b->key)
- return (0);
-
- if (a->key > b->key)
- return (1);
-
- else
- return (-1);
-}
-
-/*
- * Convert a list of ace_t entries to equivalent regular and default
- * aclent_t lists. Return error (ENOTSUP) when conversion is not possible.
- */
-static int
-ln_ace_to_aent(ace_t *ace, int n, uid_t owner, gid_t group,
- aclent_t **aclentp, int *aclcnt, aclent_t **dfaclentp, int *dfaclcnt,
- boolean_t isdir)
-{
- int error = 0;
- ace_t *acep;
- uint32_t bits;
- int i;
- ace_list_t *normacl = NULL, *dfacl = NULL, *acl;
- acevals_t *vals;
-
- *aclentp = NULL;
- *aclcnt = 0;
- *dfaclentp = NULL;
- *dfaclcnt = 0;
-
- /* we need at least user_obj, group_obj, and other_obj */
- if (n < 6) {
- error = ENOTSUP;
- goto out;
- }
- if (ace == NULL) {
- error = EINVAL;
- goto out;
- }
-
- error = cacl_malloc((void **)&normacl, sizeof (ace_list_t));
- if (error != 0)
- goto out;
-
- avl_create(&normacl->user, acevals_compare, sizeof (acevals_t),
- offsetof(acevals_t, avl));
- avl_create(&normacl->group, acevals_compare, sizeof (acevals_t),
- offsetof(acevals_t, avl));
-
- ace_list_init(normacl, 0);
-
- error = cacl_malloc((void **)&dfacl, sizeof (ace_list_t));
- if (error != 0)
- goto out;
-
- avl_create(&dfacl->user, acevals_compare, sizeof (acevals_t),
- offsetof(acevals_t, avl));
- avl_create(&dfacl->group, acevals_compare, sizeof (acevals_t),
- offsetof(acevals_t, avl));
- ace_list_init(dfacl, ACL_DEFAULT);
-
- /* process every ace_t... */
- for (i = 0; i < n; i++) {
- acep = &ace[i];
-
- /* rule out certain cases quickly */
- error = ace_to_aent_legal(acep);
- if (error != 0)
- goto out;
-
- /*
- * Turn off these bits in order to not have to worry about
- * them when doing the checks for compliments.
- */
- acep->a_access_mask &= ~(ACE_WRITE_OWNER | ACE_DELETE |
- ACE_SYNCHRONIZE | ACE_WRITE_ATTRIBUTES |
- ACE_READ_NAMED_ATTRS | ACE_WRITE_NAMED_ATTRS);
-
- /* see if this should be a regular or default acl */
- bits = acep->a_flags &
- (ACE_INHERIT_ONLY_ACE |
- ACE_FILE_INHERIT_ACE |
- ACE_DIRECTORY_INHERIT_ACE);
- if (bits != 0) {
- /* all or nothing on these inherit bits */
- if (bits != (ACE_INHERIT_ONLY_ACE |
- ACE_FILE_INHERIT_ACE |
- ACE_DIRECTORY_INHERIT_ACE)) {
- error = ENOTSUP;
- goto out;
- }
- acl = dfacl;
- } else {
- acl = normacl;
- }
-
- if ((acep->a_flags & ACE_OWNER)) {
- if (acl->state > ace_user_obj) {
- error = ENOTSUP;
- goto out;
- }
- acl->state = ace_user_obj;
- acl->seen |= USER_OBJ;
- vals = &acl->user_obj;
- vals->aent_type = USER_OBJ | acl->dfacl_flag;
- } else if ((acep->a_flags & ACE_EVERYONE)) {
- acl->state = ace_other_obj;
- acl->seen |= OTHER_OBJ;
- vals = &acl->other_obj;
- vals->aent_type = OTHER_OBJ | acl->dfacl_flag;
- } else if (acep->a_flags & ACE_IDENTIFIER_GROUP) {
- if (acl->state > ace_group) {
- error = ENOTSUP;
- goto out;
- }
- if ((acep->a_flags & ACE_GROUP)) {
- acl->seen |= GROUP_OBJ;
- vals = &acl->group_obj;
- vals->aent_type = GROUP_OBJ | acl->dfacl_flag;
- } else {
- acl->seen |= GROUP;
- vals = acevals_find(acep, &acl->group,
- &acl->numgroups);
- if (vals == NULL) {
- error = ENOMEM;
- goto out;
- }
- vals->aent_type = GROUP | acl->dfacl_flag;
- }
- acl->state = ace_group;
- } else {
- if (acl->state > ace_user) {
- error = ENOTSUP;
- goto out;
- }
- acl->state = ace_user;
- acl->seen |= USER;
- vals = acevals_find(acep, &acl->user,
- &acl->numusers);
- if (vals == NULL) {
- error = ENOMEM;
- goto out;
- }
- vals->aent_type = USER | acl->dfacl_flag;
- }
-
- if (!(acl->state > ace_unused)) {
- error = EINVAL;
- goto out;
- }
-
- if (acep->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE) {
- /* no more than one allowed per aclent_t */
- if (vals->allowed != ACE_MASK_UNDEFINED) {
- error = ENOTSUP;
- goto out;
- }
- vals->allowed = acep->a_access_mask;
- } else {
- /*
- * it's a DENY; if there was a previous DENY, it
- * must have been an ACL_MASK.
- */
- if (vals->denied != ACE_MASK_UNDEFINED) {
- /* ACL_MASK is for USER and GROUP only */
- if ((acl->state != ace_user) &&
- (acl->state != ace_group)) {
- error = ENOTSUP;
- goto out;
- }
-
- if (! acl->hasmask) {
- acl->hasmask = 1;
- acl->acl_mask = vals->denied;
- /* check for mismatched ACL_MASK emulations */
- } else if (acl->acl_mask != vals->denied) {
- error = ENOTSUP;
- goto out;
- }
- vals->mask = vals->denied;
- }
- vals->denied = acep->a_access_mask;
- }
- }
-
- /* done collating; produce the aclent_t lists */
- if (normacl->state != ace_unused) {
- error = ace_list_to_aent(normacl, aclentp, aclcnt,
- owner, group, isdir);
- if (error != 0) {
- goto out;
- }
- }
- if (dfacl->state != ace_unused) {
- error = ace_list_to_aent(dfacl, dfaclentp, dfaclcnt,
- owner, group, isdir);
- if (error != 0) {
- goto out;
- }
- }
-
-out:
- if (normacl != NULL)
- ace_list_free(normacl);
- if (dfacl != NULL)
- ace_list_free(dfacl);
-
- return (error);
-}
-
-static int
-convert_ace_to_aent(ace_t *acebufp, int acecnt, boolean_t isdir,
- uid_t owner, gid_t group, aclent_t **retaclentp, int *retaclcnt)
-{
- int error = 0;
- aclent_t *aclentp, *dfaclentp;
- int aclcnt, dfaclcnt;
- int aclsz, dfaclsz;
-
- error = ln_ace_to_aent(acebufp, acecnt, owner, group,
- &aclentp, &aclcnt, &dfaclentp, &dfaclcnt, isdir);
-
- if (error)
- return (error);
-
-
- if (dfaclcnt != 0) {
- /*
- * Slap aclentp and dfaclentp into a single array.
- */
- aclsz = sizeof (aclent_t) * aclcnt;
- dfaclsz = sizeof (aclent_t) * dfaclcnt;
- aclentp = cacl_realloc(aclentp, aclsz, aclsz + dfaclsz);
- if (aclentp != NULL) {
- (void) memcpy(aclentp + aclcnt, dfaclentp, dfaclsz);
- } else {
- error = ENOMEM;
- }
- }
-
- if (aclentp) {
- *retaclentp = aclentp;
- *retaclcnt = aclcnt + dfaclcnt;
- }
-
- if (dfaclentp)
- cacl_free(dfaclentp, dfaclsz);
-
- return (error);
-}
-
-
-int
-acl_translate(acl_t *aclp, int target_flavor, boolean_t isdir, uid_t owner,
- gid_t group)
-{
- int aclcnt;
- void *acldata;
- int error;
-
- /*
- * See if we need to translate
- */
- if ((target_flavor == _ACL_ACE_ENABLED && aclp->acl_type == ACE_T) ||
- (target_flavor == _ACL_ACLENT_ENABLED &&
- aclp->acl_type == ACLENT_T))
- return (0);
-
- if (target_flavor == -1) {
- error = EINVAL;
- goto out;
- }
-
- if (target_flavor == _ACL_ACE_ENABLED &&
- aclp->acl_type == ACLENT_T) {
- error = convert_aent_to_ace(aclp->acl_aclp,
- aclp->acl_cnt, isdir, (ace_t **)&acldata, &aclcnt);
- if (error)
- goto out;
-
- } else if (target_flavor == _ACL_ACLENT_ENABLED &&
- aclp->acl_type == ACE_T) {
- error = convert_ace_to_aent(aclp->acl_aclp, aclp->acl_cnt,
- isdir, owner, group, (aclent_t **)&acldata, &aclcnt);
- if (error)
- goto out;
- } else {
- error = ENOTSUP;
- goto out;
- }
-
- /*
- * replace old acl with newly translated acl
- */
- cacl_free(aclp->acl_aclp, aclp->acl_cnt * aclp->acl_entry_size);
- aclp->acl_aclp = acldata;
- aclp->acl_cnt = aclcnt;
- if (target_flavor == _ACL_ACE_ENABLED) {
- aclp->acl_type = ACE_T;
- aclp->acl_entry_size = sizeof (ace_t);
- } else {
- aclp->acl_type = ACLENT_T;
- aclp->acl_entry_size = sizeof (aclent_t);
- }
- return (0);
-
-out:
-
-#if !defined(_KERNEL)
- errno = error;
- return (-1);
-#else
- return (error);
-#endif
-}
-#endif /* !_KERNEL */
-
-#define SET_ACE(acl, index, who, mask, type, flags) { \
- acl[0][index].a_who = (uint32_t)who; \
- acl[0][index].a_type = type; \
- acl[0][index].a_flags = flags; \
- acl[0][index++].a_access_mask = mask; \
-}
-
-void
-acl_trivial_access_masks(mode_t mode, boolean_t isdir, trivial_acl_t *masks)
-{
- uint32_t read_mask = ACE_READ_DATA;
- uint32_t write_mask = ACE_WRITE_DATA|ACE_APPEND_DATA;
- uint32_t execute_mask = ACE_EXECUTE;
-
- (void) isdir; /* will need this later */
-
- masks->deny1 = 0;
- if (!(mode & S_IRUSR) && (mode & (S_IRGRP|S_IROTH)))
- masks->deny1 |= read_mask;
- if (!(mode & S_IWUSR) && (mode & (S_IWGRP|S_IWOTH)))
- masks->deny1 |= write_mask;
- if (!(mode & S_IXUSR) && (mode & (S_IXGRP|S_IXOTH)))
- masks->deny1 |= execute_mask;
-
- masks->deny2 = 0;
- if (!(mode & S_IRGRP) && (mode & S_IROTH))
- masks->deny2 |= read_mask;
- if (!(mode & S_IWGRP) && (mode & S_IWOTH))
- masks->deny2 |= write_mask;
- if (!(mode & S_IXGRP) && (mode & S_IXOTH))
- masks->deny2 |= execute_mask;
-
- masks->allow0 = 0;
- if ((mode & S_IRUSR) && (!(mode & S_IRGRP) && (mode & S_IROTH)))
- masks->allow0 |= read_mask;
- if ((mode & S_IWUSR) && (!(mode & S_IWGRP) && (mode & S_IWOTH)))
- masks->allow0 |= write_mask;
- if ((mode & S_IXUSR) && (!(mode & S_IXGRP) && (mode & S_IXOTH)))
- masks->allow0 |= execute_mask;
-
- masks->owner = ACE_WRITE_ATTRIBUTES|ACE_WRITE_OWNER|ACE_WRITE_ACL|
- ACE_WRITE_NAMED_ATTRS|ACE_READ_ACL|ACE_READ_ATTRIBUTES|
- ACE_READ_NAMED_ATTRS|ACE_SYNCHRONIZE;
- if (mode & S_IRUSR)
- masks->owner |= read_mask;
- if (mode & S_IWUSR)
- masks->owner |= write_mask;
- if (mode & S_IXUSR)
- masks->owner |= execute_mask;
-
- masks->group = ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_READ_NAMED_ATTRS|
- ACE_SYNCHRONIZE;
- if (mode & S_IRGRP)
- masks->group |= read_mask;
- if (mode & S_IWGRP)
- masks->group |= write_mask;
- if (mode & S_IXGRP)
- masks->group |= execute_mask;
-
- masks->everyone = ACE_READ_ACL|ACE_READ_ATTRIBUTES|ACE_READ_NAMED_ATTRS|
- ACE_SYNCHRONIZE;
- if (mode & S_IROTH)
- masks->everyone |= read_mask;
- if (mode & S_IWOTH)
- masks->everyone |= write_mask;
- if (mode & S_IXOTH)
- masks->everyone |= execute_mask;
-}
-
-int
-acl_trivial_create(mode_t mode, boolean_t isdir, ace_t **acl, int *count)
-{
- int index = 0;
- int error;
- trivial_acl_t masks;
-
- *count = 3;
- acl_trivial_access_masks(mode, isdir, &masks);
-
- if (masks.allow0)
- (*count)++;
- if (masks.deny1)
- (*count)++;
- if (masks.deny2)
- (*count)++;
-
- if ((error = cacl_malloc((void **)acl, *count * sizeof (ace_t))) != 0)
- return (error);
-
- if (masks.allow0) {
- SET_ACE(acl, index, -1, masks.allow0,
- ACE_ACCESS_ALLOWED_ACE_TYPE, ACE_OWNER);
- }
- if (masks.deny1) {
- SET_ACE(acl, index, -1, masks.deny1,
- ACE_ACCESS_DENIED_ACE_TYPE, ACE_OWNER);
- }
- if (masks.deny2) {
- SET_ACE(acl, index, -1, masks.deny2,
- ACE_ACCESS_DENIED_ACE_TYPE, ACE_GROUP|ACE_IDENTIFIER_GROUP);
- }
-
- SET_ACE(acl, index, -1, masks.owner, ACE_ACCESS_ALLOWED_ACE_TYPE,
- ACE_OWNER);
- SET_ACE(acl, index, -1, masks.group, ACE_ACCESS_ALLOWED_ACE_TYPE,
- ACE_IDENTIFIER_GROUP|ACE_GROUP);
- SET_ACE(acl, index, -1, masks.everyone, ACE_ACCESS_ALLOWED_ACE_TYPE,
- ACE_EVERYONE);
-
- return (0);
-}
-
-/*
- * ace_trivial:
- * determine whether an ace_t acl is trivial
- *
- * Trivialness implies that the acl is composed of only
- * owner, group, everyone entries. ACL can't
- * have read_acl denied, and write_owner/write_acl/write_attributes
- * can only be owner@ entry.
- */
-int
-ace_trivial_common(void *acep, int aclcnt,
- uint64_t (*walk)(void *, uint64_t, int aclcnt,
- uint16_t *, uint16_t *, uint32_t *))
-{
- uint16_t flags;
- uint32_t mask;
- uint16_t type;
- uint64_t cookie = 0;
-
- while (cookie = walk(acep, cookie, aclcnt, &flags, &type, &mask)) {
- switch (flags & ACE_TYPE_FLAGS) {
- case ACE_OWNER:
- case ACE_GROUP|ACE_IDENTIFIER_GROUP:
- case ACE_EVERYONE:
- break;
- default:
- return (1);
-
- }
-
- if (flags & (ACE_FILE_INHERIT_ACE|
- ACE_DIRECTORY_INHERIT_ACE|ACE_NO_PROPAGATE_INHERIT_ACE|
- ACE_INHERIT_ONLY_ACE))
- return (1);
-
- /*
- * Special check for some special bits
- *
- * Don't allow anybody to deny reading basic
- * attributes or a files ACL.
- */
- if ((mask & (ACE_READ_ACL|ACE_READ_ATTRIBUTES)) &&
- (type == ACE_ACCESS_DENIED_ACE_TYPE))
- return (1);
-
- /*
- * Delete permissions are never set by default
- */
- if (mask & (ACE_DELETE|ACE_DELETE_CHILD))
- return (1);
- /*
- * only allow owner@ to have
- * write_acl/write_owner/write_attributes/write_xattr/
- */
- if (type == ACE_ACCESS_ALLOWED_ACE_TYPE &&
- (!(flags & ACE_OWNER) && (mask &
- (ACE_WRITE_OWNER|ACE_WRITE_ACL| ACE_WRITE_ATTRIBUTES|
- ACE_WRITE_NAMED_ATTRS))))
- return (1);
-
- }
- return (0);
-}
-
-uint64_t
-ace_walk(void *datap, uint64_t cookie, int aclcnt, uint16_t *flags,
- uint16_t *type, uint32_t *mask)
-{
- ace_t *acep = datap;
-
- if (cookie >= aclcnt)
- return (0);
-
- *flags = acep[cookie].a_flags;
- *type = acep[cookie].a_type;
- *mask = acep[cookie++].a_access_mask;
-
- return (cookie);
-}
-
-int
-ace_trivial(ace_t *acep, int aclcnt)
-{
- return (ace_trivial_common(acep, aclcnt, ace_walk));
-}
diff --git a/sys/cddl/contrib/opensolaris/common/acl/acl_common.h b/sys/cddl/contrib/opensolaris/common/acl/acl_common.h
deleted file mode 100644
index acf1f5da89d6..000000000000
--- a/sys/cddl/contrib/opensolaris/common/acl/acl_common.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
- */
-
-#ifndef _ACL_COMMON_H
-#define _ACL_COMMON_H
-
-#include <sys/types.h>
-#include <sys/acl.h>
-#include <sys/stat.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct trivial_acl {
- uint32_t allow0; /* allow mask for bits only in owner */
- uint32_t deny1; /* deny mask for bits not in owner */
- uint32_t deny2; /* deny mask for bits not in group */
- uint32_t owner; /* allow mask matching mode */
- uint32_t group; /* allow mask matching mode */
- uint32_t everyone; /* allow mask matching mode */
-} trivial_acl_t;
-
-extern int acltrivial(const char *);
-extern void adjust_ace_pair(ace_t *pair, mode_t mode);
-extern void adjust_ace_pair_common(void *, size_t, size_t, mode_t);
-extern int ace_trivial(ace_t *acep, int aclcnt);
-extern int ace_trivial_common(void *, int,
- uint64_t (*walk)(void *, uint64_t, int aclcnt, uint16_t *, uint16_t *,
- uint32_t *mask));
-#if !defined(_KERNEL)
-extern acl_t *acl_alloc(acl_type_t);
-extern void acl_free(acl_t *aclp);
-extern int acl_translate(acl_t *aclp, int target_flavor, boolean_t isdir,
- uid_t owner, gid_t group);
-#endif /* !_KERNEL */
-void ksort(caddr_t v, int n, int s, int (*f)());
-int cmp2acls(void *a, void *b);
-int acl_trivial_create(mode_t mode, boolean_t isdir, ace_t **acl, int *count);
-void acl_trivial_access_masks(mode_t mode, boolean_t isdir,
- trivial_acl_t *masks);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ACL_COMMON_H */
diff --git a/sys/cddl/contrib/opensolaris/common/atomic/i386/opensolaris_atomic.S b/sys/cddl/contrib/opensolaris/common/atomic/i386/opensolaris_atomic.S
deleted file mode 100644
index bc21e85878df..000000000000
--- a/sys/cddl/contrib/opensolaris/common/atomic/i386/opensolaris_atomic.S
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
- .file "atomic.s"
-
-#define _ASM
-#include <sys/asm_linkage.h>
-
- /*
- * NOTE: If atomic_dec_64 and atomic_dec_64_nv are ever
- * separated, it is important to edit the libc i386 platform
- * specific mapfile and remove the NODYNSORT attribute
- * from atomic_dec_64_nv.
- */
- ENTRY(atomic_dec_64)
- ALTENTRY(atomic_dec_64_nv)
- pushl %edi
- pushl %ebx
- movl 12(%esp), %edi // %edi = target address
- movl (%edi), %eax
- movl 4(%edi), %edx // %edx:%eax = old value
-1:
- xorl %ebx, %ebx
- xorl %ecx, %ecx
- not %ecx
- not %ebx // %ecx:%ebx = -1
- addl %eax, %ebx
- adcl %edx, %ecx // add in the carry from inc
- lock
- cmpxchg8b (%edi) // try to stick it in
- jne 1b
- movl %ebx, %eax
- movl %ecx, %edx // return new value
- popl %ebx
- popl %edi
- ret
- SET_SIZE(atomic_dec_64_nv)
- SET_SIZE(atomic_dec_64)
-
- /*
- * NOTE: If atomic_add_64 and atomic_add_64_nv are ever
- * separated, it is important to edit the libc i386 platform
- * specific mapfile and remove the NODYNSORT attribute
- * from atomic_add_64_nv.
- */
- ENTRY(atomic_add_64)
- ALTENTRY(atomic_add_64_nv)
- pushl %edi
- pushl %ebx
- movl 12(%esp), %edi // %edi = target address
- movl (%edi), %eax
- movl 4(%edi), %edx // %edx:%eax = old value
-1:
- movl 16(%esp), %ebx
- movl 20(%esp), %ecx // %ecx:%ebx = delta
- addl %eax, %ebx
- adcl %edx, %ecx // %ecx:%ebx = new value
- lock
- cmpxchg8b (%edi) // try to stick it in
- jne 1b
- movl %ebx, %eax
- movl %ecx, %edx // return new value
- popl %ebx
- popl %edi
- ret
- SET_SIZE(atomic_add_64_nv)
- SET_SIZE(atomic_add_64)
-
- ENTRY(atomic_cas_64)
- pushl %ebx
- pushl %esi
- movl 12(%esp), %esi
- movl 16(%esp), %eax
- movl 20(%esp), %edx
- movl 24(%esp), %ebx
- movl 28(%esp), %ecx
- lock
- cmpxchg8b (%esi)
- popl %esi
- popl %ebx
- ret
- SET_SIZE(atomic_cas_64)
-
- ENTRY(atomic_swap_64)
- pushl %esi
- pushl %ebx
- movl 12(%esp), %esi
- movl 16(%esp), %ebx
- movl 20(%esp), %ecx
- movl (%esi), %eax
- movl 4(%esi), %edx // %edx:%eax = old value
-1:
- lock
- cmpxchg8b (%esi)
- jne 1b
- popl %ebx
- popl %esi
- ret
- SET_SIZE(atomic_swap_64)
-
- ENTRY(atomic_load_64)
- pushl %esi
- movl 8(%esp), %esi
- movl %ebx, %eax // make old and new values equal, so that
- movl %ecx, %edx // destination is never changed
- lock
- cmpxchg8b (%esi)
- popl %esi
- ret
- SET_SIZE(atomic_load_64)
diff --git a/sys/cddl/contrib/opensolaris/common/avl/avl.c b/sys/cddl/contrib/opensolaris/common/avl/avl.c
deleted file mode 100644
index 2349aba2bf3e..000000000000
--- a/sys/cddl/contrib/opensolaris/common/avl/avl.c
+++ /dev/null
@@ -1,1063 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-/*
- * Copyright (c) 2014 by Delphix. All rights reserved.
- * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
- */
-
-/*
- * AVL - generic AVL tree implementation for kernel use
- *
- * A complete description of AVL trees can be found in many CS textbooks.
- *
- * Here is a very brief overview. An AVL tree is a binary search tree that is
- * almost perfectly balanced. By "almost" perfectly balanced, we mean that at
- * any given node, the left and right subtrees are allowed to differ in height
- * by at most 1 level.
- *
- * This relaxation from a perfectly balanced binary tree allows doing
- * insertion and deletion relatively efficiently. Searching the tree is
- * still a fast operation, roughly O(log(N)).
- *
- * The key to insertion and deletion is a set of tree manipulations called
- * rotations, which bring unbalanced subtrees back into the semi-balanced state.
- *
- * This implementation of AVL trees has the following peculiarities:
- *
- * - The AVL specific data structures are physically embedded as fields
- * in the "using" data structures. To maintain generality the code
- * must constantly translate between "avl_node_t *" and containing
- * data structure "void *"s by adding/subtracting the avl_offset.
- *
- * - Since the AVL data is always embedded in other structures, there is
- * no locking or memory allocation in the AVL routines. This must be
- * provided for by the enclosing data structure's semantics. Typically,
- * avl_insert()/_add()/_remove()/avl_insert_here() require some kind of
- * exclusive write lock. Other operations require a read lock.
- *
- * - The implementation uses iteration instead of explicit recursion,
- * since it is intended to run on limited size kernel stacks. Since
- * there is no recursion stack present to move "up" in the tree,
- * there is an explicit "parent" link in the avl_node_t.
- *
- * - The left/right children pointers of a node are in an array.
- * In the code, variables (instead of constants) are used to represent
- * left and right indices. The implementation is written as if it only
- * dealt with left handed manipulations. By changing the value assigned
- * to "left", the code also works for right handed trees. The
- * following variables/terms are frequently used:
- *
- * int left; // 0 when dealing with left children,
- * // 1 for dealing with right children
- *
- * int left_heavy; // -1 when left subtree is taller at some node,
- * // +1 when right subtree is taller
- *
- * int right; // will be the opposite of left (0 or 1)
- * int right_heavy;// will be the opposite of left_heavy (-1 or 1)
- *
- * int direction; // 0 for "<" (ie. left child); 1 for ">" (right)
- *
- * Though it is a little more confusing to read the code, the approach
- * allows using half as much code (and hence cache footprint) for tree
- * manipulations and eliminates many conditional branches.
- *
- * - The avl_index_t is an opaque "cookie" used to find nodes at or
- * adjacent to where a new value would be inserted in the tree. The value
- * is a modified "avl_node_t *". The bottom bit (normally 0 for a
- * pointer) is set to indicate if that the new node has a value greater
- * than the value of the indicated "avl_node_t *".
- *
- * Note - in addition to userland (e.g. libavl and libutil) and the kernel
- * (e.g. genunix), avl.c is compiled into ld.so and kmdb's genunix module,
- * which each have their own compilation environments and subsequent
- * requirements. Each of these environments must be considered when adding
- * dependencies from avl.c.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stdint.h>
-#include <sys/debug.h>
-#include <sys/avl.h>
-
-/*
- * Small arrays to translate between balance (or diff) values and child indices.
- *
- * Code that deals with binary tree data structures will randomly use
- * left and right children when examining a tree. C "if()" statements
- * which evaluate randomly suffer from very poor hardware branch prediction.
- * In this code we avoid some of the branch mispredictions by using the
- * following translation arrays. They replace random branches with an
- * additional memory reference. Since the translation arrays are both very
- * small the data should remain efficiently in cache.
- */
-static const int avl_child2balance[2] = {-1, 1};
-static const int avl_balance2child[] = {0, 0, 1};
-
-
-/*
- * Walk from one node to the previous valued node (ie. an infix walk
- * towards the left). At any given node we do one of 2 things:
- *
- * - If there is a left child, go to it, then to it's rightmost descendant.
- *
- * - otherwise we return through parent nodes until we've come from a right
- * child.
- *
- * Return Value:
- * NULL - if at the end of the nodes
- * otherwise next node
- */
-void *
-avl_walk(avl_tree_t *tree, void *oldnode, int left)
-{
- size_t off = tree->avl_offset;
- avl_node_t *node = AVL_DATA2NODE(oldnode, off);
- int right = 1 - left;
- int was_child;
-
-
- /*
- * nowhere to walk to if tree is empty
- */
- if (node == NULL)
- return (NULL);
-
- /*
- * Visit the previous valued node. There are two possibilities:
- *
- * If this node has a left child, go down one left, then all
- * the way right.
- */
- if (node->avl_child[left] != NULL) {
- for (node = node->avl_child[left];
- node->avl_child[right] != NULL;
- node = node->avl_child[right])
- ;
- /*
- * Otherwise, return thru left children as far as we can.
- */
- } else {
- for (;;) {
- was_child = AVL_XCHILD(node);
- node = AVL_XPARENT(node);
- if (node == NULL)
- return (NULL);
- if (was_child == right)
- break;
- }
- }
-
- return (AVL_NODE2DATA(node, off));
-}
-
-/*
- * Return the lowest valued node in a tree or NULL.
- * (leftmost child from root of tree)
- */
-void *
-avl_first(avl_tree_t *tree)
-{
- avl_node_t *node;
- avl_node_t *prev = NULL;
- size_t off = tree->avl_offset;
-
- for (node = tree->avl_root; node != NULL; node = node->avl_child[0])
- prev = node;
-
- if (prev != NULL)
- return (AVL_NODE2DATA(prev, off));
- return (NULL);
-}
-
-/*
- * Return the highest valued node in a tree or NULL.
- * (rightmost child from root of tree)
- */
-void *
-avl_last(avl_tree_t *tree)
-{
- avl_node_t *node;
- avl_node_t *prev = NULL;
- size_t off = tree->avl_offset;
-
- for (node = tree->avl_root; node != NULL; node = node->avl_child[1])
- prev = node;
-
- if (prev != NULL)
- return (AVL_NODE2DATA(prev, off));
- return (NULL);
-}
-
-/*
- * Access the node immediately before or after an insertion point.
- *
- * "avl_index_t" is a (avl_node_t *) with the bottom bit indicating a child
- *
- * Return value:
- * NULL: no node in the given direction
- * "void *" of the found tree node
- */
-void *
-avl_nearest(avl_tree_t *tree, avl_index_t where, int direction)
-{
- int child = AVL_INDEX2CHILD(where);
- avl_node_t *node = AVL_INDEX2NODE(where);
- void *data;
- size_t off = tree->avl_offset;
-
- if (node == NULL) {
- ASSERT(tree->avl_root == NULL);
- return (NULL);
- }
- data = AVL_NODE2DATA(node, off);
- if (child != direction)
- return (data);
-
- return (avl_walk(tree, data, direction));
-}
-
-
-/*
- * Search for the node which contains "value". The algorithm is a
- * simple binary tree search.
- *
- * return value:
- * NULL: the value is not in the AVL tree
- * *where (if not NULL) is set to indicate the insertion point
- * "void *" of the found tree node
- */
-void *
-avl_find(avl_tree_t *tree, const void *value, avl_index_t *where)
-{
- avl_node_t *node;
- avl_node_t *prev = NULL;
- int child = 0;
- int diff;
- size_t off = tree->avl_offset;
-
- for (node = tree->avl_root; node != NULL;
- node = node->avl_child[child]) {
-
- prev = node;
-
- diff = tree->avl_compar(value, AVL_NODE2DATA(node, off));
- ASSERT(-1 <= diff && diff <= 1);
- if (diff == 0) {
-#ifdef DEBUG
- if (where != NULL)
- *where = 0;
-#endif
- return (AVL_NODE2DATA(node, off));
- }
- child = avl_balance2child[1 + diff];
-
- }
-
- if (where != NULL)
- *where = AVL_MKINDEX(prev, child);
-
- return (NULL);
-}
-
-
-/*
- * Perform a rotation to restore balance at the subtree given by depth.
- *
- * This routine is used by both insertion and deletion. The return value
- * indicates:
- * 0 : subtree did not change height
- * !0 : subtree was reduced in height
- *
- * The code is written as if handling left rotations, right rotations are
- * symmetric and handled by swapping values of variables right/left[_heavy]
- *
- * On input balance is the "new" balance at "node". This value is either
- * -2 or +2.
- */
-static int
-avl_rotation(avl_tree_t *tree, avl_node_t *node, int balance)
-{
- int left = !(balance < 0); /* when balance = -2, left will be 0 */
- int right = 1 - left;
- int left_heavy = balance >> 1;
- int right_heavy = -left_heavy;
- avl_node_t *parent = AVL_XPARENT(node);
- avl_node_t *child = node->avl_child[left];
- avl_node_t *cright;
- avl_node_t *gchild;
- avl_node_t *gright;
- avl_node_t *gleft;
- int which_child = AVL_XCHILD(node);
- int child_bal = AVL_XBALANCE(child);
-
- /* BEGIN CSTYLED */
- /*
- * case 1 : node is overly left heavy, the left child is balanced or
- * also left heavy. This requires the following rotation.
- *
- * (node bal:-2)
- * / \
- * / \
- * (child bal:0 or -1)
- * / \
- * / \
- * cright
- *
- * becomes:
- *
- * (child bal:1 or 0)
- * / \
- * / \
- * (node bal:-1 or 0)
- * / \
- * / \
- * cright
- *
- * we detect this situation by noting that child's balance is not
- * right_heavy.
- */
- /* END CSTYLED */
- if (child_bal != right_heavy) {
-
- /*
- * compute new balance of nodes
- *
- * If child used to be left heavy (now balanced) we reduced
- * the height of this sub-tree -- used in "return...;" below
- */
- child_bal += right_heavy; /* adjust towards right */
-
- /*
- * move "cright" to be node's left child
- */
- cright = child->avl_child[right];
- node->avl_child[left] = cright;
- if (cright != NULL) {
- AVL_SETPARENT(cright, node);
- AVL_SETCHILD(cright, left);
- }
-
- /*
- * move node to be child's right child
- */
- child->avl_child[right] = node;
- AVL_SETBALANCE(node, -child_bal);
- AVL_SETCHILD(node, right);
- AVL_SETPARENT(node, child);
-
- /*
- * update the pointer into this subtree
- */
- AVL_SETBALANCE(child, child_bal);
- AVL_SETCHILD(child, which_child);
- AVL_SETPARENT(child, parent);
- if (parent != NULL)
- parent->avl_child[which_child] = child;
- else
- tree->avl_root = child;
-
- return (child_bal == 0);
- }
-
- /* BEGIN CSTYLED */
- /*
- * case 2 : When node is left heavy, but child is right heavy we use
- * a different rotation.
- *
- * (node b:-2)
- * / \
- * / \
- * / \
- * (child b:+1)
- * / \
- * / \
- * (gchild b: != 0)
- * / \
- * / \
- * gleft gright
- *
- * becomes:
- *
- * (gchild b:0)
- * / \
- * / \
- * / \
- * (child b:?) (node b:?)
- * / \ / \
- * / \ / \
- * gleft gright
- *
- * computing the new balances is more complicated. As an example:
- * if gchild was right_heavy, then child is now left heavy
- * else it is balanced
- */
- /* END CSTYLED */
- gchild = child->avl_child[right];
- gleft = gchild->avl_child[left];
- gright = gchild->avl_child[right];
-
- /*
- * move gright to left child of node and
- *
- * move gleft to right child of node
- */
- node->avl_child[left] = gright;
- if (gright != NULL) {
- AVL_SETPARENT(gright, node);
- AVL_SETCHILD(gright, left);
- }
-
- child->avl_child[right] = gleft;
- if (gleft != NULL) {
- AVL_SETPARENT(gleft, child);
- AVL_SETCHILD(gleft, right);
- }
-
- /*
- * move child to left child of gchild and
- *
- * move node to right child of gchild and
- *
- * fixup parent of all this to point to gchild
- */
- balance = AVL_XBALANCE(gchild);
- gchild->avl_child[left] = child;
- AVL_SETBALANCE(child, (balance == right_heavy ? left_heavy : 0));
- AVL_SETPARENT(child, gchild);
- AVL_SETCHILD(child, left);
-
- gchild->avl_child[right] = node;
- AVL_SETBALANCE(node, (balance == left_heavy ? right_heavy : 0));
- AVL_SETPARENT(node, gchild);
- AVL_SETCHILD(node, right);
-
- AVL_SETBALANCE(gchild, 0);
- AVL_SETPARENT(gchild, parent);
- AVL_SETCHILD(gchild, which_child);
- if (parent != NULL)
- parent->avl_child[which_child] = gchild;
- else
- tree->avl_root = gchild;
-
- return (1); /* the new tree is always shorter */
-}
-
-
-/*
- * Insert a new node into an AVL tree at the specified (from avl_find()) place.
- *
- * Newly inserted nodes are always leaf nodes in the tree, since avl_find()
- * searches out to the leaf positions. The avl_index_t indicates the node
- * which will be the parent of the new node.
- *
- * After the node is inserted, a single rotation further up the tree may
- * be necessary to maintain an acceptable AVL balance.
- */
-void
-avl_insert(avl_tree_t *tree, void *new_data, avl_index_t where)
-{
- avl_node_t *node;
- avl_node_t *parent = AVL_INDEX2NODE(where);
- int old_balance;
- int new_balance;
- int which_child = AVL_INDEX2CHILD(where);
- size_t off = tree->avl_offset;
-
- ASSERT(tree);
-#ifdef _LP64
- ASSERT(((uintptr_t)new_data & 0x7) == 0);
-#endif
-
- node = AVL_DATA2NODE(new_data, off);
-
- /*
- * First, add the node to the tree at the indicated position.
- */
- ++tree->avl_numnodes;
-
- node->avl_child[0] = NULL;
- node->avl_child[1] = NULL;
-
- AVL_SETCHILD(node, which_child);
- AVL_SETBALANCE(node, 0);
- AVL_SETPARENT(node, parent);
- if (parent != NULL) {
- ASSERT(parent->avl_child[which_child] == NULL);
- parent->avl_child[which_child] = node;
- } else {
- ASSERT(tree->avl_root == NULL);
- tree->avl_root = node;
- }
- /*
- * Now, back up the tree modifying the balance of all nodes above the
- * insertion point. If we get to a highly unbalanced ancestor, we
- * need to do a rotation. If we back out of the tree we are done.
- * If we brought any subtree into perfect balance (0), we are also done.
- */
- for (;;) {
- node = parent;
- if (node == NULL)
- return;
-
- /*
- * Compute the new balance
- */
- old_balance = AVL_XBALANCE(node);
- new_balance = old_balance + avl_child2balance[which_child];
-
- /*
- * If we introduced equal balance, then we are done immediately
- */
- if (new_balance == 0) {
- AVL_SETBALANCE(node, 0);
- return;
- }
-
- /*
- * If both old and new are not zero we went
- * from -1 to -2 balance, do a rotation.
- */
- if (old_balance != 0)
- break;
-
- AVL_SETBALANCE(node, new_balance);
- parent = AVL_XPARENT(node);
- which_child = AVL_XCHILD(node);
- }
-
- /*
- * perform a rotation to fix the tree and return
- */
- (void) avl_rotation(tree, node, new_balance);
-}
-
-/*
- * Insert "new_data" in "tree" in the given "direction" either after or
- * before (AVL_AFTER, AVL_BEFORE) the data "here".
- *
- * Insertions can only be done at empty leaf points in the tree, therefore
- * if the given child of the node is already present we move to either
- * the AVL_PREV or AVL_NEXT and reverse the insertion direction. Since
- * every other node in the tree is a leaf, this always works.
- *
- * To help developers using this interface, we assert that the new node
- * is correctly ordered at every step of the way in DEBUG kernels.
- */
-void
-avl_insert_here(
- avl_tree_t *tree,
- void *new_data,
- void *here,
- int direction)
-{
- avl_node_t *node;
- int child = direction; /* rely on AVL_BEFORE == 0, AVL_AFTER == 1 */
-#ifdef DEBUG
- int diff;
-#endif
-
- ASSERT(tree != NULL);
- ASSERT(new_data != NULL);
- ASSERT(here != NULL);
- ASSERT(direction == AVL_BEFORE || direction == AVL_AFTER);
-
- /*
- * If corresponding child of node is not NULL, go to the neighboring
- * node and reverse the insertion direction.
- */
- node = AVL_DATA2NODE(here, tree->avl_offset);
-
-#ifdef DEBUG
- diff = tree->avl_compar(new_data, here);
- ASSERT(-1 <= diff && diff <= 1);
- ASSERT(diff != 0);
- ASSERT(diff > 0 ? child == 1 : child == 0);
-#endif
-
- if (node->avl_child[child] != NULL) {
- node = node->avl_child[child];
- child = 1 - child;
- while (node->avl_child[child] != NULL) {
-#ifdef DEBUG
- diff = tree->avl_compar(new_data,
- AVL_NODE2DATA(node, tree->avl_offset));
- ASSERT(-1 <= diff && diff <= 1);
- ASSERT(diff != 0);
- ASSERT(diff > 0 ? child == 1 : child == 0);
-#endif
- node = node->avl_child[child];
- }
-#ifdef DEBUG
- diff = tree->avl_compar(new_data,
- AVL_NODE2DATA(node, tree->avl_offset));
- ASSERT(-1 <= diff && diff <= 1);
- ASSERT(diff != 0);
- ASSERT(diff > 0 ? child == 1 : child == 0);
-#endif
- }
- ASSERT(node->avl_child[child] == NULL);
-
- avl_insert(tree, new_data, AVL_MKINDEX(node, child));
-}
-
-/*
- * Add a new node to an AVL tree.
- */
-void
-avl_add(avl_tree_t *tree, void *new_node)
-{
- avl_index_t where;
-
- /*
- * This is unfortunate. We want to call panic() here, even for
- * non-DEBUG kernels. In userland, however, we can't depend on anything
- * in libc or else the rtld build process gets confused.
- * Thankfully, rtld provides us with its own assfail() so we can use
- * that here. We use assfail() directly to get a nice error message
- * in the core - much like what panic() does for crashdumps.
- */
- if (avl_find(tree, new_node, &where) != NULL)
-#ifdef _KERNEL
- panic("avl_find() succeeded inside avl_add()");
-#else
- (void) assfail("avl_find() succeeded inside avl_add()",
- __FILE__, __LINE__);
-#endif
- avl_insert(tree, new_node, where);
-}
-
-/*
- * Delete a node from the AVL tree. Deletion is similar to insertion, but
- * with 2 complications.
- *
- * First, we may be deleting an interior node. Consider the following subtree:
- *
- * d c c
- * / \ / \ / \
- * b e b e b e
- * / \ / \ /
- * a c a a
- *
- * When we are deleting node (d), we find and bring up an adjacent valued leaf
- * node, say (c), to take the interior node's place. In the code this is
- * handled by temporarily swapping (d) and (c) in the tree and then using
- * common code to delete (d) from the leaf position.
- *
- * Secondly, an interior deletion from a deep tree may require more than one
- * rotation to fix the balance. This is handled by moving up the tree through
- * parents and applying rotations as needed. The return value from
- * avl_rotation() is used to detect when a subtree did not change overall
- * height due to a rotation.
- */
-void
-avl_remove(avl_tree_t *tree, void *data)
-{
- avl_node_t *delete;
- avl_node_t *parent;
- avl_node_t *node;
- avl_node_t tmp;
- int old_balance;
- int new_balance;
- int left;
- int right;
- int which_child;
- size_t off = tree->avl_offset;
-
- ASSERT(tree);
-
- delete = AVL_DATA2NODE(data, off);
-
- /*
- * Deletion is easiest with a node that has at most 1 child.
- * We swap a node with 2 children with a sequentially valued
- * neighbor node. That node will have at most 1 child. Note this
- * has no effect on the ordering of the remaining nodes.
- *
- * As an optimization, we choose the greater neighbor if the tree
- * is right heavy, otherwise the left neighbor. This reduces the
- * number of rotations needed.
- */
- if (delete->avl_child[0] != NULL && delete->avl_child[1] != NULL) {
-
- /*
- * choose node to swap from whichever side is taller
- */
- old_balance = AVL_XBALANCE(delete);
- left = avl_balance2child[old_balance + 1];
- right = 1 - left;
-
- /*
- * get to the previous value'd node
- * (down 1 left, as far as possible right)
- */
- for (node = delete->avl_child[left];
- node->avl_child[right] != NULL;
- node = node->avl_child[right])
- ;
-
- /*
- * create a temp placeholder for 'node'
- * move 'node' to delete's spot in the tree
- */
- tmp = *node;
-
- *node = *delete;
- if (node->avl_child[left] == node)
- node->avl_child[left] = &tmp;
-
- parent = AVL_XPARENT(node);
- if (parent != NULL)
- parent->avl_child[AVL_XCHILD(node)] = node;
- else
- tree->avl_root = node;
- AVL_SETPARENT(node->avl_child[left], node);
- AVL_SETPARENT(node->avl_child[right], node);
-
- /*
- * Put tmp where node used to be (just temporary).
- * It always has a parent and at most 1 child.
- */
- delete = &tmp;
- parent = AVL_XPARENT(delete);
- parent->avl_child[AVL_XCHILD(delete)] = delete;
- which_child = (delete->avl_child[1] != 0);
- if (delete->avl_child[which_child] != NULL)
- AVL_SETPARENT(delete->avl_child[which_child], delete);
- }
-
-
- /*
- * Here we know "delete" is at least partially a leaf node. It can
- * be easily removed from the tree.
- */
- ASSERT(tree->avl_numnodes > 0);
- --tree->avl_numnodes;
- parent = AVL_XPARENT(delete);
- which_child = AVL_XCHILD(delete);
- if (delete->avl_child[0] != NULL)
- node = delete->avl_child[0];
- else
- node = delete->avl_child[1];
-
- /*
- * Connect parent directly to node (leaving out delete).
- */
- if (node != NULL) {
- AVL_SETPARENT(node, parent);
- AVL_SETCHILD(node, which_child);
- }
- if (parent == NULL) {
- tree->avl_root = node;
- return;
- }
- parent->avl_child[which_child] = node;
-
-
- /*
- * Since the subtree is now shorter, begin adjusting parent balances
- * and performing any needed rotations.
- */
- do {
-
- /*
- * Move up the tree and adjust the balance
- *
- * Capture the parent and which_child values for the next
- * iteration before any rotations occur.
- */
- node = parent;
- old_balance = AVL_XBALANCE(node);
- new_balance = old_balance - avl_child2balance[which_child];
- parent = AVL_XPARENT(node);
- which_child = AVL_XCHILD(node);
-
- /*
- * If a node was in perfect balance but isn't anymore then
- * we can stop, since the height didn't change above this point
- * due to a deletion.
- */
- if (old_balance == 0) {
- AVL_SETBALANCE(node, new_balance);
- break;
- }
-
- /*
- * If the new balance is zero, we don't need to rotate
- * else
- * need a rotation to fix the balance.
- * If the rotation doesn't change the height
- * of the sub-tree we have finished adjusting.
- */
- if (new_balance == 0)
- AVL_SETBALANCE(node, new_balance);
- else if (!avl_rotation(tree, node, new_balance))
- break;
- } while (parent != NULL);
-}
-
-#define AVL_REINSERT(tree, obj) \
- avl_remove((tree), (obj)); \
- avl_add((tree), (obj))
-
-boolean_t
-avl_update_lt(avl_tree_t *t, void *obj)
-{
- void *neighbor;
-
- ASSERT(((neighbor = AVL_NEXT(t, obj)) == NULL) ||
- (t->avl_compar(obj, neighbor) <= 0));
-
- neighbor = AVL_PREV(t, obj);
- if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) < 0)) {
- AVL_REINSERT(t, obj);
- return (B_TRUE);
- }
-
- return (B_FALSE);
-}
-
-boolean_t
-avl_update_gt(avl_tree_t *t, void *obj)
-{
- void *neighbor;
-
- ASSERT(((neighbor = AVL_PREV(t, obj)) == NULL) ||
- (t->avl_compar(obj, neighbor) >= 0));
-
- neighbor = AVL_NEXT(t, obj);
- if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) > 0)) {
- AVL_REINSERT(t, obj);
- return (B_TRUE);
- }
-
- return (B_FALSE);
-}
-
-boolean_t
-avl_update(avl_tree_t *t, void *obj)
-{
- void *neighbor;
-
- neighbor = AVL_PREV(t, obj);
- if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) < 0)) {
- AVL_REINSERT(t, obj);
- return (B_TRUE);
- }
-
- neighbor = AVL_NEXT(t, obj);
- if ((neighbor != NULL) && (t->avl_compar(obj, neighbor) > 0)) {
- AVL_REINSERT(t, obj);
- return (B_TRUE);
- }
-
- return (B_FALSE);
-}
-
-void
-avl_swap(avl_tree_t *tree1, avl_tree_t *tree2)
-{
- avl_node_t *temp_node;
- ulong_t temp_numnodes;
-
- ASSERT3P(tree1->avl_compar, ==, tree2->avl_compar);
- ASSERT3U(tree1->avl_offset, ==, tree2->avl_offset);
- ASSERT3U(tree1->avl_size, ==, tree2->avl_size);
-
- temp_node = tree1->avl_root;
- temp_numnodes = tree1->avl_numnodes;
- tree1->avl_root = tree2->avl_root;
- tree1->avl_numnodes = tree2->avl_numnodes;
- tree2->avl_root = temp_node;
- tree2->avl_numnodes = temp_numnodes;
-}
-
-/*
- * initialize a new AVL tree
- */
-void
-avl_create(avl_tree_t *tree, int (*compar) (const void *, const void *),
- size_t size, size_t offset)
-{
- ASSERT(tree);
- ASSERT(compar);
- ASSERT(size > 0);
- ASSERT(size >= offset + sizeof (avl_node_t));
-#ifdef _LP64
- ASSERT((offset & 0x7) == 0);
-#endif
-
- tree->avl_compar = compar;
- tree->avl_root = NULL;
- tree->avl_numnodes = 0;
- tree->avl_size = size;
- tree->avl_offset = offset;
-}
-
-/*
- * Delete a tree.
- */
-/* ARGSUSED */
-void
-avl_destroy(avl_tree_t *tree)
-{
- ASSERT(tree);
- ASSERT(tree->avl_numnodes == 0);
- ASSERT(tree->avl_root == NULL);
-}
-
-
-/*
- * Return the number of nodes in an AVL tree.
- */
-ulong_t
-avl_numnodes(avl_tree_t *tree)
-{
- ASSERT(tree);
- return (tree->avl_numnodes);
-}
-
-boolean_t
-avl_is_empty(avl_tree_t *tree)
-{
- ASSERT(tree);
- return (tree->avl_numnodes == 0);
-}
-
-#define CHILDBIT (1L)
-
-/*
- * Post-order tree walk used to visit all tree nodes and destroy the tree
- * in post order. This is used for destroying a tree without paying any cost
- * for rebalancing it.
- *
- * example:
- *
- * void *cookie = NULL;
- * my_data_t *node;
- *
- * while ((node = avl_destroy_nodes(tree, &cookie)) != NULL)
- * free(node);
- * avl_destroy(tree);
- *
- * The cookie is really an avl_node_t to the current node's parent and
- * an indication of which child you looked at last.
- *
- * On input, a cookie value of CHILDBIT indicates the tree is done.
- */
-void *
-avl_destroy_nodes(avl_tree_t *tree, void **cookie)
-{
- avl_node_t *node;
- avl_node_t *parent;
- int child;
- void *first;
- size_t off = tree->avl_offset;
-
- /*
- * Initial calls go to the first node or it's right descendant.
- */
- if (*cookie == NULL) {
- first = avl_first(tree);
-
- /*
- * deal with an empty tree
- */
- if (first == NULL) {
- *cookie = (void *)CHILDBIT;
- return (NULL);
- }
-
- node = AVL_DATA2NODE(first, off);
- parent = AVL_XPARENT(node);
- goto check_right_side;
- }
-
- /*
- * If there is no parent to return to we are done.
- */
- parent = (avl_node_t *)((uintptr_t)(*cookie) & ~CHILDBIT);
- if (parent == NULL) {
- if (tree->avl_root != NULL) {
- ASSERT(tree->avl_numnodes == 1);
- tree->avl_root = NULL;
- tree->avl_numnodes = 0;
- }
- return (NULL);
- }
-
- /*
- * Remove the child pointer we just visited from the parent and tree.
- */
- child = (uintptr_t)(*cookie) & CHILDBIT;
- parent->avl_child[child] = NULL;
- ASSERT(tree->avl_numnodes > 1);
- --tree->avl_numnodes;
-
- /*
- * If we just did a right child or there isn't one, go up to parent.
- */
- if (child == 1 || parent->avl_child[1] == NULL) {
- node = parent;
- parent = AVL_XPARENT(parent);
- goto done;
- }
-
- /*
- * Do parent's right child, then leftmost descendent.
- */
- node = parent->avl_child[1];
- while (node->avl_child[0] != NULL) {
- parent = node;
- node = node->avl_child[0];
- }
-
- /*
- * If here, we moved to a left child. It may have one
- * child on the right (when balance == +1).
- */
-check_right_side:
- if (node->avl_child[1] != NULL) {
- ASSERT(AVL_XBALANCE(node) == 1);
- parent = node;
- node = node->avl_child[1];
- ASSERT(node->avl_child[0] == NULL &&
- node->avl_child[1] == NULL);
- } else {
- ASSERT(AVL_XBALANCE(node) <= 0);
- }
-
-done:
- if (parent == NULL) {
- *cookie = (void *)CHILDBIT;
- ASSERT(node == tree->avl_root);
- } else {
- *cookie = (void *)((uintptr_t)parent | AVL_XCHILD(node));
- }
-
- return (AVL_NODE2DATA(node, off));
-}
diff --git a/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c
deleted file mode 100644
index eb200a24e6d2..000000000000
--- a/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_fnvpair.c
+++ /dev/null
@@ -1,512 +0,0 @@
-
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright (c) 2012 by Delphix. All rights reserved.
- */
-
-#include <sys/nvpair.h>
-#ifndef _KERNEL
-#include <sys/zfs_context.h>
-#else
-#include <sys/debug.h>
-#include <sys/kmem.h>
-#include <sys/param.h>
-#include <sys/debug.h>
-#endif
-
-/*
- * "Force" nvlist wrapper.
- *
- * These functions wrap the nvlist_* functions with assertions that assume
- * the operation is successful. This allows the caller's code to be much
- * more readable, especially for the fnvlist_lookup_* and fnvpair_value_*
- * functions, which can return the requested value (rather than filling in
- * a pointer).
- *
- * These functions use NV_UNIQUE_NAME, encoding NV_ENCODE_NATIVE, and allocate
- * with KM_SLEEP.
- *
- * More wrappers should be added as needed -- for example
- * nvlist_lookup_*_array and nvpair_value_*_array.
- */
-
-nvlist_t *
-fnvlist_alloc(void)
-{
- nvlist_t *nvl;
- VERIFY0(nvlist_alloc(&nvl, NV_UNIQUE_NAME, KM_SLEEP));
- return (nvl);
-}
-
-void
-fnvlist_free(nvlist_t *nvl)
-{
- nvlist_free(nvl);
-}
-
-size_t
-fnvlist_size(nvlist_t *nvl)
-{
- size_t size;
- VERIFY0(nvlist_size(nvl, &size, NV_ENCODE_NATIVE));
- return (size);
-}
-
-/*
- * Returns allocated buffer of size *sizep. Caller must free the buffer with
- * fnvlist_pack_free().
- */
-char *
-fnvlist_pack(nvlist_t *nvl, size_t *sizep)
-{
- char *packed = 0;
- VERIFY3U(nvlist_pack(nvl, &packed, sizep, NV_ENCODE_NATIVE,
- KM_SLEEP), ==, 0);
- return (packed);
-}
-
-/*ARGSUSED*/
-void
-fnvlist_pack_free(char *pack, size_t size)
-{
-#ifdef _KERNEL
- kmem_free(pack, size);
-#else
- free(pack);
-#endif
-}
-
-nvlist_t *
-fnvlist_unpack(char *buf, size_t buflen)
-{
- nvlist_t *rv;
- VERIFY0(nvlist_unpack(buf, buflen, &rv, KM_SLEEP));
- return (rv);
-}
-
-nvlist_t *
-fnvlist_dup(nvlist_t *nvl)
-{
- nvlist_t *rv;
- VERIFY0(nvlist_dup(nvl, &rv, KM_SLEEP));
- return (rv);
-}
-
-void
-fnvlist_merge(nvlist_t *dst, nvlist_t *src)
-{
- VERIFY0(nvlist_merge(dst, src, KM_SLEEP));
-}
-
-size_t
-fnvlist_num_pairs(nvlist_t *nvl)
-{
- size_t count = 0;
- nvpair_t *pair;
-
- for (pair = nvlist_next_nvpair(nvl, 0); pair != NULL;
- pair = nvlist_next_nvpair(nvl, pair))
- count++;
- return (count);
-}
-
-void
-fnvlist_add_boolean(nvlist_t *nvl, const char *name)
-{
- VERIFY0(nvlist_add_boolean(nvl, name));
-}
-
-void
-fnvlist_add_boolean_value(nvlist_t *nvl, const char *name, boolean_t val)
-{
- VERIFY0(nvlist_add_boolean_value(nvl, name, val));
-}
-
-void
-fnvlist_add_byte(nvlist_t *nvl, const char *name, uchar_t val)
-{
- VERIFY0(nvlist_add_byte(nvl, name, val));
-}
-
-void
-fnvlist_add_int8(nvlist_t *nvl, const char *name, int8_t val)
-{
- VERIFY0(nvlist_add_int8(nvl, name, val));
-}
-
-void
-fnvlist_add_uint8(nvlist_t *nvl, const char *name, uint8_t val)
-{
- VERIFY0(nvlist_add_uint8(nvl, name, val));
-}
-
-void
-fnvlist_add_int16(nvlist_t *nvl, const char *name, int16_t val)
-{
- VERIFY0(nvlist_add_int16(nvl, name, val));
-}
-
-void
-fnvlist_add_uint16(nvlist_t *nvl, const char *name, uint16_t val)
-{
- VERIFY0(nvlist_add_uint16(nvl, name, val));
-}
-
-void
-fnvlist_add_int32(nvlist_t *nvl, const char *name, int32_t val)
-{
- VERIFY0(nvlist_add_int32(nvl, name, val));
-}
-
-void
-fnvlist_add_uint32(nvlist_t *nvl, const char *name, uint32_t val)
-{
- VERIFY0(nvlist_add_uint32(nvl, name, val));
-}
-
-void
-fnvlist_add_int64(nvlist_t *nvl, const char *name, int64_t val)
-{
- VERIFY0(nvlist_add_int64(nvl, name, val));
-}
-
-void
-fnvlist_add_uint64(nvlist_t *nvl, const char *name, uint64_t val)
-{
- VERIFY0(nvlist_add_uint64(nvl, name, val));
-}
-
-void
-fnvlist_add_string(nvlist_t *nvl, const char *name, const char *val)
-{
- VERIFY0(nvlist_add_string(nvl, name, val));
-}
-
-void
-fnvlist_add_nvlist(nvlist_t *nvl, const char *name, nvlist_t *val)
-{
- VERIFY0(nvlist_add_nvlist(nvl, name, val));
-}
-
-void
-fnvlist_add_nvpair(nvlist_t *nvl, nvpair_t *pair)
-{
- VERIFY0(nvlist_add_nvpair(nvl, pair));
-}
-
-void
-fnvlist_add_boolean_array(nvlist_t *nvl, const char *name,
- boolean_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_boolean_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_byte_array(nvlist_t *nvl, const char *name, uchar_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_byte_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_int8_array(nvlist_t *nvl, const char *name, int8_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_int8_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_uint8_array(nvlist_t *nvl, const char *name, uint8_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_uint8_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_int16_array(nvlist_t *nvl, const char *name, int16_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_int16_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_uint16_array(nvlist_t *nvl, const char *name,
- uint16_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_uint16_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_int32_array(nvlist_t *nvl, const char *name, int32_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_int32_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_uint32_array(nvlist_t *nvl, const char *name,
- uint32_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_uint32_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_int64_array(nvlist_t *nvl, const char *name, int64_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_int64_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_uint64_array(nvlist_t *nvl, const char *name,
- uint64_t *val, uint_t n)
-{
- VERIFY0(nvlist_add_uint64_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_string_array(nvlist_t *nvl, const char *name,
- char * const *val, uint_t n)
-{
- VERIFY0(nvlist_add_string_array(nvl, name, val, n));
-}
-
-void
-fnvlist_add_nvlist_array(nvlist_t *nvl, const char *name,
- nvlist_t **val, uint_t n)
-{
- VERIFY0(nvlist_add_nvlist_array(nvl, name, val, n));
-}
-
-void
-fnvlist_remove(nvlist_t *nvl, const char *name)
-{
- VERIFY0(nvlist_remove_all(nvl, name));
-}
-
-void
-fnvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *pair)
-{
- VERIFY0(nvlist_remove_nvpair(nvl, pair));
-}
-
-nvpair_t *
-fnvlist_lookup_nvpair(nvlist_t *nvl, const char *name)
-{
- nvpair_t *rv;
- VERIFY0(nvlist_lookup_nvpair(nvl, name, &rv));
- return (rv);
-}
-
-/* returns B_TRUE if the entry exists */
-boolean_t
-fnvlist_lookup_boolean(nvlist_t *nvl, const char *name)
-{
- return (nvlist_lookup_boolean(nvl, name) == 0);
-}
-
-boolean_t
-fnvlist_lookup_boolean_value(nvlist_t *nvl, const char *name)
-{
- boolean_t rv;
- VERIFY0(nvlist_lookup_boolean_value(nvl, name, &rv));
- return (rv);
-}
-
-uchar_t
-fnvlist_lookup_byte(nvlist_t *nvl, const char *name)
-{
- uchar_t rv;
- VERIFY0(nvlist_lookup_byte(nvl, name, &rv));
- return (rv);
-}
-
-int8_t
-fnvlist_lookup_int8(nvlist_t *nvl, const char *name)
-{
- int8_t rv;
- VERIFY0(nvlist_lookup_int8(nvl, name, &rv));
- return (rv);
-}
-
-int16_t
-fnvlist_lookup_int16(nvlist_t *nvl, const char *name)
-{
- int16_t rv;
- VERIFY0(nvlist_lookup_int16(nvl, name, &rv));
- return (rv);
-}
-
-int32_t
-fnvlist_lookup_int32(nvlist_t *nvl, const char *name)
-{
- int32_t rv;
- VERIFY0(nvlist_lookup_int32(nvl, name, &rv));
- return (rv);
-}
-
-int64_t
-fnvlist_lookup_int64(nvlist_t *nvl, const char *name)
-{
- int64_t rv;
- VERIFY0(nvlist_lookup_int64(nvl, name, &rv));
- return (rv);
-}
-
-uint8_t
-fnvlist_lookup_uint8_t(nvlist_t *nvl, const char *name)
-{
- uint8_t rv;
- VERIFY0(nvlist_lookup_uint8(nvl, name, &rv));
- return (rv);
-}
-
-uint16_t
-fnvlist_lookup_uint16(nvlist_t *nvl, const char *name)
-{
- uint16_t rv;
- VERIFY0(nvlist_lookup_uint16(nvl, name, &rv));
- return (rv);
-}
-
-uint32_t
-fnvlist_lookup_uint32(nvlist_t *nvl, const char *name)
-{
- uint32_t rv;
- VERIFY0(nvlist_lookup_uint32(nvl, name, &rv));
- return (rv);
-}
-
-uint64_t
-fnvlist_lookup_uint64(nvlist_t *nvl, const char *name)
-{
- uint64_t rv;
- VERIFY0(nvlist_lookup_uint64(nvl, name, &rv));
- return (rv);
-}
-
-char *
-fnvlist_lookup_string(nvlist_t *nvl, const char *name)
-{
- char *rv;
- VERIFY0(nvlist_lookup_string(nvl, name, &rv));
- return (rv);
-}
-
-nvlist_t *
-fnvlist_lookup_nvlist(nvlist_t *nvl, const char *name)
-{
- nvlist_t *rv;
- VERIFY0(nvlist_lookup_nvlist(nvl, name, &rv));
- return (rv);
-}
-
-boolean_t
-fnvpair_value_boolean_value(nvpair_t *nvp)
-{
- boolean_t rv;
- VERIFY0(nvpair_value_boolean_value(nvp, &rv));
- return (rv);
-}
-
-uchar_t
-fnvpair_value_byte(nvpair_t *nvp)
-{
- uchar_t rv;
- VERIFY0(nvpair_value_byte(nvp, &rv));
- return (rv);
-}
-
-int8_t
-fnvpair_value_int8(nvpair_t *nvp)
-{
- int8_t rv;
- VERIFY0(nvpair_value_int8(nvp, &rv));
- return (rv);
-}
-
-int16_t
-fnvpair_value_int16(nvpair_t *nvp)
-{
- int16_t rv;
- VERIFY0(nvpair_value_int16(nvp, &rv));
- return (rv);
-}
-
-int32_t
-fnvpair_value_int32(nvpair_t *nvp)
-{
- int32_t rv;
- VERIFY0(nvpair_value_int32(nvp, &rv));
- return (rv);
-}
-
-int64_t
-fnvpair_value_int64(nvpair_t *nvp)
-{
- int64_t rv;
- VERIFY0(nvpair_value_int64(nvp, &rv));
- return (rv);
-}
-
-uint8_t
-fnvpair_value_uint8_t(nvpair_t *nvp)
-{
- uint8_t rv;
- VERIFY0(nvpair_value_uint8(nvp, &rv));
- return (rv);
-}
-
-uint16_t
-fnvpair_value_uint16(nvpair_t *nvp)
-{
- uint16_t rv;
- VERIFY0(nvpair_value_uint16(nvp, &rv));
- return (rv);
-}
-
-uint32_t
-fnvpair_value_uint32(nvpair_t *nvp)
-{
- uint32_t rv;
- VERIFY0(nvpair_value_uint32(nvp, &rv));
- return (rv);
-}
-
-uint64_t
-fnvpair_value_uint64(nvpair_t *nvp)
-{
- uint64_t rv;
- VERIFY0(nvpair_value_uint64(nvp, &rv));
- return (rv);
-}
-
-char *
-fnvpair_value_string(nvpair_t *nvp)
-{
- char *rv;
- VERIFY0(nvpair_value_string(nvp, &rv));
- return (rv);
-}
-
-nvlist_t *
-fnvpair_value_nvlist(nvpair_t *nvp)
-{
- nvlist_t *rv;
- VERIFY0(nvpair_value_nvlist(nvp, &rv));
- return (rv);
-}
diff --git a/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c
deleted file mode 100644
index c322a5bd2179..000000000000
--- a/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c
+++ /dev/null
@@ -1,3600 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2015, 2017 by Delphix. All rights reserved.
- */
-
-#include <sys/debug.h>
-#include <sys/nvpair.h>
-#include <sys/nvpair_impl.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-
-#if defined(_KERNEL) && !defined(_BOOT)
-#include <sys/varargs.h>
-#include <sys/sunddi.h>
-#else
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#endif
-
-#ifndef offsetof
-#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
-#endif
-#define skip_whitespace(p) while ((*(p) == ' ') || (*(p) == '\t')) p++
-
-#if defined(__FreeBSD__) && !defined(_KERNEL)
-/*
- * libnvpair is the lowest commen denominator for ZFS related libraries,
- * defining aok here makes it usable by all ZFS related libraries
- */
-int aok;
-#endif
-
-/*
- * nvpair.c - Provides kernel & userland interfaces for manipulating
- * name-value pairs.
- *
- * Overview Diagram
- *
- * +--------------+
- * | nvlist_t |
- * |--------------|
- * | nvl_version |
- * | nvl_nvflag |
- * | nvl_priv -+-+
- * | nvl_flag | |
- * | nvl_pad | |
- * +--------------+ |
- * V
- * +--------------+ last i_nvp in list
- * | nvpriv_t | +--------------------->
- * |--------------| |
- * +--+- nvp_list | | +------------+
- * | | nvp_last -+--+ + nv_alloc_t |
- * | | nvp_curr | |------------|
- * | | nvp_nva -+----> | nva_ops |
- * | | nvp_stat | | nva_arg |
- * | +--------------+ +------------+
- * |
- * +-------+
- * V
- * +---------------------+ +-------------------+
- * | i_nvp_t | +-->| i_nvp_t | +-->
- * |---------------------| | |-------------------| |
- * | nvi_next -+--+ | nvi_next -+--+
- * | nvi_prev (NULL) | <----+ nvi_prev |
- * | . . . . . . . . . . | | . . . . . . . . . |
- * | nvp (nvpair_t) | | nvp (nvpair_t) |
- * | - nvp_size | | - nvp_size |
- * | - nvp_name_sz | | - nvp_name_sz |
- * | - nvp_value_elem | | - nvp_value_elem |
- * | - nvp_type | | - nvp_type |
- * | - data ... | | - data ... |
- * +---------------------+ +-------------------+
- *
- *
- *
- * +---------------------+ +---------------------+
- * | i_nvp_t | +--> +-->| i_nvp_t (last) |
- * |---------------------| | | |---------------------|
- * | nvi_next -+--+ ... --+ | nvi_next (NULL) |
- * <-+- nvi_prev |<-- ... <----+ nvi_prev |
- * | . . . . . . . . . | | . . . . . . . . . |
- * | nvp (nvpair_t) | | nvp (nvpair_t) |
- * | - nvp_size | | - nvp_size |
- * | - nvp_name_sz | | - nvp_name_sz |
- * | - nvp_value_elem | | - nvp_value_elem |
- * | - DATA_TYPE_NVLIST | | - nvp_type |
- * | - data (embedded) | | - data ... |
- * | nvlist name | +---------------------+
- * | +--------------+ |
- * | | nvlist_t | |
- * | |--------------| |
- * | | nvl_version | |
- * | | nvl_nvflag | |
- * | | nvl_priv --+---+---->
- * | | nvl_flag | |
- * | | nvl_pad | |
- * | +--------------+ |
- * +---------------------+
- *
- *
- * N.B. nvpair_t may be aligned on 4 byte boundary, so +4 will
- * allow value to be aligned on 8 byte boundary
- *
- * name_len is the length of the name string including the null terminator
- * so it must be >= 1
- */
-#define NVP_SIZE_CALC(name_len, data_len) \
- (NV_ALIGN((sizeof (nvpair_t)) + name_len) + NV_ALIGN(data_len))
-
-static int i_get_value_size(data_type_t type, const void *data, uint_t nelem);
-static int nvlist_add_common(nvlist_t *nvl, const char *name, data_type_t type,
- uint_t nelem, const void *data);
-
-#define NV_STAT_EMBEDDED 0x1
-#define EMBEDDED_NVL(nvp) ((nvlist_t *)(void *)NVP_VALUE(nvp))
-#define EMBEDDED_NVL_ARRAY(nvp) ((nvlist_t **)(void *)NVP_VALUE(nvp))
-
-#define NVP_VALOFF(nvp) (NV_ALIGN(sizeof (nvpair_t) + (nvp)->nvp_name_sz))
-#define NVPAIR2I_NVP(nvp) \
- ((i_nvp_t *)((size_t)(nvp) - offsetof(i_nvp_t, nvi_nvp)))
-
-#ifdef _KERNEL
-int nvpair_max_recursion = 20;
-#else
-int nvpair_max_recursion = 100;
-#endif
-
-uint64_t nvlist_hashtable_init_size = (1 << 4);
-
-int
-nv_alloc_init(nv_alloc_t *nva, const nv_alloc_ops_t *nvo, /* args */ ...)
-{
- va_list valist;
- int err = 0;
-
- nva->nva_ops = nvo;
- nva->nva_arg = NULL;
-
- va_start(valist, nvo);
- if (nva->nva_ops->nv_ao_init != NULL)
- err = nva->nva_ops->nv_ao_init(nva, valist);
- va_end(valist);
-
- return (err);
-}
-
-void
-nv_alloc_reset(nv_alloc_t *nva)
-{
- if (nva->nva_ops->nv_ao_reset != NULL)
- nva->nva_ops->nv_ao_reset(nva);
-}
-
-void
-nv_alloc_fini(nv_alloc_t *nva)
-{
- if (nva->nva_ops->nv_ao_fini != NULL)
- nva->nva_ops->nv_ao_fini(nva);
-}
-
-nv_alloc_t *
-nvlist_lookup_nv_alloc(nvlist_t *nvl)
-{
- nvpriv_t *priv;
-
- if (nvl == NULL ||
- (priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
- return (NULL);
-
- return (priv->nvp_nva);
-}
-
-static void *
-nv_mem_zalloc(nvpriv_t *nvp, size_t size)
-{
- nv_alloc_t *nva = nvp->nvp_nva;
- void *buf;
-
- if ((buf = nva->nva_ops->nv_ao_alloc(nva, size)) != NULL)
- bzero(buf, size);
-
- return (buf);
-}
-
-static void
-nv_mem_free(nvpriv_t *nvp, void *buf, size_t size)
-{
- nv_alloc_t *nva = nvp->nvp_nva;
-
- nva->nva_ops->nv_ao_free(nva, buf, size);
-}
-
-static void
-nv_priv_init(nvpriv_t *priv, nv_alloc_t *nva, uint32_t stat)
-{
- bzero(priv, sizeof (nvpriv_t));
-
- priv->nvp_nva = nva;
- priv->nvp_stat = stat;
-}
-
-static nvpriv_t *
-nv_priv_alloc(nv_alloc_t *nva)
-{
- nvpriv_t *priv;
-
- /*
- * nv_mem_alloc() cannot called here because it needs the priv
- * argument.
- */
- if ((priv = nva->nva_ops->nv_ao_alloc(nva, sizeof (nvpriv_t))) == NULL)
- return (NULL);
-
- nv_priv_init(priv, nva, 0);
-
- return (priv);
-}
-
-/*
- * Embedded lists need their own nvpriv_t's. We create a new
- * nvpriv_t using the parameters and allocator from the parent
- * list's nvpriv_t.
- */
-static nvpriv_t *
-nv_priv_alloc_embedded(nvpriv_t *priv)
-{
- nvpriv_t *emb_priv;
-
- if ((emb_priv = nv_mem_zalloc(priv, sizeof (nvpriv_t))) == NULL)
- return (NULL);
-
- nv_priv_init(emb_priv, priv->nvp_nva, NV_STAT_EMBEDDED);
-
- return (emb_priv);
-}
-
-static int
-nvt_tab_alloc(nvpriv_t *priv, uint64_t buckets)
-{
- ASSERT3P(priv->nvp_hashtable, ==, NULL);
- ASSERT0(priv->nvp_nbuckets);
- ASSERT0(priv->nvp_nentries);
-
- i_nvp_t **tab = nv_mem_zalloc(priv, buckets * sizeof (i_nvp_t *));
- if (tab == NULL)
- return (ENOMEM);
-
- priv->nvp_hashtable = tab;
- priv->nvp_nbuckets = buckets;
- return (0);
-}
-
-static void
-nvt_tab_free(nvpriv_t *priv)
-{
- i_nvp_t **tab = priv->nvp_hashtable;
- if (tab == NULL) {
- ASSERT0(priv->nvp_nbuckets);
- ASSERT0(priv->nvp_nentries);
- return;
- }
-
- nv_mem_free(priv, tab, priv->nvp_nbuckets * sizeof (i_nvp_t *));
-
- priv->nvp_hashtable = NULL;
- priv->nvp_nbuckets = 0;
- priv->nvp_nentries = 0;
-}
-
-static uint32_t
-nvt_hash(const char *p)
-{
- uint32_t g, hval = 0;
-
- while (*p) {
- hval = (hval << 4) + *p++;
- if ((g = (hval & 0xf0000000)) != 0)
- hval ^= g >> 24;
- hval &= ~g;
- }
- return (hval);
-}
-
-static boolean_t
-nvt_nvpair_match(nvpair_t *nvp1, nvpair_t *nvp2, uint32_t nvflag)
-{
- boolean_t match = B_FALSE;
- if (nvflag & NV_UNIQUE_NAME_TYPE) {
- if (strcmp(NVP_NAME(nvp1), NVP_NAME(nvp2)) == 0 &&
- NVP_TYPE(nvp1) == NVP_TYPE(nvp2))
- match = B_TRUE;
- } else {
- ASSERT(nvflag == 0 || nvflag & NV_UNIQUE_NAME);
- if (strcmp(NVP_NAME(nvp1), NVP_NAME(nvp2)) == 0)
- match = B_TRUE;
- }
- return (match);
-}
-
-static nvpair_t *
-nvt_lookup_name_type(nvlist_t *nvl, const char *name, data_type_t type)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- ASSERT(priv != NULL);
-
- i_nvp_t **tab = priv->nvp_hashtable;
-
- if (tab == NULL) {
- ASSERT3P(priv->nvp_list, ==, NULL);
- ASSERT0(priv->nvp_nbuckets);
- ASSERT0(priv->nvp_nentries);
- return (NULL);
- } else {
- ASSERT(priv->nvp_nbuckets != 0);
- }
-
- uint64_t hash = nvt_hash(name);
- uint64_t index = hash & (priv->nvp_nbuckets - 1);
-
- ASSERT3U(index, <, priv->nvp_nbuckets);
- i_nvp_t *entry = tab[index];
-
- for (i_nvp_t *e = entry; e != NULL; e = e->nvi_hashtable_next) {
- if (strcmp(NVP_NAME(&e->nvi_nvp), name) == 0 &&
- (type == DATA_TYPE_DONTCARE ||
- NVP_TYPE(&e->nvi_nvp) == type))
- return (&e->nvi_nvp);
- }
- return (NULL);
-}
-
-static nvpair_t *
-nvt_lookup_name(nvlist_t *nvl, const char *name)
-{
- return (nvt_lookup_name_type(nvl, name, DATA_TYPE_DONTCARE));
-}
-
-static int
-nvt_resize(nvpriv_t *priv, uint32_t new_size)
-{
- i_nvp_t **tab = priv->nvp_hashtable;
-
- /*
- * Migrate all the entries from the current table
- * to a newly-allocated table with the new size by
- * re-adjusting the pointers of their entries.
- */
- uint32_t size = priv->nvp_nbuckets;
- uint32_t new_mask = new_size - 1;
- ASSERT(((new_size) & ((new_size) - 1)) == 0);
-
- i_nvp_t **new_tab = nv_mem_zalloc(priv, new_size * sizeof (i_nvp_t *));
- if (new_tab == NULL)
- return (ENOMEM);
-
- uint32_t nentries = 0;
- for (uint32_t i = 0; i < size; i++) {
- i_nvp_t *next, *e = tab[i];
-
- while (e != NULL) {
- next = e->nvi_hashtable_next;
-
- uint32_t hash = nvt_hash(NVP_NAME(&e->nvi_nvp));
- uint32_t index = hash & new_mask;
-
- e->nvi_hashtable_next = new_tab[index];
- new_tab[index] = e;
- nentries++;
-
- e = next;
- }
- tab[i] = NULL;
- }
- ASSERT3U(nentries, ==, priv->nvp_nentries);
-
- nvt_tab_free(priv);
-
- priv->nvp_hashtable = new_tab;
- priv->nvp_nbuckets = new_size;
- priv->nvp_nentries = nentries;
-
- return (0);
-}
-
-static boolean_t
-nvt_needs_togrow(nvpriv_t *priv)
-{
- /*
- * Grow only when we have more elements than buckets
- * and the # of buckets doesn't overflow.
- */
- return (priv->nvp_nentries > priv->nvp_nbuckets &&
- (UINT32_MAX >> 1) >= priv->nvp_nbuckets);
-}
-
-/*
- * Allocate a new table that's twice the size of the old one,
- * and migrate all the entries from the old one to the new
- * one by re-adjusting their pointers.
- */
-static int
-nvt_grow(nvpriv_t *priv)
-{
- uint32_t current_size = priv->nvp_nbuckets;
- /* ensure we won't overflow */
- ASSERT3U(UINT32_MAX >> 1, >=, current_size);
- return (nvt_resize(priv, current_size << 1));
-}
-
-static boolean_t
-nvt_needs_toshrink(nvpriv_t *priv)
-{
- /*
- * Shrink only when the # of elements is less than or
- * equal to 1/4 the # of buckets. Never shrink less than
- * nvlist_hashtable_init_size.
- */
- ASSERT3U(priv->nvp_nbuckets, >=, nvlist_hashtable_init_size);
- if (priv->nvp_nbuckets == nvlist_hashtable_init_size)
- return (B_FALSE);
- return (priv->nvp_nentries <= (priv->nvp_nbuckets >> 2));
-}
-
-/*
- * Allocate a new table that's half the size of the old one,
- * and migrate all the entries from the old one to the new
- * one by re-adjusting their pointers.
- */
-static int
-nvt_shrink(nvpriv_t *priv)
-{
- uint32_t current_size = priv->nvp_nbuckets;
- /* ensure we won't overflow */
- ASSERT3U(current_size, >=, nvlist_hashtable_init_size);
- return (nvt_resize(priv, current_size >> 1));
-}
-
-static int
-nvt_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
-
- if (nvt_needs_toshrink(priv)) {
- int err = nvt_shrink(priv);
- if (err != 0)
- return (err);
- }
- i_nvp_t **tab = priv->nvp_hashtable;
-
- char *name = NVP_NAME(nvp);
- uint64_t hash = nvt_hash(name);
- uint64_t index = hash & (priv->nvp_nbuckets - 1);
-
- ASSERT3U(index, <, priv->nvp_nbuckets);
- i_nvp_t *bucket = tab[index];
-
- for (i_nvp_t *prev = NULL, *e = bucket;
- e != NULL; prev = e, e = e->nvi_hashtable_next) {
- if (nvt_nvpair_match(&e->nvi_nvp, nvp, nvl->nvl_flag)) {
- if (prev != NULL) {
- prev->nvi_hashtable_next =
- e->nvi_hashtable_next;
- } else {
- ASSERT3P(e, ==, bucket);
- tab[index] = e->nvi_hashtable_next;
- }
- e->nvi_hashtable_next = NULL;
- priv->nvp_nentries--;
- break;
- }
- }
-
- return (0);
-}
-
-static int
-nvt_add_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
-
- /* initialize nvpair table now if it doesn't exist. */
- if (priv->nvp_hashtable == NULL) {
- int err = nvt_tab_alloc(priv, nvlist_hashtable_init_size);
- if (err != 0)
- return (err);
- }
-
- /*
- * if we don't allow duplicate entries, make sure to
- * unlink any existing entries from the table.
- */
- if (nvl->nvl_nvflag != 0) {
- int err = nvt_remove_nvpair(nvl, nvp);
- if (err != 0)
- return (err);
- }
-
- if (nvt_needs_togrow(priv)) {
- int err = nvt_grow(priv);
- if (err != 0)
- return (err);
- }
- i_nvp_t **tab = priv->nvp_hashtable;
-
- char *name = NVP_NAME(nvp);
- uint64_t hash = nvt_hash(name);
- uint64_t index = hash & (priv->nvp_nbuckets - 1);
-
- ASSERT3U(index, <, priv->nvp_nbuckets);
- i_nvp_t *bucket = tab[index];
-
- /* insert link at the beginning of the bucket */
- i_nvp_t *new_entry = NVPAIR2I_NVP(nvp);
- ASSERT3P(new_entry->nvi_hashtable_next, ==, NULL);
- new_entry->nvi_hashtable_next = bucket;
- tab[index] = new_entry;
-
- priv->nvp_nentries++;
- return (0);
-}
-
-static void
-nvlist_init(nvlist_t *nvl, uint32_t nvflag, nvpriv_t *priv)
-{
- nvl->nvl_version = NV_VERSION;
- nvl->nvl_nvflag = nvflag & (NV_UNIQUE_NAME|NV_UNIQUE_NAME_TYPE);
- nvl->nvl_priv = (uint64_t)(uintptr_t)priv;
- nvl->nvl_flag = 0;
- nvl->nvl_pad = 0;
-}
-
-uint_t
-nvlist_nvflag(nvlist_t *nvl)
-{
- return (nvl->nvl_nvflag);
-}
-
-/*
- * nvlist_alloc - Allocate nvlist.
- */
-/*ARGSUSED1*/
-int
-nvlist_alloc(nvlist_t **nvlp, uint_t nvflag, int kmflag)
-{
-#if defined(_KERNEL) && !defined(_BOOT)
- return (nvlist_xalloc(nvlp, nvflag,
- (kmflag == KM_SLEEP ? nv_alloc_sleep : nv_alloc_nosleep)));
-#else
- return (nvlist_xalloc(nvlp, nvflag, nv_alloc_nosleep));
-#endif
-}
-
-int
-nvlist_xalloc(nvlist_t **nvlp, uint_t nvflag, nv_alloc_t *nva)
-{
- nvpriv_t *priv;
-
- if (nvlp == NULL || nva == NULL)
- return (EINVAL);
-
- if ((priv = nv_priv_alloc(nva)) == NULL)
- return (ENOMEM);
-
- if ((*nvlp = nv_mem_zalloc(priv,
- NV_ALIGN(sizeof (nvlist_t)))) == NULL) {
- nv_mem_free(priv, priv, sizeof (nvpriv_t));
- return (ENOMEM);
- }
-
- nvlist_init(*nvlp, nvflag, priv);
-
- return (0);
-}
-
-/*
- * nvp_buf_alloc - Allocate i_nvp_t for storing a new nv pair.
- */
-static nvpair_t *
-nvp_buf_alloc(nvlist_t *nvl, size_t len)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- i_nvp_t *buf;
- nvpair_t *nvp;
- size_t nvsize;
-
- /*
- * Allocate the buffer
- */
- nvsize = len + offsetof(i_nvp_t, nvi_nvp);
-
- if ((buf = nv_mem_zalloc(priv, nvsize)) == NULL)
- return (NULL);
-
- nvp = &buf->nvi_nvp;
- nvp->nvp_size = len;
-
- return (nvp);
-}
-
-/*
- * nvp_buf_free - de-Allocate an i_nvp_t.
- */
-static void
-nvp_buf_free(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- size_t nvsize = nvp->nvp_size + offsetof(i_nvp_t, nvi_nvp);
-
- nv_mem_free(priv, NVPAIR2I_NVP(nvp), nvsize);
-}
-
-/*
- * nvp_buf_link - link a new nv pair into the nvlist.
- */
-static void
-nvp_buf_link(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- i_nvp_t *curr = NVPAIR2I_NVP(nvp);
-
- /* Put element at end of nvlist */
- if (priv->nvp_list == NULL) {
- priv->nvp_list = priv->nvp_last = curr;
- } else {
- curr->nvi_prev = priv->nvp_last;
- priv->nvp_last->nvi_next = curr;
- priv->nvp_last = curr;
- }
-}
-
-/*
- * nvp_buf_unlink - unlink an removed nvpair out of the nvlist.
- */
-static void
-nvp_buf_unlink(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- i_nvp_t *curr = NVPAIR2I_NVP(nvp);
-
- /*
- * protect nvlist_next_nvpair() against walking on freed memory.
- */
- if (priv->nvp_curr == curr)
- priv->nvp_curr = curr->nvi_next;
-
- if (curr == priv->nvp_list)
- priv->nvp_list = curr->nvi_next;
- else
- curr->nvi_prev->nvi_next = curr->nvi_next;
-
- if (curr == priv->nvp_last)
- priv->nvp_last = curr->nvi_prev;
- else
- curr->nvi_next->nvi_prev = curr->nvi_prev;
-}
-
-/*
- * take a nvpair type and number of elements and make sure the are valid
- */
-static int
-i_validate_type_nelem(data_type_t type, uint_t nelem)
-{
- switch (type) {
- case DATA_TYPE_BOOLEAN:
- if (nelem != 0)
- return (EINVAL);
- break;
- case DATA_TYPE_BOOLEAN_VALUE:
- case DATA_TYPE_BYTE:
- case DATA_TYPE_INT8:
- case DATA_TYPE_UINT8:
- case DATA_TYPE_INT16:
- case DATA_TYPE_UINT16:
- case DATA_TYPE_INT32:
- case DATA_TYPE_UINT32:
- case DATA_TYPE_INT64:
- case DATA_TYPE_UINT64:
- case DATA_TYPE_STRING:
- case DATA_TYPE_HRTIME:
- case DATA_TYPE_NVLIST:
-#if !defined(_KERNEL)
- case DATA_TYPE_DOUBLE:
-#endif
- if (nelem != 1)
- return (EINVAL);
- break;
- case DATA_TYPE_BOOLEAN_ARRAY:
- case DATA_TYPE_BYTE_ARRAY:
- case DATA_TYPE_INT8_ARRAY:
- case DATA_TYPE_UINT8_ARRAY:
- case DATA_TYPE_INT16_ARRAY:
- case DATA_TYPE_UINT16_ARRAY:
- case DATA_TYPE_INT32_ARRAY:
- case DATA_TYPE_UINT32_ARRAY:
- case DATA_TYPE_INT64_ARRAY:
- case DATA_TYPE_UINT64_ARRAY:
- case DATA_TYPE_STRING_ARRAY:
- case DATA_TYPE_NVLIST_ARRAY:
- /* we allow arrays with 0 elements */
- break;
- default:
- return (EINVAL);
- }
- return (0);
-}
-
-/*
- * Verify nvp_name_sz and check the name string length.
- */
-static int
-i_validate_nvpair_name(nvpair_t *nvp)
-{
- if ((nvp->nvp_name_sz <= 0) ||
- (nvp->nvp_size < NVP_SIZE_CALC(nvp->nvp_name_sz, 0)))
- return (EFAULT);
-
- /* verify the name string, make sure its terminated */
- if (NVP_NAME(nvp)[nvp->nvp_name_sz - 1] != '\0')
- return (EFAULT);
-
- return (strlen(NVP_NAME(nvp)) == nvp->nvp_name_sz - 1 ? 0 : EFAULT);
-}
-
-static int
-i_validate_nvpair_value(data_type_t type, uint_t nelem, const void *data)
-{
- switch (type) {
- case DATA_TYPE_BOOLEAN_VALUE:
- if (*(boolean_t *)data != B_TRUE &&
- *(boolean_t *)data != B_FALSE)
- return (EINVAL);
- break;
- case DATA_TYPE_BOOLEAN_ARRAY: {
- int i;
-
- for (i = 0; i < nelem; i++)
- if (((boolean_t *)data)[i] != B_TRUE &&
- ((boolean_t *)data)[i] != B_FALSE)
- return (EINVAL);
- break;
- }
- default:
- break;
- }
-
- return (0);
-}
-
-/*
- * This function takes a pointer to what should be a nvpair and it's size
- * and then verifies that all the nvpair fields make sense and can be
- * trusted. This function is used when decoding packed nvpairs.
- */
-static int
-i_validate_nvpair(nvpair_t *nvp)
-{
- data_type_t type = NVP_TYPE(nvp);
- int size1, size2;
-
- /* verify nvp_name_sz, check the name string length */
- if (i_validate_nvpair_name(nvp) != 0)
- return (EFAULT);
-
- if (i_validate_nvpair_value(type, NVP_NELEM(nvp), NVP_VALUE(nvp)) != 0)
- return (EFAULT);
-
- /*
- * verify nvp_type, nvp_value_elem, and also possibly
- * verify string values and get the value size.
- */
- size2 = i_get_value_size(type, NVP_VALUE(nvp), NVP_NELEM(nvp));
- size1 = nvp->nvp_size - NVP_VALOFF(nvp);
- if (size2 < 0 || size1 != NV_ALIGN(size2))
- return (EFAULT);
-
- return (0);
-}
-
-static int
-nvlist_copy_pairs(nvlist_t *snvl, nvlist_t *dnvl)
-{
- nvpriv_t *priv;
- i_nvp_t *curr;
-
- if ((priv = (nvpriv_t *)(uintptr_t)snvl->nvl_priv) == NULL)
- return (EINVAL);
-
- for (curr = priv->nvp_list; curr != NULL; curr = curr->nvi_next) {
- nvpair_t *nvp = &curr->nvi_nvp;
- int err;
-
- if ((err = nvlist_add_common(dnvl, NVP_NAME(nvp), NVP_TYPE(nvp),
- NVP_NELEM(nvp), NVP_VALUE(nvp))) != 0)
- return (err);
- }
-
- return (0);
-}
-
-/*
- * Frees all memory allocated for an nvpair (like embedded lists) with
- * the exception of the nvpair buffer itself.
- */
-static void
-nvpair_free(nvpair_t *nvp)
-{
- switch (NVP_TYPE(nvp)) {
- case DATA_TYPE_NVLIST:
- nvlist_free(EMBEDDED_NVL(nvp));
- break;
- case DATA_TYPE_NVLIST_ARRAY: {
- nvlist_t **nvlp = EMBEDDED_NVL_ARRAY(nvp);
- int i;
-
- for (i = 0; i < NVP_NELEM(nvp); i++)
- nvlist_free(nvlp[i]);
- break;
- }
- default:
- break;
- }
-}
-
-/*
- * nvlist_free - free an unpacked nvlist
- */
-void
-nvlist_free(nvlist_t *nvl)
-{
- nvpriv_t *priv;
- i_nvp_t *curr;
-
- if (nvl == NULL ||
- (priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
- return;
-
- /*
- * Unpacked nvlist are linked through i_nvp_t
- */
- curr = priv->nvp_list;
- while (curr != NULL) {
- nvpair_t *nvp = &curr->nvi_nvp;
- curr = curr->nvi_next;
-
- nvpair_free(nvp);
- nvp_buf_free(nvl, nvp);
- }
-
- if (!(priv->nvp_stat & NV_STAT_EMBEDDED))
- nv_mem_free(priv, nvl, NV_ALIGN(sizeof (nvlist_t)));
- else
- nvl->nvl_priv = 0;
-
- nvt_tab_free(priv);
- nv_mem_free(priv, priv, sizeof (nvpriv_t));
-}
-
-static int
-nvlist_contains_nvp(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- i_nvp_t *curr;
-
- if (nvp == NULL)
- return (0);
-
- for (curr = priv->nvp_list; curr != NULL; curr = curr->nvi_next)
- if (&curr->nvi_nvp == nvp)
- return (1);
-
- return (0);
-}
-
-/*
- * Make a copy of nvlist
- */
-/*ARGSUSED1*/
-int
-nvlist_dup(nvlist_t *nvl, nvlist_t **nvlp, int kmflag)
-{
-#if defined(_KERNEL) && !defined(_BOOT)
- return (nvlist_xdup(nvl, nvlp,
- (kmflag == KM_SLEEP ? nv_alloc_sleep : nv_alloc_nosleep)));
-#else
- return (nvlist_xdup(nvl, nvlp, nv_alloc_nosleep));
-#endif
-}
-
-int
-nvlist_xdup(nvlist_t *nvl, nvlist_t **nvlp, nv_alloc_t *nva)
-{
- int err;
- nvlist_t *ret;
-
- if (nvl == NULL || nvlp == NULL)
- return (EINVAL);
-
- if ((err = nvlist_xalloc(&ret, nvl->nvl_nvflag, nva)) != 0)
- return (err);
-
- if ((err = nvlist_copy_pairs(nvl, ret)) != 0)
- nvlist_free(ret);
- else
- *nvlp = ret;
-
- return (err);
-}
-
-/*
- * Remove all with matching name
- */
-int
-nvlist_remove_all(nvlist_t *nvl, const char *name)
-{
- int error = ENOENT;
-
- if (nvl == NULL || name == NULL || nvl->nvl_priv == 0)
- return (EINVAL);
-
- nvpair_t *nvp;
- while ((nvp = nvt_lookup_name(nvl, name)) != NULL) {
- VERIFY0(nvlist_remove_nvpair(nvl, nvp));
- error = 0;
- }
-
- return (error);
-}
-
-/*
- * Remove first one with matching name and type
- */
-int
-nvlist_remove(nvlist_t *nvl, const char *name, data_type_t type)
-{
- if (nvl == NULL || name == NULL || nvl->nvl_priv == 0)
- return (EINVAL);
-
- nvpair_t *nvp = nvt_lookup_name_type(nvl, name, type);
- if (nvp == NULL)
- return (ENOENT);
-
- return (nvlist_remove_nvpair(nvl, nvp));
-}
-
-int
-nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
- if (nvl == NULL || nvp == NULL)
- return (EINVAL);
-
- int err = nvt_remove_nvpair(nvl, nvp);
- if (err != 0)
- return (err);
-
- nvp_buf_unlink(nvl, nvp);
- nvpair_free(nvp);
- nvp_buf_free(nvl, nvp);
- return (0);
-}
-
-/*
- * This function calculates the size of an nvpair value.
- *
- * The data argument controls the behavior in case of the data types
- * DATA_TYPE_STRING and
- * DATA_TYPE_STRING_ARRAY
- * Is data == NULL then the size of the string(s) is excluded.
- */
-static int
-i_get_value_size(data_type_t type, const void *data, uint_t nelem)
-{
- uint64_t value_sz;
-
- if (i_validate_type_nelem(type, nelem) != 0)
- return (-1);
-
- /* Calculate required size for holding value */
- switch (type) {
- case DATA_TYPE_BOOLEAN:
- value_sz = 0;
- break;
- case DATA_TYPE_BOOLEAN_VALUE:
- value_sz = sizeof (boolean_t);
- break;
- case DATA_TYPE_BYTE:
- value_sz = sizeof (uchar_t);
- break;
- case DATA_TYPE_INT8:
- value_sz = sizeof (int8_t);
- break;
- case DATA_TYPE_UINT8:
- value_sz = sizeof (uint8_t);
- break;
- case DATA_TYPE_INT16:
- value_sz = sizeof (int16_t);
- break;
- case DATA_TYPE_UINT16:
- value_sz = sizeof (uint16_t);
- break;
- case DATA_TYPE_INT32:
- value_sz = sizeof (int32_t);
- break;
- case DATA_TYPE_UINT32:
- value_sz = sizeof (uint32_t);
- break;
- case DATA_TYPE_INT64:
- value_sz = sizeof (int64_t);
- break;
- case DATA_TYPE_UINT64:
- value_sz = sizeof (uint64_t);
- break;
-#if !defined(_KERNEL)
- case DATA_TYPE_DOUBLE:
- value_sz = sizeof (double);
- break;
-#endif
- case DATA_TYPE_STRING:
- if (data == NULL)
- value_sz = 0;
- else
- value_sz = strlen(data) + 1;
- break;
- case DATA_TYPE_BOOLEAN_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (boolean_t);
- break;
- case DATA_TYPE_BYTE_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (uchar_t);
- break;
- case DATA_TYPE_INT8_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (int8_t);
- break;
- case DATA_TYPE_UINT8_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (uint8_t);
- break;
- case DATA_TYPE_INT16_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (int16_t);
- break;
- case DATA_TYPE_UINT16_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (uint16_t);
- break;
- case DATA_TYPE_INT32_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (int32_t);
- break;
- case DATA_TYPE_UINT32_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (uint32_t);
- break;
- case DATA_TYPE_INT64_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (int64_t);
- break;
- case DATA_TYPE_UINT64_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (uint64_t);
- break;
- case DATA_TYPE_STRING_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (uint64_t);
-
- if (data != NULL) {
- char *const *strs = data;
- uint_t i;
-
- /* no alignment requirement for strings */
- for (i = 0; i < nelem; i++) {
- if (strs[i] == NULL)
- return (-1);
- value_sz += strlen(strs[i]) + 1;
- }
- }
- break;
- case DATA_TYPE_HRTIME:
- value_sz = sizeof (hrtime_t);
- break;
- case DATA_TYPE_NVLIST:
- value_sz = NV_ALIGN(sizeof (nvlist_t));
- break;
- case DATA_TYPE_NVLIST_ARRAY:
- value_sz = (uint64_t)nelem * sizeof (uint64_t) +
- (uint64_t)nelem * NV_ALIGN(sizeof (nvlist_t));
- break;
- default:
- return (-1);
- }
-
- return (value_sz > INT32_MAX ? -1 : (int)value_sz);
-}
-
-static int
-nvlist_copy_embedded(nvlist_t *nvl, nvlist_t *onvl, nvlist_t *emb_nvl)
-{
- nvpriv_t *priv;
- int err;
-
- if ((priv = nv_priv_alloc_embedded((nvpriv_t *)(uintptr_t)
- nvl->nvl_priv)) == NULL)
- return (ENOMEM);
-
- nvlist_init(emb_nvl, onvl->nvl_nvflag, priv);
-
- if ((err = nvlist_copy_pairs(onvl, emb_nvl)) != 0) {
- nvlist_free(emb_nvl);
- emb_nvl->nvl_priv = 0;
- }
-
- return (err);
-}
-
-/*
- * nvlist_add_common - Add new <name,value> pair to nvlist
- */
-static int
-nvlist_add_common(nvlist_t *nvl, const char *name,
- data_type_t type, uint_t nelem, const void *data)
-{
- nvpair_t *nvp;
- uint_t i;
-
- int nvp_sz, name_sz, value_sz;
- int err = 0;
-
- if (name == NULL || nvl == NULL || nvl->nvl_priv == 0)
- return (EINVAL);
-
- if (nelem != 0 && data == NULL)
- return (EINVAL);
-
- /*
- * Verify type and nelem and get the value size.
- * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
- * is the size of the string(s) included.
- */
- if ((value_sz = i_get_value_size(type, data, nelem)) < 0)
- return (EINVAL);
-
- if (i_validate_nvpair_value(type, nelem, data) != 0)
- return (EINVAL);
-
- /*
- * If we're adding an nvlist or nvlist array, ensure that we are not
- * adding the input nvlist to itself, which would cause recursion,
- * and ensure that no NULL nvlist pointers are present.
- */
- switch (type) {
- case DATA_TYPE_NVLIST:
- if (data == nvl || data == NULL)
- return (EINVAL);
- break;
- case DATA_TYPE_NVLIST_ARRAY: {
- nvlist_t **onvlp = (nvlist_t **)data;
- for (i = 0; i < nelem; i++) {
- if (onvlp[i] == nvl || onvlp[i] == NULL)
- return (EINVAL);
- }
- break;
- }
- default:
- break;
- }
-
- /* calculate sizes of the nvpair elements and the nvpair itself */
- name_sz = strlen(name) + 1;
- if (name_sz >= 1ULL << (sizeof (nvp->nvp_name_sz) * 8 - 1))
- return (EINVAL);
-
- nvp_sz = NVP_SIZE_CALC(name_sz, value_sz);
-
- if ((nvp = nvp_buf_alloc(nvl, nvp_sz)) == NULL)
- return (ENOMEM);
-
- ASSERT(nvp->nvp_size == nvp_sz);
- nvp->nvp_name_sz = name_sz;
- nvp->nvp_value_elem = nelem;
- nvp->nvp_type = type;
- bcopy(name, NVP_NAME(nvp), name_sz);
-
- switch (type) {
- case DATA_TYPE_BOOLEAN:
- break;
- case DATA_TYPE_STRING_ARRAY: {
- char *const *strs = data;
- char *buf = NVP_VALUE(nvp);
- char **cstrs = (void *)buf;
-
- /* skip pre-allocated space for pointer array */
- buf += nelem * sizeof (uint64_t);
- for (i = 0; i < nelem; i++) {
- int slen = strlen(strs[i]) + 1;
- bcopy(strs[i], buf, slen);
- cstrs[i] = buf;
- buf += slen;
- }
- break;
- }
- case DATA_TYPE_NVLIST: {
- nvlist_t *nnvl = EMBEDDED_NVL(nvp);
- nvlist_t *onvl = (nvlist_t *)data;
-
- if ((err = nvlist_copy_embedded(nvl, onvl, nnvl)) != 0) {
- nvp_buf_free(nvl, nvp);
- return (err);
- }
- break;
- }
- case DATA_TYPE_NVLIST_ARRAY: {
- nvlist_t **onvlp = (nvlist_t **)data;
- nvlist_t **nvlp = EMBEDDED_NVL_ARRAY(nvp);
- nvlist_t *embedded = (nvlist_t *)
- ((uintptr_t)nvlp + nelem * sizeof (uint64_t));
-
- for (i = 0; i < nelem; i++) {
- if ((err = nvlist_copy_embedded(nvl,
- onvlp[i], embedded)) != 0) {
- /*
- * Free any successfully created lists
- */
- nvpair_free(nvp);
- nvp_buf_free(nvl, nvp);
- return (err);
- }
-
- nvlp[i] = embedded++;
- }
- break;
- }
- default:
- bcopy(data, NVP_VALUE(nvp), value_sz);
- }
-
- /* if unique name, remove before add */
- if (nvl->nvl_nvflag & NV_UNIQUE_NAME)
- (void) nvlist_remove_all(nvl, name);
- else if (nvl->nvl_nvflag & NV_UNIQUE_NAME_TYPE)
- (void) nvlist_remove(nvl, name, type);
-
- err = nvt_add_nvpair(nvl, nvp);
- if (err != 0) {
- nvpair_free(nvp);
- nvp_buf_free(nvl, nvp);
- return (err);
- }
- nvp_buf_link(nvl, nvp);
-
- return (0);
-}
-
-int
-nvlist_add_boolean(nvlist_t *nvl, const char *name)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_BOOLEAN, 0, NULL));
-}
-
-int
-nvlist_add_boolean_value(nvlist_t *nvl, const char *name, boolean_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_BOOLEAN_VALUE, 1, &val));
-}
-
-int
-nvlist_add_byte(nvlist_t *nvl, const char *name, uchar_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_BYTE, 1, &val));
-}
-
-int
-nvlist_add_int8(nvlist_t *nvl, const char *name, int8_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT8, 1, &val));
-}
-
-int
-nvlist_add_uint8(nvlist_t *nvl, const char *name, uint8_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT8, 1, &val));
-}
-
-int
-nvlist_add_int16(nvlist_t *nvl, const char *name, int16_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT16, 1, &val));
-}
-
-int
-nvlist_add_uint16(nvlist_t *nvl, const char *name, uint16_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT16, 1, &val));
-}
-
-int
-nvlist_add_int32(nvlist_t *nvl, const char *name, int32_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT32, 1, &val));
-}
-
-int
-nvlist_add_uint32(nvlist_t *nvl, const char *name, uint32_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT32, 1, &val));
-}
-
-int
-nvlist_add_int64(nvlist_t *nvl, const char *name, int64_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT64, 1, &val));
-}
-
-int
-nvlist_add_uint64(nvlist_t *nvl, const char *name, uint64_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT64, 1, &val));
-}
-
-#if !defined(_KERNEL)
-int
-nvlist_add_double(nvlist_t *nvl, const char *name, double val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_DOUBLE, 1, &val));
-}
-#endif
-
-int
-nvlist_add_string(nvlist_t *nvl, const char *name, const char *val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_STRING, 1, (void *)val));
-}
-
-int
-nvlist_add_boolean_array(nvlist_t *nvl, const char *name,
- boolean_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_BOOLEAN_ARRAY, n, a));
-}
-
-int
-nvlist_add_byte_array(nvlist_t *nvl, const char *name, uchar_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_BYTE_ARRAY, n, a));
-}
-
-int
-nvlist_add_int8_array(nvlist_t *nvl, const char *name, int8_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT8_ARRAY, n, a));
-}
-
-int
-nvlist_add_uint8_array(nvlist_t *nvl, const char *name, uint8_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT8_ARRAY, n, a));
-}
-
-int
-nvlist_add_int16_array(nvlist_t *nvl, const char *name, int16_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT16_ARRAY, n, a));
-}
-
-int
-nvlist_add_uint16_array(nvlist_t *nvl, const char *name, uint16_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT16_ARRAY, n, a));
-}
-
-int
-nvlist_add_int32_array(nvlist_t *nvl, const char *name, int32_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT32_ARRAY, n, a));
-}
-
-int
-nvlist_add_uint32_array(nvlist_t *nvl, const char *name, uint32_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT32_ARRAY, n, a));
-}
-
-int
-nvlist_add_int64_array(nvlist_t *nvl, const char *name, int64_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_INT64_ARRAY, n, a));
-}
-
-int
-nvlist_add_uint64_array(nvlist_t *nvl, const char *name, uint64_t *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_UINT64_ARRAY, n, a));
-}
-
-int
-nvlist_add_string_array(nvlist_t *nvl, const char *name,
- char *const *a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_STRING_ARRAY, n, a));
-}
-
-int
-nvlist_add_hrtime(nvlist_t *nvl, const char *name, hrtime_t val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_HRTIME, 1, &val));
-}
-
-int
-nvlist_add_nvlist(nvlist_t *nvl, const char *name, nvlist_t *val)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_NVLIST, 1, val));
-}
-
-int
-nvlist_add_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **a, uint_t n)
-{
- return (nvlist_add_common(nvl, name, DATA_TYPE_NVLIST_ARRAY, n, a));
-}
-
-/* reading name-value pairs */
-nvpair_t *
-nvlist_next_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv;
- i_nvp_t *curr;
-
- if (nvl == NULL ||
- (priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
- return (NULL);
-
- curr = NVPAIR2I_NVP(nvp);
-
- /*
- * Ensure that nvp is a valid nvpair on this nvlist.
- * NB: nvp_curr is used only as a hint so that we don't always
- * have to walk the list to determine if nvp is still on the list.
- */
- if (nvp == NULL)
- curr = priv->nvp_list;
- else if (priv->nvp_curr == curr || nvlist_contains_nvp(nvl, nvp))
- curr = curr->nvi_next;
- else
- curr = NULL;
-
- priv->nvp_curr = curr;
-
- return (curr != NULL ? &curr->nvi_nvp : NULL);
-}
-
-nvpair_t *
-nvlist_prev_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
- nvpriv_t *priv;
- i_nvp_t *curr;
-
- if (nvl == NULL ||
- (priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
- return (NULL);
-
- curr = NVPAIR2I_NVP(nvp);
-
- if (nvp == NULL)
- curr = priv->nvp_last;
- else if (priv->nvp_curr == curr || nvlist_contains_nvp(nvl, nvp))
- curr = curr->nvi_prev;
- else
- curr = NULL;
-
- priv->nvp_curr = curr;
-
- return (curr != NULL ? &curr->nvi_nvp : NULL);
-}
-
-boolean_t
-nvlist_empty(nvlist_t *nvl)
-{
- nvpriv_t *priv;
-
- if (nvl == NULL ||
- (priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
- return (B_TRUE);
-
- return (priv->nvp_list == NULL);
-}
-
-char *
-nvpair_name(nvpair_t *nvp)
-{
- return (NVP_NAME(nvp));
-}
-
-data_type_t
-nvpair_type(nvpair_t *nvp)
-{
- return (NVP_TYPE(nvp));
-}
-
-int
-nvpair_type_is_array(nvpair_t *nvp)
-{
- data_type_t type = NVP_TYPE(nvp);
-
- if ((type == DATA_TYPE_BYTE_ARRAY) ||
- (type == DATA_TYPE_INT8_ARRAY) ||
- (type == DATA_TYPE_UINT8_ARRAY) ||
- (type == DATA_TYPE_INT16_ARRAY) ||
- (type == DATA_TYPE_UINT16_ARRAY) ||
- (type == DATA_TYPE_INT32_ARRAY) ||
- (type == DATA_TYPE_UINT32_ARRAY) ||
- (type == DATA_TYPE_INT64_ARRAY) ||
- (type == DATA_TYPE_UINT64_ARRAY) ||
- (type == DATA_TYPE_BOOLEAN_ARRAY) ||
- (type == DATA_TYPE_STRING_ARRAY) ||
- (type == DATA_TYPE_NVLIST_ARRAY))
- return (1);
- return (0);
-
-}
-
-static int
-nvpair_value_common(nvpair_t *nvp, data_type_t type, uint_t *nelem, void *data)
-{
- if (nvp == NULL || nvpair_type(nvp) != type)
- return (EINVAL);
-
- /*
- * For non-array types, we copy the data.
- * For array types (including string), we set a pointer.
- */
- switch (type) {
- case DATA_TYPE_BOOLEAN:
- if (nelem != NULL)
- *nelem = 0;
- break;
-
- case DATA_TYPE_BOOLEAN_VALUE:
- case DATA_TYPE_BYTE:
- case DATA_TYPE_INT8:
- case DATA_TYPE_UINT8:
- case DATA_TYPE_INT16:
- case DATA_TYPE_UINT16:
- case DATA_TYPE_INT32:
- case DATA_TYPE_UINT32:
- case DATA_TYPE_INT64:
- case DATA_TYPE_UINT64:
- case DATA_TYPE_HRTIME:
-#if !defined(_KERNEL)
- case DATA_TYPE_DOUBLE:
-#endif
- if (data == NULL)
- return (EINVAL);
- bcopy(NVP_VALUE(nvp), data,
- (size_t)i_get_value_size(type, NULL, 1));
- if (nelem != NULL)
- *nelem = 1;
- break;
-
- case DATA_TYPE_NVLIST:
- case DATA_TYPE_STRING:
- if (data == NULL)
- return (EINVAL);
- *(void **)data = (void *)NVP_VALUE(nvp);
- if (nelem != NULL)
- *nelem = 1;
- break;
-
- case DATA_TYPE_BOOLEAN_ARRAY:
- case DATA_TYPE_BYTE_ARRAY:
- case DATA_TYPE_INT8_ARRAY:
- case DATA_TYPE_UINT8_ARRAY:
- case DATA_TYPE_INT16_ARRAY:
- case DATA_TYPE_UINT16_ARRAY:
- case DATA_TYPE_INT32_ARRAY:
- case DATA_TYPE_UINT32_ARRAY:
- case DATA_TYPE_INT64_ARRAY:
- case DATA_TYPE_UINT64_ARRAY:
- case DATA_TYPE_STRING_ARRAY:
- case DATA_TYPE_NVLIST_ARRAY:
- if (nelem == NULL || data == NULL)
- return (EINVAL);
- if ((*nelem = NVP_NELEM(nvp)) != 0)
- *(void **)data = (void *)NVP_VALUE(nvp);
- else
- *(void **)data = NULL;
- break;
-
- default:
- return (ENOTSUP);
- }
-
- return (0);
-}
-
-static int
-nvlist_lookup_common(nvlist_t *nvl, const char *name, data_type_t type,
- uint_t *nelem, void *data)
-{
- if (name == NULL || nvl == NULL || nvl->nvl_priv == 0)
- return (EINVAL);
-
- if (!(nvl->nvl_nvflag & (NV_UNIQUE_NAME | NV_UNIQUE_NAME_TYPE)))
- return (ENOTSUP);
-
- nvpair_t *nvp = nvt_lookup_name_type(nvl, name, type);
- if (nvp == NULL)
- return (ENOENT);
-
- return (nvpair_value_common(nvp, type, nelem, data));
-}
-
-int
-nvlist_lookup_boolean(nvlist_t *nvl, const char *name)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_BOOLEAN, NULL, NULL));
-}
-
-int
-nvlist_lookup_boolean_value(nvlist_t *nvl, const char *name, boolean_t *val)
-{
- return (nvlist_lookup_common(nvl, name,
- DATA_TYPE_BOOLEAN_VALUE, NULL, val));
-}
-
-int
-nvlist_lookup_byte(nvlist_t *nvl, const char *name, uchar_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_BYTE, NULL, val));
-}
-
-int
-nvlist_lookup_int8(nvlist_t *nvl, const char *name, int8_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT8, NULL, val));
-}
-
-int
-nvlist_lookup_uint8(nvlist_t *nvl, const char *name, uint8_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT8, NULL, val));
-}
-
-int
-nvlist_lookup_int16(nvlist_t *nvl, const char *name, int16_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT16, NULL, val));
-}
-
-int
-nvlist_lookup_uint16(nvlist_t *nvl, const char *name, uint16_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT16, NULL, val));
-}
-
-int
-nvlist_lookup_int32(nvlist_t *nvl, const char *name, int32_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT32, NULL, val));
-}
-
-int
-nvlist_lookup_uint32(nvlist_t *nvl, const char *name, uint32_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT32, NULL, val));
-}
-
-int
-nvlist_lookup_int64(nvlist_t *nvl, const char *name, int64_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT64, NULL, val));
-}
-
-int
-nvlist_lookup_uint64(nvlist_t *nvl, const char *name, uint64_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT64, NULL, val));
-}
-
-#if !defined(_KERNEL)
-int
-nvlist_lookup_double(nvlist_t *nvl, const char *name, double *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_DOUBLE, NULL, val));
-}
-#endif
-
-int
-nvlist_lookup_string(nvlist_t *nvl, const char *name, char **val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_STRING, NULL, val));
-}
-
-int
-nvlist_lookup_nvlist(nvlist_t *nvl, const char *name, nvlist_t **val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_NVLIST, NULL, val));
-}
-
-int
-nvlist_lookup_boolean_array(nvlist_t *nvl, const char *name,
- boolean_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name,
- DATA_TYPE_BOOLEAN_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_byte_array(nvlist_t *nvl, const char *name,
- uchar_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_BYTE_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_int8_array(nvlist_t *nvl, const char *name, int8_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT8_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_uint8_array(nvlist_t *nvl, const char *name,
- uint8_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT8_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_int16_array(nvlist_t *nvl, const char *name,
- int16_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT16_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_uint16_array(nvlist_t *nvl, const char *name,
- uint16_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT16_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_int32_array(nvlist_t *nvl, const char *name,
- int32_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT32_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_uint32_array(nvlist_t *nvl, const char *name,
- uint32_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT32_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_int64_array(nvlist_t *nvl, const char *name,
- int64_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_INT64_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_uint64_array(nvlist_t *nvl, const char *name,
- uint64_t **a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_UINT64_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_string_array(nvlist_t *nvl, const char *name,
- char ***a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_STRING_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_nvlist_array(nvlist_t *nvl, const char *name,
- nvlist_t ***a, uint_t *n)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_NVLIST_ARRAY, n, a));
-}
-
-int
-nvlist_lookup_hrtime(nvlist_t *nvl, const char *name, hrtime_t *val)
-{
- return (nvlist_lookup_common(nvl, name, DATA_TYPE_HRTIME, NULL, val));
-}
-
-int
-nvlist_lookup_pairs(nvlist_t *nvl, int flag, ...)
-{
- va_list ap;
- char *name;
- int noentok = (flag & NV_FLAG_NOENTOK ? 1 : 0);
- int ret = 0;
-
- va_start(ap, flag);
- while (ret == 0 && (name = va_arg(ap, char *)) != NULL) {
- data_type_t type;
- void *val;
- uint_t *nelem;
-
- switch (type = va_arg(ap, data_type_t)) {
- case DATA_TYPE_BOOLEAN:
- ret = nvlist_lookup_common(nvl, name, type, NULL, NULL);
- break;
-
- case DATA_TYPE_BOOLEAN_VALUE:
- case DATA_TYPE_BYTE:
- case DATA_TYPE_INT8:
- case DATA_TYPE_UINT8:
- case DATA_TYPE_INT16:
- case DATA_TYPE_UINT16:
- case DATA_TYPE_INT32:
- case DATA_TYPE_UINT32:
- case DATA_TYPE_INT64:
- case DATA_TYPE_UINT64:
- case DATA_TYPE_HRTIME:
- case DATA_TYPE_STRING:
- case DATA_TYPE_NVLIST:
-#if !defined(_KERNEL)
- case DATA_TYPE_DOUBLE:
-#endif
- val = va_arg(ap, void *);
- ret = nvlist_lookup_common(nvl, name, type, NULL, val);
- break;
-
- case DATA_TYPE_BYTE_ARRAY:
- case DATA_TYPE_BOOLEAN_ARRAY:
- case DATA_TYPE_INT8_ARRAY:
- case DATA_TYPE_UINT8_ARRAY:
- case DATA_TYPE_INT16_ARRAY:
- case DATA_TYPE_UINT16_ARRAY:
- case DATA_TYPE_INT32_ARRAY:
- case DATA_TYPE_UINT32_ARRAY:
- case DATA_TYPE_INT64_ARRAY:
- case DATA_TYPE_UINT64_ARRAY:
- case DATA_TYPE_STRING_ARRAY:
- case DATA_TYPE_NVLIST_ARRAY:
- val = va_arg(ap, void *);
- nelem = va_arg(ap, uint_t *);
- ret = nvlist_lookup_common(nvl, name, type, nelem, val);
- break;
-
- default:
- ret = EINVAL;
- }
-
- if (ret == ENOENT && noentok)
- ret = 0;
- }
- va_end(ap);
-
- return (ret);
-}
-
-/*
- * Find the 'name'ed nvpair in the nvlist 'nvl'. If 'name' found, the function
- * returns zero and a pointer to the matching nvpair is returned in '*ret'
- * (given 'ret' is non-NULL). If 'sep' is specified then 'name' will penitrate
- * multiple levels of embedded nvlists, with 'sep' as the separator. As an
- * example, if sep is '.', name might look like: "a" or "a.b" or "a.c[3]" or
- * "a.d[3].e[1]". This matches the C syntax for array embed (for convience,
- * code also supports "a.d[3]e[1]" syntax).
- *
- * If 'ip' is non-NULL and the last name component is an array, return the
- * value of the "...[index]" array index in *ip. For an array reference that
- * is not indexed, *ip will be returned as -1. If there is a syntax error in
- * 'name', and 'ep' is non-NULL then *ep will be set to point to the location
- * inside the 'name' string where the syntax error was detected.
- */
-static int
-nvlist_lookup_nvpair_ei_sep(nvlist_t *nvl, const char *name, const char sep,
- nvpair_t **ret, int *ip, char **ep)
-{
- nvpair_t *nvp;
- const char *np;
- char *sepp;
- char *idxp, *idxep;
- nvlist_t **nva;
- long idx;
- int n;
-
- if (ip)
- *ip = -1; /* not indexed */
- if (ep)
- *ep = NULL;
-
- if ((nvl == NULL) || (name == NULL))
- return (EINVAL);
-
- sepp = NULL;
- idx = 0;
- /* step through components of name */
- for (np = name; np && *np; np = sepp) {
- /* ensure unique names */
- if (!(nvl->nvl_nvflag & NV_UNIQUE_NAME))
- return (ENOTSUP);
-
- /* skip white space */
- skip_whitespace(np);
- if (*np == 0)
- break;
-
- /* set 'sepp' to end of current component 'np' */
- if (sep)
- sepp = strchr(np, sep);
- else
- sepp = NULL;
-
- /* find start of next "[ index ]..." */
- idxp = strchr(np, '[');
-
- /* if sepp comes first, set idxp to NULL */
- if (sepp && idxp && (sepp < idxp))
- idxp = NULL;
-
- /*
- * At this point 'idxp' is set if there is an index
- * expected for the current component.
- */
- if (idxp) {
- /* set 'n' to length of current 'np' name component */
- n = idxp++ - np;
-
- /* keep sepp up to date for *ep use as we advance */
- skip_whitespace(idxp);
- sepp = idxp;
-
- /* determine the index value */
-#if defined(_KERNEL) && !defined(_BOOT)
- if (ddi_strtol(idxp, &idxep, 0, &idx))
- goto fail;
-#else
- idx = strtol(idxp, &idxep, 0);
-#endif
- if (idxep == idxp)
- goto fail;
-
- /* keep sepp up to date for *ep use as we advance */
- sepp = idxep;
-
- /* skip white space index value and check for ']' */
- skip_whitespace(sepp);
- if (*sepp++ != ']')
- goto fail;
-
- /* for embedded arrays, support C syntax: "a[1].b" */
- skip_whitespace(sepp);
- if (sep && (*sepp == sep))
- sepp++;
- } else if (sepp) {
- n = sepp++ - np;
- } else {
- n = strlen(np);
- }
-
- /* trim trailing whitespace by reducing length of 'np' */
- if (n == 0)
- goto fail;
- for (n--; (np[n] == ' ') || (np[n] == '\t'); n--)
- ;
- n++;
-
- /* skip whitespace, and set sepp to NULL if complete */
- if (sepp) {
- skip_whitespace(sepp);
- if (*sepp == 0)
- sepp = NULL;
- }
-
- /*
- * At this point:
- * o 'n' is the length of current 'np' component.
- * o 'idxp' is set if there was an index, and value 'idx'.
- * o 'sepp' is set to the beginning of the next component,
- * and set to NULL if we have no more components.
- *
- * Search for nvpair with matching component name.
- */
- for (nvp = nvlist_next_nvpair(nvl, NULL); nvp != NULL;
- nvp = nvlist_next_nvpair(nvl, nvp)) {
-
- /* continue if no match on name */
- if (strncmp(np, nvpair_name(nvp), n) ||
- (strlen(nvpair_name(nvp)) != n))
- continue;
-
- /* if indexed, verify type is array oriented */
- if (idxp && !nvpair_type_is_array(nvp))
- goto fail;
-
- /*
- * Full match found, return nvp and idx if this
- * was the last component.
- */
- if (sepp == NULL) {
- if (ret)
- *ret = nvp;
- if (ip && idxp)
- *ip = (int)idx; /* return index */
- return (0); /* found */
- }
-
- /*
- * More components: current match must be
- * of DATA_TYPE_NVLIST or DATA_TYPE_NVLIST_ARRAY
- * to support going deeper.
- */
- if (nvpair_type(nvp) == DATA_TYPE_NVLIST) {
- nvl = EMBEDDED_NVL(nvp);
- break;
- } else if (nvpair_type(nvp) == DATA_TYPE_NVLIST_ARRAY) {
- (void) nvpair_value_nvlist_array(nvp,
- &nva, (uint_t *)&n);
- if ((n < 0) || (idx >= n))
- goto fail;
- nvl = nva[idx];
- break;
- }
-
- /* type does not support more levels */
- goto fail;
- }
- if (nvp == NULL)
- goto fail; /* 'name' not found */
-
- /* search for match of next component in embedded 'nvl' list */
- }
-
-fail: if (ep && sepp)
- *ep = sepp;
- return (EINVAL);
-}
-
-/*
- * Return pointer to nvpair with specified 'name'.
- */
-int
-nvlist_lookup_nvpair(nvlist_t *nvl, const char *name, nvpair_t **ret)
-{
- return (nvlist_lookup_nvpair_ei_sep(nvl, name, 0, ret, NULL, NULL));
-}
-
-/*
- * Determine if named nvpair exists in nvlist (use embedded separator of '.'
- * and return array index). See nvlist_lookup_nvpair_ei_sep for more detailed
- * description.
- */
-int nvlist_lookup_nvpair_embedded_index(nvlist_t *nvl,
- const char *name, nvpair_t **ret, int *ip, char **ep)
-{
- return (nvlist_lookup_nvpair_ei_sep(nvl, name, '.', ret, ip, ep));
-}
-
-boolean_t
-nvlist_exists(nvlist_t *nvl, const char *name)
-{
- nvpriv_t *priv;
- nvpair_t *nvp;
- i_nvp_t *curr;
-
- if (name == NULL || nvl == NULL ||
- (priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
- return (B_FALSE);
-
- for (curr = priv->nvp_list; curr != NULL; curr = curr->nvi_next) {
- nvp = &curr->nvi_nvp;
-
- if (strcmp(name, NVP_NAME(nvp)) == 0)
- return (B_TRUE);
- }
-
- return (B_FALSE);
-}
-
-int
-nvpair_value_boolean_value(nvpair_t *nvp, boolean_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_BOOLEAN_VALUE, NULL, val));
-}
-
-int
-nvpair_value_byte(nvpair_t *nvp, uchar_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_BYTE, NULL, val));
-}
-
-int
-nvpair_value_int8(nvpair_t *nvp, int8_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT8, NULL, val));
-}
-
-int
-nvpair_value_uint8(nvpair_t *nvp, uint8_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT8, NULL, val));
-}
-
-int
-nvpair_value_int16(nvpair_t *nvp, int16_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT16, NULL, val));
-}
-
-int
-nvpair_value_uint16(nvpair_t *nvp, uint16_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT16, NULL, val));
-}
-
-int
-nvpair_value_int32(nvpair_t *nvp, int32_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT32, NULL, val));
-}
-
-int
-nvpair_value_uint32(nvpair_t *nvp, uint32_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT32, NULL, val));
-}
-
-int
-nvpair_value_int64(nvpair_t *nvp, int64_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT64, NULL, val));
-}
-
-int
-nvpair_value_uint64(nvpair_t *nvp, uint64_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT64, NULL, val));
-}
-
-#if !defined(_KERNEL)
-int
-nvpair_value_double(nvpair_t *nvp, double *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_DOUBLE, NULL, val));
-}
-#endif
-
-int
-nvpair_value_string(nvpair_t *nvp, char **val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_STRING, NULL, val));
-}
-
-int
-nvpair_value_nvlist(nvpair_t *nvp, nvlist_t **val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_NVLIST, NULL, val));
-}
-
-int
-nvpair_value_boolean_array(nvpair_t *nvp, boolean_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_BOOLEAN_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_byte_array(nvpair_t *nvp, uchar_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_BYTE_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_int8_array(nvpair_t *nvp, int8_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT8_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_uint8_array(nvpair_t *nvp, uint8_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT8_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_int16_array(nvpair_t *nvp, int16_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT16_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_uint16_array(nvpair_t *nvp, uint16_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT16_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_int32_array(nvpair_t *nvp, int32_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT32_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_uint32_array(nvpair_t *nvp, uint32_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT32_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_int64_array(nvpair_t *nvp, int64_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_INT64_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_uint64_array(nvpair_t *nvp, uint64_t **val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_UINT64_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_string_array(nvpair_t *nvp, char ***val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_STRING_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_nvlist_array(nvpair_t *nvp, nvlist_t ***val, uint_t *nelem)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_NVLIST_ARRAY, nelem, val));
-}
-
-int
-nvpair_value_hrtime(nvpair_t *nvp, hrtime_t *val)
-{
- return (nvpair_value_common(nvp, DATA_TYPE_HRTIME, NULL, val));
-}
-
-/*
- * Add specified pair to the list.
- */
-int
-nvlist_add_nvpair(nvlist_t *nvl, nvpair_t *nvp)
-{
- if (nvl == NULL || nvp == NULL)
- return (EINVAL);
-
- return (nvlist_add_common(nvl, NVP_NAME(nvp), NVP_TYPE(nvp),
- NVP_NELEM(nvp), NVP_VALUE(nvp)));
-}
-
-/*
- * Merge the supplied nvlists and put the result in dst.
- * The merged list will contain all names specified in both lists,
- * the values are taken from nvl in the case of duplicates.
- * Return 0 on success.
- */
-/*ARGSUSED*/
-int
-nvlist_merge(nvlist_t *dst, nvlist_t *nvl, int flag)
-{
- if (nvl == NULL || dst == NULL)
- return (EINVAL);
-
- if (dst != nvl)
- return (nvlist_copy_pairs(nvl, dst));
-
- return (0);
-}
-
-/*
- * Encoding related routines
- */
-#define NVS_OP_ENCODE 0
-#define NVS_OP_DECODE 1
-#define NVS_OP_GETSIZE 2
-
-typedef struct nvs_ops nvs_ops_t;
-
-typedef struct {
- int nvs_op;
- const nvs_ops_t *nvs_ops;
- void *nvs_private;
- nvpriv_t *nvs_priv;
- int nvs_recursion;
-} nvstream_t;
-
-/*
- * nvs operations are:
- * - nvs_nvlist
- * encoding / decoding of a nvlist header (nvlist_t)
- * calculates the size used for header and end detection
- *
- * - nvs_nvpair
- * responsible for the first part of encoding / decoding of an nvpair
- * calculates the decoded size of an nvpair
- *
- * - nvs_nvp_op
- * second part of encoding / decoding of an nvpair
- *
- * - nvs_nvp_size
- * calculates the encoding size of an nvpair
- *
- * - nvs_nvl_fini
- * encodes the end detection mark (zeros).
- */
-struct nvs_ops {
- int (*nvs_nvlist)(nvstream_t *, nvlist_t *, size_t *);
- int (*nvs_nvpair)(nvstream_t *, nvpair_t *, size_t *);
- int (*nvs_nvp_op)(nvstream_t *, nvpair_t *);
- int (*nvs_nvp_size)(nvstream_t *, nvpair_t *, size_t *);
- int (*nvs_nvl_fini)(nvstream_t *);
-};
-
-typedef struct {
- char nvh_encoding; /* nvs encoding method */
- char nvh_endian; /* nvs endian */
- char nvh_reserved1; /* reserved for future use */
- char nvh_reserved2; /* reserved for future use */
-} nvs_header_t;
-
-static int
-nvs_encode_pairs(nvstream_t *nvs, nvlist_t *nvl)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- i_nvp_t *curr;
-
- /*
- * Walk nvpair in list and encode each nvpair
- */
- for (curr = priv->nvp_list; curr != NULL; curr = curr->nvi_next)
- if (nvs->nvs_ops->nvs_nvpair(nvs, &curr->nvi_nvp, NULL) != 0)
- return (EFAULT);
-
- return (nvs->nvs_ops->nvs_nvl_fini(nvs));
-}
-
-static int
-nvs_decode_pairs(nvstream_t *nvs, nvlist_t *nvl)
-{
- nvpair_t *nvp;
- size_t nvsize;
- int err;
-
- /*
- * Get decoded size of next pair in stream, alloc
- * memory for nvpair_t, then decode the nvpair
- */
- while ((err = nvs->nvs_ops->nvs_nvpair(nvs, NULL, &nvsize)) == 0) {
- if (nvsize == 0) /* end of list */
- break;
-
- /* make sure len makes sense */
- if (nvsize < NVP_SIZE_CALC(1, 0))
- return (EFAULT);
-
- if ((nvp = nvp_buf_alloc(nvl, nvsize)) == NULL)
- return (ENOMEM);
-
- if ((err = nvs->nvs_ops->nvs_nvp_op(nvs, nvp)) != 0) {
- nvp_buf_free(nvl, nvp);
- return (err);
- }
-
- if (i_validate_nvpair(nvp) != 0) {
- nvpair_free(nvp);
- nvp_buf_free(nvl, nvp);
- return (EFAULT);
- }
-
- err = nvt_add_nvpair(nvl, nvp);
- if (err != 0) {
- nvpair_free(nvp);
- nvp_buf_free(nvl, nvp);
- return (err);
- }
- nvp_buf_link(nvl, nvp);
- }
- return (err);
-}
-
-static int
-nvs_getsize_pairs(nvstream_t *nvs, nvlist_t *nvl, size_t *buflen)
-{
- nvpriv_t *priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv;
- i_nvp_t *curr;
- uint64_t nvsize = *buflen;
- size_t size;
-
- /*
- * Get encoded size of nvpairs in nvlist
- */
- for (curr = priv->nvp_list; curr != NULL; curr = curr->nvi_next) {
- if (nvs->nvs_ops->nvs_nvp_size(nvs, &curr->nvi_nvp, &size) != 0)
- return (EINVAL);
-
- if ((nvsize += size) > INT32_MAX)
- return (EINVAL);
- }
-
- *buflen = nvsize;
- return (0);
-}
-
-static int
-nvs_operation(nvstream_t *nvs, nvlist_t *nvl, size_t *buflen)
-{
- int err;
-
- if (nvl->nvl_priv == 0)
- return (EFAULT);
-
- /*
- * Perform the operation, starting with header, then each nvpair
- */
- if ((err = nvs->nvs_ops->nvs_nvlist(nvs, nvl, buflen)) != 0)
- return (err);
-
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- err = nvs_encode_pairs(nvs, nvl);
- break;
-
- case NVS_OP_DECODE:
- err = nvs_decode_pairs(nvs, nvl);
- break;
-
- case NVS_OP_GETSIZE:
- err = nvs_getsize_pairs(nvs, nvl, buflen);
- break;
-
- default:
- err = EINVAL;
- }
-
- return (err);
-}
-
-static int
-nvs_embedded(nvstream_t *nvs, nvlist_t *embedded)
-{
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE: {
- int err;
-
- if (nvs->nvs_recursion >= nvpair_max_recursion)
- return (EINVAL);
- nvs->nvs_recursion++;
- err = nvs_operation(nvs, embedded, NULL);
- nvs->nvs_recursion--;
- return (err);
- }
- case NVS_OP_DECODE: {
- nvpriv_t *priv;
- int err;
-
- if (embedded->nvl_version != NV_VERSION)
- return (ENOTSUP);
-
- if ((priv = nv_priv_alloc_embedded(nvs->nvs_priv)) == NULL)
- return (ENOMEM);
-
- nvlist_init(embedded, embedded->nvl_nvflag, priv);
-
- if (nvs->nvs_recursion >= nvpair_max_recursion) {
- nvlist_free(embedded);
- return (EINVAL);
- }
- nvs->nvs_recursion++;
- if ((err = nvs_operation(nvs, embedded, NULL)) != 0)
- nvlist_free(embedded);
- nvs->nvs_recursion--;
- return (err);
- }
- default:
- break;
- }
-
- return (EINVAL);
-}
-
-static int
-nvs_embedded_nvl_array(nvstream_t *nvs, nvpair_t *nvp, size_t *size)
-{
- size_t nelem = NVP_NELEM(nvp);
- nvlist_t **nvlp = EMBEDDED_NVL_ARRAY(nvp);
- int i;
-
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- for (i = 0; i < nelem; i++)
- if (nvs_embedded(nvs, nvlp[i]) != 0)
- return (EFAULT);
- break;
-
- case NVS_OP_DECODE: {
- size_t len = nelem * sizeof (uint64_t);
- nvlist_t *embedded = (nvlist_t *)((uintptr_t)nvlp + len);
-
- bzero(nvlp, len); /* don't trust packed data */
- for (i = 0; i < nelem; i++) {
- if (nvs_embedded(nvs, embedded) != 0) {
- nvpair_free(nvp);
- return (EFAULT);
- }
-
- nvlp[i] = embedded++;
- }
- break;
- }
- case NVS_OP_GETSIZE: {
- uint64_t nvsize = 0;
-
- for (i = 0; i < nelem; i++) {
- size_t nvp_sz = 0;
-
- if (nvs_operation(nvs, nvlp[i], &nvp_sz) != 0)
- return (EINVAL);
-
- if ((nvsize += nvp_sz) > INT32_MAX)
- return (EINVAL);
- }
-
- *size = nvsize;
- break;
- }
- default:
- return (EINVAL);
- }
-
- return (0);
-}
-
-static int nvs_native(nvstream_t *, nvlist_t *, char *, size_t *);
-static int nvs_xdr(nvstream_t *, nvlist_t *, char *, size_t *);
-
-/*
- * Common routine for nvlist operations:
- * encode, decode, getsize (encoded size).
- */
-static int
-nvlist_common(nvlist_t *nvl, char *buf, size_t *buflen, int encoding,
- int nvs_op)
-{
- int err = 0;
- nvstream_t nvs;
- int nvl_endian;
-#if BYTE_ORDER == _LITTLE_ENDIAN
- int host_endian = 1;
-#else
- int host_endian = 0;
-#endif /* _LITTLE_ENDIAN */
- nvs_header_t *nvh = (void *)buf;
-
- if (buflen == NULL || nvl == NULL ||
- (nvs.nvs_priv = (nvpriv_t *)(uintptr_t)nvl->nvl_priv) == NULL)
- return (EINVAL);
-
- nvs.nvs_op = nvs_op;
- nvs.nvs_recursion = 0;
-
- /*
- * For NVS_OP_ENCODE and NVS_OP_DECODE make sure an nvlist and
- * a buffer is allocated. The first 4 bytes in the buffer are
- * used for encoding method and host endian.
- */
- switch (nvs_op) {
- case NVS_OP_ENCODE:
- if (buf == NULL || *buflen < sizeof (nvs_header_t))
- return (EINVAL);
-
- nvh->nvh_encoding = encoding;
- nvh->nvh_endian = nvl_endian = host_endian;
- nvh->nvh_reserved1 = 0;
- nvh->nvh_reserved2 = 0;
- break;
-
- case NVS_OP_DECODE:
- if (buf == NULL || *buflen < sizeof (nvs_header_t))
- return (EINVAL);
-
- /* get method of encoding from first byte */
- encoding = nvh->nvh_encoding;
- nvl_endian = nvh->nvh_endian;
- break;
-
- case NVS_OP_GETSIZE:
- nvl_endian = host_endian;
-
- /*
- * add the size for encoding
- */
- *buflen = sizeof (nvs_header_t);
- break;
-
- default:
- return (ENOTSUP);
- }
-
- /*
- * Create an nvstream with proper encoding method
- */
- switch (encoding) {
- case NV_ENCODE_NATIVE:
- /*
- * check endianness, in case we are unpacking
- * from a file
- */
- if (nvl_endian != host_endian)
- return (ENOTSUP);
- err = nvs_native(&nvs, nvl, buf, buflen);
- break;
- case NV_ENCODE_XDR:
- err = nvs_xdr(&nvs, nvl, buf, buflen);
- break;
- default:
- err = ENOTSUP;
- break;
- }
-
- return (err);
-}
-
-int
-nvlist_size(nvlist_t *nvl, size_t *size, int encoding)
-{
- return (nvlist_common(nvl, NULL, size, encoding, NVS_OP_GETSIZE));
-}
-
-/*
- * Pack nvlist into contiguous memory
- */
-/*ARGSUSED1*/
-int
-nvlist_pack(nvlist_t *nvl, char **bufp, size_t *buflen, int encoding,
- int kmflag)
-{
-#if defined(_KERNEL) && !defined(_BOOT)
- return (nvlist_xpack(nvl, bufp, buflen, encoding,
- (kmflag == KM_SLEEP ? nv_alloc_sleep : nv_alloc_nosleep)));
-#else
- return (nvlist_xpack(nvl, bufp, buflen, encoding, nv_alloc_nosleep));
-#endif
-}
-
-int
-nvlist_xpack(nvlist_t *nvl, char **bufp, size_t *buflen, int encoding,
- nv_alloc_t *nva)
-{
- nvpriv_t nvpriv;
- size_t alloc_size;
- char *buf;
- int err;
-
- if (nva == NULL || nvl == NULL || bufp == NULL || buflen == NULL)
- return (EINVAL);
-
- if (*bufp != NULL)
- return (nvlist_common(nvl, *bufp, buflen, encoding,
- NVS_OP_ENCODE));
-
- /*
- * Here is a difficult situation:
- * 1. The nvlist has fixed allocator properties.
- * All other nvlist routines (like nvlist_add_*, ...) use
- * these properties.
- * 2. When using nvlist_pack() the user can specify their own
- * allocator properties (e.g. by using KM_NOSLEEP).
- *
- * We use the user specified properties (2). A clearer solution
- * will be to remove the kmflag from nvlist_pack(), but we will
- * not change the interface.
- */
- nv_priv_init(&nvpriv, nva, 0);
-
- if ((err = nvlist_size(nvl, &alloc_size, encoding)))
- return (err);
-
- if ((buf = nv_mem_zalloc(&nvpriv, alloc_size)) == NULL)
- return (ENOMEM);
-
- if ((err = nvlist_common(nvl, buf, &alloc_size, encoding,
- NVS_OP_ENCODE)) != 0) {
- nv_mem_free(&nvpriv, buf, alloc_size);
- } else {
- *buflen = alloc_size;
- *bufp = buf;
- }
-
- return (err);
-}
-
-/*
- * Unpack buf into an nvlist_t
- */
-/*ARGSUSED1*/
-int
-nvlist_unpack(char *buf, size_t buflen, nvlist_t **nvlp, int kmflag)
-{
-#if defined(_KERNEL) && !defined(_BOOT)
- return (nvlist_xunpack(buf, buflen, nvlp,
- (kmflag == KM_SLEEP ? nv_alloc_sleep : nv_alloc_nosleep)));
-#else
- return (nvlist_xunpack(buf, buflen, nvlp, nv_alloc_nosleep));
-#endif
-}
-
-int
-nvlist_xunpack(char *buf, size_t buflen, nvlist_t **nvlp, nv_alloc_t *nva)
-{
- nvlist_t *nvl;
- int err;
-
- if (nvlp == NULL)
- return (EINVAL);
-
- if ((err = nvlist_xalloc(&nvl, 0, nva)) != 0)
- return (err);
-
- if ((err = nvlist_common(nvl, buf, &buflen, 0, NVS_OP_DECODE)) != 0)
- nvlist_free(nvl);
- else
- *nvlp = nvl;
-
- return (err);
-}
-
-/*
- * Native encoding functions
- */
-typedef struct {
- /*
- * This structure is used when decoding a packed nvpair in
- * the native format. n_base points to a buffer containing the
- * packed nvpair. n_end is a pointer to the end of the buffer.
- * (n_end actually points to the first byte past the end of the
- * buffer.) n_curr is a pointer that lies between n_base and n_end.
- * It points to the current data that we are decoding.
- * The amount of data left in the buffer is equal to n_end - n_curr.
- * n_flag is used to recognize a packed embedded list.
- */
- caddr_t n_base;
- caddr_t n_end;
- caddr_t n_curr;
- uint_t n_flag;
-} nvs_native_t;
-
-static int
-nvs_native_create(nvstream_t *nvs, nvs_native_t *native, char *buf,
- size_t buflen)
-{
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- case NVS_OP_DECODE:
- nvs->nvs_private = native;
- native->n_curr = native->n_base = buf;
- native->n_end = buf + buflen;
- native->n_flag = 0;
- return (0);
-
- case NVS_OP_GETSIZE:
- nvs->nvs_private = native;
- native->n_curr = native->n_base = native->n_end = NULL;
- native->n_flag = 0;
- return (0);
- default:
- return (EINVAL);
- }
-}
-
-/*ARGSUSED*/
-static void
-nvs_native_destroy(nvstream_t *nvs)
-{
-}
-
-static int
-native_cp(nvstream_t *nvs, void *buf, size_t size)
-{
- nvs_native_t *native = (nvs_native_t *)nvs->nvs_private;
-
- if (native->n_curr + size > native->n_end)
- return (EFAULT);
-
- /*
- * The bcopy() below eliminates alignment requirement
- * on the buffer (stream) and is preferred over direct access.
- */
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- bcopy(buf, native->n_curr, size);
- break;
- case NVS_OP_DECODE:
- bcopy(native->n_curr, buf, size);
- break;
- default:
- return (EINVAL);
- }
-
- native->n_curr += size;
- return (0);
-}
-
-/*
- * operate on nvlist_t header
- */
-static int
-nvs_native_nvlist(nvstream_t *nvs, nvlist_t *nvl, size_t *size)
-{
- nvs_native_t *native = nvs->nvs_private;
-
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- case NVS_OP_DECODE:
- if (native->n_flag)
- return (0); /* packed embedded list */
-
- native->n_flag = 1;
-
- /* copy version and nvflag of the nvlist_t */
- if (native_cp(nvs, &nvl->nvl_version, sizeof (int32_t)) != 0 ||
- native_cp(nvs, &nvl->nvl_nvflag, sizeof (int32_t)) != 0)
- return (EFAULT);
-
- return (0);
-
- case NVS_OP_GETSIZE:
- /*
- * if calculate for packed embedded list
- * 4 for end of the embedded list
- * else
- * 2 * sizeof (int32_t) for nvl_version and nvl_nvflag
- * and 4 for end of the entire list
- */
- if (native->n_flag) {
- *size += 4;
- } else {
- native->n_flag = 1;
- *size += 2 * sizeof (int32_t) + 4;
- }
-
- return (0);
-
- default:
- return (EINVAL);
- }
-}
-
-static int
-nvs_native_nvl_fini(nvstream_t *nvs)
-{
- if (nvs->nvs_op == NVS_OP_ENCODE) {
- nvs_native_t *native = (nvs_native_t *)nvs->nvs_private;
- /*
- * Add 4 zero bytes at end of nvlist. They are used
- * for end detection by the decode routine.
- */
- if (native->n_curr + sizeof (int) > native->n_end)
- return (EFAULT);
-
- bzero(native->n_curr, sizeof (int));
- native->n_curr += sizeof (int);
- }
-
- return (0);
-}
-
-static int
-nvpair_native_embedded(nvstream_t *nvs, nvpair_t *nvp)
-{
- if (nvs->nvs_op == NVS_OP_ENCODE) {
- nvs_native_t *native = (nvs_native_t *)nvs->nvs_private;
- char *packed = (void *)
- (native->n_curr - nvp->nvp_size + NVP_VALOFF(nvp));
- /*
- * Null out the pointer that is meaningless in the packed
- * structure. The address may not be aligned, so we have
- * to use bzero.
- */
- bzero(packed + offsetof(nvlist_t, nvl_priv),
- sizeof(((nvlist_t *)NULL)->nvl_priv));
- }
-
- return (nvs_embedded(nvs, EMBEDDED_NVL(nvp)));
-}
-
-static int
-nvpair_native_embedded_array(nvstream_t *nvs, nvpair_t *nvp)
-{
- if (nvs->nvs_op == NVS_OP_ENCODE) {
- nvs_native_t *native = (nvs_native_t *)nvs->nvs_private;
- char *value = native->n_curr - nvp->nvp_size + NVP_VALOFF(nvp);
- size_t len = NVP_NELEM(nvp) * sizeof (uint64_t);
- int i;
- /*
- * Null out pointers that are meaningless in the packed
- * structure. The addresses may not be aligned, so we have
- * to use bzero.
- */
- bzero(value, len);
-
- value += len;
- for (i = 0; i < NVP_NELEM(nvp); i++) {
- /*
- * Null out the pointer that is meaningless in the
- * packed structure. The address may not be aligned,
- * so we have to use bzero.
- */
- bzero(value + offsetof(nvlist_t, nvl_priv),
- sizeof(((nvlist_t *)NULL)->nvl_priv));
- value += sizeof(nvlist_t);
- }
- }
-
- return (nvs_embedded_nvl_array(nvs, nvp, NULL));
-}
-
-static void
-nvpair_native_string_array(nvstream_t *nvs, nvpair_t *nvp)
-{
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE: {
- nvs_native_t *native = (nvs_native_t *)nvs->nvs_private;
- uint64_t *strp = (void *)
- (native->n_curr - nvp->nvp_size + NVP_VALOFF(nvp));
- /*
- * Null out pointers that are meaningless in the packed
- * structure. The addresses may not be aligned, so we have
- * to use bzero.
- */
- bzero(strp, NVP_NELEM(nvp) * sizeof (uint64_t));
- break;
- }
- case NVS_OP_DECODE: {
- char **strp = (void *)NVP_VALUE(nvp);
- char *buf = ((char *)strp + NVP_NELEM(nvp) * sizeof (uint64_t));
- int i;
-
- for (i = 0; i < NVP_NELEM(nvp); i++) {
- strp[i] = buf;
- buf += strlen(buf) + 1;
- }
- break;
- }
- }
-}
-
-static int
-nvs_native_nvp_op(nvstream_t *nvs, nvpair_t *nvp)
-{
- data_type_t type;
- int value_sz;
- int ret = 0;
-
- /*
- * We do the initial bcopy of the data before we look at
- * the nvpair type, because when we're decoding, we won't
- * have the correct values for the pair until we do the bcopy.
- */
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- case NVS_OP_DECODE:
- if (native_cp(nvs, nvp, nvp->nvp_size) != 0)
- return (EFAULT);
- break;
- default:
- return (EINVAL);
- }
-
- /* verify nvp_name_sz, check the name string length */
- if (i_validate_nvpair_name(nvp) != 0)
- return (EFAULT);
-
- type = NVP_TYPE(nvp);
-
- /*
- * Verify type and nelem and get the value size.
- * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
- * is the size of the string(s) excluded.
- */
- if ((value_sz = i_get_value_size(type, NULL, NVP_NELEM(nvp))) < 0)
- return (EFAULT);
-
- if (NVP_SIZE_CALC(nvp->nvp_name_sz, value_sz) > nvp->nvp_size)
- return (EFAULT);
-
- switch (type) {
- case DATA_TYPE_NVLIST:
- ret = nvpair_native_embedded(nvs, nvp);
- break;
- case DATA_TYPE_NVLIST_ARRAY:
- ret = nvpair_native_embedded_array(nvs, nvp);
- break;
- case DATA_TYPE_STRING_ARRAY:
- nvpair_native_string_array(nvs, nvp);
- break;
- default:
- break;
- }
-
- return (ret);
-}
-
-static int
-nvs_native_nvp_size(nvstream_t *nvs, nvpair_t *nvp, size_t *size)
-{
- uint64_t nvp_sz = nvp->nvp_size;
-
- switch (NVP_TYPE(nvp)) {
- case DATA_TYPE_NVLIST: {
- size_t nvsize = 0;
-
- if (nvs_operation(nvs, EMBEDDED_NVL(nvp), &nvsize) != 0)
- return (EINVAL);
-
- nvp_sz += nvsize;
- break;
- }
- case DATA_TYPE_NVLIST_ARRAY: {
- size_t nvsize;
-
- if (nvs_embedded_nvl_array(nvs, nvp, &nvsize) != 0)
- return (EINVAL);
-
- nvp_sz += nvsize;
- break;
- }
- default:
- break;
- }
-
- if (nvp_sz > INT32_MAX)
- return (EINVAL);
-
- *size = nvp_sz;
-
- return (0);
-}
-
-static int
-nvs_native_nvpair(nvstream_t *nvs, nvpair_t *nvp, size_t *size)
-{
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- return (nvs_native_nvp_op(nvs, nvp));
-
- case NVS_OP_DECODE: {
- nvs_native_t *native = (nvs_native_t *)nvs->nvs_private;
- int32_t decode_len;
-
- /* try to read the size value from the stream */
- if (native->n_curr + sizeof (int32_t) > native->n_end)
- return (EFAULT);
- bcopy(native->n_curr, &decode_len, sizeof (int32_t));
-
- /* sanity check the size value */
- if (decode_len < 0 ||
- decode_len > native->n_end - native->n_curr)
- return (EFAULT);
-
- *size = decode_len;
-
- /*
- * If at the end of the stream then move the cursor
- * forward, otherwise nvpair_native_op() will read
- * the entire nvpair at the same cursor position.
- */
- if (*size == 0)
- native->n_curr += sizeof (int32_t);
- break;
- }
-
- default:
- return (EINVAL);
- }
-
- return (0);
-}
-
-static const nvs_ops_t nvs_native_ops = {
- nvs_native_nvlist,
- nvs_native_nvpair,
- nvs_native_nvp_op,
- nvs_native_nvp_size,
- nvs_native_nvl_fini
-};
-
-static int
-nvs_native(nvstream_t *nvs, nvlist_t *nvl, char *buf, size_t *buflen)
-{
- nvs_native_t native;
- int err;
-
- nvs->nvs_ops = &nvs_native_ops;
-
- if ((err = nvs_native_create(nvs, &native, buf + sizeof (nvs_header_t),
- *buflen - sizeof (nvs_header_t))) != 0)
- return (err);
-
- err = nvs_operation(nvs, nvl, buflen);
-
- nvs_native_destroy(nvs);
-
- return (err);
-}
-
-/*
- * XDR encoding functions
- *
- * An xdr packed nvlist is encoded as:
- *
- * - encoding methode and host endian (4 bytes)
- * - nvl_version (4 bytes)
- * - nvl_nvflag (4 bytes)
- *
- * - encoded nvpairs, the format of one xdr encoded nvpair is:
- * - encoded size of the nvpair (4 bytes)
- * - decoded size of the nvpair (4 bytes)
- * - name string, (4 + sizeof(NV_ALIGN4(string))
- * a string is coded as size (4 bytes) and data
- * - data type (4 bytes)
- * - number of elements in the nvpair (4 bytes)
- * - data
- *
- * - 2 zero's for end of the entire list (8 bytes)
- */
-static int
-nvs_xdr_create(nvstream_t *nvs, XDR *xdr, char *buf, size_t buflen)
-{
- /* xdr data must be 4 byte aligned */
- if ((ulong_t)buf % 4 != 0)
- return (EFAULT);
-
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- xdrmem_create(xdr, buf, (uint_t)buflen, XDR_ENCODE);
- nvs->nvs_private = xdr;
- return (0);
- case NVS_OP_DECODE:
- xdrmem_create(xdr, buf, (uint_t)buflen, XDR_DECODE);
- nvs->nvs_private = xdr;
- return (0);
- case NVS_OP_GETSIZE:
- nvs->nvs_private = NULL;
- return (0);
- default:
- return (EINVAL);
- }
-}
-
-static void
-nvs_xdr_destroy(nvstream_t *nvs)
-{
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- case NVS_OP_DECODE:
- xdr_destroy((XDR *)nvs->nvs_private);
- break;
- default:
- break;
- }
-}
-
-static int
-nvs_xdr_nvlist(nvstream_t *nvs, nvlist_t *nvl, size_t *size)
-{
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE:
- case NVS_OP_DECODE: {
- XDR *xdr = nvs->nvs_private;
-
- if (!xdr_int(xdr, &nvl->nvl_version) ||
- !xdr_u_int(xdr, &nvl->nvl_nvflag))
- return (EFAULT);
- break;
- }
- case NVS_OP_GETSIZE: {
- /*
- * 2 * 4 for nvl_version + nvl_nvflag
- * and 8 for end of the entire list
- */
- *size += 2 * 4 + 8;
- break;
- }
- default:
- return (EINVAL);
- }
- return (0);
-}
-
-static int
-nvs_xdr_nvl_fini(nvstream_t *nvs)
-{
- if (nvs->nvs_op == NVS_OP_ENCODE) {
- XDR *xdr = nvs->nvs_private;
- int zero = 0;
-
- if (!xdr_int(xdr, &zero) || !xdr_int(xdr, &zero))
- return (EFAULT);
- }
-
- return (0);
-}
-
-/*
- * The format of xdr encoded nvpair is:
- * encode_size, decode_size, name string, data type, nelem, data
- */
-static int
-nvs_xdr_nvp_op(nvstream_t *nvs, nvpair_t *nvp)
-{
- data_type_t type;
- char *buf;
- char *buf_end = (char *)nvp + nvp->nvp_size;
- int value_sz;
- uint_t nelem, buflen;
- bool_t ret = FALSE;
- XDR *xdr = nvs->nvs_private;
-
- ASSERT(xdr != NULL && nvp != NULL);
-
- /* name string */
- if ((buf = NVP_NAME(nvp)) >= buf_end)
- return (EFAULT);
- buflen = buf_end - buf;
-
- if (!xdr_string(xdr, &buf, buflen - 1))
- return (EFAULT);
- nvp->nvp_name_sz = strlen(buf) + 1;
-
- /* type and nelem */
- if (!xdr_int(xdr, (int *)&nvp->nvp_type) ||
- !xdr_int(xdr, &nvp->nvp_value_elem))
- return (EFAULT);
-
- type = NVP_TYPE(nvp);
- nelem = nvp->nvp_value_elem;
-
- /*
- * Verify type and nelem and get the value size.
- * In case of data types DATA_TYPE_STRING and DATA_TYPE_STRING_ARRAY
- * is the size of the string(s) excluded.
- */
- if ((value_sz = i_get_value_size(type, NULL, nelem)) < 0)
- return (EFAULT);
-
- /* if there is no data to extract then return */
- if (nelem == 0)
- return (0);
-
- /* value */
- if ((buf = NVP_VALUE(nvp)) >= buf_end)
- return (EFAULT);
- buflen = buf_end - buf;
-
- if (buflen < value_sz)
- return (EFAULT);
-
- switch (type) {
- case DATA_TYPE_NVLIST:
- if (nvs_embedded(nvs, (void *)buf) == 0)
- return (0);
- break;
-
- case DATA_TYPE_NVLIST_ARRAY:
- if (nvs_embedded_nvl_array(nvs, nvp, NULL) == 0)
- return (0);
- break;
-
- case DATA_TYPE_BOOLEAN:
- ret = TRUE;
- break;
-
- case DATA_TYPE_BYTE:
- case DATA_TYPE_INT8:
- case DATA_TYPE_UINT8:
- ret = xdr_char(xdr, buf);
- break;
-
- case DATA_TYPE_INT16:
- ret = xdr_short(xdr, (void *)buf);
- break;
-
- case DATA_TYPE_UINT16:
- ret = xdr_u_short(xdr, (void *)buf);
- break;
-
- case DATA_TYPE_BOOLEAN_VALUE:
- case DATA_TYPE_INT32:
- ret = xdr_int(xdr, (void *)buf);
- break;
-
- case DATA_TYPE_UINT32:
- ret = xdr_u_int(xdr, (void *)buf);
- break;
-
- case DATA_TYPE_INT64:
- ret = xdr_longlong_t(xdr, (void *)buf);
- break;
-
- case DATA_TYPE_UINT64:
- ret = xdr_u_longlong_t(xdr, (void *)buf);
- break;
-
- case DATA_TYPE_HRTIME:
- /*
- * NOTE: must expose the definition of hrtime_t here
- */
- ret = xdr_longlong_t(xdr, (void *)buf);
- break;
-#if !defined(_KERNEL)
- case DATA_TYPE_DOUBLE:
- ret = xdr_double(xdr, (void *)buf);
- break;
-#endif
- case DATA_TYPE_STRING:
- ret = xdr_string(xdr, &buf, buflen - 1);
- break;
-
- case DATA_TYPE_BYTE_ARRAY:
- ret = xdr_opaque(xdr, buf, nelem);
- break;
-
- case DATA_TYPE_INT8_ARRAY:
- case DATA_TYPE_UINT8_ARRAY:
- ret = xdr_array(xdr, &buf, &nelem, buflen, sizeof (int8_t),
- (xdrproc_t)xdr_char);
- break;
-
- case DATA_TYPE_INT16_ARRAY:
- ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (int16_t),
- sizeof (int16_t), (xdrproc_t)xdr_short);
- break;
-
- case DATA_TYPE_UINT16_ARRAY:
- ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (uint16_t),
- sizeof (uint16_t), (xdrproc_t)xdr_u_short);
- break;
-
- case DATA_TYPE_BOOLEAN_ARRAY:
- case DATA_TYPE_INT32_ARRAY:
- ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (int32_t),
- sizeof (int32_t), (xdrproc_t)xdr_int);
- break;
-
- case DATA_TYPE_UINT32_ARRAY:
- ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (uint32_t),
- sizeof (uint32_t), (xdrproc_t)xdr_u_int);
- break;
-
- case DATA_TYPE_INT64_ARRAY:
- ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (int64_t),
- sizeof (int64_t), (xdrproc_t)xdr_longlong_t);
- break;
-
- case DATA_TYPE_UINT64_ARRAY:
- ret = xdr_array(xdr, &buf, &nelem, buflen / sizeof (uint64_t),
- sizeof (uint64_t), (xdrproc_t)xdr_u_longlong_t);
- break;
-
- case DATA_TYPE_STRING_ARRAY: {
- size_t len = nelem * sizeof (uint64_t);
- char **strp = (void *)buf;
- int i;
-
- if (nvs->nvs_op == NVS_OP_DECODE)
- bzero(buf, len); /* don't trust packed data */
-
- for (i = 0; i < nelem; i++) {
- if (buflen <= len)
- return (EFAULT);
-
- buf += len;
- buflen -= len;
-
- if (xdr_string(xdr, &buf, buflen - 1) != TRUE)
- return (EFAULT);
-
- if (nvs->nvs_op == NVS_OP_DECODE)
- strp[i] = buf;
- len = strlen(buf) + 1;
- }
- ret = TRUE;
- break;
- }
- default:
- break;
- }
-
- return (ret == TRUE ? 0 : EFAULT);
-}
-
-static int
-nvs_xdr_nvp_size(nvstream_t *nvs, nvpair_t *nvp, size_t *size)
-{
- data_type_t type = NVP_TYPE(nvp);
- /*
- * encode_size + decode_size + name string size + data type + nelem
- * where name string size = 4 + NV_ALIGN4(strlen(NVP_NAME(nvp)))
- */
- uint64_t nvp_sz = 4 + 4 + 4 + NV_ALIGN4(strlen(NVP_NAME(nvp))) + 4 + 4;
-
- switch (type) {
- case DATA_TYPE_BOOLEAN:
- break;
-
- case DATA_TYPE_BOOLEAN_VALUE:
- case DATA_TYPE_BYTE:
- case DATA_TYPE_INT8:
- case DATA_TYPE_UINT8:
- case DATA_TYPE_INT16:
- case DATA_TYPE_UINT16:
- case DATA_TYPE_INT32:
- case DATA_TYPE_UINT32:
- nvp_sz += 4; /* 4 is the minimum xdr unit */
- break;
-
- case DATA_TYPE_INT64:
- case DATA_TYPE_UINT64:
- case DATA_TYPE_HRTIME:
-#if !defined(_KERNEL)
- case DATA_TYPE_DOUBLE:
-#endif
- nvp_sz += 8;
- break;
-
- case DATA_TYPE_STRING:
- nvp_sz += 4 + NV_ALIGN4(strlen((char *)NVP_VALUE(nvp)));
- break;
-
- case DATA_TYPE_BYTE_ARRAY:
- nvp_sz += NV_ALIGN4(NVP_NELEM(nvp));
- break;
-
- case DATA_TYPE_BOOLEAN_ARRAY:
- case DATA_TYPE_INT8_ARRAY:
- case DATA_TYPE_UINT8_ARRAY:
- case DATA_TYPE_INT16_ARRAY:
- case DATA_TYPE_UINT16_ARRAY:
- case DATA_TYPE_INT32_ARRAY:
- case DATA_TYPE_UINT32_ARRAY:
- nvp_sz += 4 + 4 * (uint64_t)NVP_NELEM(nvp);
- break;
-
- case DATA_TYPE_INT64_ARRAY:
- case DATA_TYPE_UINT64_ARRAY:
- nvp_sz += 4 + 8 * (uint64_t)NVP_NELEM(nvp);
- break;
-
- case DATA_TYPE_STRING_ARRAY: {
- int i;
- char **strs = (void *)NVP_VALUE(nvp);
-
- for (i = 0; i < NVP_NELEM(nvp); i++)
- nvp_sz += 4 + NV_ALIGN4(strlen(strs[i]));
-
- break;
- }
-
- case DATA_TYPE_NVLIST:
- case DATA_TYPE_NVLIST_ARRAY: {
- size_t nvsize = 0;
- int old_nvs_op = nvs->nvs_op;
- int err;
-
- nvs->nvs_op = NVS_OP_GETSIZE;
- if (type == DATA_TYPE_NVLIST)
- err = nvs_operation(nvs, EMBEDDED_NVL(nvp), &nvsize);
- else
- err = nvs_embedded_nvl_array(nvs, nvp, &nvsize);
- nvs->nvs_op = old_nvs_op;
-
- if (err != 0)
- return (EINVAL);
-
- nvp_sz += nvsize;
- break;
- }
-
- default:
- return (EINVAL);
- }
-
- if (nvp_sz > INT32_MAX)
- return (EINVAL);
-
- *size = nvp_sz;
-
- return (0);
-}
-
-
-/*
- * The NVS_XDR_MAX_LEN macro takes a packed xdr buffer of size x and estimates
- * the largest nvpair that could be encoded in the buffer.
- *
- * See comments above nvpair_xdr_op() for the format of xdr encoding.
- * The size of a xdr packed nvpair without any data is 5 words.
- *
- * Using the size of the data directly as an estimate would be ok
- * in all cases except one. If the data type is of DATA_TYPE_STRING_ARRAY
- * then the actual nvpair has space for an array of pointers to index
- * the strings. These pointers are not encoded into the packed xdr buffer.
- *
- * If the data is of type DATA_TYPE_STRING_ARRAY and all the strings are
- * of length 0, then each string is endcoded in xdr format as a single word.
- * Therefore when expanded to an nvpair there will be 2.25 word used for
- * each string. (a int64_t allocated for pointer usage, and a single char
- * for the null termination.)
- *
- * This is the calculation performed by the NVS_XDR_MAX_LEN macro.
- */
-#define NVS_XDR_HDR_LEN ((size_t)(5 * 4))
-#define NVS_XDR_DATA_LEN(y) (((size_t)(y) <= NVS_XDR_HDR_LEN) ? \
- 0 : ((size_t)(y) - NVS_XDR_HDR_LEN))
-#define NVS_XDR_MAX_LEN(x) (NVP_SIZE_CALC(1, 0) + \
- (NVS_XDR_DATA_LEN(x) * 2) + \
- NV_ALIGN4((NVS_XDR_DATA_LEN(x) / 4)))
-
-static int
-nvs_xdr_nvpair(nvstream_t *nvs, nvpair_t *nvp, size_t *size)
-{
- XDR *xdr = nvs->nvs_private;
- int32_t encode_len, decode_len;
-
- switch (nvs->nvs_op) {
- case NVS_OP_ENCODE: {
- size_t nvsize;
-
- if (nvs_xdr_nvp_size(nvs, nvp, &nvsize) != 0)
- return (EFAULT);
-
- decode_len = nvp->nvp_size;
- encode_len = nvsize;
- if (!xdr_int(xdr, &encode_len) || !xdr_int(xdr, &decode_len))
- return (EFAULT);
-
- return (nvs_xdr_nvp_op(nvs, nvp));
- }
- case NVS_OP_DECODE: {
- struct xdr_bytesrec bytesrec;
-
- /* get the encode and decode size */
- if (!xdr_int(xdr, &encode_len) || !xdr_int(xdr, &decode_len))
- return (EFAULT);
- *size = decode_len;
-
- /* are we at the end of the stream? */
- if (*size == 0)
- return (0);
-
- /* sanity check the size parameter */
- if (!xdr_control(xdr, XDR_GET_BYTES_AVAIL, &bytesrec))
- return (EFAULT);
-
- if (*size > NVS_XDR_MAX_LEN(bytesrec.xc_num_avail))
- return (EFAULT);
- break;
- }
-
- default:
- return (EINVAL);
- }
- return (0);
-}
-
-static const struct nvs_ops nvs_xdr_ops = {
- nvs_xdr_nvlist,
- nvs_xdr_nvpair,
- nvs_xdr_nvp_op,
- nvs_xdr_nvp_size,
- nvs_xdr_nvl_fini
-};
-
-static int
-nvs_xdr(nvstream_t *nvs, nvlist_t *nvl, char *buf, size_t *buflen)
-{
- XDR xdr;
- int err;
-
- nvs->nvs_ops = &nvs_xdr_ops;
-
- if ((err = nvs_xdr_create(nvs, &xdr, buf + sizeof (nvs_header_t),
- *buflen - sizeof (nvs_header_t))) != 0)
- return (err);
-
- err = nvs_operation(nvs, nvl, buflen);
-
- nvs_xdr_destroy(nvs);
-
- return (err);
-}
diff --git a/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c b/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c
deleted file mode 100644
index 620171e4ca4e..000000000000
--- a/sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair_alloc_fixed.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#include <sys/nvpair.h>
-#include <sys/sysmacros.h>
-#if defined(_KERNEL) && !defined(_BOOT)
-#include <sys/varargs.h>
-#else
-#include <stdarg.h>
-#include <strings.h>
-#endif
-
-/*
- * This allocator is very simple.
- * - it uses a pre-allocated buffer for memory allocations.
- * - it does _not_ free memory in the pre-allocated buffer.
- *
- * The reason for the selected implemention is simplicity.
- * This allocator is designed for the usage in interrupt context when
- * the caller may not wait for free memory.
- */
-
-/* pre-allocated buffer for memory allocations */
-typedef struct nvbuf {
- uintptr_t nvb_buf; /* address of pre-allocated buffer */
- uintptr_t nvb_lim; /* limit address in the buffer */
- uintptr_t nvb_cur; /* current address in the buffer */
-} nvbuf_t;
-
-/*
- * Initialize the pre-allocated buffer allocator. The caller needs to supply
- *
- * buf address of pre-allocated buffer
- * bufsz size of pre-allocated buffer
- *
- * nv_fixed_init() calculates the remaining members of nvbuf_t.
- */
-static int
-nv_fixed_init(nv_alloc_t *nva, va_list valist)
-{
- uintptr_t base = va_arg(valist, uintptr_t);
- uintptr_t lim = base + va_arg(valist, size_t);
- nvbuf_t *nvb = (nvbuf_t *)P2ROUNDUP(base, sizeof (uintptr_t));
-
- if (base == 0 || (uintptr_t)&nvb[1] > lim)
- return (EINVAL);
-
- nvb->nvb_buf = (uintptr_t)&nvb[0];
- nvb->nvb_cur = (uintptr_t)&nvb[1];
- nvb->nvb_lim = lim;
- nva->nva_arg = nvb;
-
- return (0);
-}
-
-static void *
-nv_fixed_alloc(nv_alloc_t *nva, size_t size)
-{
- nvbuf_t *nvb = nva->nva_arg;
- uintptr_t new = nvb->nvb_cur;
-
- if (size == 0 || new + size > nvb->nvb_lim)
- return (NULL);
-
- nvb->nvb_cur = P2ROUNDUP(new + size, sizeof (uintptr_t));
-
- return ((void *)new);
-}
-
-/*ARGSUSED*/
-static void
-nv_fixed_free(nv_alloc_t *nva, void *buf, size_t size)
-{
- /* don't free memory in the pre-allocated buffer */
-}
-
-static void
-nv_fixed_reset(nv_alloc_t *nva)
-{
- nvbuf_t *nvb = nva->nva_arg;
-
- nvb->nvb_cur = (uintptr_t)&nvb[1];
-}
-
-const nv_alloc_ops_t nv_fixed_ops_def = {
- nv_fixed_init, /* nv_ao_init() */
- NULL, /* nv_ao_fini() */
- nv_fixed_alloc, /* nv_ao_alloc() */
- nv_fixed_free, /* nv_ao_free() */
- nv_fixed_reset /* nv_ao_reset() */
-};
-
-const nv_alloc_ops_t *nv_fixed_ops = &nv_fixed_ops_def;
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c b/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c
deleted file mode 100644
index ba79eeaaefea..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
- * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
- * Copyright (c) 2013, Joyent, Inc. All rights reserved.
- * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved.
- * Copyright (c) 2014 Integros [integros.com]
- * Copyright (c) 2017, Intel Corporation.
- */
-
-#ifdef _KERNEL
-#include <sys/systm.h>
-#else
-#include <errno.h>
-#include <string.h>
-#endif
-#include <sys/debug.h>
-#include <sys/fs/zfs.h>
-#include <sys/types.h>
-#include "zfeature_common.h"
-
-/*
- * Set to disable all feature checks while opening pools, allowing pools with
- * unsupported features to be opened. Set for testing only.
- */
-boolean_t zfeature_checks_disable = B_FALSE;
-
-zfeature_info_t spa_feature_table[SPA_FEATURES];
-
-/*
- * Valid characters for feature guids. This list is mainly for aesthetic
- * purposes and could be expanded in the future. There are different allowed
- * characters in the guids reverse dns portion (before the colon) and its
- * short name (after the colon).
- */
-static int
-valid_char(char c, boolean_t after_colon)
-{
- return ((c >= 'a' && c <= 'z') ||
- (c >= '0' && c <= '9') ||
- (after_colon && c == '_') ||
- (!after_colon && (c == '.' || c == '-')));
-}
-
-/*
- * Every feature guid must contain exactly one colon which separates a reverse
- * dns organization name from the feature's "short" name (e.g.
- * "com.company:feature_name").
- */
-boolean_t
-zfeature_is_valid_guid(const char *name)
-{
- int i;
- boolean_t has_colon = B_FALSE;
-
- i = 0;
- while (name[i] != '\0') {
- char c = name[i++];
- if (c == ':') {
- if (has_colon)
- return (B_FALSE);
- has_colon = B_TRUE;
- continue;
- }
- if (!valid_char(c, has_colon))
- return (B_FALSE);
- }
-
- return (has_colon);
-}
-
-boolean_t
-zfeature_is_supported(const char *guid)
-{
- if (zfeature_checks_disable)
- return (B_TRUE);
-
- for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
- zfeature_info_t *feature = &spa_feature_table[i];
- if (strcmp(guid, feature->fi_guid) == 0)
- return (B_TRUE);
- }
- return (B_FALSE);
-}
-
-int
-zfeature_lookup_name(const char *name, spa_feature_t *res)
-{
- for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
- zfeature_info_t *feature = &spa_feature_table[i];
- if (strcmp(name, feature->fi_uname) == 0) {
- if (res != NULL)
- *res = i;
- return (0);
- }
- }
-
- return (ENOENT);
-}
-
-boolean_t
-zfeature_depends_on(spa_feature_t fid, spa_feature_t check)
-{
- zfeature_info_t *feature = &spa_feature_table[fid];
-
- for (int i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) {
- if (feature->fi_depends[i] == check)
- return (B_TRUE);
- }
- return (B_FALSE);
-}
-
-static void
-zfeature_register(spa_feature_t fid, const char *guid, const char *name,
- const char *desc, zfeature_flags_t flags, const spa_feature_t *deps)
-{
- zfeature_info_t *feature = &spa_feature_table[fid];
- static spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
-
- ASSERT(name != NULL);
- ASSERT(desc != NULL);
- ASSERT((flags & ZFEATURE_FLAG_READONLY_COMPAT) == 0 ||
- (flags & ZFEATURE_FLAG_MOS) == 0);
- ASSERT3U(fid, <, SPA_FEATURES);
- ASSERT(zfeature_is_valid_guid(guid));
-
- if (deps == NULL)
- deps = nodeps;
-
- feature->fi_feature = fid;
- feature->fi_guid = guid;
- feature->fi_uname = name;
- feature->fi_desc = desc;
- feature->fi_flags = flags;
- feature->fi_depends = deps;
-}
-
-void
-zpool_feature_init(void)
-{
- zfeature_register(SPA_FEATURE_ASYNC_DESTROY,
- "com.delphix:async_destroy", "async_destroy",
- "Destroy filesystems asynchronously.",
- ZFEATURE_FLAG_READONLY_COMPAT, NULL);
-
- zfeature_register(SPA_FEATURE_EMPTY_BPOBJ,
- "com.delphix:empty_bpobj", "empty_bpobj",
- "Snapshots use less space.",
- ZFEATURE_FLAG_READONLY_COMPAT, NULL);
-
- zfeature_register(SPA_FEATURE_LZ4_COMPRESS,
- "org.illumos:lz4_compress", "lz4_compress",
- "LZ4 compression algorithm support.",
- ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, NULL);
-
- zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP,
- "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump",
- "Crash dumps to multiple vdev pools.",
- 0, NULL);
-
- zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM,
- "com.delphix:spacemap_histogram", "spacemap_histogram",
- "Spacemaps maintain space histograms.",
- ZFEATURE_FLAG_READONLY_COMPAT, NULL);
-
- zfeature_register(SPA_FEATURE_ENABLED_TXG,
- "com.delphix:enabled_txg", "enabled_txg",
- "Record txg at which a feature is enabled",
- ZFEATURE_FLAG_READONLY_COMPAT, NULL);
-
- static spa_feature_t hole_birth_deps[] = { SPA_FEATURE_ENABLED_TXG,
- SPA_FEATURE_NONE };
- zfeature_register(SPA_FEATURE_HOLE_BIRTH,
- "com.delphix:hole_birth", "hole_birth",
- "Retain hole birth txg for more precise zfs send",
- ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE,
- hole_birth_deps);
-
- zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET,
- "com.delphix:extensible_dataset", "extensible_dataset",
- "Enhanced dataset functionality, used by other features.",
- 0, NULL);
-
- static const spa_feature_t bookmarks_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_BOOKMARKS,
- "com.delphix:bookmarks", "bookmarks",
- "\"zfs bookmark\" command",
- ZFEATURE_FLAG_READONLY_COMPAT, bookmarks_deps);
-
- static const spa_feature_t filesystem_limits_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_FS_SS_LIMIT,
- "com.joyent:filesystem_limits", "filesystem_limits",
- "Filesystem and snapshot limits.",
- ZFEATURE_FLAG_READONLY_COMPAT, filesystem_limits_deps);
-
- zfeature_register(SPA_FEATURE_EMBEDDED_DATA,
- "com.delphix:embedded_data", "embedded_data",
- "Blocks which compress very well use even less space.",
- ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE,
- NULL);
-
- zfeature_register(SPA_FEATURE_POOL_CHECKPOINT,
- "com.delphix:zpool_checkpoint", "zpool_checkpoint",
- "Pool state can be checkpointed, allowing rewind later.",
- ZFEATURE_FLAG_READONLY_COMPAT, NULL);
-
- zfeature_register(SPA_FEATURE_SPACEMAP_V2,
- "com.delphix:spacemap_v2", "spacemap_v2",
- "Space maps representing large segments are more efficient.",
- ZFEATURE_FLAG_READONLY_COMPAT | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE,
- NULL);
-
- static const spa_feature_t large_blocks_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_LARGE_BLOCKS,
- "org.open-zfs:large_blocks", "large_blocks",
- "Support for blocks larger than 128KB.",
- ZFEATURE_FLAG_PER_DATASET, large_blocks_deps);
-
- {
- static const spa_feature_t large_dnode_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_LARGE_DNODE,
- "org.zfsonlinux:large_dnode", "large_dnode",
- "Variable on-disk size of dnodes.",
- ZFEATURE_FLAG_PER_DATASET, large_dnode_deps);
- }
-
- static const spa_feature_t sha512_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_SHA512,
- "org.illumos:sha512", "sha512",
- "SHA-512/256 hash algorithm.",
- ZFEATURE_FLAG_PER_DATASET, sha512_deps);
-
- static const spa_feature_t skein_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_SKEIN,
- "org.illumos:skein", "skein",
- "Skein hash algorithm.",
- ZFEATURE_FLAG_PER_DATASET, skein_deps);
-
-#ifdef illumos
- static const spa_feature_t edonr_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_EDONR,
- "org.illumos:edonr", "edonr",
- "Edon-R hash algorithm.",
- ZFEATURE_FLAG_PER_DATASET, edonr_deps);
-#endif
-
- zfeature_register(SPA_FEATURE_DEVICE_REMOVAL,
- "com.delphix:device_removal", "device_removal",
- "Top-level vdevs can be removed, reducing logical pool size.",
- ZFEATURE_FLAG_MOS, NULL);
-
- static const spa_feature_t obsolete_counts_deps[] = {
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_DEVICE_REMOVAL,
- SPA_FEATURE_NONE
- };
- zfeature_register(SPA_FEATURE_OBSOLETE_COUNTS,
- "com.delphix:obsolete_counts", "obsolete_counts",
- "Reduce memory used by removed devices when their blocks are "
- "freed or remapped.",
- ZFEATURE_FLAG_READONLY_COMPAT, obsolete_counts_deps);
-
- {
- zfeature_register(SPA_FEATURE_ALLOCATION_CLASSES,
- "org.zfsonlinux:allocation_classes", "allocation_classes",
- "Support for separate allocation classes.",
- ZFEATURE_FLAG_READONLY_COMPAT, NULL);
- }
-}
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h b/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h
deleted file mode 100644
index d23a4e226e2d..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
- * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
- * Copyright (c) 2013, Joyent, Inc. All rights reserved.
- * Copyright (c) 2014 Integros [integros.com]
- * Copyright (c) 2017, Intel Corporation.
- */
-
-#ifndef _ZFEATURE_COMMON_H
-#define _ZFEATURE_COMMON_H
-
-#include <sys/fs/zfs.h>
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct zfeature_info;
-
-typedef enum spa_feature {
- SPA_FEATURE_NONE = -1,
- SPA_FEATURE_ASYNC_DESTROY,
- SPA_FEATURE_EMPTY_BPOBJ,
- SPA_FEATURE_LZ4_COMPRESS,
- SPA_FEATURE_MULTI_VDEV_CRASH_DUMP,
- SPA_FEATURE_SPACEMAP_HISTOGRAM,
- SPA_FEATURE_ENABLED_TXG,
- SPA_FEATURE_HOLE_BIRTH,
- SPA_FEATURE_EXTENSIBLE_DATASET,
- SPA_FEATURE_EMBEDDED_DATA,
- SPA_FEATURE_BOOKMARKS,
- SPA_FEATURE_FS_SS_LIMIT,
- SPA_FEATURE_LARGE_BLOCKS,
- SPA_FEATURE_LARGE_DNODE,
- SPA_FEATURE_SHA512,
- SPA_FEATURE_SKEIN,
-#ifdef illumos
- SPA_FEATURE_EDONR,
-#endif
- SPA_FEATURE_DEVICE_REMOVAL,
- SPA_FEATURE_OBSOLETE_COUNTS,
- SPA_FEATURE_POOL_CHECKPOINT,
- SPA_FEATURE_SPACEMAP_V2,
- SPA_FEATURE_ALLOCATION_CLASSES,
- SPA_FEATURES
-} spa_feature_t;
-
-#define SPA_FEATURE_DISABLED (-1ULL)
-
-typedef enum zfeature_flags {
- /* Can open pool readonly even if this feature is not supported. */
- ZFEATURE_FLAG_READONLY_COMPAT = (1 << 0),
- /* Is this feature necessary to read the MOS? */
- ZFEATURE_FLAG_MOS = (1 << 1),
- /* Activate this feature at the same time it is enabled. */
- ZFEATURE_FLAG_ACTIVATE_ON_ENABLE = (1 << 2),
- /* Each dataset has a field set if it has ever used this feature. */
- ZFEATURE_FLAG_PER_DATASET = (1 << 3)
-} zfeature_flags_t;
-
-typedef struct zfeature_info {
- spa_feature_t fi_feature;
- const char *fi_uname; /* User-facing feature name */
- const char *fi_guid; /* On-disk feature identifier */
- const char *fi_desc; /* Feature description */
- zfeature_flags_t fi_flags;
- /* array of dependencies, terminated by SPA_FEATURE_NONE */
- const spa_feature_t *fi_depends;
-} zfeature_info_t;
-
-typedef int (zfeature_func_t)(zfeature_info_t *, void *);
-
-#define ZFS_FEATURE_DEBUG
-
-extern zfeature_info_t spa_feature_table[SPA_FEATURES];
-
-extern boolean_t zfeature_is_valid_guid(const char *);
-
-extern boolean_t zfeature_is_supported(const char *);
-extern int zfeature_lookup_name(const char *, spa_feature_t *);
-extern boolean_t zfeature_depends_on(spa_feature_t, spa_feature_t);
-
-extern void zpool_feature_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZFEATURE_COMMON_H */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.c b/sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.c
deleted file mode 100644
index f18d82b507b2..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
- */
-
-/*
- * This file is intended for functions that ought to be common between user
- * land (libzfs) and the kernel. When many common routines need to be shared
- * then a separate file should to be created.
- */
-
-#if defined(_KERNEL)
-#include <sys/systm.h>
-#else
-#include <string.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/fs/zfs.h>
-#include <sys/nvpair.h>
-#include "zfs_comutil.h"
-
-/*
- * Are there allocatable vdevs?
- */
-boolean_t
-zfs_allocatable_devs(nvlist_t *nv)
-{
- uint64_t is_log;
- uint_t c;
- nvlist_t **child;
- uint_t children;
-
- if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
- &child, &children) != 0) {
- return (B_FALSE);
- }
- for (c = 0; c < children; c++) {
- is_log = 0;
- (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
- &is_log);
- if (!is_log)
- return (B_TRUE);
- }
- return (B_FALSE);
-}
-
-void
-zpool_get_load_policy(nvlist_t *nvl, zpool_load_policy_t *zlpp)
-{
- nvlist_t *policy;
- nvpair_t *elem;
- char *nm;
-
- /* Defaults */
- zlpp->zlp_rewind = ZPOOL_NO_REWIND;
- zlpp->zlp_maxmeta = 0;
- zlpp->zlp_maxdata = UINT64_MAX;
- zlpp->zlp_txg = UINT64_MAX;
-
- if (nvl == NULL)
- return;
-
- elem = NULL;
- while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
- nm = nvpair_name(elem);
- if (strcmp(nm, ZPOOL_LOAD_POLICY) == 0) {
- if (nvpair_value_nvlist(elem, &policy) == 0)
- zpool_get_load_policy(policy, zlpp);
- return;
- } else if (strcmp(nm, ZPOOL_LOAD_REWIND_POLICY) == 0) {
- if (nvpair_value_uint32(elem, &zlpp->zlp_rewind) == 0)
- if (zlpp->zlp_rewind & ~ZPOOL_REWIND_POLICIES)
- zlpp->zlp_rewind = ZPOOL_NO_REWIND;
- } else if (strcmp(nm, ZPOOL_LOAD_REQUEST_TXG) == 0) {
- (void) nvpair_value_uint64(elem, &zlpp->zlp_txg);
- } else if (strcmp(nm, ZPOOL_LOAD_META_THRESH) == 0) {
- (void) nvpair_value_uint64(elem, &zlpp->zlp_maxmeta);
- } else if (strcmp(nm, ZPOOL_LOAD_DATA_THRESH) == 0) {
- (void) nvpair_value_uint64(elem, &zlpp->zlp_maxdata);
- }
- }
- if (zlpp->zlp_rewind == 0)
- zlpp->zlp_rewind = ZPOOL_NO_REWIND;
-}
-
-typedef struct zfs_version_spa_map {
- int version_zpl;
- int version_spa;
-} zfs_version_spa_map_t;
-
-/*
- * Keep this table in monotonically increasing version number order.
- */
-static zfs_version_spa_map_t zfs_version_table[] = {
- {ZPL_VERSION_INITIAL, SPA_VERSION_INITIAL},
- {ZPL_VERSION_DIRENT_TYPE, SPA_VERSION_INITIAL},
- {ZPL_VERSION_FUID, SPA_VERSION_FUID},
- {ZPL_VERSION_USERSPACE, SPA_VERSION_USERSPACE},
- {ZPL_VERSION_SA, SPA_VERSION_SA},
- {0, 0}
-};
-
-/*
- * Return the max zpl version for a corresponding spa version
- * -1 is returned if no mapping exists.
- */
-int
-zfs_zpl_version_map(int spa_version)
-{
- int i;
- int version = -1;
-
- for (i = 0; zfs_version_table[i].version_spa; i++) {
- if (spa_version >= zfs_version_table[i].version_spa)
- version = zfs_version_table[i].version_zpl;
- }
-
- return (version);
-}
-
-/*
- * Return the min spa version for a corresponding spa version
- * -1 is returned if no mapping exists.
- */
-int
-zfs_spa_version_map(int zpl_version)
-{
- int i;
- int version = -1;
-
- for (i = 0; zfs_version_table[i].version_zpl; i++) {
- if (zfs_version_table[i].version_zpl >= zpl_version)
- return (zfs_version_table[i].version_spa);
- }
-
- return (version);
-}
-
-/*
- * This is the table of legacy internal event names; it should not be modified.
- * The internal events are now stored in the history log as strings.
- */
-const char *zfs_history_event_names[ZFS_NUM_LEGACY_HISTORY_EVENTS] = {
- "invalid event",
- "pool create",
- "vdev add",
- "pool remove",
- "pool destroy",
- "pool export",
- "pool import",
- "vdev attach",
- "vdev replace",
- "vdev detach",
- "vdev online",
- "vdev offline",
- "vdev upgrade",
- "pool clear",
- "pool scrub",
- "pool property set",
- "create",
- "clone",
- "destroy",
- "destroy_begin_sync",
- "inherit",
- "property set",
- "quota set",
- "permission update",
- "permission remove",
- "permission who remove",
- "promote",
- "receive",
- "rename",
- "reservation set",
- "replay_inc_sync",
- "replay_full_sync",
- "rollback",
- "snapshot",
- "filesystem version upgrade",
- "refquota set",
- "refreservation set",
- "pool scrub done",
- "user hold",
- "user release",
- "pool split",
-};
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.h b/sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.h
deleted file mode 100644
index 1c828e41e29f..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_comutil.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
- * Copyright 2019 Joyent, Inc.
- */
-
-#ifndef _ZFS_COMUTIL_H
-#define _ZFS_COMUTIL_H
-
-#include <sys/fs/zfs.h>
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Needed for ZoL errno usage in MMP kernel and user code */
-#define EREMOTEIO EREMOTE
-
-extern boolean_t zfs_allocatable_devs(nvlist_t *);
-extern void zpool_get_load_policy(nvlist_t *, zpool_load_policy_t *);
-
-extern int zfs_zpl_version_map(int spa_version);
-extern int zfs_spa_version_map(int zpl_version);
-#define ZFS_NUM_LEGACY_HISTORY_EVENTS 41
-extern const char *zfs_history_event_names[ZFS_NUM_LEGACY_HISTORY_EVENTS];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZFS_COMUTIL_H */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.c b/sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.c
deleted file mode 100644
index a3383f4ccf2d..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
- * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
- * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
- */
-
-#include <sys/zfs_context.h>
-
-#if defined(_KERNEL)
-#include <sys/systm.h>
-#include <sys/sunddi.h>
-#include <sys/ctype.h>
-#else
-#include <stdio.h>
-#include <unistd.h>
-#include <strings.h>
-#include <libnvpair.h>
-#include <ctype.h>
-#endif
-#include <sys/dsl_deleg.h>
-#include "zfs_prop.h"
-#include "zfs_deleg.h"
-#include "zfs_namecheck.h"
-
-zfs_deleg_perm_tab_t zfs_deleg_perm_tab[] = {
- {ZFS_DELEG_PERM_ALLOW},
- {ZFS_DELEG_PERM_BOOKMARK},
- {ZFS_DELEG_PERM_CLONE},
- {ZFS_DELEG_PERM_CREATE},
- {ZFS_DELEG_PERM_DESTROY},
- {ZFS_DELEG_PERM_DIFF},
- {ZFS_DELEG_PERM_MOUNT},
- {ZFS_DELEG_PERM_PROMOTE},
- {ZFS_DELEG_PERM_RECEIVE},
- {ZFS_DELEG_PERM_REMAP},
- {ZFS_DELEG_PERM_RENAME},
- {ZFS_DELEG_PERM_ROLLBACK},
- {ZFS_DELEG_PERM_SNAPSHOT},
- {ZFS_DELEG_PERM_SHARE},
- {ZFS_DELEG_PERM_SEND},
- {ZFS_DELEG_PERM_USERPROP},
- {ZFS_DELEG_PERM_USERQUOTA},
- {ZFS_DELEG_PERM_GROUPQUOTA},
- {ZFS_DELEG_PERM_USERUSED},
- {ZFS_DELEG_PERM_GROUPUSED},
- {ZFS_DELEG_PERM_HOLD},
- {ZFS_DELEG_PERM_RELEASE},
- {NULL}
-};
-
-static int
-zfs_valid_permission_name(const char *perm)
-{
- if (zfs_deleg_canonicalize_perm(perm))
- return (0);
-
- return (permset_namecheck(perm, NULL, NULL));
-}
-
-const char *
-zfs_deleg_canonicalize_perm(const char *perm)
-{
- int i;
- zfs_prop_t prop;
-
- for (i = 0; zfs_deleg_perm_tab[i].z_perm != NULL; i++) {
- if (strcmp(perm, zfs_deleg_perm_tab[i].z_perm) == 0)
- return (perm);
- }
-
- prop = zfs_name_to_prop(perm);
- if (prop != ZPROP_INVAL && zfs_prop_delegatable(prop))
- return (zfs_prop_to_name(prop));
- return (NULL);
-
-}
-
-static int
-zfs_validate_who(char *who)
-{
- char *p;
-
- if (who[2] != ZFS_DELEG_FIELD_SEP_CHR)
- return (-1);
-
- switch (who[0]) {
- case ZFS_DELEG_USER:
- case ZFS_DELEG_GROUP:
- case ZFS_DELEG_USER_SETS:
- case ZFS_DELEG_GROUP_SETS:
- if (who[1] != ZFS_DELEG_LOCAL && who[1] != ZFS_DELEG_DESCENDENT)
- return (-1);
- for (p = &who[3]; *p; p++)
- if (!isdigit(*p))
- return (-1);
- break;
-
- case ZFS_DELEG_NAMED_SET:
- case ZFS_DELEG_NAMED_SET_SETS:
- if (who[1] != ZFS_DELEG_NA)
- return (-1);
- return (permset_namecheck(&who[3], NULL, NULL));
-
- case ZFS_DELEG_CREATE:
- case ZFS_DELEG_CREATE_SETS:
- if (who[1] != ZFS_DELEG_NA)
- return (-1);
- if (who[3] != '\0')
- return (-1);
- break;
-
- case ZFS_DELEG_EVERYONE:
- case ZFS_DELEG_EVERYONE_SETS:
- if (who[1] != ZFS_DELEG_LOCAL && who[1] != ZFS_DELEG_DESCENDENT)
- return (-1);
- if (who[3] != '\0')
- return (-1);
- break;
-
- default:
- return (-1);
- }
-
- return (0);
-}
-
-int
-zfs_deleg_verify_nvlist(nvlist_t *nvp)
-{
- nvpair_t *who, *perm_name;
- nvlist_t *perms;
- int error;
-
- if (nvp == NULL)
- return (-1);
-
- who = nvlist_next_nvpair(nvp, NULL);
- if (who == NULL)
- return (-1);
-
- do {
- if (zfs_validate_who(nvpair_name(who)))
- return (-1);
-
- error = nvlist_lookup_nvlist(nvp, nvpair_name(who), &perms);
-
- if (error && error != ENOENT)
- return (-1);
- if (error == ENOENT)
- continue;
-
- perm_name = nvlist_next_nvpair(perms, NULL);
- if (perm_name == NULL) {
- return (-1);
- }
- do {
- error = zfs_valid_permission_name(
- nvpair_name(perm_name));
- if (error)
- return (-1);
- } while ((perm_name = nvlist_next_nvpair(perms, perm_name))
- != NULL);
- } while ((who = nvlist_next_nvpair(nvp, who)) != NULL);
- return (0);
-}
-
-/*
- * Construct the base attribute name. The base attribute names
- * are the "key" to locate the jump objects which contain the actual
- * permissions. The base attribute names are encoded based on
- * type of entry and whether it is a local or descendent permission.
- *
- * Arguments:
- * attr - attribute name return string, attribute is assumed to be
- * ZFS_MAX_DELEG_NAME long.
- * type - type of entry to construct
- * inheritchr - inheritance type (local,descendent, or NA for create and
- * permission set definitions
- * data - is either a permission set name or a 64 bit uid/gid.
- */
-void
-zfs_deleg_whokey(char *attr, zfs_deleg_who_type_t type,
- char inheritchr, void *data)
-{
- int len = ZFS_MAX_DELEG_NAME;
- uint64_t *id = data;
-
- switch (type) {
- case ZFS_DELEG_USER:
- case ZFS_DELEG_GROUP:
- case ZFS_DELEG_USER_SETS:
- case ZFS_DELEG_GROUP_SETS:
- (void) snprintf(attr, len, "%c%c%c%lld", type, inheritchr,
- ZFS_DELEG_FIELD_SEP_CHR, (longlong_t)*id);
- break;
- case ZFS_DELEG_NAMED_SET_SETS:
- case ZFS_DELEG_NAMED_SET:
- (void) snprintf(attr, len, "%c-%c%s", type,
- ZFS_DELEG_FIELD_SEP_CHR, (char *)data);
- break;
- case ZFS_DELEG_CREATE:
- case ZFS_DELEG_CREATE_SETS:
- (void) snprintf(attr, len, "%c-%c", type,
- ZFS_DELEG_FIELD_SEP_CHR);
- break;
- case ZFS_DELEG_EVERYONE:
- case ZFS_DELEG_EVERYONE_SETS:
- (void) snprintf(attr, len, "%c%c%c", type, inheritchr,
- ZFS_DELEG_FIELD_SEP_CHR);
- break;
- default:
- ASSERT(!"bad zfs_deleg_who_type_t");
- }
-}
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.h b/sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.h
deleted file mode 100644
index 06d2df9bb80d..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_deleg.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
- * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
- */
-
-#ifndef _ZFS_DELEG_H
-#define _ZFS_DELEG_H
-
-#include <sys/fs/zfs.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define ZFS_DELEG_SET_NAME_CHR '@' /* set name lead char */
-#define ZFS_DELEG_FIELD_SEP_CHR '$' /* field separator */
-
-/*
- * Max name length for a delegation attribute
- */
-#define ZFS_MAX_DELEG_NAME 128
-
-#define ZFS_DELEG_LOCAL 'l'
-#define ZFS_DELEG_DESCENDENT 'd'
-#define ZFS_DELEG_NA '-'
-
-typedef enum {
- ZFS_DELEG_NOTE_CREATE,
- ZFS_DELEG_NOTE_DESTROY,
- ZFS_DELEG_NOTE_SNAPSHOT,
- ZFS_DELEG_NOTE_ROLLBACK,
- ZFS_DELEG_NOTE_CLONE,
- ZFS_DELEG_NOTE_PROMOTE,
- ZFS_DELEG_NOTE_RENAME,
- ZFS_DELEG_NOTE_SEND,
- ZFS_DELEG_NOTE_RECEIVE,
- ZFS_DELEG_NOTE_ALLOW,
- ZFS_DELEG_NOTE_USERPROP,
- ZFS_DELEG_NOTE_MOUNT,
- ZFS_DELEG_NOTE_SHARE,
- ZFS_DELEG_NOTE_USERQUOTA,
- ZFS_DELEG_NOTE_GROUPQUOTA,
- ZFS_DELEG_NOTE_USERUSED,
- ZFS_DELEG_NOTE_GROUPUSED,
- ZFS_DELEG_NOTE_HOLD,
- ZFS_DELEG_NOTE_RELEASE,
- ZFS_DELEG_NOTE_DIFF,
- ZFS_DELEG_NOTE_BOOKMARK,
- ZFS_DELEG_NOTE_REMAP,
- ZFS_DELEG_NOTE_NONE
-} zfs_deleg_note_t;
-
-typedef struct zfs_deleg_perm_tab {
- char *z_perm;
- zfs_deleg_note_t z_note;
-} zfs_deleg_perm_tab_t;
-
-extern zfs_deleg_perm_tab_t zfs_deleg_perm_tab[];
-
-int zfs_deleg_verify_nvlist(nvlist_t *nvlist);
-void zfs_deleg_whokey(char *attr, zfs_deleg_who_type_t type,
- char checkflag, void *data);
-const char *zfs_deleg_canonicalize_perm(const char *perm);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZFS_DELEG_H */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.c b/sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.c
deleted file mode 100644
index c889169b426b..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * Copyright 2013 Saso Kiselkov. All rights reserved.
- * Copyright (c) 2016 by Delphix. All rights reserved.
- */
-
-/*
- * Fletcher Checksums
- * ------------------
- *
- * ZFS's 2nd and 4th order Fletcher checksums are defined by the following
- * recurrence relations:
- *
- * a = a + f
- * i i-1 i-1
- *
- * b = b + a
- * i i-1 i
- *
- * c = c + b (fletcher-4 only)
- * i i-1 i
- *
- * d = d + c (fletcher-4 only)
- * i i-1 i
- *
- * Where
- * a_0 = b_0 = c_0 = d_0 = 0
- * and
- * f_0 .. f_(n-1) are the input data.
- *
- * Using standard techniques, these translate into the following series:
- *
- * __n_ __n_
- * \ | \ |
- * a = > f b = > i * f
- * n /___| n - i n /___| n - i
- * i = 1 i = 1
- *
- *
- * __n_ __n_
- * \ | i*(i+1) \ | i*(i+1)*(i+2)
- * c = > ------- f d = > ------------- f
- * n /___| 2 n - i n /___| 6 n - i
- * i = 1 i = 1
- *
- * For fletcher-2, the f_is are 64-bit, and [ab]_i are 64-bit accumulators.
- * Since the additions are done mod (2^64), errors in the high bits may not
- * be noticed. For this reason, fletcher-2 is deprecated.
- *
- * For fletcher-4, the f_is are 32-bit, and [abcd]_i are 64-bit accumulators.
- * A conservative estimate of how big the buffer can get before we overflow
- * can be estimated using f_i = 0xffffffff for all i:
- *
- * % bc
- * f=2^32-1;d=0; for (i = 1; d<2^64; i++) { d += f*i*(i+1)*(i+2)/6 }; (i-1)*4
- * 2264
- * quit
- * %
- *
- * So blocks of up to 2k will not overflow. Our largest block size is
- * 128k, which has 32k 4-byte words, so we can compute the largest possible
- * accumulators, then divide by 2^64 to figure the max amount of overflow:
- *
- * % bc
- * a=b=c=d=0; f=2^32-1; for (i=1; i<=32*1024; i++) { a+=f; b+=a; c+=b; d+=c }
- * a/2^64;b/2^64;c/2^64;d/2^64
- * 0
- * 0
- * 1365
- * 11186858
- * quit
- * %
- *
- * So a and b cannot overflow. To make sure each bit of input has some
- * effect on the contents of c and d, we can look at what the factors of
- * the coefficients in the equations for c_n and d_n are. The number of 2s
- * in the factors determines the lowest set bit in the multiplier. Running
- * through the cases for n*(n+1)/2 reveals that the highest power of 2 is
- * 2^14, and for n*(n+1)*(n+2)/6 it is 2^15. So while some data may overflow
- * the 64-bit accumulators, every bit of every f_i effects every accumulator,
- * even for 128k blocks.
- *
- * If we wanted to make a stronger version of fletcher4 (fletcher4c?),
- * we could do our calculations mod (2^32 - 1) by adding in the carries
- * periodically, and store the number of carries in the top 32-bits.
- *
- * --------------------
- * Checksum Performance
- * --------------------
- *
- * There are two interesting components to checksum performance: cached and
- * uncached performance. With cached data, fletcher-2 is about four times
- * faster than fletcher-4. With uncached data, the performance difference is
- * negligible, since the cost of a cache fill dominates the processing time.
- * Even though fletcher-4 is slower than fletcher-2, it is still a pretty
- * efficient pass over the data.
- *
- * In normal operation, the data which is being checksummed is in a buffer
- * which has been filled either by:
- *
- * 1. a compression step, which will be mostly cached, or
- * 2. a bcopy() or copyin(), which will be uncached (because the
- * copy is cache-bypassing).
- *
- * For both cached and uncached data, both fletcher checksums are much faster
- * than sha-256, and slower than 'off', which doesn't touch the data at all.
- */
-
-#include <sys/types.h>
-#include <sys/sysmacros.h>
-#include <sys/byteorder.h>
-#include <sys/zio.h>
-#include <sys/spa.h>
-#include <zfs_fletcher.h>
-
-void
-fletcher_init(zio_cksum_t *zcp)
-{
- ZIO_SET_CHECKSUM(zcp, 0, 0, 0, 0);
-}
-
-int
-fletcher_2_incremental_native(void *buf, size_t size, void *data)
-{
- zio_cksum_t *zcp = data;
-
- const uint64_t *ip = buf;
- const uint64_t *ipend = ip + (size / sizeof (uint64_t));
- uint64_t a0, b0, a1, b1;
-
- a0 = zcp->zc_word[0];
- a1 = zcp->zc_word[1];
- b0 = zcp->zc_word[2];
- b1 = zcp->zc_word[3];
-
- for (; ip < ipend; ip += 2) {
- a0 += ip[0];
- a1 += ip[1];
- b0 += a0;
- b1 += a1;
- }
-
- ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
- return (0);
-}
-
-/*ARGSUSED*/
-void
-fletcher_2_native(const void *buf, size_t size,
- const void *ctx_template, zio_cksum_t *zcp)
-{
- fletcher_init(zcp);
- (void) fletcher_2_incremental_native((void *) buf, size, zcp);
-}
-
-int
-fletcher_2_incremental_byteswap(void *buf, size_t size, void *data)
-{
- zio_cksum_t *zcp = data;
-
- const uint64_t *ip = buf;
- const uint64_t *ipend = ip + (size / sizeof (uint64_t));
- uint64_t a0, b0, a1, b1;
-
- a0 = zcp->zc_word[0];
- a1 = zcp->zc_word[1];
- b0 = zcp->zc_word[2];
- b1 = zcp->zc_word[3];
-
- for (; ip < ipend; ip += 2) {
- a0 += BSWAP_64(ip[0]);
- a1 += BSWAP_64(ip[1]);
- b0 += a0;
- b1 += a1;
- }
-
- ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
- return (0);
-}
-
-/*ARGSUSED*/
-void
-fletcher_2_byteswap(const void *buf, size_t size,
- const void *ctx_template, zio_cksum_t *zcp)
-{
- fletcher_init(zcp);
- (void) fletcher_2_incremental_byteswap((void *) buf, size, zcp);
-}
-
-int
-fletcher_4_incremental_native(void *buf, size_t size, void *data)
-{
- zio_cksum_t *zcp = data;
-
- const uint32_t *ip = buf;
- const uint32_t *ipend = ip + (size / sizeof (uint32_t));
- uint64_t a, b, c, d;
-
- a = zcp->zc_word[0];
- b = zcp->zc_word[1];
- c = zcp->zc_word[2];
- d = zcp->zc_word[3];
-
- for (; ip < ipend; ip++) {
- a += ip[0];
- b += a;
- c += b;
- d += c;
- }
-
- ZIO_SET_CHECKSUM(zcp, a, b, c, d);
- return (0);
-}
-
-/*ARGSUSED*/
-void
-fletcher_4_native(const void *buf, size_t size,
- const void *ctx_template, zio_cksum_t *zcp)
-{
- fletcher_init(zcp);
- (void) fletcher_4_incremental_native((void *) buf, size, zcp);
-}
-
-int
-fletcher_4_incremental_byteswap(void *buf, size_t size, void *data)
-{
- zio_cksum_t *zcp = data;
-
- const uint32_t *ip = buf;
- const uint32_t *ipend = ip + (size / sizeof (uint32_t));
- uint64_t a, b, c, d;
-
- a = zcp->zc_word[0];
- b = zcp->zc_word[1];
- c = zcp->zc_word[2];
- d = zcp->zc_word[3];
-
- for (; ip < ipend; ip++) {
- a += BSWAP_32(ip[0]);
- b += a;
- c += b;
- d += c;
- }
-
- ZIO_SET_CHECKSUM(zcp, a, b, c, d);
- return (0);
-}
-
-/*ARGSUSED*/
-void
-fletcher_4_byteswap(const void *buf, size_t size,
- const void *ctx_template, zio_cksum_t *zcp)
-{
- fletcher_init(zcp);
- (void) fletcher_4_incremental_byteswap((void *) buf, size, zcp);
-}
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.h b/sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.h
deleted file mode 100644
index 33c6c728cf61..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_fletcher.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * Copyright 2013 Saso Kiselkov. All rights reserved.
- * Copyright (c) 2016 by Delphix. All rights reserved.
- */
-
-#ifndef _ZFS_FLETCHER_H
-#define _ZFS_FLETCHER_H
-
-#include <sys/types.h>
-#include <sys/spa.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * fletcher checksum functions
- */
-
-void fletcher_init(zio_cksum_t *);
-void fletcher_2_native(const void *, size_t, const void *, zio_cksum_t *);
-void fletcher_2_byteswap(const void *, size_t, const void *, zio_cksum_t *);
-int fletcher_2_incremental_native(void *, size_t, void *);
-int fletcher_2_incremental_byteswap(void *, size_t, void *);
-void fletcher_4_native(const void *, size_t, const void *, zio_cksum_t *);
-void fletcher_4_byteswap(const void *, size_t, const void *, zio_cksum_t *);
-int fletcher_4_incremental_native(void *, size_t, void *);
-int fletcher_4_incremental_byteswap(void *, size_t, void *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZFS_FLETCHER_H */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.c b/sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.c
deleted file mode 100644
index e5ac73f96b98..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.c
+++ /dev/null
@@ -1,1380 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2013 Xin Li <delphij@FreeBSD.org>. All rights reserved.
- * Copyright 2013 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
- * Portions Copyright 2005, 2010, Oracle and/or its affiliates.
- * All rights reserved.
- * Use is subject to license terms.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/cred.h>
-#include <sys/dmu.h>
-#include <sys/zio.h>
-#include <sys/nvpair.h>
-#include <sys/dsl_deleg.h>
-#include <sys/zfs_ioctl.h>
-#include "zfs_namecheck.h"
-#include "zfs_ioctl_compat.h"
-
-static int zfs_version_ioctl = ZFS_IOCVER_CURRENT;
-SYSCTL_DECL(_vfs_zfs_version);
-SYSCTL_INT(_vfs_zfs_version, OID_AUTO, ioctl, CTLFLAG_RD, &zfs_version_ioctl,
- 0, "ZFS_IOCTL_VERSION");
-
-/*
- * FreeBSD zfs_cmd compatibility with older binaries
- * appropriately remap/extend the zfs_cmd_t structure
- */
-void
-zfs_cmd_compat_get(zfs_cmd_t *zc, caddr_t addr, const int cflag)
-{
- zfs_cmd_v15_t *zc_c;
- zfs_cmd_v28_t *zc28_c;
- zfs_cmd_deadman_t *zcdm_c;
- zfs_cmd_zcmd_t *zcmd_c;
- zfs_cmd_edbp_t *edbp_c;
- zfs_cmd_resume_t *resume_c;
- zfs_cmd_inlanes_t *inlanes_c;
-
- switch (cflag) {
- case ZFS_CMD_COMPAT_INLANES:
- inlanes_c = (void *)addr;
- /* zc */
- strlcpy(zc->zc_name, inlanes_c->zc_name, MAXPATHLEN);
- strlcpy(zc->zc_value, inlanes_c->zc_value, MAXPATHLEN * 2);
- strlcpy(zc->zc_string, inlanes_c->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) zc->field = inlanes_c->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- FIELD_COPY(zc_begin_record);
- FIELD_COPY(zc_inject_record);
- FIELD_COPY(zc_defer_destroy);
- FIELD_COPY(zc_flags);
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- FIELD_COPY(zc_resumable);
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
- break;
-
- case ZFS_CMD_COMPAT_RESUME:
- resume_c = (void *)addr;
- /* zc */
- strlcpy(zc->zc_name, resume_c->zc_name, MAXPATHLEN);
- strlcpy(zc->zc_value, resume_c->zc_value, MAXPATHLEN * 2);
- strlcpy(zc->zc_string, resume_c->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) zc->field = resume_c->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- FIELD_COPY(zc_begin_record);
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(zc->zc_inject_record.zi_func,
- resume_c->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- zc->zc_inject_record.zi_nlanes = 1;
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
- FIELD_COPY(zc_defer_destroy);
- FIELD_COPY(zc_flags);
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- FIELD_COPY(zc_resumable);
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
- break;
-
- case ZFS_CMD_COMPAT_EDBP:
- edbp_c = (void *)addr;
- /* zc */
- strlcpy(zc->zc_name, edbp_c->zc_name, MAXPATHLEN);
- strlcpy(zc->zc_value, edbp_c->zc_value, MAXPATHLEN * 2);
- strlcpy(zc->zc_string, edbp_c->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) zc->field = edbp_c->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- zc->zc_begin_record.drr_u.drr_begin = edbp_c->zc_begin_record;
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(zc->zc_inject_record.zi_func,
- edbp_c->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- zc->zc_inject_record.zi_nlanes = 1;
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
- FIELD_COPY(zc_defer_destroy);
- FIELD_COPY(zc_flags);
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- zc->zc_resumable = B_FALSE;
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
- break;
-
- case ZFS_CMD_COMPAT_ZCMD:
- zcmd_c = (void *)addr;
- /* zc */
- strlcpy(zc->zc_name, zcmd_c->zc_name, MAXPATHLEN);
- strlcpy(zc->zc_value, zcmd_c->zc_value, MAXPATHLEN * 2);
- strlcpy(zc->zc_string, zcmd_c->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) zc->field = zcmd_c->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- zc->zc_begin_record.drr_u.drr_begin = zcmd_c->zc_begin_record;
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(zc->zc_inject_record.zi_func,
- zcmd_c->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- zc->zc_inject_record.zi_nlanes = 1;
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
-
- /* boolean_t -> uint32_t */
- zc->zc_defer_destroy = (uint32_t)(zcmd_c->zc_defer_destroy);
- zc->zc_flags = 0;
-
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- zc->zc_resumable = B_FALSE;
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
-
- break;
-
- case ZFS_CMD_COMPAT_DEADMAN:
- zcdm_c = (void *)addr;
- /* zc */
- strlcpy(zc->zc_name, zcdm_c->zc_name, MAXPATHLEN);
- strlcpy(zc->zc_value, zcdm_c->zc_value, MAXPATHLEN * 2);
- strlcpy(zc->zc_string, zcdm_c->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) zc->field = zcdm_c->field
- zc->zc_guid = zcdm_c->zc_guid;
- zc->zc_nvlist_conf = zcdm_c->zc_nvlist_conf;
- zc->zc_nvlist_conf_size = zcdm_c->zc_nvlist_conf_size;
- zc->zc_nvlist_src = zcdm_c->zc_nvlist_src;
- zc->zc_nvlist_src_size = zcdm_c->zc_nvlist_src_size;
- zc->zc_nvlist_dst = zcdm_c->zc_nvlist_dst;
- zc->zc_nvlist_dst_size = zcdm_c->zc_nvlist_dst_size;
- zc->zc_cookie = zcdm_c->zc_cookie;
- zc->zc_objset_type = zcdm_c->zc_objset_type;
- zc->zc_perm_action = zcdm_c->zc_perm_action;
- zc->zc_history = zcdm_c->zc_history;
- zc->zc_history_len = zcdm_c->zc_history_len;
- zc->zc_history_offset = zcdm_c->zc_history_offset;
- zc->zc_obj = zcdm_c->zc_obj;
- zc->zc_iflags = zcdm_c->zc_iflags;
- zc->zc_share = zcdm_c->zc_share;
- zc->zc_jailid = zcdm_c->zc_jailid;
- zc->zc_objset_stats = zcdm_c->zc_objset_stats;
- zc->zc_begin_record.drr_u.drr_begin = zcdm_c->zc_begin_record;
- zc->zc_defer_destroy = zcdm_c->zc_defer_destroy;
- (void)zcdm_c->zc_temphold;
- zc->zc_action_handle = zcdm_c->zc_action_handle;
- zc->zc_cleanup_fd = zcdm_c->zc_cleanup_fd;
- zc->zc_simple = zcdm_c->zc_simple;
- zc->zc_resumable = B_FALSE;
- zc->zc_sendobj = zcdm_c->zc_sendobj;
- zc->zc_fromobj = zcdm_c->zc_fromobj;
- zc->zc_createtxg = zcdm_c->zc_createtxg;
- zc->zc_stat = zcdm_c->zc_stat;
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(zc->zc_inject_record.zi_func,
- resume_c->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- zc->zc_inject_record.zi_nlanes = 1;
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
-
- /* we always assume zc_nvlist_dst_filled is true */
- zc->zc_nvlist_dst_filled = B_TRUE;
-#undef FIELD_COPY
- break;
-
- case ZFS_CMD_COMPAT_V28:
- zc28_c = (void *)addr;
-
- /* zc */
- strlcpy(zc->zc_name, zc28_c->zc_name, MAXPATHLEN);
- strlcpy(zc->zc_value, zc28_c->zc_value, MAXPATHLEN * 2);
- strlcpy(zc->zc_string, zc28_c->zc_string, MAXPATHLEN);
- zc->zc_guid = zc28_c->zc_guid;
- zc->zc_nvlist_conf = zc28_c->zc_nvlist_conf;
- zc->zc_nvlist_conf_size = zc28_c->zc_nvlist_conf_size;
- zc->zc_nvlist_src = zc28_c->zc_nvlist_src;
- zc->zc_nvlist_src_size = zc28_c->zc_nvlist_src_size;
- zc->zc_nvlist_dst = zc28_c->zc_nvlist_dst;
- zc->zc_nvlist_dst_size = zc28_c->zc_nvlist_dst_size;
- zc->zc_cookie = zc28_c->zc_cookie;
- zc->zc_objset_type = zc28_c->zc_objset_type;
- zc->zc_perm_action = zc28_c->zc_perm_action;
- zc->zc_history = zc28_c->zc_history;
- zc->zc_history_len = zc28_c->zc_history_len;
- zc->zc_history_offset = zc28_c->zc_history_offset;
- zc->zc_obj = zc28_c->zc_obj;
- zc->zc_iflags = zc28_c->zc_iflags;
- zc->zc_share = zc28_c->zc_share;
- zc->zc_jailid = zc28_c->zc_jailid;
- zc->zc_objset_stats = zc28_c->zc_objset_stats;
- zc->zc_begin_record.drr_u.drr_begin = zc28_c->zc_begin_record;
- zc->zc_defer_destroy = zc28_c->zc_defer_destroy;
- (void)zc28_c->zc_temphold;
- zc->zc_action_handle = zc28_c->zc_action_handle;
- zc->zc_cleanup_fd = zc28_c->zc_cleanup_fd;
- zc->zc_simple = zc28_c->zc_simple;
- zc->zc_resumable = B_FALSE;
- zc->zc_sendobj = zc28_c->zc_sendobj;
- zc->zc_fromobj = zc28_c->zc_fromobj;
- zc->zc_createtxg = zc28_c->zc_createtxg;
- zc->zc_stat = zc28_c->zc_stat;
-
- /* zc->zc_inject_record */
- zc->zc_inject_record.zi_objset =
- zc28_c->zc_inject_record.zi_objset;
- zc->zc_inject_record.zi_object =
- zc28_c->zc_inject_record.zi_object;
- zc->zc_inject_record.zi_start =
- zc28_c->zc_inject_record.zi_start;
- zc->zc_inject_record.zi_end =
- zc28_c->zc_inject_record.zi_end;
- zc->zc_inject_record.zi_guid =
- zc28_c->zc_inject_record.zi_guid;
- zc->zc_inject_record.zi_level =
- zc28_c->zc_inject_record.zi_level;
- zc->zc_inject_record.zi_error =
- zc28_c->zc_inject_record.zi_error;
- zc->zc_inject_record.zi_type =
- zc28_c->zc_inject_record.zi_type;
- zc->zc_inject_record.zi_freq =
- zc28_c->zc_inject_record.zi_freq;
- zc->zc_inject_record.zi_failfast =
- zc28_c->zc_inject_record.zi_failfast;
- strlcpy(zc->zc_inject_record.zi_func,
- zc28_c->zc_inject_record.zi_func, MAXNAMELEN);
- zc->zc_inject_record.zi_iotype =
- zc28_c->zc_inject_record.zi_iotype;
- zc->zc_inject_record.zi_duration =
- zc28_c->zc_inject_record.zi_duration;
- zc->zc_inject_record.zi_timer =
- zc28_c->zc_inject_record.zi_timer;
- zc->zc_inject_record.zi_nlanes = 1;
- zc->zc_inject_record.zi_cmd = ZINJECT_UNINITIALIZED;
- zc->zc_inject_record.zi_pad = 0;
- break;
-
- case ZFS_CMD_COMPAT_V15:
- zc_c = (void *)addr;
-
- /* zc */
- strlcpy(zc->zc_name, zc_c->zc_name, MAXPATHLEN);
- strlcpy(zc->zc_value, zc_c->zc_value, MAXPATHLEN);
- strlcpy(zc->zc_string, zc_c->zc_string, MAXPATHLEN);
- zc->zc_guid = zc_c->zc_guid;
- zc->zc_nvlist_conf = zc_c->zc_nvlist_conf;
- zc->zc_nvlist_conf_size = zc_c->zc_nvlist_conf_size;
- zc->zc_nvlist_src = zc_c->zc_nvlist_src;
- zc->zc_nvlist_src_size = zc_c->zc_nvlist_src_size;
- zc->zc_nvlist_dst = zc_c->zc_nvlist_dst;
- zc->zc_nvlist_dst_size = zc_c->zc_nvlist_dst_size;
- zc->zc_cookie = zc_c->zc_cookie;
- zc->zc_objset_type = zc_c->zc_objset_type;
- zc->zc_perm_action = zc_c->zc_perm_action;
- zc->zc_history = zc_c->zc_history;
- zc->zc_history_len = zc_c->zc_history_len;
- zc->zc_history_offset = zc_c->zc_history_offset;
- zc->zc_obj = zc_c->zc_obj;
- zc->zc_share = zc_c->zc_share;
- zc->zc_jailid = zc_c->zc_jailid;
- zc->zc_objset_stats = zc_c->zc_objset_stats;
- zc->zc_begin_record.drr_u.drr_begin = zc_c->zc_begin_record;
-
- /* zc->zc_inject_record */
- zc->zc_inject_record.zi_objset =
- zc_c->zc_inject_record.zi_objset;
- zc->zc_inject_record.zi_object =
- zc_c->zc_inject_record.zi_object;
- zc->zc_inject_record.zi_start =
- zc_c->zc_inject_record.zi_start;
- zc->zc_inject_record.zi_end =
- zc_c->zc_inject_record.zi_end;
- zc->zc_inject_record.zi_guid =
- zc_c->zc_inject_record.zi_guid;
- zc->zc_inject_record.zi_level =
- zc_c->zc_inject_record.zi_level;
- zc->zc_inject_record.zi_error =
- zc_c->zc_inject_record.zi_error;
- zc->zc_inject_record.zi_type =
- zc_c->zc_inject_record.zi_type;
- zc->zc_inject_record.zi_freq =
- zc_c->zc_inject_record.zi_freq;
- zc->zc_inject_record.zi_failfast =
- zc_c->zc_inject_record.zi_failfast;
- break;
- }
-}
-
-void
-zfs_cmd_compat_put(zfs_cmd_t *zc, caddr_t addr, const int request,
- const int cflag)
-{
- zfs_cmd_v15_t *zc_c;
- zfs_cmd_v28_t *zc28_c;
- zfs_cmd_deadman_t *zcdm_c;
- zfs_cmd_zcmd_t *zcmd_c;
- zfs_cmd_edbp_t *edbp_c;
- zfs_cmd_resume_t *resume_c;
- zfs_cmd_inlanes_t *inlanes_c;
-
- switch (cflag) {
- case ZFS_CMD_COMPAT_INLANES:
- inlanes_c = (void *)addr;
- strlcpy(inlanes_c->zc_name, zc->zc_name, MAXPATHLEN);
- strlcpy(inlanes_c->zc_value, zc->zc_value, MAXPATHLEN * 2);
- strlcpy(inlanes_c->zc_string, zc->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) inlanes_c->field = zc->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- FIELD_COPY(zc_begin_record);
- FIELD_COPY(zc_inject_record);
- FIELD_COPY(zc_defer_destroy);
- FIELD_COPY(zc_flags);
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
- break;
-
- case ZFS_CMD_COMPAT_RESUME:
- resume_c = (void *)addr;
- strlcpy(resume_c->zc_name, zc->zc_name, MAXPATHLEN);
- strlcpy(resume_c->zc_value, zc->zc_value, MAXPATHLEN * 2);
- strlcpy(resume_c->zc_string, zc->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) resume_c->field = zc->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- FIELD_COPY(zc_begin_record);
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(resume_c->zc_inject_record.zi_func,
- zc->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
- FIELD_COPY(zc_defer_destroy);
- FIELD_COPY(zc_flags);
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
- break;
-
- case ZFS_CMD_COMPAT_EDBP:
- edbp_c = (void *)addr;
- strlcpy(edbp_c->zc_name, zc->zc_name, MAXPATHLEN);
- strlcpy(edbp_c->zc_value, zc->zc_value, MAXPATHLEN * 2);
- strlcpy(edbp_c->zc_string, zc->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) edbp_c->field = zc->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- edbp_c->zc_begin_record = zc->zc_begin_record.drr_u.drr_begin;
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(resume_c->zc_inject_record.zi_func,
- zc->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
- FIELD_COPY(zc_defer_destroy);
- FIELD_COPY(zc_flags);
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
- break;
-
- case ZFS_CMD_COMPAT_ZCMD:
- zcmd_c = (void *)addr;
- /* zc */
- strlcpy(zcmd_c->zc_name, zc->zc_name, MAXPATHLEN);
- strlcpy(zcmd_c->zc_value, zc->zc_value, MAXPATHLEN * 2);
- strlcpy(zcmd_c->zc_string, zc->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) zcmd_c->field = zc->field
- FIELD_COPY(zc_nvlist_src);
- FIELD_COPY(zc_nvlist_src_size);
- FIELD_COPY(zc_nvlist_dst);
- FIELD_COPY(zc_nvlist_dst_size);
- FIELD_COPY(zc_nvlist_dst_filled);
- FIELD_COPY(zc_pad2);
- FIELD_COPY(zc_history);
- FIELD_COPY(zc_guid);
- FIELD_COPY(zc_nvlist_conf);
- FIELD_COPY(zc_nvlist_conf_size);
- FIELD_COPY(zc_cookie);
- FIELD_COPY(zc_objset_type);
- FIELD_COPY(zc_perm_action);
- FIELD_COPY(zc_history_len);
- FIELD_COPY(zc_history_offset);
- FIELD_COPY(zc_obj);
- FIELD_COPY(zc_iflags);
- FIELD_COPY(zc_share);
- FIELD_COPY(zc_jailid);
- FIELD_COPY(zc_objset_stats);
- zcmd_c->zc_begin_record = zc->zc_begin_record.drr_u.drr_begin;
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(resume_c->zc_inject_record.zi_func,
- zc->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
-
- /* boolean_t -> uint32_t */
- zcmd_c->zc_defer_destroy = (uint32_t)(zc->zc_defer_destroy);
- zcmd_c->zc_temphold = 0;
-
- FIELD_COPY(zc_action_handle);
- FIELD_COPY(zc_cleanup_fd);
- FIELD_COPY(zc_simple);
- FIELD_COPY(zc_sendobj);
- FIELD_COPY(zc_fromobj);
- FIELD_COPY(zc_createtxg);
- FIELD_COPY(zc_stat);
-#undef FIELD_COPY
-
- break;
-
- case ZFS_CMD_COMPAT_DEADMAN:
- zcdm_c = (void *)addr;
-
- strlcpy(zcdm_c->zc_name, zc->zc_name, MAXPATHLEN);
- strlcpy(zcdm_c->zc_value, zc->zc_value, MAXPATHLEN * 2);
- strlcpy(zcdm_c->zc_string, zc->zc_string, MAXPATHLEN);
-
-#define FIELD_COPY(field) zcdm_c->field = zc->field
- zcdm_c->zc_guid = zc->zc_guid;
- zcdm_c->zc_nvlist_conf = zc->zc_nvlist_conf;
- zcdm_c->zc_nvlist_conf_size = zc->zc_nvlist_conf_size;
- zcdm_c->zc_nvlist_src = zc->zc_nvlist_src;
- zcdm_c->zc_nvlist_src_size = zc->zc_nvlist_src_size;
- zcdm_c->zc_nvlist_dst = zc->zc_nvlist_dst;
- zcdm_c->zc_nvlist_dst_size = zc->zc_nvlist_dst_size;
- zcdm_c->zc_cookie = zc->zc_cookie;
- zcdm_c->zc_objset_type = zc->zc_objset_type;
- zcdm_c->zc_perm_action = zc->zc_perm_action;
- zcdm_c->zc_history = zc->zc_history;
- zcdm_c->zc_history_len = zc->zc_history_len;
- zcdm_c->zc_history_offset = zc->zc_history_offset;
- zcdm_c->zc_obj = zc->zc_obj;
- zcdm_c->zc_iflags = zc->zc_iflags;
- zcdm_c->zc_share = zc->zc_share;
- zcdm_c->zc_jailid = zc->zc_jailid;
- zcdm_c->zc_objset_stats = zc->zc_objset_stats;
- zcdm_c->zc_begin_record = zc->zc_begin_record.drr_u.drr_begin;
- zcdm_c->zc_defer_destroy = zc->zc_defer_destroy;
- zcdm_c->zc_temphold = 0;
- zcdm_c->zc_action_handle = zc->zc_action_handle;
- zcdm_c->zc_cleanup_fd = zc->zc_cleanup_fd;
- zcdm_c->zc_simple = zc->zc_simple;
- zcdm_c->zc_sendobj = zc->zc_sendobj;
- zcdm_c->zc_fromobj = zc->zc_fromobj;
- zcdm_c->zc_createtxg = zc->zc_createtxg;
- zcdm_c->zc_stat = zc->zc_stat;
- FIELD_COPY(zc_inject_record.zi_objset);
- FIELD_COPY(zc_inject_record.zi_object);
- FIELD_COPY(zc_inject_record.zi_start);
- FIELD_COPY(zc_inject_record.zi_end);
- FIELD_COPY(zc_inject_record.zi_guid);
- FIELD_COPY(zc_inject_record.zi_level);
- FIELD_COPY(zc_inject_record.zi_error);
- FIELD_COPY(zc_inject_record.zi_type);
- FIELD_COPY(zc_inject_record.zi_freq);
- FIELD_COPY(zc_inject_record.zi_failfast);
- strlcpy(resume_c->zc_inject_record.zi_func,
- zc->zc_inject_record.zi_func, MAXNAMELEN);
- FIELD_COPY(zc_inject_record.zi_iotype);
- FIELD_COPY(zc_inject_record.zi_duration);
- FIELD_COPY(zc_inject_record.zi_timer);
- FIELD_COPY(zc_inject_record.zi_cmd);
- FIELD_COPY(zc_inject_record.zi_pad);
-#undef FIELD_COPY
-#ifndef _KERNEL
- if (request == ZFS_IOC_RECV)
- strlcpy(zcdm_c->zc_top_ds,
- zc->zc_value + strlen(zc->zc_value) + 1,
- (MAXPATHLEN * 2) - strlen(zc->zc_value) - 1);
-#endif
- break;
-
- case ZFS_CMD_COMPAT_V28:
- zc28_c = (void *)addr;
-
- strlcpy(zc28_c->zc_name, zc->zc_name, MAXPATHLEN);
- strlcpy(zc28_c->zc_value, zc->zc_value, MAXPATHLEN * 2);
- strlcpy(zc28_c->zc_string, zc->zc_string, MAXPATHLEN);
- zc28_c->zc_guid = zc->zc_guid;
- zc28_c->zc_nvlist_conf = zc->zc_nvlist_conf;
- zc28_c->zc_nvlist_conf_size = zc->zc_nvlist_conf_size;
- zc28_c->zc_nvlist_src = zc->zc_nvlist_src;
- zc28_c->zc_nvlist_src_size = zc->zc_nvlist_src_size;
- zc28_c->zc_nvlist_dst = zc->zc_nvlist_dst;
- zc28_c->zc_nvlist_dst_size = zc->zc_nvlist_dst_size;
- zc28_c->zc_cookie = zc->zc_cookie;
- zc28_c->zc_objset_type = zc->zc_objset_type;
- zc28_c->zc_perm_action = zc->zc_perm_action;
- zc28_c->zc_history = zc->zc_history;
- zc28_c->zc_history_len = zc->zc_history_len;
- zc28_c->zc_history_offset = zc->zc_history_offset;
- zc28_c->zc_obj = zc->zc_obj;
- zc28_c->zc_iflags = zc->zc_iflags;
- zc28_c->zc_share = zc->zc_share;
- zc28_c->zc_jailid = zc->zc_jailid;
- zc28_c->zc_objset_stats = zc->zc_objset_stats;
- zc28_c->zc_begin_record = zc->zc_begin_record.drr_u.drr_begin;
- zc28_c->zc_defer_destroy = zc->zc_defer_destroy;
- zc28_c->zc_temphold = 0;
- zc28_c->zc_action_handle = zc->zc_action_handle;
- zc28_c->zc_cleanup_fd = zc->zc_cleanup_fd;
- zc28_c->zc_simple = zc->zc_simple;
- zc28_c->zc_sendobj = zc->zc_sendobj;
- zc28_c->zc_fromobj = zc->zc_fromobj;
- zc28_c->zc_createtxg = zc->zc_createtxg;
- zc28_c->zc_stat = zc->zc_stat;
-#ifndef _KERNEL
- if (request == ZFS_IOC_RECV)
- strlcpy(zc28_c->zc_top_ds,
- zc->zc_value + strlen(zc->zc_value) + 1,
- MAXPATHLEN * 2 - strlen(zc->zc_value) - 1);
-#endif
- /* zc_inject_record */
- zc28_c->zc_inject_record.zi_objset =
- zc->zc_inject_record.zi_objset;
- zc28_c->zc_inject_record.zi_object =
- zc->zc_inject_record.zi_object;
- zc28_c->zc_inject_record.zi_start =
- zc->zc_inject_record.zi_start;
- zc28_c->zc_inject_record.zi_end =
- zc->zc_inject_record.zi_end;
- zc28_c->zc_inject_record.zi_guid =
- zc->zc_inject_record.zi_guid;
- zc28_c->zc_inject_record.zi_level =
- zc->zc_inject_record.zi_level;
- zc28_c->zc_inject_record.zi_error =
- zc->zc_inject_record.zi_error;
- zc28_c->zc_inject_record.zi_type =
- zc->zc_inject_record.zi_type;
- zc28_c->zc_inject_record.zi_freq =
- zc->zc_inject_record.zi_freq;
- zc28_c->zc_inject_record.zi_failfast =
- zc->zc_inject_record.zi_failfast;
- strlcpy(zc28_c->zc_inject_record.zi_func,
- zc->zc_inject_record.zi_func, MAXNAMELEN);
- zc28_c->zc_inject_record.zi_iotype =
- zc->zc_inject_record.zi_iotype;
- zc28_c->zc_inject_record.zi_duration =
- zc->zc_inject_record.zi_duration;
- zc28_c->zc_inject_record.zi_timer =
- zc->zc_inject_record.zi_timer;
- break;
-
- case ZFS_CMD_COMPAT_V15:
- zc_c = (void *)addr;
-
- /* zc */
- strlcpy(zc_c->zc_name, zc->zc_name, MAXPATHLEN);
- strlcpy(zc_c->zc_value, zc->zc_value, MAXPATHLEN);
- strlcpy(zc_c->zc_string, zc->zc_string, MAXPATHLEN);
- zc_c->zc_guid = zc->zc_guid;
- zc_c->zc_nvlist_conf = zc->zc_nvlist_conf;
- zc_c->zc_nvlist_conf_size = zc->zc_nvlist_conf_size;
- zc_c->zc_nvlist_src = zc->zc_nvlist_src;
- zc_c->zc_nvlist_src_size = zc->zc_nvlist_src_size;
- zc_c->zc_nvlist_dst = zc->zc_nvlist_dst;
- zc_c->zc_nvlist_dst_size = zc->zc_nvlist_dst_size;
- zc_c->zc_cookie = zc->zc_cookie;
- zc_c->zc_objset_type = zc->zc_objset_type;
- zc_c->zc_perm_action = zc->zc_perm_action;
- zc_c->zc_history = zc->zc_history;
- zc_c->zc_history_len = zc->zc_history_len;
- zc_c->zc_history_offset = zc->zc_history_offset;
- zc_c->zc_obj = zc->zc_obj;
- zc_c->zc_share = zc->zc_share;
- zc_c->zc_jailid = zc->zc_jailid;
- zc_c->zc_objset_stats = zc->zc_objset_stats;
- zc_c->zc_begin_record = zc->zc_begin_record.drr_u.drr_begin;
-
- /* zc_inject_record */
- zc_c->zc_inject_record.zi_objset =
- zc->zc_inject_record.zi_objset;
- zc_c->zc_inject_record.zi_object =
- zc->zc_inject_record.zi_object;
- zc_c->zc_inject_record.zi_start =
- zc->zc_inject_record.zi_start;
- zc_c->zc_inject_record.zi_end =
- zc->zc_inject_record.zi_end;
- zc_c->zc_inject_record.zi_guid =
- zc->zc_inject_record.zi_guid;
- zc_c->zc_inject_record.zi_level =
- zc->zc_inject_record.zi_level;
- zc_c->zc_inject_record.zi_error =
- zc->zc_inject_record.zi_error;
- zc_c->zc_inject_record.zi_type =
- zc->zc_inject_record.zi_type;
- zc_c->zc_inject_record.zi_freq =
- zc->zc_inject_record.zi_freq;
- zc_c->zc_inject_record.zi_failfast =
- zc->zc_inject_record.zi_failfast;
-
- break;
- }
-}
-
-static int
-zfs_ioctl_compat_get_nvlist(uint64_t nvl, size_t size, int iflag,
- nvlist_t **nvp)
-{
- char *packed;
- int error;
- nvlist_t *list = NULL;
-
- /*
- * Read in and unpack the user-supplied nvlist.
- */
- if (size == 0)
- return (EINVAL);
-
-#ifdef _KERNEL
- packed = kmem_alloc(size, KM_SLEEP);
- if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
- iflag)) != 0) {
- kmem_free(packed, size);
- return (error);
- }
-#else
- packed = (void *)(uintptr_t)nvl;
-#endif
-
- error = nvlist_unpack(packed, size, &list, 0);
-
-#ifdef _KERNEL
- kmem_free(packed, size);
-#endif
-
- if (error != 0)
- return (error);
-
- *nvp = list;
- return (0);
-}
-
-static int
-zfs_ioctl_compat_put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
-{
- char *packed = NULL;
- int error = 0;
- size_t size;
-
- VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
-
-#ifdef _KERNEL
- packed = kmem_alloc(size, KM_SLEEP);
- VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
- KM_SLEEP) == 0);
-
- if (ddi_copyout(packed,
- (void *)(uintptr_t)zc->zc_nvlist_dst, size, zc->zc_iflags) != 0)
- error = EFAULT;
- kmem_free(packed, size);
-#else
- packed = (void *)(uintptr_t)zc->zc_nvlist_dst;
- VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
- 0) == 0);
-#endif
-
- zc->zc_nvlist_dst_size = size;
- return (error);
-}
-
-static void
-zfs_ioctl_compat_fix_stats_nvlist(nvlist_t *nvl)
-{
- nvlist_t **child;
- nvlist_t *nvroot = NULL;
- vdev_stat_t *vs;
- uint_t c, children, nelem;
-
- if (nvlist_lookup_nvlist_array(nvl, ZPOOL_CONFIG_CHILDREN,
- &child, &children) == 0) {
- for (c = 0; c < children; c++) {
- zfs_ioctl_compat_fix_stats_nvlist(child[c]);
- }
- }
-
- if (nvlist_lookup_nvlist(nvl, ZPOOL_CONFIG_VDEV_TREE,
- &nvroot) == 0)
- zfs_ioctl_compat_fix_stats_nvlist(nvroot);
-#ifdef _KERNEL
- if ((nvlist_lookup_uint64_array(nvl, ZPOOL_CONFIG_VDEV_STATS,
-#else
- if ((nvlist_lookup_uint64_array(nvl, "stats",
-#endif
-
- (uint64_t **)&vs, &nelem) == 0)) {
- nvlist_add_uint64_array(nvl,
-#ifdef _KERNEL
- "stats",
-#else
- ZPOOL_CONFIG_VDEV_STATS,
-#endif
- (uint64_t *)vs, nelem);
-#ifdef _KERNEL
- nvlist_remove(nvl, ZPOOL_CONFIG_VDEV_STATS,
-#else
- nvlist_remove(nvl, "stats",
-#endif
- DATA_TYPE_UINT64_ARRAY);
- }
-}
-
-static int
-zfs_ioctl_compat_fix_stats(zfs_cmd_t *zc, const int nc)
-{
- nvlist_t *nv, *nvp = NULL;
- nvpair_t *elem;
- int error;
-
- if ((error = zfs_ioctl_compat_get_nvlist(zc->zc_nvlist_dst,
- zc->zc_nvlist_dst_size, zc->zc_iflags, &nv)) != 0)
- return (error);
-
- if (nc == 5) { /* ZFS_IOC_POOL_STATS */
- elem = NULL;
- while ((elem = nvlist_next_nvpair(nv, elem)) != NULL) {
- if (nvpair_value_nvlist(elem, &nvp) == 0)
- zfs_ioctl_compat_fix_stats_nvlist(nvp);
- }
- elem = NULL;
- } else
- zfs_ioctl_compat_fix_stats_nvlist(nv);
-
- error = zfs_ioctl_compat_put_nvlist(zc, nv);
-
- nvlist_free(nv);
-
- return (error);
-}
-
-static int
-zfs_ioctl_compat_pool_get_props(zfs_cmd_t *zc)
-{
- nvlist_t *nv, *nva = NULL;
- int error;
-
- if ((error = zfs_ioctl_compat_get_nvlist(zc->zc_nvlist_dst,
- zc->zc_nvlist_dst_size, zc->zc_iflags, &nv)) != 0)
- return (error);
-
-#ifdef _KERNEL
- if (nvlist_lookup_nvlist(nv, "allocated", &nva) == 0) {
- nvlist_add_nvlist(nv, "used", nva);
- nvlist_remove(nv, "allocated", DATA_TYPE_NVLIST);
- }
-
- if (nvlist_lookup_nvlist(nv, "free", &nva) == 0) {
- nvlist_add_nvlist(nv, "available", nva);
- nvlist_remove(nv, "free", DATA_TYPE_NVLIST);
- }
-#else
- if (nvlist_lookup_nvlist(nv, "used", &nva) == 0) {
- nvlist_add_nvlist(nv, "allocated", nva);
- nvlist_remove(nv, "used", DATA_TYPE_NVLIST);
- }
-
- if (nvlist_lookup_nvlist(nv, "available", &nva) == 0) {
- nvlist_add_nvlist(nv, "free", nva);
- nvlist_remove(nv, "available", DATA_TYPE_NVLIST);
- }
-#endif
-
- error = zfs_ioctl_compat_put_nvlist(zc, nv);
-
- nvlist_free(nv);
-
- return (error);
-}
-
-#ifndef _KERNEL
-int
-zcmd_ioctl_compat(int fd, int request, zfs_cmd_t *zc, const int cflag)
-{
- int nc, ret;
- void *zc_c;
- unsigned long ncmd;
- zfs_iocparm_t zp;
-
- switch (cflag) {
- case ZFS_CMD_COMPAT_NONE:
- ncmd = _IOWR('Z', request, struct zfs_iocparm);
- zp.zfs_cmd = (uint64_t)zc;
- zp.zfs_cmd_size = sizeof(zfs_cmd_t);
- zp.zfs_ioctl_version = ZFS_IOCVER_CURRENT;
- return (ioctl(fd, ncmd, &zp));
- case ZFS_CMD_COMPAT_INLANES:
- ncmd = _IOWR('Z', request, struct zfs_iocparm);
- zp.zfs_cmd = (uint64_t)zc;
- zp.zfs_cmd_size = sizeof(zfs_cmd_inlanes_t);
- zp.zfs_ioctl_version = ZFS_IOCVER_INLANES;
- return (ioctl(fd, ncmd, &zp));
- case ZFS_CMD_COMPAT_RESUME:
- ncmd = _IOWR('Z', request, struct zfs_iocparm);
- zp.zfs_cmd = (uint64_t)zc;
- zp.zfs_cmd_size = sizeof(zfs_cmd_resume_t);
- zp.zfs_ioctl_version = ZFS_IOCVER_RESUME;
- return (ioctl(fd, ncmd, &zp));
- case ZFS_CMD_COMPAT_EDBP:
- ncmd = _IOWR('Z', request, struct zfs_iocparm);
- zp.zfs_cmd = (uint64_t)zc;
- zp.zfs_cmd_size = sizeof(zfs_cmd_edbp_t);
- zp.zfs_ioctl_version = ZFS_IOCVER_EDBP;
- return (ioctl(fd, ncmd, &zp));
- case ZFS_CMD_COMPAT_ZCMD:
- ncmd = _IOWR('Z', request, struct zfs_iocparm);
- zp.zfs_cmd = (uint64_t)zc;
- zp.zfs_cmd_size = sizeof(zfs_cmd_zcmd_t);
- zp.zfs_ioctl_version = ZFS_IOCVER_ZCMD;
- return (ioctl(fd, ncmd, &zp));
- case ZFS_CMD_COMPAT_LZC:
- ncmd = _IOWR('Z', request, struct zfs_cmd);
- return (ioctl(fd, ncmd, zc));
- case ZFS_CMD_COMPAT_DEADMAN:
- zc_c = malloc(sizeof(zfs_cmd_deadman_t));
- ncmd = _IOWR('Z', request, struct zfs_cmd_deadman);
- break;
- case ZFS_CMD_COMPAT_V28:
- zc_c = malloc(sizeof(zfs_cmd_v28_t));
- ncmd = _IOWR('Z', request, struct zfs_cmd_v28);
- break;
- case ZFS_CMD_COMPAT_V15:
- nc = zfs_ioctl_v28_to_v15[request];
- zc_c = malloc(sizeof(zfs_cmd_v15_t));
- ncmd = _IOWR('Z', nc, struct zfs_cmd_v15);
- break;
- default:
- return (EINVAL);
- }
-
- if (ZFS_IOCREQ(ncmd) == ZFS_IOC_COMPAT_FAIL)
- return (ENOTSUP);
-
- zfs_cmd_compat_put(zc, (caddr_t)zc_c, request, cflag);
-
- ret = ioctl(fd, ncmd, zc_c);
- if (cflag == ZFS_CMD_COMPAT_V15 &&
- nc == ZFS_IOC_POOL_IMPORT)
- ret = ioctl(fd, _IOWR('Z', ZFS_IOC_POOL_CONFIGS,
- struct zfs_cmd_v15), zc_c);
- zfs_cmd_compat_get(zc, (caddr_t)zc_c, cflag);
- free(zc_c);
-
- if (cflag == ZFS_CMD_COMPAT_V15) {
- switch (nc) {
- case ZFS_IOC_POOL_IMPORT:
- case ZFS_IOC_POOL_CONFIGS:
- case ZFS_IOC_POOL_STATS:
- case ZFS_IOC_POOL_TRYIMPORT:
- zfs_ioctl_compat_fix_stats(zc, nc);
- break;
- case 41: /* ZFS_IOC_POOL_GET_PROPS (v15) */
- zfs_ioctl_compat_pool_get_props(zc);
- break;
- }
- }
-
- return (ret);
-}
-#else /* _KERNEL */
-int
-zfs_ioctl_compat_pre(zfs_cmd_t *zc, int *vec, const int cflag)
-{
- int error = 0;
-
- /* are we creating a clone? */
- if (*vec == ZFS_IOC_CREATE && zc->zc_value[0] != '\0')
- *vec = ZFS_IOC_CLONE;
-
- if (cflag == ZFS_CMD_COMPAT_V15) {
- switch (*vec) {
-
- case 7: /* ZFS_IOC_POOL_SCRUB (v15) */
- zc->zc_cookie = POOL_SCAN_SCRUB;
- break;
- }
- }
-
- return (error);
-}
-
-void
-zfs_ioctl_compat_post(zfs_cmd_t *zc, int vec, const int cflag)
-{
- if (cflag == ZFS_CMD_COMPAT_V15) {
- switch (vec) {
- case ZFS_IOC_POOL_CONFIGS:
- case ZFS_IOC_POOL_STATS:
- case ZFS_IOC_POOL_TRYIMPORT:
- zfs_ioctl_compat_fix_stats(zc, vec);
- break;
- case 41: /* ZFS_IOC_POOL_GET_PROPS (v15) */
- zfs_ioctl_compat_pool_get_props(zc);
- break;
- }
- }
-}
-
-nvlist_t *
-zfs_ioctl_compat_innvl(zfs_cmd_t *zc, nvlist_t * innvl, const int vec,
- const int cflag)
-{
- nvlist_t *nvl, *tmpnvl, *hnvl;
- nvpair_t *elem;
- char *poolname, *snapname;
- int err;
-
- if (cflag == ZFS_CMD_COMPAT_NONE || cflag == ZFS_CMD_COMPAT_LZC ||
- cflag == ZFS_CMD_COMPAT_ZCMD || cflag == ZFS_CMD_COMPAT_EDBP ||
- cflag == ZFS_CMD_COMPAT_RESUME || cflag == ZFS_CMD_COMPAT_INLANES)
- goto out;
-
- switch (vec) {
- case ZFS_IOC_CREATE:
- nvl = fnvlist_alloc();
- fnvlist_add_int32(nvl, "type", zc->zc_objset_type);
- if (innvl != NULL) {
- fnvlist_add_nvlist(nvl, "props", innvl);
- nvlist_free(innvl);
- }
- return (nvl);
- break;
- case ZFS_IOC_CLONE:
- nvl = fnvlist_alloc();
- fnvlist_add_string(nvl, "origin", zc->zc_value);
- if (innvl != NULL) {
- fnvlist_add_nvlist(nvl, "props", innvl);
- nvlist_free(innvl);
- }
- return (nvl);
- break;
- case ZFS_IOC_SNAPSHOT:
- if (innvl == NULL)
- goto out;
- nvl = fnvlist_alloc();
- fnvlist_add_nvlist(nvl, "props", innvl);
- tmpnvl = fnvlist_alloc();
- snapname = kmem_asprintf("%s@%s", zc->zc_name, zc->zc_value);
- fnvlist_add_boolean(tmpnvl, snapname);
- kmem_free(snapname, strlen(snapname + 1));
- /* check if we are doing a recursive snapshot */
- if (zc->zc_cookie)
- dmu_get_recursive_snaps_nvl(zc->zc_name, zc->zc_value,
- tmpnvl);
- fnvlist_add_nvlist(nvl, "snaps", tmpnvl);
- fnvlist_free(tmpnvl);
- nvlist_free(innvl);
- /* strip dataset part from zc->zc_name */
- zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0';
- return (nvl);
- break;
- case ZFS_IOC_SPACE_SNAPS:
- nvl = fnvlist_alloc();
- fnvlist_add_string(nvl, "firstsnap", zc->zc_value);
- if (innvl != NULL)
- nvlist_free(innvl);
- return (nvl);
- break;
- case ZFS_IOC_DESTROY_SNAPS:
- if (innvl == NULL && cflag == ZFS_CMD_COMPAT_DEADMAN)
- goto out;
- nvl = fnvlist_alloc();
- if (innvl != NULL) {
- fnvlist_add_nvlist(nvl, "snaps", innvl);
- } else {
- /*
- * We are probably called by even older binaries,
- * allocate and populate nvlist with recursive
- * snapshots
- */
- if (zfs_component_namecheck(zc->zc_value, NULL,
- NULL) == 0) {
- tmpnvl = fnvlist_alloc();
- if (dmu_get_recursive_snaps_nvl(zc->zc_name,
- zc->zc_value, tmpnvl) == 0)
- fnvlist_add_nvlist(nvl, "snaps",
- tmpnvl);
- nvlist_free(tmpnvl);
- }
- }
- if (innvl != NULL)
- nvlist_free(innvl);
- /* strip dataset part from zc->zc_name */
- zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0';
- return (nvl);
- break;
- case ZFS_IOC_HOLD:
- nvl = fnvlist_alloc();
- tmpnvl = fnvlist_alloc();
- if (zc->zc_cleanup_fd != -1)
- fnvlist_add_int32(nvl, "cleanup_fd",
- (int32_t)zc->zc_cleanup_fd);
- if (zc->zc_cookie) {
- hnvl = fnvlist_alloc();
- if (dmu_get_recursive_snaps_nvl(zc->zc_name,
- zc->zc_value, hnvl) == 0) {
- elem = NULL;
- while ((elem = nvlist_next_nvpair(hnvl,
- elem)) != NULL) {
- nvlist_add_string(tmpnvl,
- nvpair_name(elem), zc->zc_string);
- }
- }
- nvlist_free(hnvl);
- } else {
- snapname = kmem_asprintf("%s@%s", zc->zc_name,
- zc->zc_value);
- nvlist_add_string(tmpnvl, snapname, zc->zc_string);
- kmem_free(snapname, strlen(snapname + 1));
- }
- fnvlist_add_nvlist(nvl, "holds", tmpnvl);
- nvlist_free(tmpnvl);
- if (innvl != NULL)
- nvlist_free(innvl);
- /* strip dataset part from zc->zc_name */
- zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0';
- return (nvl);
- break;
- case ZFS_IOC_RELEASE:
- nvl = fnvlist_alloc();
- tmpnvl = fnvlist_alloc();
- if (zc->zc_cookie) {
- hnvl = fnvlist_alloc();
- if (dmu_get_recursive_snaps_nvl(zc->zc_name,
- zc->zc_value, hnvl) == 0) {
- elem = NULL;
- while ((elem = nvlist_next_nvpair(hnvl,
- elem)) != NULL) {
- fnvlist_add_boolean(tmpnvl,
- zc->zc_string);
- fnvlist_add_nvlist(nvl,
- nvpair_name(elem), tmpnvl);
- }
- }
- nvlist_free(hnvl);
- } else {
- snapname = kmem_asprintf("%s@%s", zc->zc_name,
- zc->zc_value);
- fnvlist_add_boolean(tmpnvl, zc->zc_string);
- fnvlist_add_nvlist(nvl, snapname, tmpnvl);
- kmem_free(snapname, strlen(snapname + 1));
- }
- nvlist_free(tmpnvl);
- if (innvl != NULL)
- nvlist_free(innvl);
- /* strip dataset part from zc->zc_name */
- zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0';
- return (nvl);
- break;
- }
-out:
- return (innvl);
-}
-
-nvlist_t *
-zfs_ioctl_compat_outnvl(zfs_cmd_t *zc, nvlist_t * outnvl, const int vec,
- const int cflag)
-{
- nvlist_t *tmpnvl;
-
- if (cflag == ZFS_CMD_COMPAT_NONE || cflag == ZFS_CMD_COMPAT_LZC ||
- cflag == ZFS_CMD_COMPAT_ZCMD || cflag == ZFS_CMD_COMPAT_EDBP ||
- cflag == ZFS_CMD_COMPAT_RESUME || cflag == ZFS_CMD_COMPAT_INLANES)
- return (outnvl);
-
- switch (vec) {
- case ZFS_IOC_SPACE_SNAPS:
- (void) nvlist_lookup_uint64(outnvl, "used", &zc->zc_cookie);
- (void) nvlist_lookup_uint64(outnvl, "compressed",
- &zc->zc_objset_type);
- (void) nvlist_lookup_uint64(outnvl, "uncompressed",
- &zc->zc_perm_action);
- nvlist_free(outnvl);
- /* return empty outnvl */
- tmpnvl = fnvlist_alloc();
- return (tmpnvl);
- break;
- case ZFS_IOC_CREATE:
- case ZFS_IOC_CLONE:
- case ZFS_IOC_HOLD:
- case ZFS_IOC_RELEASE:
- nvlist_free(outnvl);
- /* return empty outnvl */
- tmpnvl = fnvlist_alloc();
- return (tmpnvl);
- break;
- }
-
- return (outnvl);
-}
-#endif /* KERNEL */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.h b/sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.h
deleted file mode 100644
index 61f1514e3ebd..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_ioctl_compat.h
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2014 Xin Li <delphij@FreeBSD.org>. All rights reserved.
- * Copyright 2013 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _SYS_ZFS_IOCTL_COMPAT_H
-#define _SYS_ZFS_IOCTL_COMPAT_H
-
-#include <sys/cred.h>
-#include <sys/dmu.h>
-#include <sys/zio.h>
-#include <sys/dsl_deleg.h>
-#include <sys/zfs_ioctl.h>
-
-#ifdef _KERNEL
-#include <sys/nvpair.h>
-#endif /* _KERNEL */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Backwards ioctl compatibility
- */
-
-/* ioctl versions for vfs.zfs.version.ioctl */
-#define ZFS_IOCVER_UNDEF -1
-#define ZFS_IOCVER_NONE 0
-#define ZFS_IOCVER_DEADMAN 1
-#define ZFS_IOCVER_LZC 2
-#define ZFS_IOCVER_ZCMD 3
-#define ZFS_IOCVER_EDBP 4
-#define ZFS_IOCVER_RESUME 5
-#define ZFS_IOCVER_INLANES 6
-#define ZFS_IOCVER_PAD 7
-#define ZFS_IOCVER_CURRENT ZFS_IOCVER_PAD
-
-/* compatibility conversion flag */
-#define ZFS_CMD_COMPAT_NONE 0
-#define ZFS_CMD_COMPAT_V15 1
-#define ZFS_CMD_COMPAT_V28 2
-#define ZFS_CMD_COMPAT_DEADMAN 3
-#define ZFS_CMD_COMPAT_LZC 4
-#define ZFS_CMD_COMPAT_ZCMD 5
-#define ZFS_CMD_COMPAT_EDBP 6
-#define ZFS_CMD_COMPAT_RESUME 7
-#define ZFS_CMD_COMPAT_INLANES 8
-
-#define ZFS_IOC_COMPAT_PASS 254
-#define ZFS_IOC_COMPAT_FAIL 255
-
-#define ZFS_IOCREQ(ioreq) ((ioreq) & 0xff)
-
-typedef struct zfs_iocparm {
- uint32_t zfs_ioctl_version;
- uint64_t zfs_cmd;
- uint64_t zfs_cmd_size;
-} zfs_iocparm_t;
-
-typedef struct zinject_record_v15 {
- uint64_t zi_objset;
- uint64_t zi_object;
- uint64_t zi_start;
- uint64_t zi_end;
- uint64_t zi_guid;
- uint32_t zi_level;
- uint32_t zi_error;
- uint64_t zi_type;
- uint32_t zi_freq;
- uint32_t zi_failfast;
-} zinject_record_v15_t;
-
-typedef struct zfs_cmd_v15 {
- char zc_name[MAXPATHLEN];
- char zc_value[MAXPATHLEN];
- char zc_string[MAXNAMELEN];
- uint64_t zc_guid;
- uint64_t zc_nvlist_conf; /* really (char *) */
- uint64_t zc_nvlist_conf_size;
- uint64_t zc_nvlist_src; /* really (char *) */
- uint64_t zc_nvlist_src_size;
- uint64_t zc_nvlist_dst; /* really (char *) */
- uint64_t zc_nvlist_dst_size;
- uint64_t zc_cookie;
- uint64_t zc_objset_type;
- uint64_t zc_perm_action;
- uint64_t zc_history; /* really (char *) */
- uint64_t zc_history_len;
- uint64_t zc_history_offset;
- uint64_t zc_obj;
- zfs_share_t zc_share;
- uint64_t zc_jailid;
- dmu_objset_stats_t zc_objset_stats;
- struct drr_begin zc_begin_record;
- zinject_record_v15_t zc_inject_record;
-} zfs_cmd_v15_t;
-
-typedef struct zinject_record_v28 {
- uint64_t zi_objset;
- uint64_t zi_object;
- uint64_t zi_start;
- uint64_t zi_end;
- uint64_t zi_guid;
- uint32_t zi_level;
- uint32_t zi_error;
- uint64_t zi_type;
- uint32_t zi_freq;
- uint32_t zi_failfast;
- char zi_func[MAXNAMELEN];
- uint32_t zi_iotype;
- int32_t zi_duration;
- uint64_t zi_timer;
-} zinject_record_v28_t;
-
-typedef struct zfs_cmd_v28 {
- char zc_name[MAXPATHLEN];
- char zc_value[MAXPATHLEN * 2];
- char zc_string[MAXNAMELEN];
- char zc_top_ds[MAXPATHLEN];
- uint64_t zc_guid;
- uint64_t zc_nvlist_conf; /* really (char *) */
- uint64_t zc_nvlist_conf_size;
- uint64_t zc_nvlist_src; /* really (char *) */
- uint64_t zc_nvlist_src_size;
- uint64_t zc_nvlist_dst; /* really (char *) */
- uint64_t zc_nvlist_dst_size;
- uint64_t zc_cookie;
- uint64_t zc_objset_type;
- uint64_t zc_perm_action;
- uint64_t zc_history; /* really (char *) */
- uint64_t zc_history_len;
- uint64_t zc_history_offset;
- uint64_t zc_obj;
- uint64_t zc_iflags; /* internal to zfs(7fs) */
- zfs_share_t zc_share;
- uint64_t zc_jailid;
- dmu_objset_stats_t zc_objset_stats;
- struct drr_begin zc_begin_record;
- zinject_record_v28_t zc_inject_record;
- boolean_t zc_defer_destroy;
- boolean_t zc_temphold;
- uint64_t zc_action_handle;
- int zc_cleanup_fd;
- uint8_t zc_simple;
- uint8_t zc_pad[3]; /* alignment */
- uint64_t zc_sendobj;
- uint64_t zc_fromobj;
- uint64_t zc_createtxg;
- zfs_stat_t zc_stat;
-} zfs_cmd_v28_t;
-
-typedef struct zinject_record_deadman {
- uint64_t zi_objset;
- uint64_t zi_object;
- uint64_t zi_start;
- uint64_t zi_end;
- uint64_t zi_guid;
- uint32_t zi_level;
- uint32_t zi_error;
- uint64_t zi_type;
- uint32_t zi_freq;
- uint32_t zi_failfast;
- char zi_func[MAXNAMELEN];
- uint32_t zi_iotype;
- int32_t zi_duration;
- uint64_t zi_timer;
- uint32_t zi_cmd;
- uint32_t zi_pad;
-} zinject_record_deadman_t;
-
-typedef struct zfs_cmd_deadman {
- char zc_name[MAXPATHLEN];
- char zc_value[MAXPATHLEN * 2];
- char zc_string[MAXNAMELEN];
- char zc_top_ds[MAXPATHLEN];
- uint64_t zc_guid;
- uint64_t zc_nvlist_conf; /* really (char *) */
- uint64_t zc_nvlist_conf_size;
- uint64_t zc_nvlist_src; /* really (char *) */
- uint64_t zc_nvlist_src_size;
- uint64_t zc_nvlist_dst; /* really (char *) */
- uint64_t zc_nvlist_dst_size;
- uint64_t zc_cookie;
- uint64_t zc_objset_type;
- uint64_t zc_perm_action;
- uint64_t zc_history; /* really (char *) */
- uint64_t zc_history_len;
- uint64_t zc_history_offset;
- uint64_t zc_obj;
- uint64_t zc_iflags; /* internal to zfs(7fs) */
- zfs_share_t zc_share;
- uint64_t zc_jailid;
- dmu_objset_stats_t zc_objset_stats;
- struct drr_begin zc_begin_record;
- /* zc_inject_record doesn't change in libzfs_core */
- zinject_record_deadman_t zc_inject_record;
- boolean_t zc_defer_destroy;
- boolean_t zc_temphold;
- uint64_t zc_action_handle;
- int zc_cleanup_fd;
- uint8_t zc_simple;
- uint8_t zc_pad[3]; /* alignment */
- uint64_t zc_sendobj;
- uint64_t zc_fromobj;
- uint64_t zc_createtxg;
- zfs_stat_t zc_stat;
-} zfs_cmd_deadman_t;
-
-typedef struct zfs_cmd_zcmd {
- char zc_name[MAXPATHLEN]; /* name of pool or dataset */
- uint64_t zc_nvlist_src; /* really (char *) */
- uint64_t zc_nvlist_src_size;
- uint64_t zc_nvlist_dst; /* really (char *) */
- uint64_t zc_nvlist_dst_size;
- boolean_t zc_nvlist_dst_filled; /* put an nvlist in dst? */
- int zc_pad2;
-
- /*
- * The following members are for legacy ioctls which haven't been
- * converted to the new method.
- */
- uint64_t zc_history; /* really (char *) */
- char zc_value[MAXPATHLEN * 2];
- char zc_string[MAXNAMELEN];
- uint64_t zc_guid;
- uint64_t zc_nvlist_conf; /* really (char *) */
- uint64_t zc_nvlist_conf_size;
- uint64_t zc_cookie;
- uint64_t zc_objset_type;
- uint64_t zc_perm_action;
- uint64_t zc_history_len;
- uint64_t zc_history_offset;
- uint64_t zc_obj;
- uint64_t zc_iflags; /* internal to zfs(7fs) */
- zfs_share_t zc_share;
- uint64_t zc_jailid;
- dmu_objset_stats_t zc_objset_stats;
- struct drr_begin zc_begin_record;
- zinject_record_deadman_t zc_inject_record;
- boolean_t zc_defer_destroy;
- boolean_t zc_temphold;
- uint64_t zc_action_handle;
- int zc_cleanup_fd;
- uint8_t zc_simple;
- uint8_t zc_pad[3]; /* alignment */
- uint64_t zc_sendobj;
- uint64_t zc_fromobj;
- uint64_t zc_createtxg;
- zfs_stat_t zc_stat;
-} zfs_cmd_zcmd_t;
-
-typedef struct zfs_cmd_edbp {
- char zc_name[MAXPATHLEN]; /* name of pool or dataset */
- uint64_t zc_nvlist_src; /* really (char *) */
- uint64_t zc_nvlist_src_size;
- uint64_t zc_nvlist_dst; /* really (char *) */
- uint64_t zc_nvlist_dst_size;
- boolean_t zc_nvlist_dst_filled; /* put an nvlist in dst? */
- int zc_pad2;
-
- /*
- * The following members are for legacy ioctls which haven't been
- * converted to the new method.
- */
- uint64_t zc_history; /* really (char *) */
- char zc_value[MAXPATHLEN * 2];
- char zc_string[MAXNAMELEN];
- uint64_t zc_guid;
- uint64_t zc_nvlist_conf; /* really (char *) */
- uint64_t zc_nvlist_conf_size;
- uint64_t zc_cookie;
- uint64_t zc_objset_type;
- uint64_t zc_perm_action;
- uint64_t zc_history_len;
- uint64_t zc_history_offset;
- uint64_t zc_obj;
- uint64_t zc_iflags; /* internal to zfs(7fs) */
- zfs_share_t zc_share;
- uint64_t zc_jailid;
- dmu_objset_stats_t zc_objset_stats;
- struct drr_begin zc_begin_record;
- zinject_record_deadman_t zc_inject_record;
- uint32_t zc_defer_destroy;
- uint32_t zc_flags;
- uint64_t zc_action_handle;
- int zc_cleanup_fd;
- uint8_t zc_simple;
- uint8_t zc_pad[3]; /* alignment */
- uint64_t zc_sendobj;
- uint64_t zc_fromobj;
- uint64_t zc_createtxg;
- zfs_stat_t zc_stat;
-} zfs_cmd_edbp_t;
-
-typedef struct zfs_cmd_resume {
- char zc_name[MAXPATHLEN]; /* name of pool or dataset */
- uint64_t zc_nvlist_src; /* really (char *) */
- uint64_t zc_nvlist_src_size;
- uint64_t zc_nvlist_dst; /* really (char *) */
- uint64_t zc_nvlist_dst_size;
- boolean_t zc_nvlist_dst_filled; /* put an nvlist in dst? */
- int zc_pad2;
-
- /*
- * The following members are for legacy ioctls which haven't been
- * converted to the new method.
- */
- uint64_t zc_history; /* really (char *) */
- char zc_value[MAXPATHLEN * 2];
- char zc_string[MAXNAMELEN];
- uint64_t zc_guid;
- uint64_t zc_nvlist_conf; /* really (char *) */
- uint64_t zc_nvlist_conf_size;
- uint64_t zc_cookie;
- uint64_t zc_objset_type;
- uint64_t zc_perm_action;
- uint64_t zc_history_len;
- uint64_t zc_history_offset;
- uint64_t zc_obj;
- uint64_t zc_iflags; /* internal to zfs(7fs) */
- zfs_share_t zc_share;
- uint64_t zc_jailid;
- dmu_objset_stats_t zc_objset_stats;
- dmu_replay_record_t zc_begin_record;
- zinject_record_deadman_t zc_inject_record;
- uint32_t zc_defer_destroy;
- uint32_t zc_flags;
- uint64_t zc_action_handle;
- int zc_cleanup_fd;
- uint8_t zc_simple;
- boolean_t zc_resumable;
- uint64_t zc_sendobj;
- uint64_t zc_fromobj;
- uint64_t zc_createtxg;
- zfs_stat_t zc_stat;
-} zfs_cmd_resume_t;
-
-typedef struct zfs_cmd_inlanes {
- char zc_name[MAXPATHLEN]; /* name of pool or dataset */
- uint64_t zc_nvlist_src; /* really (char *) */
- uint64_t zc_nvlist_src_size;
- uint64_t zc_nvlist_dst; /* really (char *) */
- uint64_t zc_nvlist_dst_size;
- boolean_t zc_nvlist_dst_filled; /* put an nvlist in dst? */
- int zc_pad2;
-
- /*
- * The following members are for legacy ioctls which haven't been
- * converted to the new method.
- */
- uint64_t zc_history; /* really (char *) */
- char zc_value[MAXPATHLEN * 2];
- char zc_string[MAXNAMELEN];
- uint64_t zc_guid;
- uint64_t zc_nvlist_conf; /* really (char *) */
- uint64_t zc_nvlist_conf_size;
- uint64_t zc_cookie;
- uint64_t zc_objset_type;
- uint64_t zc_perm_action;
- uint64_t zc_history_len;
- uint64_t zc_history_offset;
- uint64_t zc_obj;
- uint64_t zc_iflags; /* internal to zfs(7fs) */
- zfs_share_t zc_share;
- uint64_t zc_jailid;
- dmu_objset_stats_t zc_objset_stats;
- dmu_replay_record_t zc_begin_record;
- zinject_record_t zc_inject_record;
- uint32_t zc_defer_destroy;
- uint32_t zc_flags;
- uint64_t zc_action_handle;
- int zc_cleanup_fd;
- uint8_t zc_simple;
- boolean_t zc_resumable;
- uint64_t zc_sendobj;
- uint64_t zc_fromobj;
- uint64_t zc_createtxg;
- zfs_stat_t zc_stat;
-} zfs_cmd_inlanes_t;
-
-#ifdef _KERNEL
-unsigned static long zfs_ioctl_v15_to_v28[] = {
- 0, /* 0 ZFS_IOC_POOL_CREATE */
- 1, /* 1 ZFS_IOC_POOL_DESTROY */
- 2, /* 2 ZFS_IOC_POOL_IMPORT */
- 3, /* 3 ZFS_IOC_POOL_EXPORT */
- 4, /* 4 ZFS_IOC_POOL_CONFIGS */
- 5, /* 5 ZFS_IOC_POOL_STATS */
- 6, /* 6 ZFS_IOC_POOL_TRYIMPORT */
- 7, /* 7 ZFS_IOC_POOL_SCRUB */
- 8, /* 8 ZFS_IOC_POOL_FREEZE */
- 9, /* 9 ZFS_IOC_POOL_UPGRADE */
- 10, /* 10 ZFS_IOC_POOL_GET_HISTORY */
- 11, /* 11 ZFS_IOC_VDEV_ADD */
- 12, /* 12 ZFS_IOC_VDEV_REMOVE */
- 13, /* 13 ZFS_IOC_VDEV_SET_STATE */
- 14, /* 14 ZFS_IOC_VDEV_ATTACH */
- 15, /* 15 ZFS_IOC_VDEV_DETACH */
- 16, /* 16 ZFS_IOC_VDEV_SETPATH */
- 18, /* 17 ZFS_IOC_OBJSET_STATS */
- 19, /* 18 ZFS_IOC_OBJSET_ZPLPROPS */
- 20, /* 19 ZFS_IOC_DATASET_LIST_NEXT */
- 21, /* 20 ZFS_IOC_SNAPSHOT_LIST_NEXT */
- 22, /* 21 ZFS_IOC_SET_PROP */
- ZFS_IOC_COMPAT_PASS, /* 22 ZFS_IOC_CREATE_MINOR */
- ZFS_IOC_COMPAT_PASS, /* 23 ZFS_IOC_REMOVE_MINOR */
- 23, /* 24 ZFS_IOC_CREATE */
- 24, /* 25 ZFS_IOC_DESTROY */
- 25, /* 26 ZFS_IOC_ROLLBACK */
- 26, /* 27 ZFS_IOC_RENAME */
- 27, /* 28 ZFS_IOC_RECV */
- 28, /* 29 ZFS_IOC_SEND */
- 29, /* 30 ZFS_IOC_INJECT_FAULT */
- 30, /* 31 ZFS_IOC_CLEAR_FAULT */
- 31, /* 32 ZFS_IOC_INJECT_LIST_NEXT */
- 32, /* 33 ZFS_IOC_ERROR_LOG */
- 33, /* 34 ZFS_IOC_CLEAR */
- 34, /* 35 ZFS_IOC_PROMOTE */
- 35, /* 36 ZFS_IOC_DESTROY_SNAPS */
- 36, /* 37 ZFS_IOC_SNAPSHOT */
- 37, /* 38 ZFS_IOC_DSOBJ_TO_DSNAME */
- 38, /* 39 ZFS_IOC_OBJ_TO_PATH */
- 39, /* 40 ZFS_IOC_POOL_SET_PROPS */
- 40, /* 41 ZFS_IOC_POOL_GET_PROPS */
- 41, /* 42 ZFS_IOC_SET_FSACL */
- 42, /* 43 ZFS_IOC_GET_FSACL */
- ZFS_IOC_COMPAT_PASS, /* 44 ZFS_IOC_ISCSI_PERM_CHECK */
- 43, /* 45 ZFS_IOC_SHARE */
- 44, /* 46 ZFS_IOC_IHNERIT_PROP */
- 58, /* 47 ZFS_IOC_JAIL */
- 59, /* 48 ZFS_IOC_UNJAIL */
- 45, /* 49 ZFS_IOC_SMB_ACL */
- 46, /* 50 ZFS_IOC_USERSPACE_ONE */
- 47, /* 51 ZFS_IOC_USERSPACE_MANY */
- 48, /* 52 ZFS_IOC_USERSPACE_UPGRADE */
- 17, /* 53 ZFS_IOC_SETFRU */
-};
-
-#else /* KERNEL */
-unsigned static long zfs_ioctl_v28_to_v15[] = {
- 0, /* 0 ZFS_IOC_POOL_CREATE */
- 1, /* 1 ZFS_IOC_POOL_DESTROY */
- 2, /* 2 ZFS_IOC_POOL_IMPORT */
- 3, /* 3 ZFS_IOC_POOL_EXPORT */
- 4, /* 4 ZFS_IOC_POOL_CONFIGS */
- 5, /* 5 ZFS_IOC_POOL_STATS */
- 6, /* 6 ZFS_IOC_POOL_TRYIMPORT */
- 7, /* 7 ZFS_IOC_POOL_SCAN */
- 8, /* 8 ZFS_IOC_POOL_FREEZE */
- 9, /* 9 ZFS_IOC_POOL_UPGRADE */
- 10, /* 10 ZFS_IOC_POOL_GET_HISTORY */
- 11, /* 11 ZFS_IOC_VDEV_ADD */
- 12, /* 12 ZFS_IOC_VDEV_REMOVE */
- 13, /* 13 ZFS_IOC_VDEV_SET_STATE */
- 14, /* 14 ZFS_IOC_VDEV_ATTACH */
- 15, /* 15 ZFS_IOC_VDEV_DETACH */
- 16, /* 16 ZFS_IOC_VDEV_SETPATH */
- 53, /* 17 ZFS_IOC_VDEV_SETFRU */
- 17, /* 18 ZFS_IOC_OBJSET_STATS */
- 18, /* 19 ZFS_IOC_OBJSET_ZPLPROPS */
- 19, /* 20 ZFS_IOC_DATASET_LIST_NEXT */
- 20, /* 21 ZFS_IOC_SNAPSHOT_LIST_NEXT */
- 21, /* 22 ZFS_IOC_SET_PROP */
- 24, /* 23 ZFS_IOC_CREATE */
- 25, /* 24 ZFS_IOC_DESTROY */
- 26, /* 25 ZFS_IOC_ROLLBACK */
- 27, /* 26 ZFS_IOC_RENAME */
- 28, /* 27 ZFS_IOC_RECV */
- 29, /* 28 ZFS_IOC_SEND */
- 30, /* 39 ZFS_IOC_INJECT_FAULT */
- 31, /* 30 ZFS_IOC_CLEAR_FAULT */
- 32, /* 31 ZFS_IOC_INJECT_LIST_NEXT */
- 33, /* 32 ZFS_IOC_ERROR_LOG */
- 34, /* 33 ZFS_IOC_CLEAR */
- 35, /* 34 ZFS_IOC_PROMOTE */
- 36, /* 35 ZFS_IOC_DESTROY_SNAPS */
- 37, /* 36 ZFS_IOC_SNAPSHOT */
- 38, /* 37 ZFS_IOC_DSOBJ_TO_DSNAME */
- 39, /* 38 ZFS_IOC_OBJ_TO_PATH */
- 40, /* 39 ZFS_IOC_POOL_SET_PROPS */
- 41, /* 40 ZFS_IOC_POOL_GET_PROPS */
- 42, /* 41 ZFS_IOC_SET_FSACL */
- 43, /* 42 ZFS_IOC_GET_FSACL */
- 45, /* 43 ZFS_IOC_SHARE */
- 46, /* 44 ZFS_IOC_IHNERIT_PROP */
- 49, /* 45 ZFS_IOC_SMB_ACL */
- 50, /* 46 ZFS_IOC_USERSPACE_ONE */
- 51, /* 47 ZFS_IOC_USERSPACE_MANY */
- 52, /* 48 ZFS_IOC_USERSPACE_UPGRADE */
- ZFS_IOC_COMPAT_FAIL, /* 49 ZFS_IOC_HOLD */
- ZFS_IOC_COMPAT_FAIL, /* 50 ZFS_IOC_RELEASE */
- ZFS_IOC_COMPAT_FAIL, /* 51 ZFS_IOC_GET_HOLDS */
- ZFS_IOC_COMPAT_FAIL, /* 52 ZFS_IOC_OBJSET_RECVD_PROPS */
- ZFS_IOC_COMPAT_FAIL, /* 53 ZFS_IOC_VDEV_SPLIT */
- ZFS_IOC_COMPAT_FAIL, /* 54 ZFS_IOC_NEXT_OBJ */
- ZFS_IOC_COMPAT_FAIL, /* 55 ZFS_IOC_DIFF */
- ZFS_IOC_COMPAT_FAIL, /* 56 ZFS_IOC_TMP_SNAPSHOT */
- ZFS_IOC_COMPAT_FAIL, /* 57 ZFS_IOC_OBJ_TO_STATS */
- 47, /* 58 ZFS_IOC_JAIL */
- 48, /* 59 ZFS_IOC_UNJAIL */
-};
-#endif /* ! _KERNEL */
-
-#ifdef _KERNEL
-int zfs_ioctl_compat_pre(zfs_cmd_t *, int *, const int);
-void zfs_ioctl_compat_post(zfs_cmd_t *, const int, const int);
-nvlist_t *zfs_ioctl_compat_innvl(zfs_cmd_t *, nvlist_t *, const int,
- const int);
-nvlist_t *zfs_ioctl_compat_outnvl(zfs_cmd_t *, nvlist_t *, const int,
- const int);
-#else
-int zcmd_ioctl_compat(int, int, zfs_cmd_t *, const int);
-#endif /* _KERNEL */
-void zfs_cmd_compat_get(zfs_cmd_t *, caddr_t, const int);
-void zfs_cmd_compat_put(zfs_cmd_t *, caddr_t, const int, const int);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _SYS_ZFS_IOCTL_COMPAT_H */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.c b/sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.c
deleted file mode 100644
index bad8f20e6917..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
- */
-
-/*
- * Common name validation routines for ZFS. These routines are shared by the
- * userland code as well as the ioctl() layer to ensure that we don't
- * inadvertently expose a hole through direct ioctl()s that never gets tested.
- * In userland, however, we want significantly more information about _why_ the
- * name is invalid. In the kernel, we only care whether it's valid or not.
- * Each routine therefore takes a 'namecheck_err_t' which describes exactly why
- * the name failed to validate.
- */
-
-#if defined(_KERNEL)
-#include <sys/systm.h>
-#else
-#include <string.h>
-#endif
-
-#include <sys/dsl_dir.h>
-#include <sys/param.h>
-#include <sys/nvpair.h>
-#include "zfs_namecheck.h"
-#include "zfs_deleg.h"
-
-/*
- * Deeply nested datasets can overflow the stack, so we put a limit
- * in the amount of nesting a path can have. zfs_max_dataset_nesting
- * can be tuned temporarily to fix existing datasets that exceed our
- * predefined limit.
- */
-int zfs_max_dataset_nesting = 50;
-
-static int
-valid_char(char c)
-{
- return ((c >= 'a' && c <= 'z') ||
- (c >= 'A' && c <= 'Z') ||
- (c >= '0' && c <= '9') ||
- c == '-' || c == '_' || c == '.' || c == ':' || c == ' ');
-}
-
-/*
- * Looks at a path and returns its level of nesting (depth).
- */
-int
-get_dataset_depth(const char *path)
-{
- const char *loc = path;
- int nesting = 0;
-
- /*
- * Keep track of nesting until you hit the end of the
- * path or found the snapshot/bookmark seperator.
- */
- for (int i = 0; loc[i] != '\0' &&
- loc[i] != '@' &&
- loc[i] != '#'; i++) {
- if (loc[i] == '/')
- nesting++;
- }
-
- return (nesting);
-}
-
-/*
- * Snapshot names must be made up of alphanumeric characters plus the following
- * characters:
- *
- * [-_.: ]
- *
- * Returns 0 on success, -1 on error.
- */
-int
-zfs_component_namecheck(const char *path, namecheck_err_t *why, char *what)
-{
- const char *loc;
-
- if (strlen(path) >= ZFS_MAX_DATASET_NAME_LEN) {
- if (why)
- *why = NAME_ERR_TOOLONG;
- return (-1);
- }
-
- if (path[0] == '\0') {
- if (why)
- *why = NAME_ERR_EMPTY_COMPONENT;
- return (-1);
- }
-
- for (loc = path; *loc; loc++) {
- if (!valid_char(*loc)) {
- if (why) {
- *why = NAME_ERR_INVALCHAR;
- *what = *loc;
- }
- return (-1);
- }
- }
- return (0);
-}
-
-
-/*
- * Permissions set name must start with the letter '@' followed by the
- * same character restrictions as snapshot names, except that the name
- * cannot exceed 64 characters.
- *
- * Returns 0 on success, -1 on error.
- */
-int
-permset_namecheck(const char *path, namecheck_err_t *why, char *what)
-{
- if (strlen(path) >= ZFS_PERMSET_MAXLEN) {
- if (why)
- *why = NAME_ERR_TOOLONG;
- return (-1);
- }
-
- if (path[0] != '@') {
- if (why) {
- *why = NAME_ERR_NO_AT;
- *what = path[0];
- }
- return (-1);
- }
-
- return (zfs_component_namecheck(&path[1], why, what));
-}
-
-/*
- * Dataset paths should not be deeper than zfs_max_dataset_nesting
- * in terms of nesting.
- *
- * Returns 0 on success, -1 on error.
- */
-int
-dataset_nestcheck(const char *path)
-{
- return ((get_dataset_depth(path) < zfs_max_dataset_nesting) ? 0 : -1);
-}
-
-/*
- * Entity names must be of the following form:
- *
- * [component/]*[component][(@|#)component]?
- *
- * Where each component is made up of alphanumeric characters plus the following
- * characters:
- *
- * [-_.:%]
- *
- * We allow '%' here as we use that character internally to create unique
- * names for temporary clones (for online recv).
- *
- * Returns 0 on success, -1 on error.
- */
-int
-entity_namecheck(const char *path, namecheck_err_t *why, char *what)
-{
- const char *end;
-
- /*
- * Make sure the name is not too long.
- */
- if (strlen(path) >= ZFS_MAX_DATASET_NAME_LEN) {
- if (why)
- *why = NAME_ERR_TOOLONG;
- return (-1);
- }
-
- /* Explicitly check for a leading slash. */
- if (path[0] == '/') {
- if (why)
- *why = NAME_ERR_LEADING_SLASH;
- return (-1);
- }
-
- if (path[0] == '\0') {
- if (why)
- *why = NAME_ERR_EMPTY_COMPONENT;
- return (-1);
- }
-
- const char *start = path;
- boolean_t found_delim = B_FALSE;
- for (;;) {
- /* Find the end of this component */
- end = start;
- while (*end != '/' && *end != '@' && *end != '#' &&
- *end != '\0')
- end++;
-
- if (*end == '\0' && end[-1] == '/') {
- /* trailing slashes are not allowed */
- if (why)
- *why = NAME_ERR_TRAILING_SLASH;
- return (-1);
- }
-
- /* Validate the contents of this component */
- for (const char *loc = start; loc != end; loc++) {
- if (!valid_char(*loc) && *loc != '%') {
- if (why) {
- *why = NAME_ERR_INVALCHAR;
- *what = *loc;
- }
- return (-1);
- }
- }
-
- /* Snapshot or bookmark delimiter found */
- if (*end == '@' || *end == '#') {
- /* Multiple delimiters are not allowed */
- if (found_delim != 0) {
- if (why)
- *why = NAME_ERR_MULTIPLE_DELIMITERS;
- return (-1);
- }
-
- found_delim = B_TRUE;
- }
-
- /* Zero-length components are not allowed */
- if (start == end) {
- if (why)
- *why = NAME_ERR_EMPTY_COMPONENT;
- return (-1);
- }
-
- /* If we've reached the end of the string, we're OK */
- if (*end == '\0')
- return (0);
-
- /*
- * If there is a '/' in a snapshot or bookmark name
- * then report an error
- */
- if (*end == '/' && found_delim != 0) {
- if (why)
- *why = NAME_ERR_TRAILING_SLASH;
- return (-1);
- }
-
- /* Update to the next component */
- start = end + 1;
- }
-}
-
-/*
- * Dataset is any entity, except bookmark
- */
-int
-dataset_namecheck(const char *path, namecheck_err_t *why, char *what)
-{
- int ret = entity_namecheck(path, why, what);
-
- if (ret == 0 && strchr(path, '#') != NULL) {
- if (why != NULL) {
- *why = NAME_ERR_INVALCHAR;
- *what = '#';
- }
- return (-1);
- }
-
- return (ret);
-}
-
-/*
- * mountpoint names must be of the following form:
- *
- * /[component][/]*[component][/]
- *
- * Returns 0 on success, -1 on error.
- */
-int
-mountpoint_namecheck(const char *path, namecheck_err_t *why)
-{
- const char *start, *end;
-
- /*
- * Make sure none of the mountpoint component names are too long.
- * If a component name is too long then the mkdir of the mountpoint
- * will fail but then the mountpoint property will be set to a value
- * that can never be mounted. Better to fail before setting the prop.
- * Extra slashes are OK, they will be tossed by the mountpoint mkdir.
- */
-
- if (path == NULL || *path != '/') {
- if (why)
- *why = NAME_ERR_LEADING_SLASH;
- return (-1);
- }
-
- /* Skip leading slash */
- start = &path[1];
- do {
- end = start;
- while (*end != '/' && *end != '\0')
- end++;
-
- if (end - start >= ZFS_MAX_DATASET_NAME_LEN) {
- if (why)
- *why = NAME_ERR_TOOLONG;
- return (-1);
- }
- start = end + 1;
-
- } while (*end != '\0');
-
- return (0);
-}
-
-/*
- * For pool names, we have the same set of valid characters as described in
- * dataset names, with the additional restriction that the pool name must begin
- * with a letter. The pool names 'raidz' and 'mirror' are also reserved names
- * that cannot be used.
- *
- * Returns 0 on success, -1 on error.
- */
-int
-pool_namecheck(const char *pool, namecheck_err_t *why, char *what)
-{
- const char *c;
-
- /*
- * Make sure the name is not too long.
- * If we're creating a pool with version >= SPA_VERSION_DSL_SCRUB (v11)
- * we need to account for additional space needed by the origin ds which
- * will also be snapshotted: "poolname"+"/"+"$ORIGIN"+"@"+"$ORIGIN".
- * Play it safe and enforce this limit even if the pool version is < 11
- * so it can be upgraded without issues.
- */
- if (strlen(pool) >= (ZFS_MAX_DATASET_NAME_LEN - 2 -
- strlen(ORIGIN_DIR_NAME) * 2)) {
- if (why)
- *why = NAME_ERR_TOOLONG;
- return (-1);
- }
-
- c = pool;
- while (*c != '\0') {
- if (!valid_char(*c)) {
- if (why) {
- *why = NAME_ERR_INVALCHAR;
- *what = *c;
- }
- return (-1);
- }
- c++;
- }
-
- if (!(*pool >= 'a' && *pool <= 'z') &&
- !(*pool >= 'A' && *pool <= 'Z')) {
- if (why)
- *why = NAME_ERR_NOLETTER;
- return (-1);
- }
-
- if (strcmp(pool, "mirror") == 0 || strcmp(pool, "raidz") == 0) {
- if (why)
- *why = NAME_ERR_RESERVED;
- return (-1);
- }
-
- if (pool[0] == 'c' && (pool[1] >= '0' && pool[1] <= '9')) {
- if (why)
- *why = NAME_ERR_DISKLIKE;
- return (-1);
- }
-
- return (0);
-}
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.h b/sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.h
deleted file mode 100644
index 527db92b0cfa..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_namecheck.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * Copyright (c) 2013, 2016 by Delphix. All rights reserved.
- */
-
-#ifndef _ZFS_NAMECHECK_H
-#define _ZFS_NAMECHECK_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- NAME_ERR_LEADING_SLASH, /* name begins with leading slash */
- NAME_ERR_EMPTY_COMPONENT, /* name contains an empty component */
- NAME_ERR_TRAILING_SLASH, /* name ends with a slash */
- NAME_ERR_INVALCHAR, /* invalid character found */
- NAME_ERR_MULTIPLE_DELIMITERS, /* multiple '@'/'#' delimiters found */
- NAME_ERR_NOLETTER, /* pool doesn't begin with a letter */
- NAME_ERR_RESERVED, /* entire name is reserved */
- NAME_ERR_DISKLIKE, /* reserved disk name (c[0-9].*) */
- NAME_ERR_TOOLONG, /* name is too long */
- NAME_ERR_NO_AT, /* permission set is missing '@' */
-} namecheck_err_t;
-
-#define ZFS_PERMSET_MAXLEN 64
-
-extern int zfs_max_dataset_nesting;
-
-int get_dataset_depth(const char *);
-int pool_namecheck(const char *, namecheck_err_t *, char *);
-int entity_namecheck(const char *, namecheck_err_t *, char *);
-int dataset_namecheck(const char *, namecheck_err_t *, char *);
-int dataset_nestcheck(const char *);
-int mountpoint_namecheck(const char *, namecheck_err_t *);
-int zfs_component_namecheck(const char *, namecheck_err_t *, char *);
-int permset_namecheck(const char *, namecheck_err_t *, char *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZFS_NAMECHECK_H */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c b/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c
deleted file mode 100644
index ac8da491a9ec..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c
+++ /dev/null
@@ -1,718 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
- * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
- * Copyright (c) 2013, Joyent, Inc. All rights reserved.
- * Copyright (c) 2014 Integros [integros.com]
- */
-
-/* Portions Copyright 2010 Robert Milkowski */
-
-#include <sys/zio.h>
-#include <sys/spa.h>
-#include <sys/u8_textprep.h>
-#include <sys/zfs_acl.h>
-#include <sys/zfs_ioctl.h>
-#include <sys/zfs_znode.h>
-
-#include "zfs_prop.h"
-#include "zfs_deleg.h"
-
-#if defined(_KERNEL)
-#include <sys/systm.h>
-#else
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#endif
-
-static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
-
-/* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
-const char *zfs_userquota_prop_prefixes[] = {
- "userused@",
- "userquota@",
- "groupused@",
- "groupquota@"
-};
-
-zprop_desc_t *
-zfs_prop_get_table(void)
-{
- return (zfs_prop_table);
-}
-
-void
-zfs_prop_init(void)
-{
- static zprop_index_t checksum_table[] = {
- { "on", ZIO_CHECKSUM_ON },
- { "off", ZIO_CHECKSUM_OFF },
- { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 },
- { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 },
- { "sha256", ZIO_CHECKSUM_SHA256 },
- { "noparity", ZIO_CHECKSUM_NOPARITY },
- { "sha512", ZIO_CHECKSUM_SHA512 },
- { "skein", ZIO_CHECKSUM_SKEIN },
-#ifdef illumos
- { "edonr", ZIO_CHECKSUM_EDONR },
-#endif
- { NULL }
- };
-
- static zprop_index_t dedup_table[] = {
- { "on", ZIO_CHECKSUM_ON },
- { "off", ZIO_CHECKSUM_OFF },
- { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
- { "sha256", ZIO_CHECKSUM_SHA256 },
- { "sha256,verify",
- ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
- { "sha512", ZIO_CHECKSUM_SHA512 },
- { "sha512,verify",
- ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
- { "skein", ZIO_CHECKSUM_SKEIN },
- { "skein,verify",
- ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
-#ifdef illumos
- { "edonr,verify",
- ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
-#endif
- { NULL }
- };
-
- static zprop_index_t compress_table[] = {
- { "on", ZIO_COMPRESS_ON },
- { "off", ZIO_COMPRESS_OFF },
- { "lzjb", ZIO_COMPRESS_LZJB },
- { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */
- { "gzip-1", ZIO_COMPRESS_GZIP_1 },
- { "gzip-2", ZIO_COMPRESS_GZIP_2 },
- { "gzip-3", ZIO_COMPRESS_GZIP_3 },
- { "gzip-4", ZIO_COMPRESS_GZIP_4 },
- { "gzip-5", ZIO_COMPRESS_GZIP_5 },
- { "gzip-6", ZIO_COMPRESS_GZIP_6 },
- { "gzip-7", ZIO_COMPRESS_GZIP_7 },
- { "gzip-8", ZIO_COMPRESS_GZIP_8 },
- { "gzip-9", ZIO_COMPRESS_GZIP_9 },
- { "zle", ZIO_COMPRESS_ZLE },
- { "lz4", ZIO_COMPRESS_LZ4 },
- { NULL }
- };
-
- static zprop_index_t snapdir_table[] = {
- { "hidden", ZFS_SNAPDIR_HIDDEN },
- { "visible", ZFS_SNAPDIR_VISIBLE },
- { NULL }
- };
-
- static zprop_index_t acl_mode_table[] = {
- { "discard", ZFS_ACL_DISCARD },
- { "groupmask", ZFS_ACL_GROUPMASK },
- { "passthrough", ZFS_ACL_PASSTHROUGH },
- { "restricted", ZFS_ACL_RESTRICTED },
- { NULL }
- };
-
- static zprop_index_t acl_inherit_table[] = {
- { "discard", ZFS_ACL_DISCARD },
- { "noallow", ZFS_ACL_NOALLOW },
- { "restricted", ZFS_ACL_RESTRICTED },
- { "passthrough", ZFS_ACL_PASSTHROUGH },
- { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
- { "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
- { NULL }
- };
-
- static zprop_index_t case_table[] = {
- { "sensitive", ZFS_CASE_SENSITIVE },
- { "insensitive", ZFS_CASE_INSENSITIVE },
- { "mixed", ZFS_CASE_MIXED },
- { NULL }
- };
-
- static zprop_index_t copies_table[] = {
- { "1", 1 },
- { "2", 2 },
- { "3", 3 },
- { NULL }
- };
-
- /*
- * Use the unique flags we have to send to u8_strcmp() and/or
- * u8_textprep() to represent the various normalization property
- * values.
- */
- static zprop_index_t normalize_table[] = {
- { "none", 0 },
- { "formD", U8_TEXTPREP_NFD },
- { "formKC", U8_TEXTPREP_NFKC },
- { "formC", U8_TEXTPREP_NFC },
- { "formKD", U8_TEXTPREP_NFKD },
- { NULL }
- };
-
- static zprop_index_t version_table[] = {
- { "1", 1 },
- { "2", 2 },
- { "3", 3 },
- { "4", 4 },
- { "5", 5 },
- { "current", ZPL_VERSION },
- { NULL }
- };
-
- static zprop_index_t boolean_table[] = {
- { "off", 0 },
- { "on", 1 },
- { NULL }
- };
-
- static zprop_index_t logbias_table[] = {
- { "latency", ZFS_LOGBIAS_LATENCY },
- { "throughput", ZFS_LOGBIAS_THROUGHPUT },
- { NULL }
- };
-
- static zprop_index_t canmount_table[] = {
- { "off", ZFS_CANMOUNT_OFF },
- { "on", ZFS_CANMOUNT_ON },
- { "noauto", ZFS_CANMOUNT_NOAUTO },
- { NULL }
- };
-
- static zprop_index_t cache_table[] = {
- { "none", ZFS_CACHE_NONE },
- { "metadata", ZFS_CACHE_METADATA },
- { "all", ZFS_CACHE_ALL },
- { NULL }
- };
-
- static zprop_index_t sync_table[] = {
- { "standard", ZFS_SYNC_STANDARD },
- { "always", ZFS_SYNC_ALWAYS },
- { "disabled", ZFS_SYNC_DISABLED },
- { NULL }
- };
-
- static zprop_index_t volmode_table[] = {
- { "default", ZFS_VOLMODE_DEFAULT },
- { "geom", ZFS_VOLMODE_GEOM },
- { "dev", ZFS_VOLMODE_DEV },
- { "none", ZFS_VOLMODE_NONE },
- { NULL }
- };
-
- static zprop_index_t dnsize_table[] = {
- { "legacy", ZFS_DNSIZE_LEGACY },
- { "auto", ZFS_DNSIZE_AUTO },
- { "1k", ZFS_DNSIZE_1K },
- { "2k", ZFS_DNSIZE_2K },
- { "4k", ZFS_DNSIZE_4K },
- { "8k", ZFS_DNSIZE_8K },
- { "16k", ZFS_DNSIZE_16K },
- { NULL }
- };
-
- static zprop_index_t redundant_metadata_table[] = {
- { "all", ZFS_REDUNDANT_METADATA_ALL },
- { "most", ZFS_REDUNDANT_METADATA_MOST },
- { NULL }
- };
-
- /* inherit index properties */
- zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
- ZFS_REDUNDANT_METADATA_ALL,
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "all | most", "REDUND_MD",
- redundant_metadata_table);
- zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "standard | always | disabled", "SYNC",
- sync_table);
- zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
- ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
- ZFS_TYPE_VOLUME,
- "on | off | fletcher2 | fletcher4 | sha256 | sha512 | "
- "skein", "CHECKSUM", checksum_table);
- zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "on | off | verify | sha256[,verify], sha512[,verify], "
- "skein[,verify]", "DEDUP", dedup_table);
- zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
- ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
- "COMPRESS", compress_table);
- zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
- "hidden | visible", "SNAPDIR", snapdir_table);
- zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
- "discard | groupmask | passthrough | restricted", "ACLMODE",
- acl_mode_table);
- zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
- ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
- "discard | noallow | restricted | passthrough | passthrough-x",
- "ACLINHERIT", acl_inherit_table);
- zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "1 | 2 | 3", "COPIES", copies_table);
- zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
- ZFS_CACHE_ALL, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
- "all | none | metadata", "PRIMARYCACHE", cache_table);
- zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
- ZFS_CACHE_ALL, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
- "all | none | metadata", "SECONDARYCACHE", cache_table);
- zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "latency | throughput", "LOGBIAS", logbias_table);
- zprop_register_index(ZFS_PROP_VOLMODE, "volmode",
- ZFS_VOLMODE_DEFAULT, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
- "default | geom | dev | none", "VOLMODE", volmode_table);
-
- zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize",
- ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
- "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table);
-
- /* inherit index (boolean) properties */
- zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
- zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
- boolean_table);
- zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
- boolean_table);
- zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
- boolean_table);
- zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
- boolean_table);
- zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table);
- zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
- boolean_table);
- zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
- boolean_table);
- zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
- boolean_table);
-
- /* default index properties */
- zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
- "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
- zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
- PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
- "CANMOUNT", canmount_table);
-
- /* readonly index (boolean) properties */
- zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
- ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
- zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
- PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
- boolean_table);
-
- /* set once index properties */
- zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
- PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
- "none | formC | formD | formKC | formKD", "NORMALIZATION",
- normalize_table);
- zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
- ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
- ZFS_TYPE_SNAPSHOT,
- "sensitive | insensitive | mixed", "CASE", case_table);
-
- /* set once index (boolean) properties */
- zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
- "on | off", "UTF8ONLY", boolean_table);
-
- /* string properties */
- zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
- zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
- ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
- zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
- "MOUNTPOINT");
- zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
- "SHARENFS");
- zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
- ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
- "filesystem | volume | snapshot | bookmark", "TYPE");
- zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
- PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
- "on | off | sharemgr(1M) options", "SHARESMB");
- zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
- ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
- "<sensitivity label>", "MLSLABEL");
- zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
- "receive_resume_token",
- NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "<string token>", "RESUMETOK");
-
- /* readonly number properties */
- zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
- ZFS_TYPE_DATASET, "<size>", "USED");
- zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
- zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
- PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
- zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
- PROP_READONLY, ZFS_TYPE_DATASET,
- "<1.00x or higher if compressed>", "RATIO");
- zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
- PROP_READONLY, ZFS_TYPE_DATASET,
- "<1.00x or higher if compressed>", "REFRATIO");
- zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
- ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
- ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK");
- zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
- PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
- "USEDSNAP");
- zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
- PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
- "USEDDS");
- zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
- PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
- "USEDCHILD");
- zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
- PROP_READONLY,
- ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
- zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
- ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
- zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
- ZFS_TYPE_DATASET, "<size>", "WRITTEN");
- zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
- PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
- "LUSED");
- zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
- 0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
-
- /* default number properties */
- zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
- ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
- zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
- PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "<size> | none", "RESERV");
- zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
- ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
- zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
- ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
- zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
- PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "<size> | none", "REFRESERV");
- zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
- UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
- "<count> | none", "FSLIMIT");
- zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
- UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "<count> | none", "SSLIMIT");
- zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
- UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
- "<count>", "FSCOUNT");
- zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
- UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
- "<count>", "SSCOUNT");
- zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY,
- ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID");
- zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY,
- ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG");
-
- /* inherit number properties */
- zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
- SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
- ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE");
- zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS,
- "special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
- "zero or 512 to 128K, power of 2", "SPECIAL_SMALL_BLOCKS");
-
- /* hidden properties */
- zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER,
- PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG");
- zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
- PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
- zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
- PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME");
- zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
- PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
- zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
- PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
- "STMF_SBD_LU");
- zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
- PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
- "USERACCOUNTING");
- zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
- PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
- zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
- PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
- zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
- PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
- zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
- PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP");
-
- /* oddball properties */
- zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
- NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
- "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
-}
-
-boolean_t
-zfs_prop_delegatable(zfs_prop_t prop)
-{
- zprop_desc_t *pd = &zfs_prop_table[prop];
-
- /* The mlslabel property is never delegatable. */
- if (prop == ZFS_PROP_MLSLABEL)
- return (B_FALSE);
-
- return (pd->pd_attr != PROP_READONLY);
-}
-
-/*
- * Given a zfs dataset property name, returns the corresponding property ID.
- */
-zfs_prop_t
-zfs_name_to_prop(const char *propname)
-{
- return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
-}
-
-/*
- * For user property names, we allow all lowercase alphanumeric characters, plus
- * a few useful punctuation characters.
- */
-static int
-valid_char(char c)
-{
- return ((c >= 'a' && c <= 'z') ||
- (c >= '0' && c <= '9') ||
- c == '-' || c == '_' || c == '.' || c == ':');
-}
-
-/*
- * Returns true if this is a valid user-defined property (one with a ':').
- */
-boolean_t
-zfs_prop_user(const char *name)
-{
- int i;
- char c;
- boolean_t foundsep = B_FALSE;
-
- for (i = 0; i < strlen(name); i++) {
- c = name[i];
- if (!valid_char(c))
- return (B_FALSE);
- if (c == ':')
- foundsep = B_TRUE;
- }
-
- if (!foundsep)
- return (B_FALSE);
-
- return (B_TRUE);
-}
-
-/*
- * Returns true if this is a valid userspace-type property (one with a '@').
- * Note that after the @, any character is valid (eg, another @, for SID
- * user@domain).
- */
-boolean_t
-zfs_prop_userquota(const char *name)
-{
- zfs_userquota_prop_t prop;
-
- for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
- if (strncmp(name, zfs_userquota_prop_prefixes[prop],
- strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
- return (B_TRUE);
- }
- }
-
- return (B_FALSE);
-}
-
-/*
- * Returns true if this is a valid written@ property.
- * Note that after the @, any character is valid (eg, another @, for
- * written@pool/fs@origin).
- */
-boolean_t
-zfs_prop_written(const char *name)
-{
- static const char *prefix = "written@";
- return (strncmp(name, prefix, strlen(prefix)) == 0);
-}
-
-/*
- * Tables of index types, plus functions to convert between the user view
- * (strings) and internal representation (uint64_t).
- */
-int
-zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
-{
- return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
-}
-
-int
-zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
-{
- return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
-}
-
-uint64_t
-zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
-{
- return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
-}
-
-/*
- * Returns TRUE if the property applies to any of the given dataset types.
- */
-boolean_t
-zfs_prop_valid_for_type(int prop, zfs_type_t types)
-{
- return (zprop_valid_for_type(prop, types));
-}
-
-zprop_type_t
-zfs_prop_get_type(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_proptype);
-}
-
-/*
- * Returns TRUE if the property is readonly.
- */
-boolean_t
-zfs_prop_readonly(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
- zfs_prop_table[prop].pd_attr == PROP_ONETIME);
-}
-
-/*
- * Returns TRUE if the property is visible (not hidden).
- */
-boolean_t
-zfs_prop_visible(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_visible);
-}
-
-/*
- * Returns TRUE if the property is only allowed to be set once.
- */
-boolean_t
-zfs_prop_setonce(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
-}
-
-const char *
-zfs_prop_default_string(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_strdefault);
-}
-
-uint64_t
-zfs_prop_default_numeric(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_numdefault);
-}
-
-/*
- * Given a dataset property ID, returns the corresponding name.
- * Assuming the zfs dataset property ID is valid.
- */
-const char *
-zfs_prop_to_name(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_name);
-}
-
-/*
- * Returns TRUE if the property is inheritable.
- */
-boolean_t
-zfs_prop_inheritable(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
- zfs_prop_table[prop].pd_attr == PROP_ONETIME);
-}
-
-#ifndef _KERNEL
-
-/*
- * Returns a string describing the set of acceptable values for the given
- * zfs property, or NULL if it cannot be set.
- */
-const char *
-zfs_prop_values(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_values);
-}
-
-/*
- * Returns TRUE if this property is a string type. Note that index types
- * (compression, checksum) are treated as strings in userland, even though they
- * are stored numerically on disk.
- */
-int
-zfs_prop_is_string(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
- zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
-}
-
-/*
- * Returns the column header for the given property. Used only in
- * 'zfs list -o', but centralized here with the other property information.
- */
-const char *
-zfs_prop_column_name(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_colname);
-}
-
-/*
- * Returns whether the given property should be displayed right-justified for
- * 'zfs list'.
- */
-boolean_t
-zfs_prop_align_right(zfs_prop_t prop)
-{
- return (zfs_prop_table[prop].pd_rightalign);
-}
-
-#endif
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.h b/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.h
deleted file mode 100644
index e604abda131d..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _ZFS_PROP_H
-#define _ZFS_PROP_H
-
-#include <sys/fs/zfs.h>
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * For index types (e.g. compression and checksum), we want the numeric value
- * in the kernel, but the string value in userland.
- */
-typedef enum {
- PROP_TYPE_NUMBER, /* numeric value */
- PROP_TYPE_STRING, /* string value */
- PROP_TYPE_INDEX /* numeric value indexed by string */
-} zprop_type_t;
-
-typedef enum {
- PROP_DEFAULT,
- PROP_READONLY,
- PROP_INHERIT,
- /*
- * ONETIME properties are a sort of conglomeration of READONLY
- * and INHERIT. They can be set only during object creation,
- * after that they are READONLY. If not explicitly set during
- * creation, they can be inherited.
- */
- PROP_ONETIME
-} zprop_attr_t;
-
-typedef struct zfs_index {
- const char *pi_name;
- uint64_t pi_value;
-} zprop_index_t;
-
-typedef struct {
- const char *pd_name; /* human-readable property name */
- int pd_propnum; /* property number */
- zprop_type_t pd_proptype; /* string, boolean, index, number */
- const char *pd_strdefault; /* default for strings */
- uint64_t pd_numdefault; /* for boolean / index / number */
- zprop_attr_t pd_attr; /* default, readonly, inherit */
- int pd_types; /* bitfield of valid dataset types */
- /* fs | vol | snap; or pool */
- const char *pd_values; /* string telling acceptable values */
- const char *pd_colname; /* column header for "zfs list" */
- boolean_t pd_rightalign; /* column alignment for "zfs list" */
- boolean_t pd_visible; /* do we list this property with the */
- /* "zfs get" help message */
- const zprop_index_t *pd_table; /* for index properties, a table */
- /* defining the possible values */
- size_t pd_table_size; /* number of entries in pd_table[] */
-} zprop_desc_t;
-
-/*
- * zfs dataset property functions
- */
-void zfs_prop_init(void);
-zprop_type_t zfs_prop_get_type(zfs_prop_t);
-boolean_t zfs_prop_delegatable(zfs_prop_t prop);
-zprop_desc_t *zfs_prop_get_table(void);
-
-/*
- * zpool property functions
- */
-void zpool_prop_init(void);
-zprop_type_t zpool_prop_get_type(zpool_prop_t);
-zprop_desc_t *zpool_prop_get_table(void);
-
-/*
- * Common routines to initialize property tables
- */
-void zprop_register_impl(int, const char *, zprop_type_t, uint64_t,
- const char *, zprop_attr_t, int, const char *, const char *,
- boolean_t, boolean_t, const zprop_index_t *);
-void zprop_register_string(int, const char *, const char *,
- zprop_attr_t attr, int, const char *, const char *);
-void zprop_register_number(int, const char *, uint64_t, zprop_attr_t, int,
- const char *, const char *);
-void zprop_register_index(int, const char *, uint64_t, zprop_attr_t, int,
- const char *, const char *, const zprop_index_t *);
-void zprop_register_hidden(int, const char *, zprop_type_t, zprop_attr_t,
- int, const char *);
-
-/*
- * Common routines for zfs and zpool property management
- */
-int zprop_iter_common(zprop_func, void *, boolean_t, boolean_t, zfs_type_t);
-int zprop_name_to_prop(const char *, zfs_type_t);
-int zprop_string_to_index(int, const char *, uint64_t *, zfs_type_t);
-int zprop_index_to_string(int, uint64_t, const char **, zfs_type_t);
-uint64_t zprop_random_value(int, uint64_t, zfs_type_t);
-const char *zprop_values(int, zfs_type_t);
-size_t zprop_width(int, boolean_t *, zfs_type_t);
-boolean_t zprop_valid_for_type(int, zfs_type_t);
-boolean_t zfs_prop_written(const char *name);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZFS_PROP_H */
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zpool_prop.c b/sys/cddl/contrib/opensolaris/common/zfs/zpool_prop.c
deleted file mode 100644
index d17c7fd98043..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zpool_prop.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
- * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
- * Copyright (c) 2014 Integros [integros.com]
- */
-
-#include <sys/zio.h>
-#include <sys/spa.h>
-#include <sys/zfs_acl.h>
-#include <sys/zfs_ioctl.h>
-#include <sys/fs/zfs.h>
-
-#include "zfs_prop.h"
-
-#if defined(_KERNEL)
-#include <sys/systm.h>
-#else
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#endif
-
-static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
-
-zprop_desc_t *
-zpool_prop_get_table(void)
-{
- return (zpool_prop_table);
-}
-
-void
-zpool_prop_init(void)
-{
- static zprop_index_t boolean_table[] = {
- { "off", 0},
- { "on", 1},
- { NULL }
- };
-
- static zprop_index_t failuremode_table[] = {
- { "wait", ZIO_FAILURE_MODE_WAIT },
- { "continue", ZIO_FAILURE_MODE_CONTINUE },
- { "panic", ZIO_FAILURE_MODE_PANIC },
- { NULL }
- };
-
- /* string properties */
- zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
- ZFS_TYPE_POOL, "<path>", "ALTROOT");
- zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
- ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
- zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL,
- PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
- zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL,
- PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT");
-
- /* readonly number properties */
- zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
- ZFS_TYPE_POOL, "<size>", "SIZE");
- zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY,
- ZFS_TYPE_POOL, "<size>", "FREE");
- zprop_register_number(ZPOOL_PROP_FREEING, "freeing", 0, PROP_READONLY,
- ZFS_TYPE_POOL, "<size>", "FREEING");
- zprop_register_number(ZPOOL_PROP_CHECKPOINT, "checkpoint", 0,
- PROP_READONLY, ZFS_TYPE_POOL, "<size>", "CKPOINT");
- zprop_register_number(ZPOOL_PROP_LEAKED, "leaked", 0, PROP_READONLY,
- ZFS_TYPE_POOL, "<size>", "LEAKED");
- zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0,
- PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC");
- zprop_register_number(ZPOOL_PROP_EXPANDSZ, "expandsize", 0,
- PROP_READONLY, ZFS_TYPE_POOL, "<size>", "EXPANDSZ");
- zprop_register_number(ZPOOL_PROP_FRAGMENTATION, "fragmentation", 0,
- PROP_READONLY, ZFS_TYPE_POOL, "<percent>", "FRAG");
- zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
- ZFS_TYPE_POOL, "<size>", "CAP");
- zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
- ZFS_TYPE_POOL, "<guid>", "GUID");
- zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
- ZFS_TYPE_POOL, "<state>", "HEALTH");
- zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0,
- PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>",
- "DEDUP");
-
- /* system partition size */
- zprop_register_number(ZPOOL_PROP_BOOTSIZE, "bootsize", 0, PROP_ONETIME,
- ZFS_TYPE_POOL, "<size>", "BOOTSIZE");
-
- /* default number properties */
- zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
- PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
- zprop_register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0,
- PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO");
-
- /* default index (boolean) properties */
- zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1,
- PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION",
- boolean_table);
- zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0,
- PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
- zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0,
- PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS",
- boolean_table);
- zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0,
- PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
- zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0,
- PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table);
- zprop_register_index(ZPOOL_PROP_MULTIHOST, "multihost", 0,
- PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "MULTIHOST",
- boolean_table);
-
- /* default index properties */
- zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
- ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
- "wait | continue | panic", "FAILMODE", failuremode_table);
-
- /* hidden properties */
- zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
- PROP_READONLY, ZFS_TYPE_POOL, "NAME");
- zprop_register_hidden(ZPOOL_PROP_MAXBLOCKSIZE, "maxblocksize",
- PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXBLOCKSIZE");
- zprop_register_hidden(ZPOOL_PROP_TNAME, "tname", PROP_TYPE_STRING,
- PROP_ONETIME, ZFS_TYPE_POOL, "TNAME");
- zprop_register_hidden(ZPOOL_PROP_MAXDNODESIZE, "maxdnodesize",
- PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXDNODESIZE");
-}
-
-/*
- * Given a property name and its type, returns the corresponding property ID.
- */
-zpool_prop_t
-zpool_name_to_prop(const char *propname)
-{
- return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
-}
-
-/*
- * Given a pool property ID, returns the corresponding name.
- * Assuming the pool propety ID is valid.
- */
-const char *
-zpool_prop_to_name(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_name);
-}
-
-zprop_type_t
-zpool_prop_get_type(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_proptype);
-}
-
-boolean_t
-zpool_prop_readonly(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
-}
-
-const char *
-zpool_prop_default_string(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_strdefault);
-}
-
-uint64_t
-zpool_prop_default_numeric(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_numdefault);
-}
-
-/*
- * Returns true if this is a valid feature@ property.
- */
-boolean_t
-zpool_prop_feature(const char *name)
-{
- static const char *prefix = "feature@";
- return (strncmp(name, prefix, strlen(prefix)) == 0);
-}
-
-/*
- * Returns true if this is a valid unsupported@ property.
- */
-boolean_t
-zpool_prop_unsupported(const char *name)
-{
- static const char *prefix = "unsupported@";
- return (strncmp(name, prefix, strlen(prefix)) == 0);
-}
-
-int
-zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
- uint64_t *index)
-{
- return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
-}
-
-int
-zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
- const char **string)
-{
- return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
-}
-
-uint64_t
-zpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
-{
- return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
-}
-
-#ifndef _KERNEL
-
-const char *
-zpool_prop_values(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_values);
-}
-
-const char *
-zpool_prop_column_name(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_colname);
-}
-
-boolean_t
-zpool_prop_align_right(zpool_prop_t prop)
-{
- return (zpool_prop_table[prop].pd_rightalign);
-}
-#endif
diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zprop_common.c b/sys/cddl/contrib/opensolaris/common/zfs/zprop_common.c
deleted file mode 100644
index ca2e72c5daa4..000000000000
--- a/sys/cddl/contrib/opensolaris/common/zfs/zprop_common.c
+++ /dev/null
@@ -1,430 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * Copyright (c) 2012 by Delphix. All rights reserved.
- */
-
-/*
- * Common routines used by zfs and zpool property management.
- */
-
-#include <sys/zio.h>
-#include <sys/spa.h>
-#include <sys/zfs_acl.h>
-#include <sys/zfs_ioctl.h>
-#include <sys/zfs_znode.h>
-#include <sys/fs/zfs.h>
-
-#include "zfs_prop.h"
-#include "zfs_deleg.h"
-
-#if defined(_KERNEL)
-#include <sys/systm.h>
-#include <sys/libkern.h>
-#else
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#endif
-
-static zprop_desc_t *
-zprop_get_proptable(zfs_type_t type)
-{
- if (type == ZFS_TYPE_POOL)
- return (zpool_prop_get_table());
- else
- return (zfs_prop_get_table());
-}
-
-static int
-zprop_get_numprops(zfs_type_t type)
-{
- if (type == ZFS_TYPE_POOL)
- return (ZPOOL_NUM_PROPS);
- else
- return (ZFS_NUM_PROPS);
-}
-
-void
-zprop_register_impl(int prop, const char *name, zprop_type_t type,
- uint64_t numdefault, const char *strdefault, zprop_attr_t attr,
- int objset_types, const char *values, const char *colname,
- boolean_t rightalign, boolean_t visible, const zprop_index_t *idx_tbl)
-{
- zprop_desc_t *prop_tbl = zprop_get_proptable(objset_types);
- zprop_desc_t *pd;
-
- pd = &prop_tbl[prop];
-
- ASSERT(pd->pd_name == NULL || pd->pd_name == name);
- ASSERT(name != NULL);
- ASSERT(colname != NULL);
-
- pd->pd_name = name;
- pd->pd_propnum = prop;
- pd->pd_proptype = type;
- pd->pd_numdefault = numdefault;
- pd->pd_strdefault = strdefault;
- pd->pd_attr = attr;
- pd->pd_types = objset_types;
- pd->pd_values = values;
- pd->pd_colname = colname;
- pd->pd_rightalign = rightalign;
- pd->pd_visible = visible;
- pd->pd_table = idx_tbl;
- pd->pd_table_size = 0;
- while (idx_tbl && (idx_tbl++)->pi_name != NULL)
- pd->pd_table_size++;
-}
-
-void
-zprop_register_string(int prop, const char *name, const char *def,
- zprop_attr_t attr, int objset_types, const char *values,
- const char *colname)
-{
- zprop_register_impl(prop, name, PROP_TYPE_STRING, 0, def, attr,
- objset_types, values, colname, B_FALSE, B_TRUE, NULL);
-
-}
-
-void
-zprop_register_number(int prop, const char *name, uint64_t def,
- zprop_attr_t attr, int objset_types, const char *values,
- const char *colname)
-{
- zprop_register_impl(prop, name, PROP_TYPE_NUMBER, def, NULL, attr,
- objset_types, values, colname, B_TRUE, B_TRUE, NULL);
-}
-
-void
-zprop_register_index(int prop, const char *name, uint64_t def,
- zprop_attr_t attr, int objset_types, const char *values,
- const char *colname, const zprop_index_t *idx_tbl)
-{
- zprop_register_impl(prop, name, PROP_TYPE_INDEX, def, NULL, attr,
- objset_types, values, colname, B_TRUE, B_TRUE, idx_tbl);
-}
-
-void
-zprop_register_hidden(int prop, const char *name, zprop_type_t type,
- zprop_attr_t attr, int objset_types, const char *colname)
-{
- zprop_register_impl(prop, name, type, 0, NULL, attr,
- objset_types, NULL, colname,
- type == PROP_TYPE_NUMBER, B_FALSE, NULL);
-}
-
-
-/*
- * A comparison function we can use to order indexes into property tables.
- */
-static int
-zprop_compare(const void *arg1, const void *arg2)
-{
- const zprop_desc_t *p1 = *((zprop_desc_t **)arg1);
- const zprop_desc_t *p2 = *((zprop_desc_t **)arg2);
- boolean_t p1ro, p2ro;
-
- p1ro = (p1->pd_attr == PROP_READONLY);
- p2ro = (p2->pd_attr == PROP_READONLY);
-
- if (p1ro == p2ro)
- return (strcmp(p1->pd_name, p2->pd_name));
-
- return (p1ro ? -1 : 1);
-}
-
-/*
- * Iterate over all properties in the given property table, calling back
- * into the specified function for each property. We will continue to
- * iterate until we either reach the end or the callback function returns
- * something other than ZPROP_CONT.
- */
-int
-zprop_iter_common(zprop_func func, void *cb, boolean_t show_all,
- boolean_t ordered, zfs_type_t type)
-{
- int i, j, num_props, size, prop;
- zprop_desc_t *prop_tbl;
- zprop_desc_t **order;
-
- prop_tbl = zprop_get_proptable(type);
- num_props = zprop_get_numprops(type);
- size = num_props * sizeof (zprop_desc_t *);
-
-#if defined(_KERNEL)
- order = kmem_alloc(size, KM_SLEEP);
-#else
- if ((order = malloc(size)) == NULL)
- return (ZPROP_CONT);
-#endif
-
- for (j = 0; j < num_props; j++)
- order[j] = &prop_tbl[j];
-
- if (ordered) {
- qsort((void *)order, num_props, sizeof (zprop_desc_t *),
- zprop_compare);
- }
-
- prop = ZPROP_CONT;
- for (i = 0; i < num_props; i++) {
- if ((order[i]->pd_visible || show_all) &&
- (func(order[i]->pd_propnum, cb) != ZPROP_CONT)) {
- prop = order[i]->pd_propnum;
- break;
- }
- }
-
-#if defined(_KERNEL)
- kmem_free(order, size);
-#else
- free(order);
-#endif
- return (prop);
-}
-
-static boolean_t
-propname_match(const char *p, size_t len, zprop_desc_t *prop_entry)
-{
- const char *propname = prop_entry->pd_name;
-#ifndef _KERNEL
- const char *colname = prop_entry->pd_colname;
- int c;
-#endif
-
- if (len == strlen(propname) &&
- strncmp(p, propname, len) == 0)
- return (B_TRUE);
-
-#ifndef _KERNEL
- if (colname == NULL || len != strlen(colname))
- return (B_FALSE);
-
- for (c = 0; c < len; c++)
- if (p[c] != tolower(colname[c]))
- break;
-
- return (colname[c] == '\0');
-#else
- return (B_FALSE);
-#endif
-}
-
-typedef struct name_to_prop_cb {
- const char *propname;
- zprop_desc_t *prop_tbl;
-} name_to_prop_cb_t;
-
-static int
-zprop_name_to_prop_cb(int prop, void *cb_data)
-{
- name_to_prop_cb_t *data = cb_data;
-
- if (propname_match(data->propname, strlen(data->propname),
- &data->prop_tbl[prop]))
- return (prop);
-
- return (ZPROP_CONT);
-}
-
-int
-zprop_name_to_prop(const char *propname, zfs_type_t type)
-{
- int prop;
- name_to_prop_cb_t cb_data;
-
- cb_data.propname = propname;
- cb_data.prop_tbl = zprop_get_proptable(type);
-
- prop = zprop_iter_common(zprop_name_to_prop_cb, &cb_data,
- B_TRUE, B_FALSE, type);
-
- return (prop == ZPROP_CONT ? ZPROP_INVAL : prop);
-}
-
-int
-zprop_string_to_index(int prop, const char *string, uint64_t *index,
- zfs_type_t type)
-{
- zprop_desc_t *prop_tbl;
- const zprop_index_t *idx_tbl;
- int i;
-
- if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
- return (-1);
-
- ASSERT(prop < zprop_get_numprops(type));
- prop_tbl = zprop_get_proptable(type);
- if ((idx_tbl = prop_tbl[prop].pd_table) == NULL)
- return (-1);
-
- for (i = 0; idx_tbl[i].pi_name != NULL; i++) {
- if (strcmp(string, idx_tbl[i].pi_name) == 0) {
- *index = idx_tbl[i].pi_value;
- return (0);
- }
- }
-
- return (-1);
-}
-
-int
-zprop_index_to_string(int prop, uint64_t index, const char **string,
- zfs_type_t type)
-{
- zprop_desc_t *prop_tbl;
- const zprop_index_t *idx_tbl;
- int i;
-
- if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
- return (-1);
-
- ASSERT(prop < zprop_get_numprops(type));
- prop_tbl = zprop_get_proptable(type);
- if ((idx_tbl = prop_tbl[prop].pd_table) == NULL)
- return (-1);
-
- for (i = 0; idx_tbl[i].pi_name != NULL; i++) {
- if (idx_tbl[i].pi_value == index) {
- *string = idx_tbl[i].pi_name;
- return (0);
- }
- }
-
- return (-1);
-}
-
-/*
- * Return a random valid property value. Used by ztest.
- */
-uint64_t
-zprop_random_value(int prop, uint64_t seed, zfs_type_t type)
-{
- zprop_desc_t *prop_tbl;
- const zprop_index_t *idx_tbl;
-
- ASSERT((uint_t)prop < zprop_get_numprops(type));
- prop_tbl = zprop_get_proptable(type);
- idx_tbl = prop_tbl[prop].pd_table;
-
- if (idx_tbl == NULL)
- return (seed);
-
- return (idx_tbl[seed % prop_tbl[prop].pd_table_size].pi_value);
-}
-
-const char *
-zprop_values(int prop, zfs_type_t type)
-{
- zprop_desc_t *prop_tbl;
-
- ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
- ASSERT(prop < zprop_get_numprops(type));
-
- prop_tbl = zprop_get_proptable(type);
-
- return (prop_tbl[prop].pd_values);
-}
-
-/*
- * Returns TRUE if the property applies to any of the given dataset types.
- */
-boolean_t
-zprop_valid_for_type(int prop, zfs_type_t type)
-{
- zprop_desc_t *prop_tbl;
-
- if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
- return (B_FALSE);
-
- ASSERT(prop < zprop_get_numprops(type));
- prop_tbl = zprop_get_proptable(type);
- return ((prop_tbl[prop].pd_types & type) != 0);
-}
-
-#ifndef _KERNEL
-
-/*
- * Determines the minimum width for the column, and indicates whether it's fixed
- * or not. Only string columns are non-fixed.
- */
-size_t
-zprop_width(int prop, boolean_t *fixed, zfs_type_t type)
-{
- zprop_desc_t *prop_tbl, *pd;
- const zprop_index_t *idx;
- size_t ret;
- int i;
-
- ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
- ASSERT(prop < zprop_get_numprops(type));
-
- prop_tbl = zprop_get_proptable(type);
- pd = &prop_tbl[prop];
-
- *fixed = B_TRUE;
-
- /*
- * Start with the width of the column name.
- */
- ret = strlen(pd->pd_colname);
-
- /*
- * For fixed-width values, make sure the width is large enough to hold
- * any possible value.
- */
- switch (pd->pd_proptype) {
- case PROP_TYPE_NUMBER:
- /*
- * The maximum length of a human-readable number is 5 characters
- * ("20.4M", for example).
- */
- if (ret < 5)
- ret = 5;
- /*
- * 'creation' is handled specially because it's a number
- * internally, but displayed as a date string.
- */
- if (prop == ZFS_PROP_CREATION)
- *fixed = B_FALSE;
- break;
- case PROP_TYPE_INDEX:
- idx = prop_tbl[prop].pd_table;
- for (i = 0; idx[i].pi_name != NULL; i++) {
- if (strlen(idx[i].pi_name) > ret)
- ret = strlen(idx[i].pi_name);
- }
- break;
-
- case PROP_TYPE_STRING:
- *fixed = B_FALSE;
- break;
- }
-
- return (ret);
-}
-
-#endif
diff --git a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
index 8399be770bb0..3d68a68ba819 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
@@ -67,13 +67,15 @@
* on capital-f functions.
*/
#include <sys/errno.h>
+#include <sys/param.h>
+#include <sys/types.h>
#ifndef illumos
#include <sys/time.h>
#endif
#include <sys/stat.h>
-#include <sys/modctl.h>
#include <sys/conf.h>
#include <sys/systm.h>
+#include <sys/endian.h>
#ifdef illumos
#include <sys/ddi.h>
#include <sys/sunddi.h>
@@ -96,7 +98,6 @@
#include <sys/panic.h>
#include <sys/priv_impl.h>
#endif
-#include <sys/policy.h>
#ifdef illumos
#include <sys/cred_impl.h>
#include <sys/procfs_isa.h>
@@ -119,6 +120,7 @@
#include <sys/limits.h>
#include <sys/linker.h>
#include <sys/kdb.h>
+#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/lock.h>
@@ -129,6 +131,13 @@
#include <sys/sx.h>
#include <sys/sysctl.h>
+
+#include <sys/mount.h>
+#undef AT_UID
+#undef AT_GID
+#include <sys/vnode.h>
+#include <sys/cred.h>
+
#include <sys/dtrace_bsd.h>
#include <netinet/in.h>
@@ -299,8 +308,10 @@ static kmutex_t dtrace_meta_lock; /* meta-provider state lock */
#define ipaddr_t in_addr_t
#define mod_modname pathname
#define vuprintf vprintf
+#ifndef crgetzoneid
+#define crgetzoneid(_a) 0
+#endif
#define ttoproc(_a) ((_a)->td_proc)
-#define crgetzoneid(_a) 0
#define SNOCD 0
#define CPU_ON_INTR(_a) 0
@@ -491,7 +502,7 @@ do { \
if ((remp) != NULL) { \
*(remp) = (uintptr_t)(baseaddr) + (basesz) - (addr); \
} \
-_NOTE(CONSTCOND) } while (0)
+} while (0)
/*
diff --git a/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c b/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
index d5be43f0c3d1..4771a67a9f09 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
@@ -35,6 +35,7 @@
#include <sys/atomic.h>
#include <sys/errno.h>
#include <sys/stat.h>
+#include <sys/endian.h>
#include <sys/modctl.h>
#include <sys/conf.h>
#include <sys/systm.h>
@@ -54,6 +55,8 @@
#include <sys/dtrace_impl.h>
#include <sys/sysmacros.h>
#include <sys/proc.h>
+#undef AT_UID
+#undef AT_GID
#include <sys/policy.h>
#ifdef illumos
#include <util/qsort.h>
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/vnode.c b/sys/cddl/contrib/opensolaris/uts/common/fs/vnode.c
deleted file mode 100644
index 6d82470d220a..000000000000
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/vnode.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
- */
-
-/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
-
-/*
- * University Copyright- Copyright (c) 1982, 1986, 1988
- * The Regents of the University of California
- * All Rights Reserved
- *
- * University Acknowledgment- Portions of this document are derived from
- * software developed by the University of California, Berkeley, and its
- * contributors.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/proc.h>
-#include <sys/taskq.h>
-#include <sys/vnode.h>
-
-/* Extensible attribute (xva) routines. */
-
-/*
- * Zero out the structure, set the size of the requested/returned bitmaps,
- * set AT_XVATTR in the embedded vattr_t's va_mask, and set up the pointer
- * to the returned attributes array.
- */
-void
-xva_init(xvattr_t *xvap)
-{
- bzero(xvap, sizeof (xvattr_t));
- xvap->xva_mapsize = XVA_MAPSIZE;
- xvap->xva_magic = XVA_MAGIC;
- xvap->xva_vattr.va_mask = AT_XVATTR;
- xvap->xva_rtnattrmapp = &(xvap->xva_rtnattrmap)[0];
-}
-
-/*
- * If AT_XVATTR is set, returns a pointer to the embedded xoptattr_t
- * structure. Otherwise, returns NULL.
- */
-xoptattr_t *
-xva_getxoptattr(xvattr_t *xvap)
-{
- xoptattr_t *xoap = NULL;
- if (xvap->xva_vattr.va_mask & AT_XVATTR)
- xoap = &xvap->xva_xoptattrs;
- return (xoap);
-}
-
-/*
- * Like vn_rele() except if we are going to call VOP_INACTIVE() then do it
- * asynchronously using a taskq. This can avoid deadlocks caused by re-entering
- * the file system as a result of releasing the vnode. Note, file systems
- * already have to handle the race where the vnode is incremented before the
- * inactive routine is called and does its locking.
- *
- * Warning: Excessive use of this routine can lead to performance problems.
- * This is because taskqs throttle back allocation if too many are created.
- */
-void
-vn_rele_async(vnode_t *vp, taskq_t *taskq)
-{
- VERIFY(vp->v_count > 0);
- if (refcount_release_if_not_last(&vp->v_usecount)) {
- return;
- }
- VERIFY(taskq_dispatch((taskq_t *)taskq,
- (task_func_t *)vrele, vp, TQ_SLEEP) != 0);
-}
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash
deleted file mode 100644
index e558b2a50358..000000000000
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2011 Google, Inc.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash.descrip b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash.descrip
deleted file mode 100644
index f98cb76dfc91..000000000000
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.cityhash.descrip
+++ /dev/null
@@ -1 +0,0 @@
-CITYHASH CHECKSUM FUNCTIONALITY IN ZFS
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz4 b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz4
deleted file mode 100644
index 722cc75f01e9..000000000000
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz4
+++ /dev/null
@@ -1,30 +0,0 @@
-LZ4 - Fast LZ compression algorithm
-Copyright (C) 2011-2013, Yann Collet.
-BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-You can contact the author at :
-- LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
-- LZ4 source repository : http://code.google.com/p/lz4/
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz4.descrip b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz4.descrip
deleted file mode 100644
index 211f679b5749..000000000000
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/THIRDPARTYLICENSE.lz4.descrip
+++ /dev/null
@@ -1 +0,0 @@
-LZ4 COMPRESSION FUNCTIONALITY IN ZFS
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/abd.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/abd.c
deleted file mode 100644
index 1843c8161038..000000000000
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/abd.c
+++ /dev/null
@@ -1,960 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source. A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright (c) 2014 by Chunwei Chen. All rights reserved.
- * Copyright (c) 2016 by Delphix. All rights reserved.
- */
-
-/*
- * ARC buffer data (ABD).
- *
- * ABDs are an abstract data structure for the ARC which can use two
- * different ways of storing the underlying data:
- *
- * (a) Linear buffer. In this case, all the data in the ABD is stored in one
- * contiguous buffer in memory (from a zio_[data_]buf_* kmem cache).
- *
- * +-------------------+
- * | ABD (linear) |
- * | abd_flags = ... |
- * | abd_size = ... | +--------------------------------+
- * | abd_buf ------------->| raw buffer of size abd_size |
- * +-------------------+ +--------------------------------+
- * no abd_chunks
- *
- * (b) Scattered buffer. In this case, the