--- old/exception_lists/copyright	Fri Nov 22 15:19:10 2013
+++ new/exception_lists/copyright	Fri Nov 22 15:19:10 2013
@@ -334,6 +334,8 @@
 usr/src/lib/krb5/ss/utils.c
 usr/src/lib/librstp/common/*.[ch]
 usr/src/lib/librstp/common/[CRT]*
+usr/src/test/zfs-tests/tests/functional/history/*Z
+usr/src/test/zfs-tests/tests/functional/history/*txt
 usr/src/uts/intel/nsmb/ioc_check.ref
 usr/src/uts/intel/os/splashimage.xpm
 usr/src/uts/common/gssapi/mechs/krb5/crypto/block_size.c
--- old/exception_lists/keywords	Fri Nov 22 15:19:11 2013
+++ new/exception_lists/keywords	Fri Nov 22 15:19:11 2013
@@ -20,6 +20,7 @@
 #
 # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
 # Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+# Copyright (c) 2013 by Delphix. All rights reserved.
 #
 
 syntax: glob
@@ -32,4 +33,5 @@
 usr/src/cmd/terminfo/terminfo.src
 usr/src/cmd/zonestat/zonestat/zonestat.c
 usr/src/test/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v15.dat.bz2
+usr/src/test/zfs-tests/tests/functional/delegate/delegate_common.kshlib
 usr/src/test/test-runner/cmd/run.py
--- old/usr/src/cmd/zfs/zfs_main.c	Fri Nov 22 15:19:12 2013
+++ new/usr/src/cmd/zfs/zfs_main.c	Fri Nov 22 15:19:12 2013
@@ -2137,7 +2137,7 @@
 	USTYPE_SMB_USR,
 	USTYPE_ALL
 };
-static char *us_type_names[] = { "posixgroup", "posxiuser", "smbgroup",
+static char *us_type_names[] = { "posixgroup", "posixuser", "smbgroup",
 	"smbuser", "all" };
 
 typedef struct us_node {
--- old/usr/src/pkg/manifests/system-test-zfstest.mf	Fri Nov 22 15:19:13 2013
+++ new/usr/src/pkg/manifests/system-test-zfstest.mf	Fri Nov 22 15:19:13 2013
@@ -31,6 +31,9 @@
 dir path=opt/zfs-tests/tests/functional/acl/trivial
 dir path=opt/zfs-tests/tests/functional/atime
 dir path=opt/zfs-tests/tests/functional/bootfs
+dir path=opt/zfs-tests/tests/functional/cache
+dir path=opt/zfs-tests/tests/functional/cachefile
+dir path=opt/zfs-tests/tests/functional/clean_mirror
 dir path=opt/zfs-tests/tests/functional/cli_root
 dir path=opt/zfs-tests/tests/functional/cli_root/zdb
 dir path=opt/zfs-tests/tests/functional/cli_root/zfs
@@ -76,8 +79,64 @@
 dir path=opt/zfs-tests/tests/functional/cli_root/zpool_status
 dir path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade
 dir path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/blockfiles
+dir path=opt/zfs-tests/tests/functional/cli_user
+dir path=opt/zfs-tests/tests/functional/cli_user/misc
+dir path=opt/zfs-tests/tests/functional/cli_user/zfs_list
+dir path=opt/zfs-tests/tests/functional/cli_user/zpool_iostat
+dir path=opt/zfs-tests/tests/functional/cli_user/zpool_list
+dir path=opt/zfs-tests/tests/functional/compression
+dir path=opt/zfs-tests/tests/functional/ctime
+dir path=opt/zfs-tests/tests/functional/delegate
+dir path=opt/zfs-tests/tests/functional/devices
+dir path=opt/zfs-tests/tests/functional/exec
+dir path=opt/zfs-tests/tests/functional/features
+dir path=opt/zfs-tests/tests/functional/features/async_destroy
+dir path=opt/zfs-tests/tests/functional/grow_pool
+dir path=opt/zfs-tests/tests/functional/grow_replicas
+dir path=opt/zfs-tests/tests/functional/history
+dir path=opt/zfs-tests/tests/functional/inheritance
+dir path=opt/zfs-tests/tests/functional/interop
+dir path=opt/zfs-tests/tests/functional/inuse
+dir path=opt/zfs-tests/tests/functional/large_files
+dir path=opt/zfs-tests/tests/functional/largest_pool
+dir path=opt/zfs-tests/tests/functional/link_count
+dir path=opt/zfs-tests/tests/functional/mdb
+dir path=opt/zfs-tests/tests/functional/migration
+dir path=opt/zfs-tests/tests/functional/mmap
+dir path=opt/zfs-tests/tests/functional/mount
+dir path=opt/zfs-tests/tests/functional/mv_files
+dir path=opt/zfs-tests/tests/functional/nestedfs
+dir path=opt/zfs-tests/tests/functional/no_space
 dir path=opt/zfs-tests/tests/functional/nopwrite
+dir path=opt/zfs-tests/tests/functional/online_offline
+dir path=opt/zfs-tests/tests/functional/pool_names
+dir path=opt/zfs-tests/tests/functional/poolversion
+dir path=opt/zfs-tests/tests/functional/privilege
+dir path=opt/zfs-tests/tests/functional/quota
+dir path=opt/zfs-tests/tests/functional/redundancy
+dir path=opt/zfs-tests/tests/functional/refquota
+dir path=opt/zfs-tests/tests/functional/refreserv
+dir path=opt/zfs-tests/tests/functional/rename_dirs
+dir path=opt/zfs-tests/tests/functional/replacement
+dir path=opt/zfs-tests/tests/functional/reservation
+dir path=opt/zfs-tests/tests/functional/rootpool
+dir path=opt/zfs-tests/tests/functional/rsend
+dir path=opt/zfs-tests/tests/functional/scrub_mirror
+dir path=opt/zfs-tests/tests/functional/slog
+dir path=opt/zfs-tests/tests/functional/snapshot
+dir path=opt/zfs-tests/tests/functional/snapused
+dir path=opt/zfs-tests/tests/functional/sparse
+dir path=opt/zfs-tests/tests/functional/threadsappend
 dir path=opt/zfs-tests/tests/functional/truncate
+dir path=opt/zfs-tests/tests/functional/userquota
+dir path=opt/zfs-tests/tests/functional/utils_test
+dir path=opt/zfs-tests/tests/functional/write_dirs
+dir path=opt/zfs-tests/tests/functional/xattr
+dir path=opt/zfs-tests/tests/functional/zvol
+dir path=opt/zfs-tests/tests/functional/zvol/zvol_ENOSPC
+dir path=opt/zfs-tests/tests/functional/zvol/zvol_cli
+dir path=opt/zfs-tests/tests/functional/zvol/zvol_misc
+dir path=opt/zfs-tests/tests/functional/zvol/zvol_swap
 file path=opt/zfs-tests/README mode=0444
 file path=opt/zfs-tests/bin/chg_usr_exec mode=0555
 file path=opt/zfs-tests/bin/devname2devid mode=0555
@@ -241,6 +300,41 @@
 file path=opt/zfs-tests/tests/functional/bootfs/bootfs_006_pos mode=0555
 file path=opt/zfs-tests/tests/functional/bootfs/bootfs_007_neg mode=0555
 file path=opt/zfs-tests/tests/functional/bootfs/bootfs_008_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_004_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_005_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_007_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_008_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_009_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_010_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cache_011_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cache/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cache/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cachefile/cachefile.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/cachefile/cachefile.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/cachefile/cachefile_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cachefile/cachefile_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cachefile/cachefile_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/cachefile/cachefile_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/clean_mirror/clean_mirror_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/clean_mirror/clean_mirror_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/clean_mirror/clean_mirror_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/clean_mirror/clean_mirror_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/clean_mirror/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/clean_mirror/default.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/clean_mirror/setup mode=0555
 file path=opt/zfs-tests/tests/functional/cli_root/cli_common.kshlib mode=0555
 file path=opt/zfs-tests/tests/functional/cli_root/zdb/zdb_001_neg mode=0555
 file path=opt/zfs-tests/tests/functional/cli_root/zfs/cleanup mode=0555
@@ -1383,6 +1477,345 @@
 file \
     path=opt/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_009_neg \
     mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/misc.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zdb_001_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_001_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_clone_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_create_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_destroy_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_get_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_inherit_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_mount_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_promote_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_receive_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_rename_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_rollback_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_send_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_set_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_snapshot_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_unallow_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_unmount_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zfs_upgrade_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_001_neg mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_add_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_attach_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_clear_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_create_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_destroy_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_detach_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_export_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_get_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_history_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_import_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_import_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_offline_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_online_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_remove_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_replace_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_scrub_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_set_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_status_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/misc/zpool_upgrade_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/setup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_007_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_008_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zpool_iostat/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zpool_iostat/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_001_neg \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_002_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zpool_list/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/cli_user/zpool_list/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_001_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/compression/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/compression/compress.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/compression/compress_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/compression/compress_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/compression/compress_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/compression/compress_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/compression/setup mode=0555
+file path=opt/zfs-tests/tests/functional/ctime/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/ctime/ctime_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/ctime/setup mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/delegate.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/delegate_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/setup mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_009_neg mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_010_pos mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_011_neg mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_allow_012_neg mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_007_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/delegate/zfs_unallow_008_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/devices/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/devices/devices.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/devices/devices_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/devices/devices_002_neg mode=0555
+file path=opt/zfs-tests/tests/functional/devices/devices_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/devices/devices_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/devices/setup mode=0555
+file path=opt/zfs-tests/tests/functional/exec/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/exec/exec_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/exec/exec_002_neg mode=0555
+file path=opt/zfs-tests/tests/functional/exec/mmap_exec mode=0555
+file path=opt/zfs-tests/tests/functional/exec/setup mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/features/async_destroy/cleanup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/features/async_destroy/setup \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/grow_pool/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/grow_pool/grow_pool.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/grow_pool/grow_pool_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/grow_pool/setup mode=0555
+file path=opt/zfs-tests/tests/functional/grow_replicas/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/grow_replicas/grow_replicas.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/grow_replicas/grow_replicas_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/grow_replicas/setup mode=0555
+file path=opt/zfs-tests/tests/functional/history/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/history/history.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_005_neg mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_006_neg mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_009_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_010_pos mode=0555
+file path=opt/zfs-tests/tests/functional/history/history_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/history/i386.migratedpool.DAT.Z \
+    mode=0444
+file path=opt/zfs-tests/tests/functional/history/i386.orig_history.txt \
+    mode=0444
+file path=opt/zfs-tests/tests/functional/history/setup mode=0555
+file path=opt/zfs-tests/tests/functional/history/sparc.migratedpool.DAT.Z \
+    mode=0444
+file path=opt/zfs-tests/tests/functional/history/sparc.orig_history.txt \
+    mode=0444
+file path=opt/zfs-tests/tests/functional/history/zfs-pool-v4.dat.Z mode=0444
+file path=opt/zfs-tests/tests/functional/inheritance/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config001.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config002.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config003.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config004.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config005.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config006.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config007.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config008.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config009.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config010.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config011.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config012.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config013.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config014.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config015.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config016.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config017.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config018.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config019.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config020.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config021.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config022.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config023.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/config024.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/inherit.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/inherit_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state001.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state002.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state003.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state004.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state005.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state006.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state007.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state008.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state009.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state010.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state011.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state012.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state013.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state014.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state015.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state016.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state017.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state018.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state019.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state020.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state021.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state022.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state023.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inheritance/state024.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/interop/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/interop/interop.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/interop/interop_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/interop/setup mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/inuse_009_pos mode=0555
+file path=opt/zfs-tests/tests/functional/inuse/setup mode=0555
+file path=opt/zfs-tests/tests/functional/large_files/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/large_files/large_files_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/large_files/setup mode=0555
+file path=opt/zfs-tests/tests/functional/largest_pool/largest_pool.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/link_count/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/link_count/link_count_001 mode=0555
+file path=opt/zfs-tests/tests/functional/link_count/setup mode=0555
+file path=opt/zfs-tests/tests/functional/mdb/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/mdb/mdb_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/mdb/setup mode=0555
+file path=opt/zfs-tests/tests/functional/migration/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_009_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_010_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_011_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/migration_012_pos mode=0555
+file path=opt/zfs-tests/tests/functional/migration/setup mode=0555
+file path=opt/zfs-tests/tests/functional/mmap/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/mmap/mmap_read_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/mmap/mmap_write_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/mmap/setup mode=0555
+file path=opt/zfs-tests/tests/functional/mount/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/mount/setup mode=0555
+file path=opt/zfs-tests/tests/functional/mount/umount_001 mode=0555
+file path=opt/zfs-tests/tests/functional/mount/umountall_001 mode=0555
+file path=opt/zfs-tests/tests/functional/mv_files/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/mv_files/mv_files.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/mv_files/mv_files_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/mv_files/mv_files_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/mv_files/setup mode=0555
+file path=opt/zfs-tests/tests/functional/nestedfs/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/nestedfs/nestedfs_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/nestedfs/setup mode=0555
+file path=opt/zfs-tests/tests/functional/no_space/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/no_space/enospc.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/no_space/enospc_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/no_space/setup mode=0555
 file path=opt/zfs-tests/tests/functional/nopwrite/cleanup mode=0555
 file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite.shlib mode=0555
 file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_copies mode=0555
@@ -1396,11 +1829,335 @@
     mode=0555
 file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_volume mode=0555
 file path=opt/zfs-tests/tests/functional/nopwrite/setup mode=0555
+file path=opt/zfs-tests/tests/functional/online_offline/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/online_offline/online_offline.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/online_offline/online_offline_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/online_offline/online_offline_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/online_offline/online_offline_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/online_offline/setup mode=0555
+file path=opt/zfs-tests/tests/functional/pool_names/pool_names_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/pool_names/pool_names_002_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/poolversion/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/poolversion/poolversion_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/poolversion/poolversion_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/poolversion/setup mode=0555
+file path=opt/zfs-tests/tests/functional/privilege/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/privilege/privilege_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/privilege/privilege_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/privilege/setup mode=0555
+file path=opt/zfs-tests/tests/functional/quota/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/quota/quota_006_neg mode=0555
+file path=opt/zfs-tests/tests/functional/quota/setup mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/redundancy.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/redundancy.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/redundancy_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/redundancy_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/redundancy_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/redundancy_004_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/redundancy/setup mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/refquota_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/refquota_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/refquota_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/refquota_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/refquota_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/refquota_006_neg mode=0555
+file path=opt/zfs-tests/tests/functional/refquota/setup mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/refreserv.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/refreserv_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/refreserv_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/refreserv_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/refreserv_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/refreserv_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/refreserv/setup mode=0555
+file path=opt/zfs-tests/tests/functional/rename_dirs/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/rename_dirs/rename_dirs_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/rename_dirs/setup mode=0555
+file path=opt/zfs-tests/tests/functional/replacement/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/replacement/replacement.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/replacement/replacement_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/replacement/replacement_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/replacement/replacement_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/replacement/setup mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation.shlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_007_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_008_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_009_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_010_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_011_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_012_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_013_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_014_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_015_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_016_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_017_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/reservation_018_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/reservation/setup mode=0555
+file path=opt/zfs-tests/tests/functional/rootpool/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/rootpool/rootpool_002_neg mode=0555
+file path=opt/zfs-tests/tests/functional/rootpool/rootpool_003_neg mode=0555
+file path=opt/zfs-tests/tests/functional/rootpool/rootpool_007_neg mode=0555
+file path=opt/zfs-tests/tests/functional/rootpool/setup mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_009_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_010_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_011_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_012_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/rsend_013_pos mode=0555
+file path=opt/zfs-tests/tests/functional/rsend/setup mode=0555
+file path=opt/zfs-tests/tests/functional/scrub_mirror/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/scrub_mirror/default.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_004_pos \
+    mode=0555
+file \
+    path=opt/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/scrub_mirror/setup mode=0555
+file path=opt/zfs-tests/tests/functional/slog/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/slog/setup mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_008_neg mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_009_neg mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_010_neg mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_011_neg mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_012_neg mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_013_pos mode=0555
+file path=opt/zfs-tests/tests/functional/slog/slog_014_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/clone_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/rollback_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/rollback_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/rollback_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/setup mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_009_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_010_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_011_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_012_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_013_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_014_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_015_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_016_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapshot/snapshot_017_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/setup mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/snapused.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/snapused_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/snapused_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/snapused_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/snapused_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/snapused/snapused_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/sparse/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/sparse/setup mode=0555
+file path=opt/zfs-tests/tests/functional/sparse/sparse.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/sparse/sparse_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/threadsappend/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/threadsappend/setup mode=0555
+file path=opt/zfs-tests/tests/functional/threadsappend/threadsappend mode=0555
+file path=opt/zfs-tests/tests/functional/threadsappend/threadsappend_001_pos \
+    mode=0555
 file path=opt/zfs-tests/tests/functional/truncate/cleanup mode=0555
 file path=opt/zfs-tests/tests/functional/truncate/setup mode=0555
 file path=opt/zfs-tests/tests/functional/truncate/truncate.cfg mode=0555
 file path=opt/zfs-tests/tests/functional/truncate/truncate_001_pos mode=0555
 file path=opt/zfs-tests/tests/functional/truncate/truncate_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/groupspace_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/groupspace_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/setup mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_003_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_005_neg mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_007_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_009_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_010_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_011_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_012_neg mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userquota_common.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userspace_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/userquota/userspace_002_pos mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/setup mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test.kshlib \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_007_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_008_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/utils_test/utils_test_009_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/write_dirs/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/write_dirs/setup mode=0555
+file path=opt/zfs-tests/tests/functional/write_dirs/write_dirs_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/write_dirs/write_dirs_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/setup mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_001_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_002_neg mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_003_neg mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_004_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_005_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_006_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_007_neg mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_008_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_009_neg mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_010_neg mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_011_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_012_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_013_pos mode=0555
+file path=opt/zfs-tests/tests/functional/xattr/xattr_common.kshlib mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol.cfg mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_ENOSPC/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_ENOSPC/setup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_cli/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_cli/setup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_common.shlib mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/setup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_001_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_003_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_005_neg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_006_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/cleanup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/setup mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap.cfg \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_001_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_002_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_003_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos \
+    mode=0555
+file path=opt/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_006_pos \
+    mode=0555
 license cr_Sun license=cr_Sun
 license lic_CDDL license=lic_CDDL
 depend fmri=system/file-system/zfs/tests type=require
--- old/usr/src/test/test-runner/cmd/run.py	Fri Nov 22 15:19:14 2013
+++ new/usr/src/test/test-runner/cmd/run.py	Fri Nov 22 15:19:14 2013
@@ -12,7 +12,7 @@
 #
 
 #
-# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright (c) 2013 by Delphix. All rights reserved.
 #
 
 import ConfigParser
@@ -234,7 +234,8 @@
         if logger is None:
             return
 
-        user = ' (run as %s)' % self.user if len(self.user) else ''
+        logname = getpwuid(os.getuid()).pw_name
+        user = ' (run as %s)' % (self.user if len(self.user) else logname)
         msga = 'Test: %s%s ' % (self.pathname, user)
         msgb = '[%s] [%s]' % (self.result.runtime, self.result.result)
         pad = ' ' * (80 - (len(msga) + len(msgb)))
--- old/usr/src/test/zfs-tests/include/commands.cfg	Fri Nov 22 15:19:15 2013
+++ new/usr/src/test/zfs-tests/include/commands.cfg	Fri Nov 22 15:19:15 2013
@@ -10,7 +10,7 @@
 #
 
 #
-# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright (c) 2013 by Delphix. All rights reserved.
 #
 
 export ARP="/usr/sbin/arp"
@@ -141,6 +141,7 @@
 export UFSRESTORE="/usr/sbin/ufsrestore"
 export UMASK="/usr/bin/umask"
 export UMOUNT="/usr/sbin/umount"
+export UMOUNTALL="/usr/sbin/umountall"
 export UNAME="/usr/bin/uname"
 export UNCOMPRESS="/usr/bin/uncompress"
 export UNIQ="/usr/bin/uniq"
--- old/usr/src/test/zfs-tests/include/libtest.shlib	Fri Nov 22 15:19:16 2013
+++ new/usr/src/test/zfs-tests/include/libtest.shlib	Fri Nov 22 15:19:16 2013
@@ -25,7 +25,7 @@
 #
 
 #
-# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright (c) 2013 by Delphix. All rights reserved.
 #
 
 . ${STF_TOOLS}/contrib/include/logapi.shlib
@@ -2568,4 +2568,20 @@
 	else
 		return 0
 	fi
+}
+
+# Utility function to determine if a system has multiple cpus.
+function is_mp
+{
+	(($(psrinfo -p) > 1))
+}
+
+# Run the given command as the user provided.
+function user_run
+{
+	typeset user=$1
+	shift
+
+	eval \$SU \$user -c \"$@\" > /tmp/out 2>/tmp/err
+	return $?
 }
--- old/usr/src/test/zfs-tests/runfiles/delphix.run	Fri Nov 22 15:19:17 2013
+++ new/usr/src/test/zfs-tests/runfiles/delphix.run	Fri Nov 22 15:19:17 2013
@@ -55,11 +55,27 @@
 tests = ['atime_001_pos', 'atime_002_neg']
 
 [/opt/zfs-tests/tests/functional/bootfs]
-tests = ['bootfs_001_pos', 'bootfs_002_neg', 'bootfs_003_pos', 'bootfs_004_neg',
-    'bootfs_005_neg', 'bootfs_006_pos', 'bootfs_007_neg', 'bootfs_008_neg']
+tests = ['bootfs_001_pos', 'bootfs_002_neg', 'bootfs_003_pos',
+    'bootfs_004_neg', 'bootfs_005_neg', 'bootfs_006_pos', 'bootfs_007_neg',
+    'bootfs_008_neg']
 pre =
 post =
 
+[/opt/zfs-tests/tests/functional/cache]
+tests = ['cache_001_pos', 'cache_002_pos', 'cache_003_pos', 'cache_004_neg',
+    'cache_005_neg', 'cache_006_pos', 'cache_007_neg', 'cache_008_neg',
+    'cache_009_pos', 'cache_010_neg', 'cache_011_pos']
+
+[/opt/zfs-tests/tests/functional/cachefile]
+tests = ['cachefile_001_pos', 'cachefile_002_pos', 'cachefile_003_pos',
+    'cachefile_004_pos']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/clean_mirror]
+tests = [ 'clean_mirror_001_pos', 'clean_mirror_002_pos',
+    'clean_mirror_003_pos', 'clean_mirror_004_pos']
+
 [/opt/zfs-tests/tests/functional/cli_root/zdb]
 tests = ['zdb_001_neg']
 pre =
@@ -117,7 +133,7 @@
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_receive]
 tests = ['zfs_receive_001_pos', 'zfs_receive_002_pos', 'zfs_receive_003_pos',
-    'zfs_receive_004_neg', 'zfs_receive_005_neg', 'zfs_receive_006_pos',
+    'zfs_receive_005_neg', 'zfs_receive_006_pos',
     'zfs_receive_007_neg', 'zfs_receive_008_pos', 'zfs_receive_009_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_rename]
@@ -131,8 +147,8 @@
 tests = ['zfs_reservation_001_pos', 'zfs_reservation_002_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_rollback]
-tests = ['zfs_rollback_001_pos', 'zfs_rollback_002_pos', 'zfs_rollback_003_neg',
-    'zfs_rollback_004_neg']
+tests = ['zfs_rollback_001_pos', 'zfs_rollback_002_pos',
+    'zfs_rollback_003_neg', 'zfs_rollback_004_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_send]
 tests = ['zfs_send_001_pos', 'zfs_send_002_pos', 'zfs_send_003_pos',
@@ -156,9 +172,10 @@
     'zfs_share_010_neg', 'zfs_share_011_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_snapshot]
-tests = ['zfs_snapshot_001_neg', 'zfs_snapshot_002_neg', 'zfs_snapshot_003_neg',
-    'zfs_snapshot_004_neg', 'zfs_snapshot_005_neg', 'zfs_snapshot_006_pos',
-    'zfs_snapshot_007_neg', 'zfs_snapshot_008_neg', 'zfs_snapshot_009_pos']
+tests = ['zfs_snapshot_001_neg', 'zfs_snapshot_002_neg',
+    'zfs_snapshot_003_neg', 'zfs_snapshot_004_neg', 'zfs_snapshot_005_neg',
+    'zfs_snapshot_006_pos', 'zfs_snapshot_007_neg', 'zfs_snapshot_008_neg',
+    'zfs_snapshot_009_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_unmount]
 tests = ['zfs_unmount_001_pos', 'zfs_unmount_002_pos', 'zfs_unmount_003_pos',
@@ -190,14 +207,14 @@
 tests = ['zpool_clear_001_pos', 'zpool_clear_002_neg', 'zpool_clear_003_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_create]
-tests = ['zpool_create_001_pos', 'zpool_create_002_pos', 'zpool_create_003_pos',
-    'zpool_create_004_pos', 'zpool_create_005_pos', 'zpool_create_006_pos',
-    'zpool_create_007_neg', 'zpool_create_008_pos', 'zpool_create_009_neg',
-    'zpool_create_010_neg', 'zpool_create_011_neg', 'zpool_create_012_neg',
-    'zpool_create_013_neg', 'zpool_create_014_neg', 'zpool_create_015_neg',
-    'zpool_create_016_pos', 'zpool_create_017_neg', 'zpool_create_018_pos',
-    'zpool_create_019_pos', 'zpool_create_020_pos', 'zpool_create_021_pos',
-    'zpool_create_022_pos', 'zpool_create_023_neg',
+tests = ['zpool_create_001_pos', 'zpool_create_002_pos',
+    'zpool_create_003_pos', 'zpool_create_004_pos', 'zpool_create_005_pos',
+    'zpool_create_006_pos', 'zpool_create_007_neg', 'zpool_create_008_pos',
+    'zpool_create_009_neg', 'zpool_create_010_neg', 'zpool_create_011_neg',
+    'zpool_create_012_neg', 'zpool_create_013_neg', 'zpool_create_014_neg',
+    'zpool_create_015_neg', 'zpool_create_016_pos', 'zpool_create_017_neg',
+    'zpool_create_018_pos', 'zpool_create_019_pos', 'zpool_create_020_pos',
+    'zpool_create_021_pos', 'zpool_create_022_pos', 'zpool_create_023_neg',
     'zpool_create_features_001_pos', 'zpool_create_features_002_pos',
     'zpool_create_features_003_pos', 'zpool_create_features_004_neg']
 
@@ -211,11 +228,12 @@
 tests = ['zpool_detach_001_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_expand]
-tests = ['zpool_expand_001_pos', 'zpool_expand_002_pos', 'zpool_expand_003_neg']
+tests = ['zpool_expand_001_pos', 'zpool_expand_002_pos',
+    'zpool_expand_003_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_export]
-tests = ['zpool_export_001_pos', 'zpool_export_002_pos', 'zpool_export_003_neg',
-    'zpool_export_004_pos']
+tests = ['zpool_export_001_pos', 'zpool_export_002_pos',
+    'zpool_export_003_neg', 'zpool_export_004_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_get]
 tests = ['zpool_get_001_pos', 'zpool_get_002_pos', 'zpool_get_003_pos',
@@ -225,11 +243,11 @@
 tests = ['zpool_history_001_neg', 'zpool_history_002_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_import]
-tests = ['zpool_import_001_pos', 'zpool_import_002_pos', 'zpool_import_003_pos',
-    'zpool_import_004_pos', 'zpool_import_005_pos', 'zpool_import_006_pos',
-    'zpool_import_007_pos', 'zpool_import_008_pos', 'zpool_import_009_neg',
-    'zpool_import_010_pos', 'zpool_import_011_neg', 'zpool_import_012_pos',
-    'zpool_import_013_neg', 'zpool_import_all_001_pos',
+tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
+    'zpool_import_003_pos', 'zpool_import_004_pos', 'zpool_import_005_pos',
+    'zpool_import_006_pos', 'zpool_import_007_pos', 'zpool_import_008_pos',
+    'zpool_import_009_neg', 'zpool_import_010_pos', 'zpool_import_011_neg',
+    'zpool_import_012_pos', 'zpool_import_013_neg', 'zpool_import_all_001_pos',
     'zpool_import_features_001_pos', 'zpool_import_features_002_neg',
     'zpool_import_features_003_pos', 'zpool_import_missing_001_pos',
     'zpool_import_missing_002_pos', 'zpool_import_missing_003_pos',
@@ -242,7 +260,8 @@
 tests = ['zpool_online_001_pos', 'zpool_online_002_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_remove]
-tests = ['zpool_remove_001_neg', 'zpool_remove_002_pos', 'zpool_remove_003_pos']
+tests = ['zpool_remove_001_neg', 'zpool_remove_002_pos',
+    'zpool_remove_003_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_replace]
 tests = ['zpool_replace_001_neg']
@@ -265,10 +284,243 @@
     'zpool_upgrade_006_neg', 'zpool_upgrade_007_pos', 'zpool_upgrade_008_pos',
     'zpool_upgrade_009_neg']
 
-[/opt/zfs-tests/tests/functional/truncate]
-tests = ['truncate_001_pos', 'truncate_002_pos']
+[/opt/zfs-tests/tests/functional/cli_user/misc]
+tests = ['zdb_001_neg', 'zfs_001_neg', 'zfs_allow_001_neg',
+    'zfs_clone_001_neg', 'zfs_create_001_neg', 'zfs_destroy_001_neg',
+    'zfs_get_001_neg', 'zfs_inherit_001_neg', 'zfs_mount_001_neg',
+    'zfs_promote_001_neg', 'zfs_receive_001_neg', 'zfs_rename_001_neg',
+    'zfs_rollback_001_neg', 'zfs_send_001_neg', 'zfs_set_001_neg',
+    'zfs_share_001_neg', 'zfs_snapshot_001_neg', 'zfs_unallow_001_neg',
+    'zfs_unmount_001_neg', 'zfs_unshare_001_neg', 'zfs_upgrade_001_neg',
+    'zpool_001_neg', 'zpool_add_001_neg', 'zpool_attach_001_neg',
+    'zpool_clear_001_neg', 'zpool_create_001_neg', 'zpool_destroy_001_neg',
+    'zpool_detach_001_neg', 'zpool_export_001_neg', 'zpool_get_001_neg',
+    'zpool_history_001_neg', 'zpool_import_001_neg', 'zpool_import_002_neg',
+    'zpool_offline_001_neg', 'zpool_online_001_neg', 'zpool_remove_001_neg',
+    'zpool_replace_001_neg', 'zpool_scrub_001_neg', 'zpool_set_001_neg',
+    'zpool_status_001_neg', 'zpool_upgrade_001_neg']
+user =
 
+[/opt/zfs-tests/tests/functional/cli_user/zfs_list]
+tests = ['zfs_list_001_pos', 'zfs_list_002_pos', 'zfs_list_003_pos',
+    'zfs_list_004_neg', 'zfs_list_007_pos', 'zfs_list_008_neg']
+user =
+
+[/opt/zfs-tests/tests/functional/cli_user/zpool_iostat]
+tests = ['zpool_iostat_001_neg', 'zpool_iostat_002_pos',
+    'zpool_iostat_003_neg']
+user =
+
+[/opt/zfs-tests/tests/functional/cli_user/zpool_list]
+tests = ['zpool_list_001_pos', 'zpool_list_002_neg']
+user =
+
+[/opt/zfs-tests/tests/functional/compression]
+tests = ['compress_001_pos', 'compress_002_pos', 'compress_003_pos',
+    'compress_004_pos']
+
+[/opt/zfs-tests/tests/functional/ctime]
+tests = ['ctime_001_pos' ]
+
+[/opt/zfs-tests/tests/functional/delegate]
+tests = ['zfs_allow_001_pos', 'zfs_allow_002_pos',
+    'zfs_allow_004_pos', 'zfs_allow_005_pos', 'zfs_allow_006_pos',
+    'zfs_allow_007_pos', 'zfs_allow_008_pos', 'zfs_allow_009_neg',
+    'zfs_allow_010_pos', 'zfs_allow_011_neg', 'zfs_allow_012_neg',
+    'zfs_unallow_001_pos', 'zfs_unallow_002_pos', 'zfs_unallow_003_pos',
+    'zfs_unallow_004_pos', 'zfs_unallow_005_pos', 'zfs_unallow_006_pos',
+    'zfs_unallow_007_neg', 'zfs_unallow_008_neg']
+
+[/opt/zfs-tests/tests/functional/devices]
+tests = ['devices_001_pos', 'devices_002_neg', 'devices_003_pos']
+
+[/opt/zfs-tests/tests/functional/exec]
+tests = ['exec_001_pos', 'exec_002_neg']
+
+[/opt/zfs-tests/tests/functional/features/async_destroy]
+tests = ['async_destroy_001_pos']
+
+[/opt/zfs-tests/tests/functional/grow_pool]
+tests = ['grow_pool_001_pos']
+
+[/opt/zfs-tests/tests/functional/grow_replicas]
+tests = ['grow_replicas_001_pos']
+
+[/opt/zfs-tests/tests/functional/history]
+tests = ['history_001_pos', 'history_002_pos', 'history_003_pos',
+    'history_004_pos', 'history_005_neg', 'history_006_neg', 'history_007_pos',
+    'history_008_pos', 'history_009_pos', 'history_010_pos']
+
+[/opt/zfs-tests/tests/functional/inheritance]
+tests = ['inherit_001_pos']
+pre =
+
+[/opt/zfs-tests/tests/functional/interop]
+tests = ['interop_001_pos']
+
+[/opt/zfs-tests/tests/functional/inuse]
+tests = ['inuse_001_pos', 'inuse_002_pos', 'inuse_003_pos', 'inuse_004_pos',
+    'inuse_005_pos', 'inuse_006_pos', 'inuse_007_pos', 'inuse_008_pos',
+    'inuse_009_pos']
+post =
+
+[/opt/zfs-tests/tests/functional/large_files]
+tests = ['large_files_001_pos']
+
+[/opt/zfs-tests/tests/functional/largest_pool]
+tests = ['largest_pool_001_pos']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/link_count]
+tests = ['link_count_001']
+
+[/opt/zfs-tests/tests/functional/mdb]
+tests = ['mdb_001_pos']
+
+[/opt/zfs-tests/tests/functional/migration]
+tests = ['migration_001_pos', 'migration_002_pos', 'migration_003_pos',
+    'migration_004_pos', 'migration_005_pos', 'migration_006_pos',
+    'migration_007_pos', 'migration_008_pos', 'migration_009_pos',
+    'migration_010_pos', 'migration_011_pos', 'migration_012_pos']
+
+[/opt/zfs-tests/tests/functional/mmap]
+tests = ['mmap_read_001_pos', 'mmap_write_001_pos']
+
+[/opt/zfs-tests/tests/functional/mount]
+tests = ['umount_001', 'umountall_001']
+
+[/opt/zfs-tests/tests/functional/mv_files]
+tests = ['mv_files_001_pos', 'mv_files_002_pos']
+
+[/opt/zfs-tests/tests/functional/nestedfs]
+tests = ['nestedfs_001_pos']
+
+[/opt/zfs-tests/tests/functional/no_space]
+tests = ['enospc_001_pos']
+
 [/opt/zfs-tests/tests/functional/nopwrite]
 tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
     'nopwrite_promoted_clone', 'nopwrite_recsize', 'nopwrite_sync',
     'nopwrite_varying_compression', 'nopwrite_volume']
+
+[/opt/zfs-tests/tests/functional/online_offline]
+tests = ['online_offline_001_pos', 'online_offline_002_neg',
+    'online_offline_003_neg']
+
+[/opt/zfs-tests/tests/functional/pool_names]
+tests = ['pool_names_001_pos', 'pool_names_002_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/poolversion]
+tests = ['poolversion_001_pos', 'poolversion_002_pos']
+
+[/opt/zfs-tests/tests/functional/privilege]
+tests = ['privilege_001_pos', 'privilege_002_pos']
+
+[/opt/zfs-tests/tests/functional/quota]
+tests = ['quota_001_pos', 'quota_002_pos', 'quota_003_pos', 'quota_004_pos',
+    'quota_005_pos', 'quota_006_neg']
+
+[/opt/zfs-tests/tests/functional/redundancy]
+tests = ['redundancy_001_pos', 'redundancy_002_pos', 'redundancy_003_pos']
+
+[/opt/zfs-tests/tests/functional/refquota]
+tests = ['refquota_001_pos', 'refquota_002_pos', 'refquota_003_pos',
+    'refquota_004_pos', 'refquota_005_pos', 'refquota_006_neg']
+
+[/opt/zfs-tests/tests/functional/refreserv]
+tests = ['refreserv_001_pos', 'refreserv_002_pos', 'refreserv_003_pos',
+    'refreserv_004_pos', 'refreserv_005_pos']
+
+[/opt/zfs-tests/tests/functional/rename_dirs]
+tests = ['rename_dirs_001_pos']
+
+[/opt/zfs-tests/tests/functional/replacement]
+tests = ['replacement_001_pos', 'replacement_002_pos']
+
+[/opt/zfs-tests/tests/functional/reservation]
+tests = ['reservation_001_pos', 'reservation_002_pos', 'reservation_003_pos',
+    'reservation_004_pos', 'reservation_005_pos', 'reservation_006_pos',
+    'reservation_007_pos', 'reservation_008_pos', 'reservation_009_pos',
+    'reservation_010_pos', 'reservation_011_pos', 'reservation_012_pos',
+    'reservation_013_pos', 'reservation_014_pos', 'reservation_015_pos',
+    'reservation_016_pos', 'reservation_017_pos', 'reservation_018_pos']
+
+[/opt/zfs-tests/tests/functional/rootpool]
+tests = ['rootpool_002_neg', 'rootpool_003_neg', 'rootpool_007_neg']
+
+[/opt/zfs-tests/tests/functional/rsend]
+tests = ['rsend_001_pos', 'rsend_002_pos', 'rsend_003_pos', 'rsend_004_pos',
+    'rsend_005_pos', 'rsend_006_pos', 'rsend_007_pos', 'rsend_008_pos',
+    'rsend_009_pos', 'rsend_010_pos', 'rsend_011_pos', 'rsend_012_pos',
+    'rsend_013_pos']
+
+[/opt/zfs-tests/tests/functional/scrub_mirror]
+tests = ['scrub_mirror_001_pos', 'scrub_mirror_002_pos',
+    'scrub_mirror_003_pos', 'scrub_mirror_004_pos']
+
+[/opt/zfs-tests/tests/functional/slog]
+tests = ['slog_001_pos', 'slog_002_pos', 'slog_003_pos', 'slog_004_pos',
+    'slog_005_pos', 'slog_006_pos', 'slog_007_pos', 'slog_008_neg',
+    'slog_009_neg', 'slog_010_neg', 'slog_011_neg', 'slog_012_neg',
+    'slog_013_pos', 'slog_014_pos']
+
+[/opt/zfs-tests/tests/functional/snapshot]
+tests = ['clone_001_pos', 'rollback_001_pos', 'rollback_002_pos',
+    'rollback_003_pos', 'snapshot_001_pos', 'snapshot_002_pos',
+    'snapshot_003_pos', 'snapshot_004_pos', 'snapshot_005_pos',
+    'snapshot_006_pos', 'snapshot_007_pos', 'snapshot_008_pos',
+    'snapshot_009_pos', 'snapshot_010_pos', 'snapshot_011_pos',
+    'snapshot_012_pos', 'snapshot_013_pos', 'snapshot_014_pos',
+    'snapshot_015_pos', 'snapshot_016_pos', 'snapshot_017_pos']
+
+[/opt/zfs-tests/tests/functional/snapused]
+tests = ['snapused_001_pos', 'snapused_002_pos', 'snapused_003_pos',
+    'snapused_004_pos', 'snapused_005_pos']
+
+[/opt/zfs-tests/tests/functional/sparse]
+tests = ['sparse_001_pos']
+
+[/opt/zfs-tests/tests/functional/threadsappend]
+tests = ['threadsappend_001_pos']
+
+[/opt/zfs-tests/tests/functional/truncate]
+tests = ['truncate_001_pos', 'truncate_002_pos']
+
+[/opt/zfs-tests/tests/functional/userquota]
+tests = ['groupspace_001_pos', 'groupspace_002_pos', 'userquota_001_pos',
+    'userquota_002_pos', 'userquota_003_pos', 'userquota_004_pos',
+    'userquota_005_neg', 'userquota_006_pos', 'userquota_007_pos',
+    'userquota_008_pos', 'userquota_009_pos', 'userquota_010_pos',
+    'userquota_011_pos', 'userquota_012_neg', 'userspace_001_pos',
+    'userspace_002_pos']
+
+[/opt/zfs-tests/tests/functional/utils_test]
+tests = ['utils_test_001_pos', 'utils_test_002_pos', 'utils_test_003_pos',
+    'utils_test_004_pos', 'utils_test_005_pos', 'utils_test_006_pos',
+    'utils_test_007_pos', 'utils_test_008_pos', 'utils_test_009_pos']
+
+[/opt/zfs-tests/tests/functional/write_dirs]
+tests = ['write_dirs_001_pos', 'write_dirs_002_pos']
+
+[/opt/zfs-tests/tests/functional/xattr]
+tests = ['xattr_001_pos', 'xattr_002_neg', 'xattr_003_neg', 'xattr_004_pos',
+    'xattr_005_pos', 'xattr_006_pos', 'xattr_007_neg', 'xattr_008_pos',
+    'xattr_009_neg', 'xattr_010_neg', 'xattr_011_pos', 'xattr_012_pos',
+    'xattr_013_pos']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_ENOSPC]
+tests = ['zvol_ENOSPC_001_pos']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_cli]
+tests = ['zvol_cli_001_pos', 'zvol_cli_002_pos', 'zvol_cli_003_neg']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_misc]
+tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg',
+    'zvol_misc_004_pos', 'zvol_misc_005_neg', 'zvol_misc_006_pos']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_swap]
+tests = ['zvol_swap_001_pos', 'zvol_swap_002_pos', 'zvol_swap_003_pos',
+    'zvol_swap_004_pos', 'zvol_swap_005_pos', 'zvol_swap_006_pos']
--- old/usr/src/test/zfs-tests/runfiles/openindiana.run	Fri Nov 22 15:19:18 2013
+++ new/usr/src/test/zfs-tests/runfiles/openindiana.run	Fri Nov 22 15:19:18 2013
@@ -55,11 +55,27 @@
 tests = ['atime_001_pos', 'atime_002_neg']
 
 [/opt/zfs-tests/tests/functional/bootfs]
-tests = ['bootfs_001_pos', 'bootfs_002_neg', 'bootfs_003_pos', 'bootfs_004_neg',
-    'bootfs_005_neg', 'bootfs_006_pos', 'bootfs_007_neg', 'bootfs_008_neg']
+tests = ['bootfs_001_pos', 'bootfs_002_neg', 'bootfs_003_pos',
+    'bootfs_004_neg', 'bootfs_005_neg', 'bootfs_006_pos', 'bootfs_007_neg',
+    'bootfs_008_neg']
 pre =
 post =
 
+[/opt/zfs-tests/tests/functional/cache]
+tests = ['cache_001_pos', 'cache_002_pos', 'cache_003_pos', 'cache_004_neg',
+    'cache_005_neg', 'cache_006_pos', 'cache_007_neg', 'cache_008_neg',
+    'cache_009_pos', 'cache_010_neg', 'cache_011_pos']
+
+[/opt/zfs-tests/tests/functional/cachefile]
+tests = ['cachefile_001_pos', 'cachefile_002_pos', 'cachefile_003_pos',
+    'cachefile_004_pos']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/clean_mirror]
+tests = [ 'clean_mirror_001_pos', 'clean_mirror_002_pos',
+    'clean_mirror_003_pos', 'clean_mirror_004_pos']
+
 [/opt/zfs-tests/tests/functional/cli_root/zdb]
 tests = ['zdb_001_neg']
 pre =
@@ -117,7 +133,7 @@
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_receive]
 tests = ['zfs_receive_001_pos', 'zfs_receive_002_pos', 'zfs_receive_003_pos',
-    'zfs_receive_004_neg', 'zfs_receive_005_neg', 'zfs_receive_006_pos',
+    'zfs_receive_005_neg', 'zfs_receive_006_pos',
     'zfs_receive_007_neg', 'zfs_receive_008_pos', 'zfs_receive_009_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_rename]
@@ -131,8 +147,8 @@
 tests = ['zfs_reservation_001_pos', 'zfs_reservation_002_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_rollback]
-tests = ['zfs_rollback_001_pos', 'zfs_rollback_002_pos', 'zfs_rollback_003_neg',
-    'zfs_rollback_004_neg']
+tests = ['zfs_rollback_001_pos', 'zfs_rollback_002_pos',
+    'zfs_rollback_003_neg', 'zfs_rollback_004_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_send]
 tests = ['zfs_send_001_pos', 'zfs_send_002_pos', 'zfs_send_003_pos',
@@ -156,9 +172,10 @@
     'zfs_share_010_neg', 'zfs_share_011_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_snapshot]
-tests = ['zfs_snapshot_001_neg', 'zfs_snapshot_002_neg', 'zfs_snapshot_003_neg',
-    'zfs_snapshot_004_neg', 'zfs_snapshot_005_neg', 'zfs_snapshot_006_pos',
-    'zfs_snapshot_007_neg', 'zfs_snapshot_008_neg', 'zfs_snapshot_009_pos']
+tests = ['zfs_snapshot_001_neg', 'zfs_snapshot_002_neg',
+    'zfs_snapshot_003_neg', 'zfs_snapshot_004_neg', 'zfs_snapshot_005_neg',
+    'zfs_snapshot_006_pos', 'zfs_snapshot_007_neg', 'zfs_snapshot_008_neg',
+    'zfs_snapshot_009_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zfs_unmount]
 tests = ['zfs_unmount_001_pos', 'zfs_unmount_002_pos', 'zfs_unmount_003_pos',
@@ -190,14 +207,14 @@
 tests = ['zpool_clear_001_pos', 'zpool_clear_002_neg', 'zpool_clear_003_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_create]
-tests = ['zpool_create_001_pos', 'zpool_create_002_pos', 'zpool_create_003_pos',
-    'zpool_create_004_pos', 'zpool_create_005_pos', 'zpool_create_006_pos',
-    'zpool_create_007_neg', 'zpool_create_008_pos', 'zpool_create_009_neg',
-    'zpool_create_010_neg', 'zpool_create_011_neg', 'zpool_create_012_neg',
-    'zpool_create_013_neg', 'zpool_create_014_neg', 'zpool_create_015_neg',
-    'zpool_create_016_pos', 'zpool_create_017_neg', 'zpool_create_018_pos',
-    'zpool_create_019_pos', 'zpool_create_020_pos', 'zpool_create_021_pos',
-    'zpool_create_022_pos', 'zpool_create_023_neg',
+tests = ['zpool_create_001_pos', 'zpool_create_002_pos',
+    'zpool_create_003_pos', 'zpool_create_004_pos', 'zpool_create_005_pos',
+    'zpool_create_006_pos', 'zpool_create_007_neg', 'zpool_create_008_pos',
+    'zpool_create_009_neg', 'zpool_create_010_neg', 'zpool_create_011_neg',
+    'zpool_create_012_neg', 'zpool_create_013_neg', 'zpool_create_014_neg',
+    'zpool_create_015_neg', 'zpool_create_016_pos', 'zpool_create_017_neg',
+    'zpool_create_018_pos', 'zpool_create_019_pos', 'zpool_create_020_pos',
+    'zpool_create_021_pos', 'zpool_create_022_pos', 'zpool_create_023_neg',
     'zpool_create_features_001_pos', 'zpool_create_features_002_pos',
     'zpool_create_features_003_pos', 'zpool_create_features_004_neg']
 
@@ -211,11 +228,12 @@
 tests = ['zpool_detach_001_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_expand]
-tests = ['zpool_expand_001_pos', 'zpool_expand_002_pos', 'zpool_expand_003_neg']
+tests = ['zpool_expand_001_pos', 'zpool_expand_002_pos',
+    'zpool_expand_003_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_export]
-tests = ['zpool_export_001_pos', 'zpool_export_002_pos', 'zpool_export_003_neg',
-    'zpool_export_004_pos']
+tests = ['zpool_export_001_pos', 'zpool_export_002_pos',
+    'zpool_export_003_neg', 'zpool_export_004_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_get]
 tests = ['zpool_get_001_pos', 'zpool_get_002_pos', 'zpool_get_003_pos',
@@ -225,11 +243,11 @@
 tests = ['zpool_history_001_neg', 'zpool_history_002_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_import]
-tests = ['zpool_import_001_pos', 'zpool_import_002_pos', 'zpool_import_003_pos',
-    'zpool_import_004_pos', 'zpool_import_005_pos', 'zpool_import_006_pos',
-    'zpool_import_007_pos', 'zpool_import_008_pos', 'zpool_import_009_neg',
-    'zpool_import_010_pos', 'zpool_import_011_neg', 'zpool_import_012_pos',
-    'zpool_import_013_neg', 'zpool_import_all_001_pos',
+tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
+    'zpool_import_003_pos', 'zpool_import_004_pos', 'zpool_import_005_pos',
+    'zpool_import_006_pos', 'zpool_import_007_pos', 'zpool_import_008_pos',
+    'zpool_import_009_neg', 'zpool_import_010_pos', 'zpool_import_011_neg',
+    'zpool_import_012_pos', 'zpool_import_013_neg', 'zpool_import_all_001_pos',
     'zpool_import_features_001_pos', 'zpool_import_features_002_neg',
     'zpool_import_features_003_pos', 'zpool_import_missing_001_pos',
     'zpool_import_missing_002_pos', 'zpool_import_missing_003_pos',
@@ -242,7 +260,8 @@
 tests = ['zpool_online_001_pos', 'zpool_online_002_neg']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_remove]
-tests = ['zpool_remove_001_neg', 'zpool_remove_002_pos', 'zpool_remove_003_pos']
+tests = ['zpool_remove_001_neg', 'zpool_remove_002_pos',
+    'zpool_remove_003_pos']
 
 [/opt/zfs-tests/tests/functional/cli_root/zpool_replace]
 tests = ['zpool_replace_001_neg']
@@ -265,10 +284,243 @@
     'zpool_upgrade_006_neg', 'zpool_upgrade_007_pos', 'zpool_upgrade_008_pos',
     'zpool_upgrade_009_neg']
 
-[/opt/zfs-tests/tests/functional/truncate]
-tests = ['truncate_001_pos', 'truncate_002_pos']
+[/opt/zfs-tests/tests/functional/cli_user/misc]
+tests = ['zdb_001_neg', 'zfs_001_neg', 'zfs_allow_001_neg',
+    'zfs_clone_001_neg', 'zfs_create_001_neg', 'zfs_destroy_001_neg',
+    'zfs_get_001_neg', 'zfs_inherit_001_neg', 'zfs_mount_001_neg',
+    'zfs_promote_001_neg', 'zfs_receive_001_neg', 'zfs_rename_001_neg',
+    'zfs_rollback_001_neg', 'zfs_send_001_neg', 'zfs_set_001_neg',
+    'zfs_share_001_neg', 'zfs_snapshot_001_neg', 'zfs_unallow_001_neg',
+    'zfs_unmount_001_neg', 'zfs_unshare_001_neg', 'zfs_upgrade_001_neg',
+    'zpool_001_neg', 'zpool_add_001_neg', 'zpool_attach_001_neg',
+    'zpool_clear_001_neg', 'zpool_create_001_neg', 'zpool_destroy_001_neg',
+    'zpool_detach_001_neg', 'zpool_export_001_neg', 'zpool_get_001_neg',
+    'zpool_history_001_neg', 'zpool_import_001_neg', 'zpool_import_002_neg',
+    'zpool_offline_001_neg', 'zpool_online_001_neg', 'zpool_remove_001_neg',
+    'zpool_replace_001_neg', 'zpool_scrub_001_neg', 'zpool_set_001_neg',
+    'zpool_status_001_neg', 'zpool_upgrade_001_neg']
+user =
 
+[/opt/zfs-tests/tests/functional/cli_user/zfs_list]
+tests = ['zfs_list_001_pos', 'zfs_list_002_pos', 'zfs_list_003_pos',
+    'zfs_list_004_neg', 'zfs_list_007_pos', 'zfs_list_008_neg']
+user =
+
+[/opt/zfs-tests/tests/functional/cli_user/zpool_iostat]
+tests = ['zpool_iostat_001_neg', 'zpool_iostat_002_pos',
+    'zpool_iostat_003_neg']
+user =
+
+[/opt/zfs-tests/tests/functional/cli_user/zpool_list]
+tests = ['zpool_list_001_pos', 'zpool_list_002_neg']
+user =
+
+[/opt/zfs-tests/tests/functional/compression]
+tests = ['compress_001_pos', 'compress_002_pos', 'compress_003_pos',
+    'compress_004_pos']
+
+[/opt/zfs-tests/tests/functional/ctime]
+tests = ['ctime_001_pos' ]
+
+[/opt/zfs-tests/tests/functional/delegate]
+tests = ['zfs_allow_001_pos', 'zfs_allow_002_pos',
+    'zfs_allow_004_pos', 'zfs_allow_005_pos', 'zfs_allow_006_pos',
+    'zfs_allow_007_pos', 'zfs_allow_008_pos', 'zfs_allow_009_neg',
+    'zfs_allow_010_pos', 'zfs_allow_011_neg', 'zfs_allow_012_neg',
+    'zfs_unallow_001_pos', 'zfs_unallow_002_pos', 'zfs_unallow_003_pos',
+    'zfs_unallow_004_pos', 'zfs_unallow_005_pos', 'zfs_unallow_006_pos',
+    'zfs_unallow_007_neg', 'zfs_unallow_008_neg']
+
+[/opt/zfs-tests/tests/functional/devices]
+tests = ['devices_001_pos', 'devices_002_neg', 'devices_003_pos']
+
+[/opt/zfs-tests/tests/functional/exec]
+tests = ['exec_001_pos', 'exec_002_neg']
+
+[/opt/zfs-tests/tests/functional/features/async_destroy]
+tests = ['async_destroy_001_pos']
+
+[/opt/zfs-tests/tests/functional/grow_pool]
+tests = ['grow_pool_001_pos']
+
+[/opt/zfs-tests/tests/functional/grow_replicas]
+tests = ['grow_replicas_001_pos']
+
+[/opt/zfs-tests/tests/functional/history]
+tests = ['history_001_pos', 'history_002_pos', 'history_003_pos',
+    'history_004_pos', 'history_005_neg', 'history_006_neg', 'history_007_pos',
+    'history_008_pos', 'history_009_pos', 'history_010_pos']
+
+[/opt/zfs-tests/tests/functional/inheritance]
+tests = ['inherit_001_pos']
+pre =
+
+[/opt/zfs-tests/tests/functional/interop]
+tests = ['interop_001_pos']
+
+[/opt/zfs-tests/tests/functional/inuse]
+tests = ['inuse_001_pos', 'inuse_002_pos', 'inuse_003_pos', 'inuse_004_pos',
+    'inuse_005_pos', 'inuse_006_pos', 'inuse_007_pos', 'inuse_008_pos',
+    'inuse_009_pos']
+post =
+
+[/opt/zfs-tests/tests/functional/large_files]
+tests = ['large_files_001_pos']
+
+[/opt/zfs-tests/tests/functional/largest_pool]
+tests = ['largest_pool_001_pos']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/link_count]
+tests = ['link_count_001']
+
+[/opt/zfs-tests/tests/functional/mdb]
+tests = ['mdb_001_pos']
+
+[/opt/zfs-tests/tests/functional/migration]
+tests = ['migration_001_pos', 'migration_002_pos', 'migration_003_pos',
+    'migration_004_pos', 'migration_005_pos', 'migration_006_pos',
+    'migration_007_pos', 'migration_008_pos', 'migration_009_pos',
+    'migration_010_pos', 'migration_011_pos', 'migration_012_pos']
+
+[/opt/zfs-tests/tests/functional/mmap]
+tests = ['mmap_read_001_pos', 'mmap_write_001_pos']
+
+[/opt/zfs-tests/tests/functional/mount]
+tests = ['umount_001', 'umountall_001']
+
+[/opt/zfs-tests/tests/functional/mv_files]
+tests = ['mv_files_001_pos', 'mv_files_002_pos']
+
+[/opt/zfs-tests/tests/functional/nestedfs]
+tests = ['nestedfs_001_pos']
+
+[/opt/zfs-tests/tests/functional/no_space]
+tests = ['enospc_001_pos']
+
 [/opt/zfs-tests/tests/functional/nopwrite]
 tests = ['nopwrite_copies', 'nopwrite_mtime', 'nopwrite_negative',
     'nopwrite_promoted_clone', 'nopwrite_recsize', 'nopwrite_sync',
     'nopwrite_varying_compression', 'nopwrite_volume']
+
+[/opt/zfs-tests/tests/functional/online_offline]
+tests = ['online_offline_001_pos', 'online_offline_002_neg',
+    'online_offline_003_neg']
+
+[/opt/zfs-tests/tests/functional/pool_names]
+tests = ['pool_names_001_pos', 'pool_names_002_neg']
+pre =
+post =
+
+[/opt/zfs-tests/tests/functional/poolversion]
+tests = ['poolversion_001_pos', 'poolversion_002_pos']
+
+[/opt/zfs-tests/tests/functional/privilege]
+tests = ['privilege_001_pos', 'privilege_002_pos']
+
+[/opt/zfs-tests/tests/functional/quota]
+tests = ['quota_001_pos', 'quota_002_pos', 'quota_003_pos', 'quota_004_pos',
+    'quota_005_pos', 'quota_006_neg']
+
+[/opt/zfs-tests/tests/functional/redundancy]
+tests = ['redundancy_001_pos', 'redundancy_002_pos', 'redundancy_003_pos']
+
+[/opt/zfs-tests/tests/functional/refquota]
+tests = ['refquota_001_pos', 'refquota_002_pos', 'refquota_003_pos',
+    'refquota_004_pos', 'refquota_005_pos', 'refquota_006_neg']
+
+[/opt/zfs-tests/tests/functional/refreserv]
+tests = ['refreserv_001_pos', 'refreserv_002_pos', 'refreserv_003_pos',
+    'refreserv_004_pos', 'refreserv_005_pos']
+
+[/opt/zfs-tests/tests/functional/rename_dirs]
+tests = ['rename_dirs_001_pos']
+
+[/opt/zfs-tests/tests/functional/replacement]
+tests = ['replacement_001_pos', 'replacement_002_pos']
+
+[/opt/zfs-tests/tests/functional/reservation]
+tests = ['reservation_001_pos', 'reservation_002_pos', 'reservation_003_pos',
+    'reservation_004_pos', 'reservation_005_pos', 'reservation_006_pos',
+    'reservation_007_pos', 'reservation_008_pos', 'reservation_009_pos',
+    'reservation_010_pos', 'reservation_011_pos', 'reservation_012_pos',
+    'reservation_013_pos', 'reservation_014_pos', 'reservation_015_pos',
+    'reservation_016_pos', 'reservation_017_pos', 'reservation_018_pos']
+
+[/opt/zfs-tests/tests/functional/rootpool]
+tests = ['rootpool_002_neg', 'rootpool_003_neg', 'rootpool_007_neg']
+
+[/opt/zfs-tests/tests/functional/rsend]
+tests = ['rsend_001_pos', 'rsend_002_pos', 'rsend_003_pos', 'rsend_004_pos',
+    'rsend_005_pos', 'rsend_006_pos', 'rsend_007_pos', 'rsend_008_pos',
+    'rsend_009_pos', 'rsend_010_pos', 'rsend_011_pos', 'rsend_012_pos',
+    'rsend_013_pos']
+
+[/opt/zfs-tests/tests/functional/scrub_mirror]
+tests = ['scrub_mirror_001_pos', 'scrub_mirror_002_pos',
+    'scrub_mirror_003_pos', 'scrub_mirror_004_pos']
+
+[/opt/zfs-tests/tests/functional/slog]
+tests = ['slog_001_pos', 'slog_002_pos', 'slog_003_pos', 'slog_004_pos',
+    'slog_005_pos', 'slog_006_pos', 'slog_007_pos', 'slog_008_neg',
+    'slog_009_neg', 'slog_010_neg', 'slog_011_neg', 'slog_012_neg',
+    'slog_013_pos', 'slog_014_pos']
+
+[/opt/zfs-tests/tests/functional/snapshot]
+tests = ['clone_001_pos', 'rollback_001_pos', 'rollback_002_pos',
+    'rollback_003_pos', 'snapshot_001_pos', 'snapshot_002_pos',
+    'snapshot_003_pos', 'snapshot_004_pos', 'snapshot_005_pos',
+    'snapshot_006_pos', 'snapshot_007_pos', 'snapshot_008_pos',
+    'snapshot_009_pos', 'snapshot_010_pos', 'snapshot_011_pos',
+    'snapshot_012_pos', 'snapshot_013_pos', 'snapshot_014_pos',
+    'snapshot_015_pos', 'snapshot_016_pos', 'snapshot_017_pos']
+
+[/opt/zfs-tests/tests/functional/snapused]
+tests = ['snapused_001_pos', 'snapused_002_pos', 'snapused_003_pos',
+    'snapused_004_pos', 'snapused_005_pos']
+
+[/opt/zfs-tests/tests/functional/sparse]
+tests = ['sparse_001_pos']
+
+[/opt/zfs-tests/tests/functional/threadsappend]
+tests = ['threadsappend_001_pos']
+
+[/opt/zfs-tests/tests/functional/truncate]
+tests = ['truncate_001_pos', 'truncate_002_pos']
+
+[/opt/zfs-tests/tests/functional/userquota]
+tests = ['groupspace_001_pos', 'groupspace_002_pos', 'userquota_001_pos',
+    'userquota_002_pos', 'userquota_003_pos', 'userquota_004_pos',
+    'userquota_005_neg', 'userquota_006_pos', 'userquota_007_pos',
+    'userquota_008_pos', 'userquota_009_pos', 'userquota_010_pos',
+    'userquota_011_pos', 'userquota_012_neg', 'userspace_001_pos',
+    'userspace_002_pos']
+
+[/opt/zfs-tests/tests/functional/utils_test]
+tests = ['utils_test_001_pos', 'utils_test_002_pos', 'utils_test_003_pos',
+    'utils_test_004_pos', 'utils_test_005_pos', 'utils_test_006_pos',
+    'utils_test_007_pos', 'utils_test_008_pos', 'utils_test_009_pos']
+
+[/opt/zfs-tests/tests/functional/write_dirs]
+tests = ['write_dirs_001_pos', 'write_dirs_002_pos']
+
+[/opt/zfs-tests/tests/functional/xattr]
+tests = ['xattr_001_pos', 'xattr_002_neg', 'xattr_003_neg', 'xattr_004_pos',
+    'xattr_005_pos', 'xattr_006_pos', 'xattr_007_neg', 'xattr_008_pos',
+    'xattr_009_neg', 'xattr_010_neg', 'xattr_011_pos', 'xattr_012_pos',
+    'xattr_013_pos']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_ENOSPC]
+tests = ['zvol_ENOSPC_001_pos']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_cli]
+tests = ['zvol_cli_001_pos', 'zvol_cli_002_pos', 'zvol_cli_003_neg']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_misc]
+tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg',
+    'zvol_misc_004_pos', 'zvol_misc_005_neg', 'zvol_misc_006_pos']
+
+[/opt/zfs-tests/tests/functional/zvol/zvol_swap]
+tests = ['zvol_swap_001_pos', 'zvol_swap_002_pos', 'zvol_swap_003_pos',
+    'zvol_swap_004_pos', 'zvol_swap_005_pos', 'zvol_swap_006_pos']
--- old/usr/src/test/zfs-tests/tests/functional/Makefile	Fri Nov 22 15:19:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/Makefile	Fri Nov 22 15:19:18 2013
@@ -1,4 +1,5 @@
 #
+#
 # 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
@@ -10,7 +11,7 @@
 #
 
 #
-# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright (c) 2013 by Delphix. All rights reserved.
 #
 
 .PARALLEL: $(SUBDIRS)
@@ -18,8 +19,59 @@
 SUBDIRS = acl \
 	atime \
 	bootfs \
+	cache \
+	cachefile \
+	clean_mirror \
 	cli_root \
+	cli_user \
+	compression \
+	ctime \
+	delegate \
+	devices \
+	exec \
+	features \
+	grow_pool \
+	grow_replicas \
+	history \
+	inheritance \
+	interop \
+	inuse \
+	large_files \
+	largest_pool \
+	link_count \
+	mdb \
+	migration \
+	mmap \
+	mount \
+	mv_files \
+	nestedfs \
+	no_space \
 	nopwrite \
-	truncate
+	online_offline \
+	pool_names \
+	poolversion \
+	privilege \
+	quota \
+	redundancy \
+	refquota \
+	refreserv \
+	rename_dirs \
+	replacement \
+	reservation \
+	rootpool \
+	rsend \
+	scrub_mirror \
+	slog \
+	snapshot \
+	snapused \
+	sparse \
+	threadsappend \
+	truncate \
+	userquota \
+	utils_test \
+	write_dirs \
+	xattr \
+	zvol
 
+
 include $(SRC)/test/Makefile.com
--- /dev/null	Fri Nov 22 15:19:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/Makefile	Fri Nov 22 15:19:19 2013
@@ -0,0 +1,54 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cache
+
+PROGS = cleanup \
+	setup \
+	cache_001_pos \
+	cache_002_pos \
+	cache_003_pos \
+	cache_004_neg \
+	cache_005_neg \
+	cache_006_pos \
+	cache_007_neg \
+	cache_008_neg \
+	cache_009_pos \
+	cache_010_neg \
+	cache_011_pos
+
+FILES = cache.cfg \
+	cache.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:19:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache.cfg	Fri Nov 22 15:19:19 2013
@@ -0,0 +1,70 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function set_disks
+{
+	set -A disk_array $(find_disks $DISKS)
+
+	typeset -i DISK_ARRAY_NUM=0
+
+	if (( ${#disk_array[*]} <= 1 )); then
+		export DISK=${DISKS%% *}
+	else
+		export DISK=""
+		typeset -i i=0
+		while (( i < ${#disk_array[*]} )); do
+			export DISK${i}="${disk_array[$i]}"
+			DISKSARRAY="$DISKSARRAY ${disk_array[$i]}"
+			(( i = i + 1 ))
+		done
+		export DISK_ARRAY_NUM=$i
+		export DISKSARRAY
+	fi
+
+	if (( $DISK_ARRAY_NUM == 0 )); then
+		export disk=$DISK
+	else
+		export disk=$DISK0
+	fi
+}
+
+set_disks
+
+export SIZE=64M
+
+export VDIR=/disk.cache
+export VDIR2=/disk2.cache
+
+export VDEV="$VDIR/a $VDIR/b $VDIR/c"
+export LDEV="$DISK0"
+export VDEV2="$VDIR2/a $VDIR2/b $VDIR2/c"
+export LDEV2="$DISK1"
--- /dev/null	Fri Nov 22 15:19:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache.kshlib	Fri Nov 22 15:19:20 2013
@@ -0,0 +1,160 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function cleanup
+{
+	if datasetexists $TESTPOOL ; then
+		log_must $ZPOOL destroy -f $TESTPOOL
+	fi
+	if datasetexists $TESTPOOL2 ; then
+		log_must $ZPOOL destroy -f $TESTPOOL2
+	fi
+}
+
+#
+# Try zpool status/iostat for given pool
+#
+# $1 pool
+#
+function display_status
+{
+	typeset pool=$1
+
+	typeset -i ret=0
+	$ZPOOL status -xv $pool > /dev/null 2>&1
+	ret=$?
+
+	$ZPOOL iostat > /dev/null 2>&1
+	((ret |= $?))
+
+	typeset mntpnt=$(get_prop mountpoint $pool)
+	$DD if=/dev/random of=$mntpnt/testfile.$$ &
+	typeset pid=$!
+
+	$ZPOOL iostat -v 1 3 > /dev/null
+	((ret |= $?))
+
+	kill -9 $pid
+
+	return $ret
+}
+
+#
+# Verify the given cache device have correct type and status
+#
+# $1 pool name
+# $2 device name
+# $3 device status
+# $4 device type
+#
+function verify_cache_device
+{
+	typeset pool=$1
+	typeset device=$2
+	typeset status=$3
+	typeset type=$4
+
+	if [[ -z $pool || -z $device || -z $status ]]; then
+		log_fail "Usage: verify_cache_device <pool> <device> " \
+			"<status> [type]"
+	fi
+
+	if [[ $WRAPPER == *"smi"* ]]; then
+		$ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
+		if (( $? == 0 )); then
+			device=${device}s2
+		fi
+	fi
+
+	#
+	# Get all the cache devices and status table like below
+	#
+	# mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE
+	#
+	set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK 'BEGIN {start=0} \
+				/\tcache/ {start=1}
+				/\tmirror/ || /\tspares/ || /^$/ {start=0}
+				(start==1) && /\t  (\/|[a-zA-Z])/ \
+					{print "stripe:" $1 " " $2}
+				(start==1) && /\t    (\/|[a-zA-Z])/ \
+					{print "mirror:" $1 " " $2}
+				# When hotspare is replacing
+				(start==1) && /\t      (\/|[a-zA-Z])/ \
+					{print "mirror:" $1 " " $2}'
+			     )
+
+	typeset -i i=0
+	typeset find=0
+	while (( i < ${#dev_stat_tab[@]} )); do
+		typeset dev=${dev_stat_tab[$i]}
+		typeset stat=${dev_stat_tab[((i+1))]}
+
+		case $dev in
+			stripe:$device)
+				if [[ "$type" == 'mirror' ]]; then
+					log_note "Unexpected type: mirror"
+					return 1
+				else
+					if [[ $stat != $status ]]; then
+						log_note "Status($stat) " \
+							"!= Expected stat($status)"
+						return 1
+					fi
+					return 0
+				fi
+				;;
+			mirror:$device)
+				if [[ -z "$type" || $type == 'stripe' ]]; then
+					log_note "Unexpected type: stripe"
+					return 1
+				else
+					if [[ $stat != $status ]]; then
+						log_note "Status($stat) " \
+							"!= Expected stat($status)"
+						return 1
+					fi
+					return 0
+				fi
+				;;
+		esac
+		((i += 2))
+	done
+
+	log_note "Can not find device: $device"
+	return 1
+}
+
+function verify_cache_support
+{
+	$ZPOOL upgrade -v | $GREP "Cache devices" > /dev/null 2>&1
+	return $?
+}
--- /dev/null	Fri Nov 22 15:19:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_001_pos.ksh	Fri Nov 22 15:19:20 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Creating a pool with a cache device succeeds.
+#
+# STRATEGY:
+#	1. Create pool with separated cache devices.
+#	2. Display pool status
+#	3. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Creating a pool with a cache device succeeds."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV \
+		cache $LDEV
+	log_must display_status $TESTPOOL
+
+	ldev=$(random_get $LDEV)
+	log_must verify_cache_device $TESTPOOL $ldev 'ONLINE'
+
+	log_must $ZPOOL remove $TESTPOOL $ldev
+	log_must check_vdev_state $TESTPOOL $ldev ""
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Creating a pool with a cache device succeeds."
--- /dev/null	Fri Nov 22 15:19:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_002_pos.ksh	Fri Nov 22 15:19:21 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Adding a cache device to normal pool works.
+#
+# STRATEGY:
+#	1. Create pool
+#	2. Add cache devices with different configuration
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Adding a cache device to normal pool works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV
+	log_must $ZPOOL add $TESTPOOL cache $LDEV
+	log_must display_status $TESTPOOL
+	typeset ldev=$(random_get $LDEV)
+	log_must verify_cache_device $TESTPOOL $ldev 'ONLINE'
+
+	log_must $ZPOOL remove $TESTPOOL $ldev
+	log_must check_vdev_state $TESTPOOL $ldev ""
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Adding a cache device to normal pool works."
--- /dev/null	Fri Nov 22 15:19:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_003_pos.ksh	Fri Nov 22 15:19:21 2013
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Adding an extra cache device works
+#
+# STRATEGY:
+#	1. Create pool with separated cache devices.
+#	2. Add an extra cache devices
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Adding an extra cache device works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV \
+		cache $LDEV
+	log_must $ZPOOL add $TESTPOOL \
+		cache $LDEV2
+
+	log_must display_status $TESTPOOL
+	ldev=$(random_get $LDEV2)
+	log_must verify_cache_device $TESTPOOL $ldev 'ONLINE'
+
+	log_must $ZPOOL remove $TESTPOOL $ldev
+	log_must check_vdev_state $TESTPOOL $ldev ""
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Adding an extra cache device works."
--- /dev/null	Fri Nov 22 15:19:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_004_neg.ksh	Fri Nov 22 15:19:21 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Attaching a cache device fails.
+#
+# STRATEGY:
+#	1. Create pool with separated cache devices.
+#	2. Attaching a cache device for existing cache device
+#	3. Verify the operation fails
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Attaching a cache device fails for an existing cache device."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV \
+		cache $LDEV
+
+	ldev=$(random_get $LDEV)
+	typeset ldev2=$(random_get $LDEV2)
+	log_mustnot $ZPOOL attach $TESTPOOL $ldev $ldev2
+	log_must check_vdev_state $TESTPOOL $ldev2 ""
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Attaching a cache device fails for an existing cache device."
--- /dev/null	Fri Nov 22 15:19:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_005_neg.ksh	Fri Nov 22 15:19:22 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Replacing a cache device fails.
+#
+# STRATEGY:
+#	1. Create pool with cache devices.
+#	2. Replacing one cache device
+#	3. Verify replace fails
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Replacing a cache device fails."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV \
+		cache $LDEV
+	sdev=$(random_get $LDEV)
+	tdev=$(random_get $LDEV2)
+	log_mustnot $ZPOOL replace $TESTPOOL $sdev $tdev
+	log_must verify_cache_device $TESTPOOL $sdev 'ONLINE'
+	log_must check_vdev_state $TESTPOOL $tdev ""
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Replacing a cache device fails."
--- /dev/null	Fri Nov 22 15:19:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_006_pos.ksh	Fri Nov 22 15:19:22 2013
@@ -0,0 +1,85 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Exporting and importing pool with cache devices passes.
+#
+# STRATEGY:
+#	1. Create pool with cache devices.
+#	2. Export and import the pool
+#	3. Display pool status
+#	4. Destroy and import the pool again
+#	5. Display pool status
+#	6. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Exporting and importing pool with cache devices passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV \
+		cache $LDEV $LDEV2
+	ldev=$(random_get $LDEV $LDEV2)
+	log_must verify_cache_device \
+		$TESTPOOL $ldev 'ONLINE'
+
+	#
+	# Nomal export/import operating
+	#
+	log_must $ZPOOL export $TESTPOOL
+	log_must $ZPOOL import -d $VDIR $TESTPOOL
+	log_must display_status $TESTPOOL
+	ldev=$(random_get $LDEV $LDEV2)
+	log_must verify_cache_device \
+		$TESTPOOL $ldev 'ONLINE'
+
+	#
+	# Destroy the pool and import again
+	#
+	log_must $ZPOOL destroy $TESTPOOL
+	log_must $ZPOOL import -Df -d $VDIR $TESTPOOL
+	log_must display_status $TESTPOOL
+	ldev=$(random_get $LDEV $LDEV2)
+	log_must verify_cache_device \
+		$TESTPOOL $ldev 'ONLINE'
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Exporting and importing pool with cache devices passes."
--- /dev/null	Fri Nov 22 15:19:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_007_neg.ksh	Fri Nov 22 15:19:22 2013
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	A mirror/raidz/raidz2 cache is not supported.
+#
+# STRATEGY:
+#	1. Try to create pool with unsupported type
+#	2. Verify failed to create pool.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "A mirror/raidz/raidz2 cache is not supported."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for cachetype in "mirror" "raidz" "raidz1" "raidz2"
+	do
+		log_mustnot $ZPOOL create $TESTPOOL $type $VDEV \
+			cache $cachetype $LDEV $LDEV2
+		ldev=$(random_get $LDEV $LDEV2)
+		log_mustnot verify_cache_device \
+			$TESTPOOL $ldev 'ONLINE' $cachetype
+		log_must datasetnonexists $TESTPOOL
+	done
+done
+
+log_pass "A mirror/raidz/raidz2 cache is not supported."
--- /dev/null	Fri Nov 22 15:19:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_008_neg.ksh	Fri Nov 22 15:19:23 2013
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	A mirror/raidz/raidz2 cache can not be added to existed pool.
+#
+# STRATEGY:
+#	1. Create pool with or without cache.
+#	2. Add a mirror/raidz/raidz2 cache to this pool.
+#	3. Verify failed to add.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "A raidz/raidz2 cache can not be added to existed pool."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for cachetype in "mirror" "raidz" "raidz1" "raidz2"
+	do
+		log_must $ZPOOL create $TESTPOOL $type $VDEV \
+			cache $LDEV
+
+		log_mustnot $ZPOOL add $TESTPOOL cache $cachetype $LDEV2
+		ldev=$(random_get $LDEV2)
+		log_mustnot verify_cache_device \
+			$TESTPOOL $ldev 'ONLINE' $cachetype
+
+		log_must $ZPOOL destroy $TESTPOOL
+	done
+done
+
+log_pass "A mirror/raidz/raidz2 cache can not be added to existed pool."
--- /dev/null	Fri Nov 22 15:19:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_009_pos.ksh	Fri Nov 22 15:19:23 2013
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Offline and online a cache device succeed.
+#
+# STRATEGY:
+#	1. Create pool with mirror cache devices.
+#	2. Offine and online a cache device
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+log_assert "Offline and online a cache device succeed."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV \
+		cache $LDEV $LDEV2
+
+	ldev=$(random_get $LDEV $LDEV2)
+	log_must $ZPOOL offline $TESTPOOL $ldev
+	log_must display_status $TESTPOOL
+	log_must verify_cache_device $TESTPOOL $ldev 'OFFLINE' ''
+
+	log_must $ZPOOL online $TESTPOOL $ldev
+	log_must display_status $TESTPOOL
+	log_must verify_cache_device $TESTPOOL $ldev 'ONLINE' ''
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Offline and online a cache device succeed."
--- /dev/null	Fri Nov 22 15:19:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_010_neg.ksh	Fri Nov 22 15:19:23 2013
@@ -0,0 +1,84 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Verify cache device must be a block device.
+#
+# STRATEGY:
+#	1. Create a pool
+#	2. Add different object as cache
+#	3. Verify character devices and files fail
+#
+
+verify_runnable "global"
+
+function cleanup_testenv
+{
+	cleanup
+	if [[ -n $lofidev ]]; then
+		log_must $LOFIADM -d $lofidev
+	fi
+}
+
+log_assert "Cache device can only be block devices."
+log_onexit cleanup_testenv
+
+TESTVOL=testvol1$$
+dsk1=${DISKS%% *}
+log_must $ZPOOL create $TESTPOOL ${DISKS#$dsk1}
+
+# Add nomal /dev/rdsk device
+log_mustnot $ZPOOL add $TESTPOOL cache /dev/rdsk/${dsk1}s0
+#log_must verify_cache_device $TESTPOOL $dsk1 'ONLINE'
+
+# Add nomal file
+log_mustnot $ZPOOL add $TESTPOOL cache $VDEV2
+
+# Add /dev/rlofi device
+lofidev=${VDEV2%% *}
+log_must $LOFIADM -a $lofidev
+lofidev=$($LOFIADM $lofidev)
+log_mustnot $ZPOOL add $TESTPOOL cache "/dev/rlofi/${lofidev#/dev/lofi/}"
+if [[ -n $lofidev ]]; then
+	log_must $LOFIADM -d $lofidev
+	lofidev=""
+fi
+
+# Add /dev/zvol/rdsk device
+log_must $ZPOOL create $TESTPOOL2 $VDEV2
+log_must $ZFS create -V $SIZE $TESTPOOL2/$TESTVOL
+log_mustnot $ZPOOL add $TESTPOOL cache /dev/zvol/rdsk/$TESTPOOL2/$TESTVOL
+
+log_pass "Cache device can only be block devices."
--- /dev/null	Fri Nov 22 15:19:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cache_011_pos.ksh	Fri Nov 22 15:19:24 2013
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+#
+# DESCRIPTION:
+#	Remove cache device from pool with spare device should succeed.
+#
+# STRATEGY:
+#	1. Create pool with cache devices and spare devices
+#	2. Remove cache device from the pool
+#	3. The upper action should succeed
+#
+
+verify_runnable "global"
+verify_disk_count "$LDEV2"
+
+function cleanup {
+	if datasetexists $TESTPOOL ; then
+		log_must $ZPOOL destroy -f $TESTPOOL
+	fi
+}
+
+log_assert "Remove cache device from pool with spare device should succeed"
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	log_must $ZPOOL create $TESTPOOL $type $VDEV \
+		cache $LDEV spare $LDEV2
+
+	log_must $ZPOOL remove $TESTPOOL $LDEV
+	log_must display_status $TESTPOOL
+
+	log_must $ZPOOL destroy -f $TESTPOOL
+done
+
+log_pass "Remove cache device from pool with spare device should succeed"
--- /dev/null	Fri Nov 22 15:19:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/cleanup.ksh	Fri Nov 22 15:19:24 2013
@@ -0,0 +1,46 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+verify_runnable "global"
+
+if datasetexists $TESTPOOL ; then
+	log_must $ZPOOL destroy -f $TESTPOOL
+fi
+if datasetexists $TESTPOOL2 ; then
+	log_must $ZPOOL destroy -f $TESTPOOL2
+fi
+
+log_must $RM -rf $VDIR $VDIR2
+
+log_pass
--- /dev/null	Fri Nov 22 15:19:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cache/setup.ksh	Fri Nov 22 15:19:24 2013
@@ -0,0 +1,45 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cache/cache.cfg
+. $STF_SUITE/tests/functional/cache/cache.kshlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $LDEV) ; then
+	log_unsupported "Only physical disk could be cache device"
+fi
+
+log_must $RM -rf $VDIR $VDIR2
+log_must $MKDIR -p $VDIR $VDIR2
+log_must $MKFILE $SIZE $VDEV $VDEV2
+
+log_pass
--- /dev/null	Fri Nov 22 15:19:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cachefile/Makefile	Fri Nov 22 15:19:25 2013
@@ -0,0 +1,45 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cachefile
+
+PROGS = cachefile_001_pos \
+	cachefile_002_pos \
+	cachefile_003_pos \
+	cachefile_004_pos
+
+FILES = cachefile.cfg \
+	cachefile.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:19:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cachefile/cachefile.cfg	Fri Nov 22 15:19:25 2013
@@ -0,0 +1,33 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export CPATH="/etc/zfs/zpool.cache"
+export CPATH1=/var/tmp/cachefile.$$
+export CPATH2=/cachefile.$$
--- /dev/null	Fri Nov 22 15:19:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cachefile/cachefile.kshlib	Fri Nov 22 15:19:25 2013
@@ -0,0 +1,47 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+#
+# A function to determine if a given pool name has an entry in cachefile
+# returns 1 if the pool is not in the cache, 0 otherwise.
+function pool_in_cache {
+
+	# checking for the pool name in the strings output of
+	# the given cachefile, default is /etc/zfs/zpool.cache
+	typeset cachefile=${2:-$CPATH}
+
+	RESULT=$($STRINGS $cachefile | $GREP -w $1)
+	if [ -z "$RESULT" ]
+	then
+		return 1
+	fi
+	return 0
+}
--- /dev/null	Fri Nov 22 15:19:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cachefile/cachefile_001_pos.ksh	Fri Nov 22 15:19:26 2013
@@ -0,0 +1,94 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#
+# Creating a pool with "cachefile" set doesn't update zpool.cache
+#
+# STRATEGY:
+# 1. Create a pool with the cachefile property set
+# 2. Verify that the pool doesn't have an entry in zpool.cache
+# 3. Verify the cachefile property is set
+# 4. Create a pool without the cachefile property
+# 5. Verify the cachefile property isn't set
+# 6. Verify that zpool.cache contains an entry for the pool
+#
+
+function cleanup
+{
+	typeset file
+
+	if poolexists $TESTPOOL ; then
+                destroy_pool $TESTPOOL
+        fi
+	for file in $CPATH1 $CPATH2 ; do
+		if [[ -f $file ]] ; then
+			log_must $RM $file
+		fi
+	done
+}
+
+verify_runnable "global"
+
+log_assert "Creating a pool with \"cachefile\" set doesn't update zpool.cache"
+log_onexit cleanup
+
+set -A opts "none" "false" "none" \
+	"$CPATH" "true" "-" \
+	"$CPATH1" "true" "$CPATH1" \
+	"$CPATH2" "true" "$CPATH2"
+
+typeset -i i=0
+
+while (( i < ${#opts[*]} )); do
+	log_must $ZPOOL create -o cachefile=${opts[i]} $TESTPOOL $DISKS
+	case ${opts[((i+1))]} in
+		false) log_mustnot pool_in_cache $TESTPOOL
+			;;
+		true) log_must pool_in_cache $TESTPOOL ${opts[i]}
+			;;
+	esac
+
+	PROP=$(get_pool_prop cachefile $TESTPOOL)
+	if [[ $PROP != ${opts[((i+2))]} ]]; then
+		log_fail "cachefile property not set as expected. " \
+			"Expect: ${opts[((i+2))]}, Current: $PROP"
+	fi
+	log_must $ZPOOL destroy $TESTPOOL
+	(( i = i + 3 ))
+done
+
+log_pass "Creating a pool with \"cachefile\" set doesn't update zpool.cache"
--- /dev/null	Fri Nov 22 15:19:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cachefile/cachefile_002_pos.ksh	Fri Nov 22 15:19:26 2013
@@ -0,0 +1,82 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#
+# Importing a pool with "cachefile" set doesn't update zpool.cache
+#
+# STRATEGY:
+# 1. Create a pool with the cachefile property set
+# 2. Verify the pool doesn't have an entry in zpool.cache
+# 3. Export the pool
+# 4. Import the pool
+# 5. Verify the pool does have an entry in zpool.cache
+# 6. Export the pool
+# 7. Import the pool -o cachefile=<cachefile>
+# 8. Verify the pool doesn't have an entry in zpool.cache
+#
+
+function cleanup
+{
+	if poolexists $TESTPOOL ; then
+                destroy_pool $TESTPOOL
+        fi
+}
+
+verify_runnable "global"
+
+log_assert "Importing a pool with \"cachefile\" set doesn't update zpool.cache"
+log_onexit cleanup
+
+log_must $ZPOOL create -o cachefile=none $TESTPOOL $DISKS
+typeset DEVICEDIR=$(get_device_dir $DISKS)
+log_mustnot pool_in_cache $TESTPOOL
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import -d $DEVICEDIR $TESTPOOL
+log_must pool_in_cache $TESTPOOL
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import -o cachefile=none -d $DEVICEDIR $TESTPOOL
+log_mustnot pool_in_cache $TESTPOOL
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import -o cachefile=$CPATH -d $DEVICEDIR $TESTPOOL
+log_must pool_in_cache $TESTPOOL
+
+log_must $ZPOOL destroy $TESTPOOL
+
+log_pass "Importing a pool with \"cachefile\" set doesn't update zpool.cache"
--- /dev/null	Fri Nov 22 15:19:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cachefile/cachefile_003_pos.ksh	Fri Nov 22 15:19:26 2013
@@ -0,0 +1,100 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#
+# Setting altroot=<path> and cachefile=$CPATH for zpool create is succeed
+#
+# STRATEGY:
+# 1. Attempt to create a pool with -o altroot=<path> -o cachefile=<value>
+# 2. Verify the command succeed
+#
+#
+
+TESTDIR=/altdir.$$
+
+function cleanup
+{
+	typeset file
+
+	if poolexists $TESTPOOL ; then
+		destroy_pool $TESTPOOL
+	fi
+
+        for file in $CPATH1 $CPATH2 ; do
+                if [[ -f $file ]] ; then
+                        log_must $RM $file
+                fi
+        done
+
+	if [ -d $TESTDIR ]
+	then
+		$RMDIR $TESTDIR
+	fi
+}
+
+verify_runnable "global"
+
+log_assert "Setting altroot=path and cachefile=$CPATH for zpool create succeed."
+log_onexit cleanup
+
+typeset -i i=0
+
+set -A opts "none" "none" \
+	"$CPATH" "-" \
+	"$CPATH1" "$CPATH1" \
+	"$CPATH2" "$CPATH2"
+
+
+while (( i < ${#opts[*]} )); do
+	log_must $ZPOOL create -o altroot=$TESTDIR -o cachefile=${opts[i]} \
+		$TESTPOOL $DISKS
+	if [[ ${opts[i]} != none ]]; then
+		log_must pool_in_cache $TESTPOOL ${opts[i]}
+	else
+		log_mustnot pool_in_cache $TESTPOOL
+	fi
+
+	PROP=$(get_pool_prop cachefile $TESTPOOL)
+	if [[ $PROP != ${opts[((i+1))]} ]]; then
+		log_fail "cachefile property not set as expected. " \
+			"Expect: ${opts[((i+1))]}, Current: $PROP"
+	fi
+	log_must $ZPOOL destroy $TESTPOOL
+	(( i = i + 2 ))
+done
+
+log_pass "Setting altroot=path and cachefile=$CPATH for zpool create succeed."
--- /dev/null	Fri Nov 22 15:19:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh	Fri Nov 22 15:19:27 2013
@@ -0,0 +1,124 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cachefile/cachefile.cfg
+. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib
+
+#
+# DESCRIPTION:
+#	Verify set, export and destroy when cachefile is set on pool.
+#
+# STRATEGY:
+#	1. Create two pools with one same cahcefile1.
+#	2. Set cachefile of the two pools to another same cachefile2.
+#	3. Verify cachefile1 not exist.
+#	4. Export the two pools.
+#	5. Verify cachefile2 not exist.
+#	6. Import the two pools and set cachefile to cachefile2.
+#	7. Destroy the two pools.
+#	8. Verify cachefile2 not exist.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+	poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
+
+	mntpnt=$(get_prop mountpoint $TESTPOOL)
+	typeset -i i=0
+	while ((i < 2)); do
+		if [[ -e $mntpnt/vdev$i ]]; then
+			log_must $RM -f $mntpnt/vdev$i
+		fi
+		((i += 1))
+	done
+
+	if poolexists $TESTPOOL ; then
+		destroy_pool $TESTPOOL
+	fi
+
+	for file in $CPATH1 $CPATH2 ; do
+		if [[ -f $file ]] ; then
+			log_must $RM $file
+		fi
+	done
+}
+
+
+log_assert "Verify set, export and destroy when cachefile is set on pool."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL $DISKS
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+typeset -i i=0
+while ((i < 2)); do
+	log_must $MKFILE 64M $mntpnt/vdev$i
+	eval vdev$i=$mntpnt/vdev$i
+	((i += 1))
+done
+
+log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL1 $vdev0
+log_must pool_in_cache $TESTPOOL1 $CPATH1
+log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL2 $vdev1
+log_must pool_in_cache $TESTPOOL2 $CPATH1
+
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1
+log_must pool_in_cache $TESTPOOL1 $CPATH2
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2
+log_must pool_in_cache $TESTPOOL2 $CPATH2
+if [[ -f $CPATH1 ]]; then
+	log_fail "Verify set when cachefile is set on pool."
+fi
+
+log_must $ZPOOL export $TESTPOOL1
+log_must $ZPOOL export $TESTPOOL2
+if [[ -f $CPATH2 ]]; then
+	log_fail "Verify export when cachefile is set on pool."
+fi
+
+log_must $ZPOOL import -d $mntpnt $TESTPOOL1
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1
+log_must pool_in_cache $TESTPOOL1 $CPATH2
+log_must $ZPOOL import -d $mntpnt $TESTPOOL2
+log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2
+log_must pool_in_cache $TESTPOOL2 $CPATH2
+
+log_must $ZPOOL destroy $TESTPOOL1
+log_must $ZPOOL destroy $TESTPOOL2
+if [[ -f $CPATH2 ]]; then
+	log_fail "Verify destroy when cachefile is set on pool."
+fi
+
+log_pass "Verify set, export and destroy when cachefile is set on pool."
--- /dev/null	Fri Nov 22 15:19:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/Makefile	Fri Nov 22 15:19:27 2013
@@ -0,0 +1,47 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/clean_mirror
+
+PROGS = clean_mirror_001_pos \
+	clean_mirror_002_pos \
+	clean_mirror_003_pos \
+	clean_mirror_004_pos \
+	cleanup \
+	setup
+
+FILES = clean_mirror_common.kshlib \
+	default.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:19:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/clean_mirror_001_pos.ksh	Fri Nov 22 15:19:28 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/zero over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_PRIMARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
--- /dev/null	Fri Nov 22 15:19:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/clean_mirror_002_pos.ksh	Fri Nov 22 15:19:28 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/zero over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_SECONDARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
--- /dev/null	Fri Nov 22 15:19:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/clean_mirror_003_pos.ksh	Fri Nov 22 15:19:28 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be mangled without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/urandom over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_PRIMARY /dev/urandom
+
+log_pass "The overwrite did not have any effect on the data"
--- /dev/null	Fri Nov 22 15:19:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/clean_mirror_004_pos.ksh	Fri Nov 22 15:19:29 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/clean_mirror/clean_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be mangled without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/urandom over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $SIDE_SECONDARY /dev/urandom
+
+log_pass "The overwrite had no effect on the data"
--- /dev/null	Fri Nov 22 15:19:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib	Fri Nov 22 15:19:29 2013
@@ -0,0 +1,78 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/clean_mirror/default.cfg
+
+# Most of the code related to the clearing of mirrors is duplicated in all
+# the test cases below this directory, barring a few minor changes
+# involving the device to be affected and the 'object' to use to mangle
+# the contents of the mirror.
+# This code is sourced into each of these test cases.
+
+function overwrite_verify_mirror
+{
+	typeset AFFECTED_DEVICE=$1
+	typeset OVERWRITING_DEVICE=$2
+
+	typeset atfile=0
+	set -A files
+	set -A cksums
+	set -A newcksums
+
+	while (( atfile < FILE_COUNT )); do
+		files[$atfile]=$TESTDIR/file.$atfile
+		log_must $FILE_WRITE -o create -f $TESTDIR/file.$atfile \
+			-b $FILE_SIZE -c 1
+		cksums[$atfile]=$($CKSUM ${files[$atfile]})
+		(( atfile = atfile + 1 ))
+	done
+
+	# dd the primary side of the mirror
+	log_must $DD if=$OVERWRITING_DEVICE of=/dev/dsk/$AFFECTED_DEVICE \
+		seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 8 )) conv=notrunc
+
+	atfile=0
+
+	typeset -i failedcount=0
+	while (( atfile < FILE_COUNT )); do
+		files[$atfile]=$TESTDIR/file.$atfile
+		newcksum=$($CKSUM ${files[$atfile]})
+		if [[ $newcksum != ${cksums[$atfile]} ]]; then
+			(( failedcount = failedcount + 1 ))
+		fi
+		$RM -f ${files[$atfile]}
+		(( atfile = atfile + 1 ))
+	done
+
+	if (( $failedcount > 0 )); then
+		log_fail "of the $FILE_COUNT files $failedcount did not " \
+		    "have the same checksum before and after."
+	fi
+}
--- /dev/null	Fri Nov 22 15:19:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/cleanup.ksh	Fri Nov 22 15:19:30 2013
@@ -0,0 +1,49 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/clean_mirror/default.cfg
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+$DF -F zfs -h | $GREP "$TESTFS " >/dev/null
+[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR
+destroy_pool $TESTPOOL
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+if [[ -n $SINGLE_DISK ]]; then
+	log_must cleanup_devices $MIRROR_PRIMARY
+else
+	log_must cleanup_devices $MIRROR_PRIMARY $MIRROR_SECONDARY
+fi
+
+log_pass
--- /dev/null	Fri Nov 22 15:19:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/default.cfg	Fri Nov 22 15:19:30 2013
@@ -0,0 +1,55 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+typeset -i NUMBER_OF_DISKS=0
+for i in $DISKS; do
+	[[ -n $MIRROR_PRIMARY ]] && MIRROR_SECONDARY=$i
+	[[ -z $MIRROR_PRIMARY ]] && MIRROR_PRIMARY=$i
+done
+
+if [[ -z $MIRROR_SECONDARY ]]; then
+	# We need to repartition the single disk to two slices
+	SINGLE_DISK=$MIRROR_PRIMARY
+	MIRROR_SECONDARY=$MIRROR_PRIMARY
+	SIDE_PRIMARY=${SINGLE_DISK}s0
+	SIDE_SECONDARY=${SINGLE_DISK}s1
+else
+	SIDE_PRIMARY=${MIRROR_PRIMARY}s0
+	SIDE_SECONDARY=${MIRROR_SECONDARY}s0
+fi
+
+export MIRROR_PRIMARY MIRROR_SECONDARY SINGLE_DISK SIDE_PRIMARY SIDE_SECONDARY
+
+export FILE_COUNT=30
+export FILE_SIZE=$(( 1024 * 1024 ))
+export MIRROR_MEGS=70
+export MIRROR_SIZE=${MIRROR_MEGS}m # default mirror size
+export DD_BLOCK=$(( 64 * 1024 ))
+export DD_COUNT=$(( MIRROR_MEGS * 1024 * 1024 / DD_BLOCK ))
--- /dev/null	Fri Nov 22 15:19:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/clean_mirror/setup.ksh	Fri Nov 22 15:19:30 2013
@@ -0,0 +1,51 @@
+#! /usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/clean_mirror/default.cfg
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+if [[ -n $SINGLE_DISK ]]; then
+	log_note "Partitioning a single disk ($SINGLE_DISK)"
+else
+	log_note "Partitioning disks ($MIRROR_PRIMARY $MIRROR_SECONDARY)"
+fi
+log_must set_partition ${SIDE_PRIMARY##*s} "" $MIRROR_SIZE $MIRROR_PRIMARY
+log_must set_partition ${SIDE_SECONDARY##*s} "" $MIRROR_SIZE $MIRROR_SECONDARY
+
+default_mirror_setup $SIDE_PRIMARY $SIDE_SECONDARY
+
+log_pass
--- old/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg	Fri Nov 22 15:19:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg	Fri Nov 22 15:19:31 2013
@@ -25,7 +25,7 @@
 #
 
 #
-# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright (c) 2013 by Delphix. All rights reserved.
 #
 
 # Set the expected properties of zpool
--- old/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos.ksh	Fri Nov 22 15:19:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_002_pos.ksh	Fri Nov 22 15:19:31 2013
@@ -25,6 +25,10 @@
 # Use is subject to license terms.
 #
 
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
 . $STF_SUITE/include/libtest.shlib
 . $STF_SUITE/tests/functional/cli_root/zpool_get/zpool_get.cfg
 
@@ -81,7 +85,7 @@
 COUNT=$($WC /tmp/values.$$ | $AWK '{print $1}')
 if [ $i -ne $COUNT ]
 then
-	log_fail "Length of output $COUNT was not equal to number of props + 1."
+	log_fail "Found zpool features not in the zpool_get test config."
 fi
 
 
--- /dev/null	Fri Nov 22 15:19:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/Makefile	Fri Nov 22 15:19:32 2013
@@ -0,0 +1,45 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_user
+
+PROGS = cli_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+SUBDIRS = misc \
+	zfs_list \
+	zpool_iostat \
+	zpool_list
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Fri Nov 22 15:19:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/Makefile	Fri Nov 22 15:19:32 2013
@@ -0,0 +1,83 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_user/misc
+
+PROGS = cleanup \
+	setup \
+	zdb_001_neg \
+	zfs_001_neg \
+	zfs_allow_001_neg \
+	zfs_clone_001_neg \
+	zfs_create_001_neg \
+	zfs_destroy_001_neg \
+	zfs_get_001_neg \
+	zfs_inherit_001_neg \
+	zfs_mount_001_neg \
+	zfs_promote_001_neg \
+	zfs_receive_001_neg \
+	zfs_rename_001_neg \
+	zfs_rollback_001_neg \
+	zfs_send_001_neg \
+	zfs_set_001_neg \
+	zfs_share_001_neg \
+	zfs_snapshot_001_neg \
+	zfs_unallow_001_neg \
+	zfs_unmount_001_neg \
+	zfs_unshare_001_neg \
+	zfs_upgrade_001_neg \
+	zpool_001_neg \
+	zpool_add_001_neg \
+	zpool_attach_001_neg \
+	zpool_clear_001_neg \
+	zpool_create_001_neg \
+	zpool_destroy_001_neg \
+	zpool_detach_001_neg \
+	zpool_export_001_neg \
+	zpool_get_001_neg \
+	zpool_history_001_neg \
+	zpool_import_001_neg \
+	zpool_import_002_neg \
+	zpool_offline_001_neg \
+	zpool_online_001_neg \
+	zpool_remove_001_neg \
+	zpool_replace_001_neg \
+	zpool_scrub_001_neg \
+	zpool_set_001_neg \
+	zpool_status_001_neg \
+	zpool_upgrade_001_neg
+
+FILES = misc.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:19:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/cleanup.ksh	Fri Nov 22 15:19:33 2013
@@ -0,0 +1,50 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+if poolexists $TESTPOOL.virt
+then
+	log_must $ZPOOL destroy $TESTPOOL.virt
+fi
+
+if poolexists v1-pool
+then
+	log_must $ZPOOL destroy v1-pool
+fi
+
+if [[ -f /tmp/zfstest_datastream.dat ]]
+then
+	log_must $RM -f /tmp/zfstest_datastream.dat
+fi
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:19:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/misc.cfg	Fri Nov 22 15:19:33 2013
@@ -0,0 +1,71 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# these are the set of setable ZFS properties
+PROP_NAMES="\
+	aclinherit	aclmode		atime		 \
+	checksum	compression			devices \
+	exec		mountpoint	quota		readonly \
+	recordsize	reservation	setuid		sharenfs \
+	snapdir"
+
+# these are a set of values we apply, for use when testing the
+# zfs get/set subcommands - ordered as per the list above so we
+# can iterate over both sets in an array
+PROP_VALS="\
+	secure		discard		on		 \
+	fletcher2	on				on \
+	on		legacy		none		on \
+	128k		none		on		on \
+	visible"
+
+# these are an alternate set of property values
+PROP_ALTVALS="\
+	noallow		groupmask	off		 \
+	fletcher4	lzjb				off \
+	off		/tmp/zfstest	100m		off \
+	512		10m		off		off \
+	hidden"
+
+
+
+# additional properties to worry about: canmount copies xattr zoned version
+
+POOL_PROPS="\
+	failmode	autoreplace"
+
+POOL_VALS="\
+	continue	on"
+
+POOL_ALTVALS="\
+	panic		off"
+
+export TESTSNAP=testsnap-misc
+export TESTCLCT=testclct-misc
--- /dev/null	Fri Nov 22 15:19:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/setup.ksh	Fri Nov 22 15:19:33 2013
@@ -0,0 +1,161 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+# This setup script is moderately complex, as it creates scenarios for all
+# of the tests included in this directory. Usually we'd want each test case
+# to setup/teardown it's own configuration, but this would be time consuming
+# given the nature of these tests. However, as a side-effect, one test
+# leaving the system in an unknown state could impact other test cases.
+
+
+DISK=${DISKS%% *}
+VOLSIZE=150m
+TESTVOL=testvol
+
+# Create a default setup that includes a volume
+default_setup_noexit "$DISK" "" "volume"
+
+#
+# The rest of this setup script creates a ZFS filesystem configuration
+# that is used to test the rest of the zfs subcommands in this directory.
+#
+
+# create a snapshot and a clone to test clone promote
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+log_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone
+# create a file in the filesystem that isn't in the above snapshot
+$TOUCH /$TESTDIR/file.txt
+
+
+# create a non-default property and a child we can use to test inherit
+log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2
+log_must $ZFS set snapdir=hidden $TESTPOOL/$TESTFS
+
+
+# create an unmounted filesystem to test unmount
+log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2.unmounted
+log_must $ZFS unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
+
+
+# send our snapshot to a known file in /tmp
+$ZFS send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.dat
+if [ ! -s /tmp/zfstest_datastream.dat ]
+then
+	log_fail "ZFS send datafile was not created!"
+fi
+log_must $CHMOD 644 /tmp/zfstest_datastream.dat
+
+
+# create a filesystem that has particular properties to test set/get
+log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/prop
+set -A props $PROP_NAMES
+set -A prop_vals $PROP_VALS
+typeset -i i=0
+
+while [[ $i -lt ${#props[*]} ]]
+do
+	prop_name=${props[$i]}
+	prop_val=${prop_vals[$i]}
+	log_must $ZFS set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop
+	i=$(( $i + 1 ))
+done
+
+# create a filesystem we don't mind renaming
+log_must $ZFS create $TESTPOOL/$TESTFS/renameme
+
+
+if is_global_zone
+then
+	# create a filesystem we can share
+	log_must $ZFS create $TESTPOOL/$TESTFS/unshared
+	log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS/unshared
+
+	# create a filesystem that we can unshare
+	log_must $ZFS create $TESTPOOL/$TESTFS/shared
+	log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared
+fi
+
+
+log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/version1
+log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/allowed
+log_must $ZFS allow everyone create $TESTPOOL/$TESTFS/allowed
+
+if is_global_zone
+then
+
+	# Now create several virtual disks to test zpool with
+
+	$MKFILE 100m /$TESTDIR/disk1.dat
+	$MKFILE 100m /$TESTDIR/disk2.dat
+	$MKFILE 100m /$TESTDIR/disk3.dat
+	$MKFILE 100m /$TESTDIR/disk-additional.dat
+	$MKFILE 100m /$TESTDIR/disk-export.dat
+	$MKFILE 100m /$TESTDIR/disk-offline.dat
+	$MKFILE 100m /$TESTDIR/disk-spare1.dat
+	$MKFILE 100m /$TESTDIR/disk-spare2.dat
+
+	# and create a pool we can perform attach remove replace,
+	# etc. operations with
+	log_must $ZPOOL create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \
+	/$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \
+	spare /$TESTDIR/disk-spare1.dat
+
+
+	# Offline one of the disks to test online
+	log_must $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat
+
+
+	# create an exported pool to test import
+	log_must $ZPOOL create $TESTPOOL.exported /$TESTDIR/disk-export.dat
+	log_must $ZPOOL export $TESTPOOL.exported
+
+	set -A props $POOL_PROPS
+	set -A prop_vals $POOL_VALS
+	typeset -i i=0
+
+	while [[ $i -lt ${#props[*]} ]]
+	do
+		prop_name=${props[$i]}
+		prop_val=${prop_vals[$i]}
+		log_must $ZPOOL set $prop_name=$prop_val $TESTPOOL
+		i=$(( $i + 1 ))
+	done
+
+	# copy a v1 pool from cli_root
+	$CP $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
+	    /$TESTDIR
+	log_must $BUNZIP2 /$TESTDIR/zfs-pool-v1.dat.bz2
+	log_must $ZPOOL import -d /$TESTDIR v1-pool
+fi
+log_pass
--- /dev/null	Fri Nov 22 15:19:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zdb_001_neg.ksh	Fri Nov 22 15:19:34 2013
@@ -0,0 +1,82 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zdb can't run as a user on datasets, but can run without arguments
+#
+# STRATEGY:
+# 1. Run zdb as a user, it should print information
+# 2. Run zdb as a user on different datasets, it should fail
+#
+
+function check_zdb
+{
+	$@ > /tmp/zdb.$$
+	$GREP "Dataset mos" /tmp/zdb.$$
+	if [ $? -eq 0 ]
+	then
+		log_fail "$@ exited 0 when run as a non root user!"
+	fi
+	$RM /tmp/zdb.$$
+}
+
+
+function cleanup
+{
+	if [ -e /tmp/zdb_001_neg.$$.txt ]
+	then
+		$RM /tmp/zdb_001_neg.$$.txt
+	fi
+
+}
+
+verify_runnable "global"
+
+log_assert "zdb can't run as a user on datasets, but can run without arguments"
+log_onexit cleanup
+
+log_must eval "$ZDB > /tmp/zdb_001_neg.$$.txt"
+# verify the output looks okay
+log_must $GREP pool_guid /tmp/zdb_001_neg.$$.txt
+log_must $RM /tmp/zdb_001_neg.$$.txt
+
+# we shouldn't able to run it on any dataset
+check_zdb $ZDB $TESTPOOL
+check_zdb $ZDB $TESTPOOL/$TESTFS
+check_zdb $ZDB $TESTPOOL/$TESTFS@snap
+check_zdb $ZDB $TESTPOOL/$TESTFS.clone
+
+log_pass "zdb can't run as a user on datasets, but can run without arguments"
--- /dev/null	Fri Nov 22 15:19:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_001_neg.ksh	Fri Nov 22 15:19:34 2013
@@ -0,0 +1,59 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs shows a usage message when run as a user
+#
+# STRATEGY:
+# 1. Run zfs as a user
+# 2. Verify it produces a usage message
+#
+
+function cleanup
+{
+	if [ -e /tmp/zfs_001_neg.$$.txt ]
+	then
+		$RM /tmp/zfs_001_neg.$$.txt
+	fi
+}
+
+log_onexit cleanup
+log_assert "zfs shows a usage message when run as a user"
+
+eval "$ZFS > /tmp/zfs_001_neg.$$.txt 2>&1"
+log_must $GREP "usage: zfs command args" /tmp/zfs_001_neg.$$.txt
+
+log_pass "zfs shows a usage message when run as a user"
--- /dev/null	Fri Nov 22 15:19:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_allow_001_neg.ksh	Fri Nov 22 15:19:35 2013
@@ -0,0 +1,67 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs allow returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that trying to show allows works as a user
+# 2. Verify that trying to set allows fails as a user
+#
+#
+
+# check to see if we have zfs allow
+$ZFS 2>&1 | $GREP "allow" > /dev/null
+if (($? != 0)) then
+	log_unsupported "ZFS allow not supported on this machine."
+fi
+
+log_assert "zfs allow returns an error when run as a user"
+
+log_must $ZFS allow $TESTPOOL/$TESTFS
+log_mustnot $ZFS allow $($LOGNAME) create $TESTPOOL/$TESTFS
+
+# now verify that the above command actually did nothing by
+# checking for any allow output. ( if no allows are granted,
+# nothing should be output )
+OUTPUT=$($ZFS allow $TESTPOOL/$TESTFS | $GREP "Local+Descendent" )
+if [ -n "$OUTPUT" ]
+then
+	log_fail "zfs allow permissions were granted on $TESTPOOL/$TESTFS"
+fi
+
+log_pass "zfs allow returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_clone_001_neg.ksh	Fri Nov 22 15:19:35 2013
@@ -0,0 +1,54 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs clone returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that we're unable to clone snapshots as a user
+#
+#
+
+log_assert "zfs clone returns an error when run as a user"
+log_mustnot $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS.myclone
+
+# check to see that the above command really did nothing
+if datasetexists $TESTPOOL/$TESTFS.myclone
+then
+	log_fail "Dataset $TESTPOOL/$TESTFS.myclone should not exist!"
+fi
+log_pass "zfs clone returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_create_001_neg.ksh	Fri Nov 22 15:19:35 2013
@@ -0,0 +1,61 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing various badly formed 'zfs create' should fail.
+#
+# STRATEGY:
+# 1. Create an array of badly formed sub-commands.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+
+set -A args  "" "create $TESTPOOL/$TESTFS" \
+    "create $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "create $TESTPOOL/$TESTCLCT/$TESTFS" \
+    "create $TESTFS/$TESTPOOL/$TESTCLCT"
+
+log_assert "Verify zfs create without parameters fails."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZFS ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'create' fails as non-root."
--- /dev/null	Fri Nov 22 15:19:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_destroy_001_neg.ksh	Fri Nov 22 15:19:36 2013
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs destroy' fails as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+
+set -A args "destroy" "destroy $TESTPOOL/$TESTFS" \
+    "destroy -f" "destroy -f $TESTPOOL/$TESTFS" \
+    "destroy -r" "destroy -r $TESTPOOL/$TESTFS" \
+    "destroy -rf $TESTPOOL/$TESTFS" \
+    "destroy -fr $TESTPOOL/$TESTFS" \
+    "destroy $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -f $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -r $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -rf $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "destroy -fr $TESTPOOL/$TESTFS@$TESTSNAP"
+
+log_assert "zfs destroy [-f|-r] [fs|snap]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZFS ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'destroy' fails as non-root."
--- /dev/null	Fri Nov 22 15:19:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_get_001_neg.ksh	Fri Nov 22 15:19:36 2013
@@ -0,0 +1,65 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs get works when run as a user
+#
+# STRATEGY:
+# 1. Run zfs get with an array of different arguments
+# 2. Verify for each property, we get the value that's expected
+#
+#
+
+log_assert "zfs get works when run as a user"
+
+typeset -i i=0
+
+set -A props $PROP_NAMES
+set -A prop_vals $PROP_VALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+	PROP=${props[$i]}
+	EXPECTED=${prop_vals[$i]}
+	ACTUAL=$( $ZFS get $PROP -o value -H snapdir $TESTPOOl/$TESTFS/prop )
+	if [ "$ACTUAL" != "$EXPECTED" ]
+	then
+		log_fail "Property $PROP value was $ACTUAL, expected $EXPECTED"
+	fi
+        i=$(( $i + 1 ))
+done
+
+log_pass "zfs get works when run as a user"
--- /dev/null	Fri Nov 22 15:19:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_inherit_001_neg.ksh	Fri Nov 22 15:19:36 2013
@@ -0,0 +1,56 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs inherit returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that we can't inherit a property when running as a user
+#
+#
+
+log_assert "zfs inherit returns an error when run as a user"
+log_mustnot $ZFS inherit snapdir $TESTPOOL/$TESTFS/$TESTFS2
+
+# check to see that the above command really did nothing
+PROP=$($ZFS get snapdir $TESTPOOL/$TESTFS)
+if [ "$PROP" = "visible" ]
+then
+	log_fail "snapdir property inherited from the $TESTPOOL/$TESTFS!"
+fi
+
+log_pass "zfs inherit returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_mount_001_neg.ksh	Fri Nov 22 15:19:37 2013
@@ -0,0 +1,57 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs mount returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify that we can't mount the unmounted filesystem created in setup
+#
+#
+
+log_assert "zfs mount returns an error when run as a user"
+
+log_mustnot $ZFS mount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
+
+# now verify that the above command didn't do anything
+MOUNTED=$($MOUNT | $GREP $TESTPOOL/$TESTFS/$TESTFS2.unmounted)
+if [ -n "$MOUNTED" ]
+then
+	log_fail "Filesystem $TESTPOOL/$TESTFS/$TESTFS2.unmounted was mounted!"
+fi
+
+log_pass "zfs mount returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_promote_001_neg.ksh	Fri Nov 22 15:19:37 2013
@@ -0,0 +1,56 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs promote returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Verify we don't have permissions to promote a clone
+#
+#
+
+log_assert "zfs promote returns an error when run as a user"
+
+log_mustnot $ZFS promote $TESTPOOL/$TESTFS/clone
+
+# Now verify that the above command didn't do anything
+if datasetexists $TESTPOOL/$TESTFS/clone@snap
+then
+	log_fail "Clone $TESTPOOl/$TESTFS/clone was actually promoted!"
+fi
+
+log_pass "zfs promote returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_receive_001_neg.ksh	Fri Nov 22 15:19:37 2013
@@ -0,0 +1,58 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs receive returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to receive a datastream as a user
+# 2. Verify that the dataset wasn't created
+#
+
+log_assert "zfs receive returns an error when run as a user"
+
+log_mustnot eval "$ZFS receive -d $TESTPOOL/$TESTFS/$TESTFS2 \
+ < /tmp/zfstest_datastream.dat"
+
+# verify that command actually did nothing
+
+if datasetexists $TESTPOOL/$TESTFS/$TESTFS2/$TESTFS
+then
+	log_fail "$TESTPOOL/$TESTFS/$TESTFS2/$TESTFS was received!"
+fi
+
+log_pass "zfs receive returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_rename_001_neg.ksh	Fri Nov 22 15:19:38 2013
@@ -0,0 +1,56 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs rename returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to rename a dataset
+# 2. Verify that the renamed dataset does not exist.
+#
+#
+
+log_assert "zfs rename returns an error when run as a user"
+
+log_mustnot $ZFS rename $TESTPOOL/$TESTFS/renameme $TESTPOOL/$TESTFS/renameme1
+
+# now verify the above command didn't actually do anything
+if datasetexists $TESTPOOL/$TESTFS/renameme1
+then
+	log_fail "The dataset $TESTPOOL/$TESTFS/renameme was renamed!"
+fi
+
+log_pass "zfs rename returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_rollback_001_neg.ksh	Fri Nov 22 15:19:38 2013
@@ -0,0 +1,60 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs rollback returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to rollback a snapshot
+# 2. Verify that a file which doesn't exist in the snapshot still exists
+#    (showing the snapshot rollback failed)
+#
+#
+
+log_assert "zfs rollback returns an error when run as a user"
+
+log_mustnot $ZFS rollback $TESTPOOL/$TESTFS@snap
+
+# now verify the above command didn't actually do anything
+
+# in the above filesystem there's a file that should not exist once
+# the snapshot is rolled back - we check for it
+if [ ! -e /$TESTDIR/file.txt ]
+then
+	log_fail "Rollback of snapshot $TESTPOOL/$TESTFS@snap succeeded!"
+fi
+
+log_pass "zfs rollback returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_send_001_neg.ksh	Fri Nov 22 15:19:38 2013
@@ -0,0 +1,67 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs send returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to send a dataset to a file
+# 2. Verify the file created has zero-size
+#
+#
+
+function cleanup
+{
+	if [ -e /tmp/zfstest_datastream.$$ ]
+	then
+		log_must $RM /tmp/zfstest_datastream.$$
+	fi
+}
+
+log_assert "zfs send returns an error when run as a user"
+log_onexit cleanup
+
+log_mustnot eval "$ZFS send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.$$"
+
+# Now check that the above command actually did nothing
+
+# We should have a non-zero-length file in /tmp
+if [ -s /tmp/zfstest_datastream.$$ ]
+then
+	log_fail "A zfs send file was created in /tmp/zfstest_datastream.$$ !"
+fi
+
+log_pass "zfs send returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_set_001_neg.ksh	Fri Nov 22 15:19:39 2013
@@ -0,0 +1,70 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs set returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to set an array of properties on a dataset
+# 2. Verify that those properties were not set and retain their original values.
+#
+#
+
+log_assert "zfs set returns an error when run as a user"
+
+typeset -i i=0
+
+set -A props $PROP_NAMES
+set -A prop_vals $PROP_VALS
+set -A prop_new $PROP_ALTVALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+	PROP=${props[$i]}
+	EXPECTED=${prop_vals[$i]}
+	NEW=${prop_new[$i]}
+	log_mustnot $ZFS set $PROP=$NEW $TESTPOOL/$TESTFS/prop
+
+	# Now verify that the above command did nothing
+	ACTUAL=$($ZFS get $PROP -o value -H snapdir $TESTPOOl/$TESTFS/prop )
+	if [ "$ACTUAL" != "$EXPECTED" ]
+	then
+		log_fail "Property $PROP was set to $ACTUAL, expected $EXPECTED"
+	fi
+        i=$(( $i + 1 ))
+done
+
+log_pass "zfs set returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh	Fri Nov 22 15:19:39 2013
@@ -0,0 +1,63 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs share returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to share a dataset
+# 2. Verify the dataset was not shared.
+#
+#
+
+verify_runnable "global"
+
+log_assert "zfs share returns an error when run as a user"
+
+if is_shared $TESTDIR/unshared
+then
+	log_fail "$TESTPOOL/$TESTFS/unshared was incorrectly shared initially!"
+fi
+
+log_mustnot $ZFS share $TESTPOOL/$TESTFS/unshared
+
+# Now verify that the above command didn't actually do anything
+if is_shared $TESTDIR/unshared
+then
+	log_fail "$TESTPOOL/$TESTFS/unshared was actually shared!"
+fi
+
+log_pass "zfs share returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_snapshot_001_neg.ksh	Fri Nov 22 15:19:39 2013
@@ -0,0 +1,56 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs snapshot returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to snapshot a dataset
+# 2. Verify the snapshot wasn't taken
+#
+#
+
+log_assert "zfs snapshot returns an error when run as a user"
+
+log_mustnot $ZFS snapshot $TESTPOOL/$TESTFS@usersnap1
+
+# Now verify that the above command didn't actually do anything
+if datasetexists $TESTPOOL/$TESTFS@usersnap1
+then
+	log_fail "Snapshot $TESTPOOL/$TESTFS@usersnap1 was taken !"
+fi
+
+log_pass "zfs snapshot returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_unallow_001_neg.ksh	Fri Nov 22 15:19:40 2013
@@ -0,0 +1,64 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs unallow returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to unallow a set of permissions
+# 2. Verify the unallow wasn't performed
+#
+#
+
+# check to see if we have zfs unallow
+$ZFS 2>&1 | $GREP "unallow" > /dev/null
+if (($? != 0)) then
+        log_unsupported "ZFS unallow not supported on this machine."
+fi
+
+log_assert "zfs unallow returns an error when run as a user"
+
+log_mustnot $ZFS unallow everyone $TESTPOOL/$TESTFS/allowed
+
+# now check with zfs allow to see if the permissions are still there
+OUTPUT=$($ZFS allow $TESTPOOL/$TESTFS/allowed | $GREP "Local+Descendent" )
+if [ -z "$OUTPUT" ]
+then
+	log_fail "Error - create permissions were unallowed on \
+	$TESTPOOL/$TESTFS/allowed"
+fi
+
+log_pass "zfs unallow returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_unmount_001_neg.ksh	Fri Nov 22 15:19:40 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zfs umount' and its variants fail as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that the commands fail with an error code.
+#
+
+verify_runnable "both"
+
+set -A args "umount" "umount -f" "unmount" "unmount -f" \
+    "umount $TESTPOOL/$TESTFS" "umount -f $TESTPOOL/$TESTFS" \
+    "unmount $TESTPOOL/$TESTFS" "unmount -f $TESTPOOL/$TESTFS" \
+    "umount $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "umount -f $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "unmount $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "unmount -f $TESTPOOL/$TESTFS@$TESTSNAP" \
+    "umount $TESTDIR" "umount -f $TESTDIR" \
+    "unmount $TESTDIR" "unmount -f $TESTDIR"
+
+log_assert "zfs u[n]mount [-f] [mountpoint|fs|snap]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZFS ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'u[n]mount' fails as non-root."
--- /dev/null	Fri Nov 22 15:19:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh	Fri Nov 22 15:19:41 2013
@@ -0,0 +1,64 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs unshare returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to unshare a shared dataset
+# 2. Verify the dataset is still shared
+#
+#
+
+verify_runnable "global"
+
+log_assert "zfs unshare returns an error when run as a user"
+
+#  verify that the filesystem was shared initially
+if not_shared $TESTDIR/shared
+then
+	log_fail "$TESTPOOL/$TESTFS/shared was not shared initially at all!"
+fi
+
+log_mustnot $ZFS unshare $TESTPOOL/$TESTFS/shared
+
+# now verify that the above command didn't do anything
+if not_shared $TESTDIR/shared
+then
+	log_fail "$TESTPOOL/$TESTFS/shared was actually unshared!"
+fi
+
+log_pass "zfs unshare returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zfs_upgrade_001_neg.ksh	Fri Nov 22 15:19:41 2013
@@ -0,0 +1,67 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zfs upgrade returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to upgrade a version1 dataset
+# 2. Verify the dataset wasn't upgraded
+#
+#
+
+# check to see if we have upgrade capability
+$ZFS upgrade > /dev/null 2>&1
+HAS_UPGRADE=$?
+if [ $HAS_UPGRADE -ne 0 ]
+then
+	log_unsupported "Zfs upgrade not supported"
+fi
+
+log_assert "zfs upgrade returns an error when run as a user"
+
+
+log_mustnot $ZFS upgrade $TESTPOOL/$TESTFS/version1
+
+# now check to see the above command didn't do anything
+VERSION=$($ZFS upgrade $TESTPOOL/$TESTFS/version1 2>&1 \
+	 | $GREP "already at this version")
+if [ -n "$VERSION" ]
+then
+	log_fail "A filesystem was upgraded!"
+fi
+
+log_pass "zfs upgrade returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_001_neg.ksh	Fri Nov 22 15:19:41 2013
@@ -0,0 +1,60 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool shows a usage message when run as a user
+#
+# STRATEGY:
+# 1. Run the zpool command
+# 2. Verify that a usage message is produced
+#
+#
+
+function cleanup
+{
+	if [ -e /tmp/zpool_001_neg.$$.txt ]
+	then
+		$RM /tmp/zpool_001_neg.$$.txt
+	fi
+}
+
+log_onexit cleanup
+log_assert "zpool shows a usage message when run as a user"
+
+eval "$ZPOOL > /tmp/zpool_001_neg.$$.txt 2>&1"
+log_must $GREP "usage: zpool command args" /tmp/zpool_001_neg.$$.txt
+
+log_pass "zpool shows a usage message when run as a user"
--- /dev/null	Fri Nov 22 15:19:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_add_001_neg.ksh	Fri Nov 22 15:19:42 2013
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool add' fails as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that an error is returned.
+#
+
+verify_runnable "global"
+
+ADD_DISK="${DISKS%% }"
+ADD_DISK="${ADD_DISK##* }"
+
+[[ -z $ADD_DISK ]] && \
+        log_fail "No spare disks available."
+
+set -A args "add" "add -f" "add -n" \
+    "add $TESTPOOL" "add -f $TESTPOOL" "add -n $TESTPOOL" \
+    "add -fn $TESTPOOL" "add -nf $TESTPOOL" \
+    "add $TESTPOOL $ADD_DISK" "add -f $TESTPOOL $ADD_DISK" \
+    "add -n $TESTPOOL $ADD_DISK" \
+    "add -fn $TESTPOOL $ADD_DISK" \
+    "add -nf $TESTPOOL $ADD_DISK" \
+
+log_assert "zpool add [-fn] pool_name vdev"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'add' and its options fail as non-root."
--- /dev/null	Fri Nov 22 15:19:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_attach_001_neg.ksh	Fri Nov 22 15:19:42 2013
@@ -0,0 +1,67 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool attach returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to attach a disk to a pool
+# 2.Verify that the attach failed
+#
+#
+
+function check_for_attach
+{
+	RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-additional.dat)
+	if [ -n "$RESULT" ]
+	then
+		log_fail "A disk was attached to the pool!"
+	fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool attach returns an error when run as a user"
+
+log_mustnot $ZPOOL attach $TESTPOOL.virt /$TESTDIR/disk1.dat \
+	/$TESTDIR/disk-additional.dat
+check_for_attach
+
+log_mustnot $ZPOOL attach -f $TESTPOOL.virt /$TESTDIR/disk1.dat \
+	 /$TESTDIR/disk-additional.dat
+check_for_attach
+
+log_pass "zpool attach returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_clear_001_neg.ksh	Fri Nov 22 15:19:42 2013
@@ -0,0 +1,52 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool clear returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to clear errors on a zpool
+# 2. Verify that the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool clear returns an error when run as a user"
+
+log_mustnot $ZPOOL clear $TESTPOOL
+
+log_pass "zpool clear returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_create_001_neg.ksh	Fri Nov 22 15:19:43 2013
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool create' fails as a non-root user.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that an error is returned.
+#
+
+verify_runnable "global"
+
+ADD_DISK="${DISKS%% }"
+ADD_DISK="${ADD_DISK##* }"
+
+[[ -z $ADD_DISK ]] && \
+        log_fail "No spare disks available."
+
+set -A args "create" "create -f" "create -n" \
+    "create $TESTPOOL" "create -f $TESTPOOL" "create -n $TESTPOOL" \
+    "create -fn $TESTPOOL" "create -nf $TESTPOOL" \
+    "create $TESTPOOL $ADD_DISK" "create -f $TESTPOOL $ADD_DISK" \
+    "create -n $TESTPOOL $ADD_DISK" \
+    "create -fn $TESTPOOL $ADD_DISK" \
+    "create -nf $TESTPOOL $ADD_DISK"
+
+log_assert "zpool create [-fn] pool_name vdev"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'create' and its options fail as non-root."
--- /dev/null	Fri Nov 22 15:19:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_destroy_001_neg.ksh	Fri Nov 22 15:19:43 2013
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool destroy' fails as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+set -A args "destroy" "destroy -f" \
+    "destroy $TESTPOOL" "destroy -f $TESTPOOL" \
+    "destroy $TESTPOOL $TESTPOOL"
+
+log_assert "zpool destroy [-f] [pool_name ...]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'destroy' and its options fail as non-root."
--- /dev/null	Fri Nov 22 15:19:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_detach_001_neg.ksh	Fri Nov 22 15:19:43 2013
@@ -0,0 +1,58 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool detach returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to detach a device from a pool
+# 2. Verify the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool detach returns an error when run as a user"
+
+log_mustnot $ZPOOL detach $TESTPOOL.virt /$TESTDIR/disk1.dat
+
+RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk1.dat)
+if [ -z "$RESULT" ]
+then
+	log_fail "A disk was detached from the pool!"
+fi
+
+log_pass "zpool detach returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_export_001_neg.ksh	Fri Nov 22 15:19:44 2013
@@ -0,0 +1,65 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool export returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to export a pool
+# 2. Verify the command fails
+#
+
+function check_for_export
+{
+	RESULT=$($ZPOOL list | $GREP $TESTPOOL.virt )
+	if [ -z "$RESULT" ]
+	then
+		log_fail "A pool was exported!"
+	fi
+
+}
+
+verify_runnable "global"
+
+log_assert "zpool export returns an error when run as a user"
+
+log_mustnot $ZPOOL export $TESTPOOL.virt
+check_for_export
+
+log_mustnot $ZPOOL export -f $TESTPOOL.virt
+check_for_export
+
+log_pass "zpool export returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_get_001_neg.ksh	Fri Nov 22 15:19:44 2013
@@ -0,0 +1,67 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool get works when run as a user
+#
+# STRATEGY:
+#
+# 1. For each property, get that property
+# 2. Verify the property was the same as that set in setup
+#
+
+verify_runnable "global"
+
+log_assert "zpool get works when run as a user"
+
+set -A props $POOL_PROPS
+set -A prop_vals $POOL_VALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+	PROP=${props[$i]}
+	EXPECTED=${prop_vals[$i]}
+	ACTUAL=$( $ZPOOL get $PROP $TESTPOOL | $GREP $PROP | $AWK '{print $1}' )
+	if [ "$ACTUAL" != "$EXPECTED" ]
+	then
+		log_fail "Property $PROP value was $ACTUAL, expected $EXPECTED"
+	fi
+        i=$(( $i + 1 ))
+done
+
+log_must $ZPOOL get all $TESTPOOL
+
+log_pass "zpool get works when run as a user"
--- /dev/null	Fri Nov 22 15:19:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_history_001_neg.ksh	Fri Nov 22 15:19:44 2013
@@ -0,0 +1,55 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool history works when run as a user
+#
+# STRATEGY:
+# 1. Attempt to get history on a test pool
+# 2. Verify the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool history returns an error when run as a user"
+
+log_mustnot $ZPOOL history
+log_mustnot $ZPOOL history $TESTPOOL
+log_mustnot $ZPOOL history -i $TESTPOOL
+log_mustnot $ZPOOL history -l $TESTPOOL
+log_mustnot $ZPOOL history -il $TESTPOOL
+
+log_assert "zpool history returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_import_001_neg.ksh	Fri Nov 22 15:19:45 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool import returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to import an exported pool
+# 2. Verify the command fails
+#
+#
+
+function check_for_import
+{
+	RESULT=$($ZPOOL list -H -o name | $GREP $TESTPOOL.exported)
+	if [ -n "$RESULT" ]
+	then
+		log_fail "Pool $TESTPOOL.export was successfully imported!"
+	fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool import returns an error when run as a user"
+log_mustnot $ZPOOL import
+
+log_mustnot $ZPOOL import -a
+check_for_import
+
+log_mustnot $ZPOOL import -d /$TESTDIR $TESTPOOL.exported
+check_for_import
+
+log_pass "zpool import returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_import_002_neg.ksh	Fri Nov 22 15:19:45 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool import' as regular user should denied.
+#
+# STRATEGY:
+# 1. Create an array of options try to detect exported/destroyed pools.
+# 2. Execute 'zpool import' with each element of the array by regular user.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+typeset testpool
+if is_global_zone ; then
+        testpool=$TESTPOOL.exported
+else
+        testpool=${TESTPOOL%%/*}
+fi
+
+set -A args "" "-D" "-Df" "-f" "-f $TESTPOOL" "-Df $TESTPOOL" "-a"
+
+log_assert "Executing 'zpool import' by regular user fails"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL import ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Executing 'zpool import' by regular user fails as expected."
--- /dev/null	Fri Nov 22 15:19:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_offline_001_neg.ksh	Fri Nov 22 15:19:46 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool offline returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to offline a device in a pool
+# 2. Verify that the command fails
+#
+#
+
+function check_for_offline
+{
+	RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-1.dat \
+		 | $GREP OFFLINE )
+	if [ -n "$RESULT" ]
+	then
+		log_fail "A disk was taken offline!"
+	fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool offline returns an error when run as a user"
+
+log_mustnot $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-1.dat
+check_for_offline
+
+log_mustnot $ZPOOL offline -t $TESTPOOL.virt /$TESTDIR/disk-1.dat
+check_for_offline
+
+log_pass "zpool offline returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_online_001_neg.ksh	Fri Nov 22 15:19:46 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool online returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to online a device in a pool
+# 2. Verify the command fails
+#
+#
+
+function check_for_online
+{
+	RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-offline.dat \
+		 | $GREP ONLINE )
+	if [ -n "$RESULT" ]
+	then
+		log_fail "A disk was brough online!"
+	fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool online returns an error when run as a user"
+
+log_mustnot $ZPOOL online $TESTPOOL.virt /$TESTDIR/disk-offline.dat
+check_for_online
+
+log_mustnot $ZPOOL online -t $TESTPOOL.virt /$TESTDIR/disk-offline.dat
+check_for_online
+
+log_pass "zpool online returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_remove_001_neg.ksh	Fri Nov 22 15:19:46 2013
@@ -0,0 +1,59 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool remove returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to remove a device from a pool
+# 2. Verify the command fails
+#
+#
+
+verify_runnable "global"
+
+log_assert "zpool remove returns an error when run as a user"
+
+log_mustnot $ZPOOL remove $TESTPOOL.virt /$TESTDIR/disk-spare1.dat
+
+RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-spare1.dat)
+if [ -z "$RESULT" ]
+then
+	log_fail "A disk was removed from the pool!"
+fi
+
+
+log_pass "zpool remove returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_replace_001_neg.ksh	Fri Nov 22 15:19:47 2013
@@ -0,0 +1,68 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool replace returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to replace a device in a pool
+# 2. Verify the command fails
+#
+#
+
+function check_for_replace
+{
+	$SLEEP 10
+	RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-additional.dat)
+	if [ -n "$RESULT" ]
+	then
+		log_fail "A disk was replaced in the pool!"
+	fi
+}
+
+verify_runnable "global"
+
+log_assert "zpool replace returns an error when run as a user"
+
+log_mustnot $ZPOOL replace $TESTPOOL.virt /$TESTDIR/disk-1.dat \
+	 /$TESTDIR/disk-additional.dat
+check_for_replace
+
+log_mustnot $ZPOOL replace -f $TESTPOOL.virt /$TESTDIR/disk-1.dat \
+ /$TESTDIR/disk-additional.dat
+check_for_replace
+
+log_pass "zpool replace returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_scrub_001_neg.ksh	Fri Nov 22 15:19:47 2013
@@ -0,0 +1,53 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool scrub returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to start a scrub on a pool
+# 2. Verify the command fails
+#
+#
+
+verify_runnable "global"
+
+log_assert "zpool scrub returns an error when run as a user"
+
+log_mustnot $ZPOOL scrub $TESTPOOL
+log_mustnot $ZPOOL scrub -s $TESTPOOL
+
+log_pass "zpool scrub returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_set_001_neg.ksh	Fri Nov 22 15:19:47 2013
@@ -0,0 +1,71 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool set returns an error when run as a user
+#
+# STRATEGY:
+# 1. Attempt to set some properties on a pool
+# 2. Verify the command fails
+#
+#
+
+verify_runnable "global"
+
+log_assert "zpool set returns an error when run as a user"
+
+set -A props $POOL_NAMES
+set -A prop_vals $POOL_VALS
+set -A prop_new $POOL_ALTVALS
+
+while [[ $i -lt ${#args[*]} ]]
+do
+	PROP=${props[$i]}
+	EXPECTED=${prop_vals[$i]}
+	NEW=${prop_new[$i]}
+	log_mustnot $POOL set $PROP=$NEW $TESTPOOL
+
+	# Now verify that the above command did nothing
+	ACTUAL=$( $ZPOOL get $PROP $TESTPOOL | $GREP $PROP | $AWK '{print $1}' )
+	if [ "$ACTUAL" != "$EXPECTED" ]
+	then
+		log_fail "Property $PROP was set to $ACTUAL, expected $EXPECTED"
+	fi
+        i=$(( $i + 1 ))
+done
+
+
+log_pass "zpool set returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_status_001_neg.ksh	Fri Nov 22 15:19:48 2013
@@ -0,0 +1,76 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool status works when run as a user
+#
+# STRATEGY:
+#
+# 1. Run zpool status as a user
+# 2. Verify we get output
+#
+
+function check_pool_status
+{
+	RESULT=$($GREP "pool:" /tmp/pool-status.$$)
+	if [ -z "$RESULT" ]
+	then
+		log_fail "No pool: string found in zpool status output!"
+	fi
+	$RM /tmp/pool-status.$$
+}
+
+verify_runnable "global"
+
+log_assert "zpool status works when run as a user"
+
+log_must eval "$ZPOOL status > /tmp/pool-status.$$"
+check_pool_status
+
+log_must eval "$ZPOOL status -v > /tmp/pool-status.$$"
+check_pool_status
+
+log_must eval "$ZPOOL status $TESTPOOL> /tmp/pool-status.$$"
+check_pool_status
+
+log_must eval "$ZPOOL status -v $TESTPOOL > /tmp/pool-status.$$"
+check_pool_status
+
+# $TESTPOOL.virt has an offline device, so -x will show it
+log_must eval "$ZPOOL status -x $TESTPOOL.virt > /tmp/pool-status.$$"
+check_pool_status
+
+log_pass "zpool status works when run as a user"
--- /dev/null	Fri Nov 22 15:19:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/misc/zpool_upgrade_001_neg.ksh	Fri Nov 22 15:19:48 2013
@@ -0,0 +1,65 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool upgrade returns an error when run as a user
+#
+# STRATEGY:
+#
+# 1. Attempt to upgrade a pool
+# 2. Verify the command fails
+#
+
+verify_runnable "global"
+
+log_assert "zpool upgrade returns an error when run as a user"
+
+log_onexit cleanup
+# zpool upgrade returns 0 when it can't do anything
+log_must $ZPOOL upgrade $TESTPOOL.virt
+
+# Now try to upgrade our version 1 pool
+log_mustnot $ZPOOL upgrade v1-pool
+
+# if the pool has been upgraded, then v1-pool won't be listed in the output
+# of zpool upgrade anymore
+RESULT=$($ZPOOL upgrade | $GREP v1-pool)
+if [ -z "$RESULT" ]
+then
+	log_fail "A pool was upgraded successfully!"
+fi
+
+log_pass "zpool upgrade returns an error when run as a user"
--- /dev/null	Fri Nov 22 15:19:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/Makefile	Fri Nov 22 15:19:48 2013
@@ -0,0 +1,49 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_user/zfs_list
+
+PROGS = cleanup \
+	setup \
+	zfs_list_001_pos \
+	zfs_list_002_pos \
+	zfs_list_003_pos \
+	zfs_list_004_neg \
+	zfs_list_007_pos \
+	zfs_list_008_neg
+
+FILES = zfs_list.cfg \
+	zfs_list.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:19:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/cleanup.ksh	Fri Nov 22 15:19:49 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+depth_fs_cleanup
+default_cleanup
--- /dev/null	Fri Nov 22 15:19:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/setup.ksh	Fri Nov 22 15:19:49 2013
@@ -0,0 +1,70 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+. $STF_SUITE/tests/functional/cli_user/zfs_list/zfs_list.cfg
+
+DISK=${DISKS%% *}
+
+default_setup_noexit $DISK
+
+# create datasets and set checksum options
+set -A cksumarray $CKSUMOPTS
+typeset -i index=0
+for dataset in $DATASETS
+do
+	log_must $ZFS create $TESTPOOL/$TESTFS/$dataset
+	$SLEEP 1
+        log_must $ZFS snapshot $TESTPOOL/$TESTFS/${dataset}@snap
+
+	$SLEEP 1
+	if is_global_zone ; then
+		log_must $ZFS create -V 64M $TESTPOOL/$TESTFS/${dataset}-vol
+		$SLEEP 1
+		log_must $ZFS snapshot $TESTPOOL/$TESTFS/${dataset}-vol@snap
+	fi
+
+	# sleep to ensure that the datasets have different creation dates
+	$SLEEP 1
+	log_must $ZFS set checksum=${cksumarray[$index]} \
+		$TESTPOOL/$TESTFS/$dataset
+	if datasetexists $TESTPOOL/$TESTFS/${dataset}-vol; then
+		log_must $ZFS set checksum=${cksumarray[$index]} \
+			$TESTPOOL/$TESTFS/${dataset}-vol
+	fi
+
+        index=$((index + 1))
+done
+
+depth_fs_setup
+
+log_pass
--- /dev/null	Fri Nov 22 15:19:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.cfg	Fri Nov 22 15:19:49 2013
@@ -0,0 +1,35 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# Datasets (in order of creation date) and which checksum options
+# we want to set for each dataset.
+# These are used by various zfs list tests
+export DATASETS="Apple Banana Carrot Orange apple banana carrot"
+export CKSUMOPTS="on sha256 sha256 sha256 fletcher4 off fletcher2"
--- /dev/null	Fri Nov 22 15:19:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib	Fri Nov 22 15:19:50 2013
@@ -0,0 +1,118 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# A function that verifies sort order. It takes as input
+# a command, which gets executed. We then iterate over the results
+# comparing that the sort order passed in via the list
+#
+function verify_sort { # command list name
+
+	# now verify we've sorted by creation date:
+	typeset CMD=$1
+	typeset list=$2
+	typeset name=$3
+
+	typeset -i RET=0
+	typeset -i index=1
+
+	# run the command to verify that it works
+	log_must eval "$CMD > /dev/null"
+
+	# Now check the sort order
+	for dataset in $( $CMD )
+	do
+		ACTUAL=$(basename $dataset)
+		if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
+		then
+			EXPECTED=$($ECHO $list | $AWK "{print \$$index}")
+			if [ "$ACTUAL" != "$EXPECTED" ]
+			then
+				log_note "WARNING:" \
+					"'$ACTUAL' does not equal '$EXPECTED'"
+				log_fail "ERROR: Sort by $name fails."
+			fi
+
+			((index = index + 1))
+		fi
+	done
+
+	# finally check to see if we have the expected number of elements
+	if [ $index -ne $($ECHO $list | $AWK '{print split($0,arr)+1}') ]
+	then
+		log_fail "Warning: " \
+			"unexpected number of filesystems found in list output!"
+	fi
+}
+
+# A function that verifies reverse sort order. It takes as input
+# a command, which gets executed. We then iterate over the results
+# comparing that the sort order passed in via the list
+#
+function verify_reverse_sort { # command list name
+
+	typeset CMD=$1
+	typeset list=$2
+	typeset name=$3
+
+	# set our index to the be number of elements in the list
+	typeset -i index=$($ECHO $list | $AWK '{print split($0,arr)}')
+
+	log_note "Checking reverse sort by '$name'," \
+		"expecting the reverse of '$list'"
+	log_must eval "$CMD > /dev/null"
+
+	for dataset in $( $CMD )
+	do
+		ACTUAL=$(basename $dataset)
+		if [ "$dataset" != "$TESTPOOL/$TESTFS" ]
+		then
+			EXPECTED=$($ECHO $list | $AWK "{print \$$index}")
+			if [ "$ACTUAL" != "$EXPECTED" ]
+			then
+				log_note "Warning:" \
+					"'$ACTUAL' does not equal to" \
+					"the reverse of '$EXPECTED'"
+				log_fail "ERROR: Reverse sort by '$name' fails."
+			fi
+
+			((index = index - 1))
+		fi
+	done
+
+	# finally check to see if we have the expected number of elements
+	if [ $index -ne 0 ]
+	then
+		log_fail "Warning: " \
+			"unexpected number of filesystems found in list output!"
+	fi
+}
--- /dev/null	Fri Nov 22 15:19:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_001_pos.ksh	Fri Nov 22 15:19:50 2013
@@ -0,0 +1,116 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+# Executing well-formed 'zfs list' commands should return success.
+#
+# STRATEGY:
+# 1. Create an array of valid options.
+# 2. Execute each element in the array.
+# 3. Verify success is returned.
+#
+
+verify_runnable "both"
+
+set -A args "list" "list -r" "list -H" \
+        "list $TESTPOOL/$TESTFS" \
+        "list -r $TESTPOOL/$TESTFS" "list -H $TESTPOOL/$TESTFS" \
+        "list -rH $TESTPOOL/$TESTFS" "list -Hr $TESTPOOL/$TESTFS" \
+        "list -o name $TESTPOOL/$TESTFS" "list -r -o name $TESTPOOL/$TESTFS" \
+        "list -H -o name $TESTPOOL/$TESTFS" "list -rH -o name $TESTPOOL/$TESTFS" \
+        "list -Hr -o name $TESTPOOL/$TESTFS"
+
+set -A d_args " " "-r" "-H" \
+        "$TESTPOOL/$TESTFS" \
+        "-r $TESTPOOL/$TESTFS" "-H $TESTPOOL/$TESTFS" \
+        "-rH $TESTPOOL/$TESTFS" "-Hr $TESTPOOL/$TESTFS" \
+        "-o name $TESTPOOL/$TESTFS" "-r -o name $TESTPOOL/$TESTFS" \
+        "-H -o name $TESTPOOL/$TESTFS" "-rH -o name $TESTPOOL/$TESTFS" \
+        "-Hr -o name $TESTPOOL/$TESTFS"
+
+typeset -i m=${#args[*]}
+typeset -i n=0
+typeset -i k=0
+while (( n<${#depth_options[*]} ));
+do
+	(( k=0 ))
+	while (( k<${#d_args[*]} ));
+	do
+		args[$m]="list"" -${depth_options[$n]}"" ${d_args[$k]}"
+		(( k+=1 ))
+		(( m+=1 ))
+	done
+	(( n+=1 ))
+done
+
+set -A pathargs "list -r $TESTDIR" "list -H $TESTDIR" \
+	"list -r ./../$TESTDIR" "list -H ./../$TESTDIR"
+
+set -A d_pathargs " $TESTDIR" "-r $TESTDIR" "-H $TESTDIR" \
+	"-r ./../$TESTDIR" "-H ./../$TESTDIR"
+
+(( m=${#pathargs[*]} ))
+(( n=0 ))
+(( k=0 ))
+while (( n<${#depth_options[*]} ));
+do
+	(( k=0 ))
+	while (( k<${#d_pathargs[*]} ));
+	do
+		pathargs[$m]="list"" -${depth_options[$n]}"" ${d_pathargs[$k]}"
+		(( k+=1 ))
+		(( m+=1 ))
+	done
+	(( n+=1 ))
+done
+
+log_assert "Verify 'zfs list [-rH] [-o property[,prop]*] [fs|clct|vol]'."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_must eval "$ZFS ${args[i]} > /dev/null"
+	((i = i + 1))
+done
+
+# Verify 'zfs list <path>' will succeed on absolute or relative path.
+
+cd /tmp
+typeset -i i=0
+while [[ $i -lt ${#pathargs[*]} ]]; do
+	log_must eval "$ZFS ${pathargs[i]} > /dev/null"
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'list' succeeds as non-root."
--- /dev/null	Fri Nov 22 15:19:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_002_pos.ksh	Fri Nov 22 15:19:50 2013
@@ -0,0 +1,176 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_user/zfs_list/zfs_list.kshlib
+
+#
+# DESCRIPTION:
+# The sort functionality in 'zfs list' works as expected.
+#
+# STRATEGY:
+# 1. Using several zfs datasets with names, creation dates, checksum options
+# 2. Sort the datasets by name, checksum options, creation date.
+# 3. Verify that the datasets are sorted correctly.
+#
+
+verify_runnable "both"
+
+# datasets ordered by name
+fs_name="Apple Banana Carrot Orange apple banana carrot"
+vol_name="Apple-vol Banana-vol Carrot-vol Orange-vol apple-vol"
+vol_name="$vol_name banana-vol carrot-vol"
+if is_global_zone ; then
+	snap_name="Apple-vol@snap Apple@snap Banana-vol@snap Banana@snap"
+	snap_name="$snap_name Carrot-vol@snap Carrot@snap Orange-vol@snap Orange@snap"
+	snap_name="$snap_name apple-vol@snap apple@snap banana-vol@snap banana@snap"
+	snap_name="$snap_name carrot-vol@snap carrot@snap"
+else
+	snap_name="Apple@snap Banana@snap"
+	snap_name="$snap_name Carrot@snap Orange@snap"
+	snap_name="$snap_name apple@snap banana@snap"
+	snap_name="$snap_name carrot@snap"
+fi
+
+fs_creation=$fs_name
+vol_creation=$vol_name
+if is_global_zone ; then
+	snap_creation="Apple@snap Apple-vol@snap Banana@snap Banana-vol@snap"
+	snap_creation="$snap_creation Carrot@snap Carrot-vol@snap Orange@snap Orange-vol@snap"
+	snap_creation="$snap_creation apple@snap apple-vol@snap banana@snap banana-vol@snap"
+	snap_creation="$snap_creation carrot@snap carrot-vol@snap"
+else
+	snap_creation="Apple@snap Banana@snap"
+	snap_creation="$snap_creation Carrot@snap Orange@snap"
+	snap_creation="$snap_creation apple@snap banana@snap"
+	snap_creation="$snap_creation carrot@snap"
+fi
+
+#
+# datsets ordered by checksum options (note, Orange, Carrot & Banana have the
+# same checksum options, so ZFS should revert to sorting them alphabetically by
+# name)
+#
+fs_cksum="carrot apple banana Apple Banana Carrot Orange"
+vol_cksum="carrot-vol apple-vol banana-vol Apple-vol Banana-vol"
+vol_cksum="$vol_cksum Carrot-vol Orange-vol"
+snap_cksum=$snap_creation
+
+fs_rev_cksum="carrot apple banana Apple Orange Carrot Banana"
+vol_rev_cksum="carrot-vol apple-vol banana-vol Apple-vol Orange-vol"
+vol_rev_cksum="$vol_rev_cksum Carrot-vol Banana-vol"
+
+log_assert "The sort functionality in 'zfs list' works as expected."
+
+#
+# we must be in the C locale here, as running in other locales
+# will make zfs use that locale's sort order.
+#
+LC_ALL=C; export LC_ALL
+
+# sort by creation
+verify_sort \
+	"$ZFS list -H -r -o name -s creation -t filesystem $TESTPOOL/$TESTFS" \
+	"$fs_creation" "creation date"
+if is_global_zone ; then
+	verify_sort \
+	"$ZFS list -H -r -o name -s creation -t volume $TESTPOOL/$TESTFS" \
+	"$vol_creation" "creation date"
+fi
+verify_sort \
+	"$ZFS list -H -r -o name -s creation -t snapshot $TESTPOOL/$TESTFS" \
+	"$snap_creation" "creation date"
+
+# sort by checksum
+verify_sort \
+	"$ZFS list -H -r -o name -s checksum -t filesystem $TESTPOOL/$TESTFS" \
+	"$fs_cksum" "checksum"
+if is_global_zone ; then
+	verify_sort \
+	"$ZFS list -H -r -o name -s checksum -t volume $TESTPOOL/$TESTFS" \
+	"$vol_cksum" "checksum"
+fi
+verify_sort \
+	"$ZFS list -H -r -o name -s checksum -t snapshot $TESTPOOL/$TESTFS" \
+	"$snap_cksum" "checksum"
+verify_sort \
+	"$ZFS list -H -r -o name -S checksum -t snapshot $TESTPOOL/$TESTFS" \
+	"$snap_cksum" "checksum"
+
+# sort by name
+verify_sort \
+	"$ZFS list -H -r -o name -s name -t filesystem $TESTPOOL/$TESTFS" \
+	"$fs_name" "name"
+if is_global_zone ; then
+	verify_sort \
+	"$ZFS list -H -r -o name -s name -t volume $TESTPOOL/$TESTFS" \
+	"$vol_name" "name"
+fi
+verify_sort \
+	"$ZFS list -H -r -o name -s name -t snapshot $TESTPOOL/$TESTFS" \
+	"$snap_name" "name"
+
+# reverse sort by creation
+verify_reverse_sort \
+	"$ZFS list -H -r -o name -S creation -t filesystem $TESTPOOL/$TESTFS" \
+	"$fs_creation" "creation date"
+if is_global_zone ; then
+	verify_reverse_sort \
+	"$ZFS list -H -r -o name -S creation -t volume $TESTPOOL/$TESTFS" \
+	"$vol_creation" "creation date"
+fi
+verify_reverse_sort \
+	"$ZFS list -H -r -o name -S creation -t snapshot $TESTPOOL/$TESTFS" \
+	"$snap_creation" "creation date"
+
+# reverse sort by checksum
+verify_reverse_sort \
+	"$ZFS list -H -r -o name -S checksum -t filesystem $TESTPOOL/$TESTFS" \
+	"$fs_rev_cksum" "checksum"
+if is_global_zone ; then
+	verify_reverse_sort \
+	"$ZFS list -H -r -o name -S checksum -t volume $TESTPOOL/$TESTFS" \
+	"$vol_rev_cksum" "checksum"
+fi
+
+# reverse sort by name
+verify_reverse_sort \
+	"$ZFS list -H -r -o name -S name -t filesystem $TESTPOOL/$TESTFS"\
+	"$fs_name" "name"
+if is_global_zone ; then
+	verify_reverse_sort \
+	"$ZFS list -H -r -o name -S name -t volume $TESTPOOL/$TESTFS"\
+	"$vol_name" "name"
+fi
+verify_reverse_sort \
+	"$ZFS list -H -r -o name -S name -t snapshot $TESTPOOL/$TESTFS"\
+	"$snap_name" "name"
+
+log_pass "The sort functionality in 'zfs list' works as expected."
--- /dev/null	Fri Nov 22 15:19:51 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_003_pos.ksh	Fri Nov 22 15:19:51 2013
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 	Verify 'zfs list -r' could recursively display any children
+#	of the dataset.
+#
+# STRATEGY:
+# 1. Prepare a set of datasets by hierarchy.
+# 2. Execute 'zfs list -r' at the top of these datasets.
+# 3. Verify all child datasets are all be shown.
+#
+
+function cleanup
+{
+	if [[ -f $tmpfile ]]; then
+		$RM -f $tmpfile
+	fi
+}
+
+verify_runnable "both"
+log_onexit cleanup
+
+log_assert "Verify 'zfs list -r' could display any children recursively."
+
+tmpfile=/var/tmp/zfslist.out.$$
+children="$TESTPOOL/$TESTFS"
+
+for fs in $DATASETS ; do
+	children="$children $TESTPOOL/$TESTFS/$fs"
+done
+
+cd /tmp
+
+for path in $TESTPOOL/$TESTFS $TESTDIR ./../$TESTDIR ; do
+	$ZFS list -rH -o name $path > $tmpfile
+	for fs in $children ; do
+		$GREP "^${fs}$" $tmpfile > /dev/null 2>&1
+		if (( $? != 0 )); then
+			log_fail "$fs not shown in the output list."
+		fi
+	done
+done
+
+log_pass "'zfs list -r' could display any children recursively."
--- /dev/null	Fri Nov 22 15:19:51 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh	Fri Nov 22 15:19:51 2013
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# 	Verify 'zfs list [-r]' should fail while
+#		* the given dataset does not exist
+#		* the given path does not exist.
+#		* the given path does not belong to zfs.
+#
+# STRATEGY:
+# 1. Create an array of invalid options.
+# 2. Execute each element in the array.
+# 3. Verify failure is returned.
+#
+
+verify_runnable "both"
+
+log_assert "Verify 'zfs list [-r]' should fail while the given " \
+	"dataset/path does not exist or not belong to zfs."
+
+paths="$TESTPOOL/NONEXISTFS $TESTPOOL/$TESTFS/NONEXISTFS \
+	/$TESTDIR/NONEXISTFS /devices /tmp ./../devices ./../tmp"
+
+cd /tmp
+
+for fs in $paths ; do
+	log_mustnot $ZFS list $fs
+	log_mustnot $ZFS list -r $fs
+done
+
+log_pass "'zfs list [-r]' fails while the given dataset/path does not exist " \
+	"or not belong to zfs."
--- /dev/null	Fri Nov 22 15:19:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_007_pos.ksh	Fri Nov 22 15:19:52 2013
@@ -0,0 +1,91 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+#	'zfs list -d <n>' should get expected output.
+#
+# STRATEGY:
+#	1. 'zfs list -d <n>' to get the output.
+#	2. 'zfs list -r|egrep' to get the expected output.
+#	3. Compare the two outputs, they shoud be same.
+#
+
+verify_runnable "both"
+
+set -A fs_type "all" "filesystem" "snapshot"
+if is_global_zone ; then
+	set -A fs_type ${fs_type[*]} "volume"
+fi
+
+function cleanup
+{
+	log_must $RM -f $DEPTH_OUTPUT
+	log_must $RM -f $EXPECT_OUTPUT
+}
+
+log_onexit cleanup
+log_assert "'zfs list -d <n>' should get expected output."
+
+mntpnt=/var/tmp
+DEPTH_OUTPUT="$mntpnt/depth_output"
+EXPECT_OUTPUT="$mntpnt/expect_output"
+typeset -i old_val=0
+typeset -i j=0
+typeset -i fs=0
+typeset eg_opt="$DEPTH_FS"$
+for dp in ${depth_array[@]}; do
+	(( j=old_val+1 ))
+	while (( j<=dp && j<=MAX_DEPTH )); do
+		eg_opt="$eg_opt""|depth""$j"$
+		(( j+=1 ))
+	done
+	(( fs=0 ))
+	while (( fs<${#fs_type[*]} )); do
+		if [[ "$dp" == "0" ]] && \
+		  [[ "${fs_type[$fs]}" == "volume" || "${fs_type[$fs]}" == "snapshot" ]]; then
+			log_must eval "$ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT"
+			[[ -s "$DEPTH_OUTPUT" ]] && \
+				log_fail "$DEPTH_OUTPUT should be null."
+			log_mustnot $ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt'
+		else
+			log_must eval "$ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT"
+			log_must eval "$ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt' > $EXPECT_OUTPUT"
+			log_must $DIFF $DEPTH_OUTPUT $EXPECT_OUTPUT
+		fi
+		(( fs+=1 ))
+	done
+	(( old_val=dp ))
+done
+
+log_pass "'zfs list -d <n>' should get expected output."
--- /dev/null	Fri Nov 22 15:19:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_008_neg.ksh	Fri Nov 22 15:19:52 2013
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib
+
+#
+# DESCRIPTION:
+# A negative depth or a non numeric depth should fail in 'zfs list -d <n>'
+#
+# STRATEGY:
+# 1. Run zfs list -d with negative depth or non numeric depth
+# 2. Verify that zfs list returns error
+#
+
+verify_runnable "both"
+
+log_assert "A negative depth or a non numeric depth should fail in 'zfs list -d <n>'"
+
+set -A  badargs "a" "AB" "aBc" "2A" "a2b" "aB2" "-1" "-32" "-999"
+
+typeset -i i=0
+while (( i < ${#badargs[*]} ))
+do
+	log_mustnot eval "$ZFS list -d ${badargs[i]} $DEPTH_FS >/dev/null 2>&1"
+	(( i = i + 1 ))
+done
+
+log_pass "A negative depth or a non numeric depth should fail in 'zfs list -d <n>'"
--- /dev/null	Fri Nov 22 15:19:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_iostat/Makefile	Fri Nov 22 15:19:52 2013
@@ -0,0 +1,43 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_user/zpool_iostat
+
+PROGS = cleanup \
+	setup \
+	zpool_iostat_001_neg \
+	zpool_iostat_002_pos \
+	zpool_iostat_003_neg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:19:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_iostat/cleanup.ksh	Fri Nov 22 15:19:53 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:19:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_iostat/setup.ksh	Fri Nov 22 15:19:53 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:19:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh	Fri Nov 22 15:19:53 2013
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool iostat' can be executed as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify that a success is returned.
+#
+
+verify_runnable "both"
+
+typeset testpool
+if is_global_zone ; then
+	testpool=$TESTPOOL
+else
+	testpool=${TESTPOOL%%/*}
+fi
+
+set -A args "iostat" "iostat $testpool"
+
+log_assert "zpool iostat [pool_name ...] [interval]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_must $ZPOOL ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'iostat' succeeds as non-root."
--- /dev/null	Fri Nov 22 15:19:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh	Fri Nov 22 15:19:54 2013
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool iostat [interval [count]' can be executed as non-root.
+#
+# STRATEGY:
+# 1. Set the interval to 1 and count to 4.
+# 2. Sleep for 4 seconds.
+# 3. Verify that the output has 4 records.
+#
+
+verify_runnable "both"
+
+typeset tmpfile=/var/tmp/zfsiostat.out.$$
+typeset -i stat_count=0
+
+function cleanup
+{
+	if [[ -f $tmpfile ]]; then
+		$RM -f $tmpfile
+	fi
+}
+
+log_onexit cleanup
+log_assert "zpool iostat [pool_name ...] [interval] [count]"
+
+if ! is_global_zone ; then
+	TESTPOOL=${TESTPOOL%%/*}
+fi
+
+$ZPOOL iostat $TESTPOOL 1 4 > $tmpfile 2>&1 &
+sleep 4
+stat_count=$($GREP $TESTPOOL $tmpfile | $WC -l)
+
+if [[ $stat_count -ne 4 ]]; then
+	log_fail "zpool iostat [pool_name] [interval] [count] failed"
+fi
+
+log_pass "zpool iostat [pool_name ...] [interval] [count] passed"
--- /dev/null	Fri Nov 22 15:19:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_003_neg.ksh	Fri Nov 22 15:19:54 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool iostat' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool iostat' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+typeset testpool
+if is_global_zone ; then
+        testpool=$TESTPOOL
+else
+        testpool=${TESTPOOL%%/*}
+fi
+
+set -A args "" "-?" "-f" "nonexistpool" "$TESTPOOL/$TESTFS" \
+	"$testpool 1.23" "$testpool 0" "$testpool -1" "$testpool 1 0" \
+	"$testpool 0 0"
+
+log_assert "Executing 'zpool iostat' with bad options fails"
+
+typeset -i i=1
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL iostat ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Executing 'zpool iostat' with bad options fails"
--- /dev/null	Fri Nov 22 15:19:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_list/Makefile	Fri Nov 22 15:19:54 2013
@@ -0,0 +1,42 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/cli_user/zpool_list
+
+PROGS = cleanup \
+	setup \
+	zpool_list_001_pos \
+	zpool_list_002_neg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:19:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_list/cleanup.ksh	Fri Nov 22 15:19:55 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:19:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_list/setup.ksh	Fri Nov 22 15:19:55 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:19:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_001_pos.ksh	Fri Nov 22 15:19:55 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that 'zpool list' succeeds as non-root.
+#
+# STRATEGY:
+# 1. Create an array of options.
+# 2. Execute each element of the array.
+# 3. Verify the command succeeds.
+#
+
+verify_runnable "both"
+
+if ! is_global_zone; then
+	TESTPOOL=${TESTPOOL%%/*}
+fi
+
+set -A args "list $TESTPOOL" "list -H $TESTPOOL" "list" "list -H" \
+    "list -H -o name $TESTPOOL" "list -o name $TESTPOOL" \
+    "list -o name,size,capacity,health,altroot $TESTPOOL" \
+    "list -H -o name,size,capacity,health,altroot $TESTPOOL"
+
+log_assert "zpool list [-H] [-o filed[,filed]*] [<pool_name> ...]"
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+	log_must $ZPOOL ${args[i]}
+
+	((i = i + 1))
+done
+
+log_pass "The sub-command 'list' succeeds as non-root."
--- /dev/null	Fri Nov 22 15:19:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_002_neg.ksh	Fri Nov 22 15:19:56 2013
@@ -0,0 +1,57 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing 'zpool list' command with bad options fails.
+#
+# STRATEGY:
+# 1. Create an array of badly formed 'zpool list' options.
+# 2. Execute each element of the array.
+# 3. Verify an error code is returned.
+#
+
+verify_runnable "both"
+
+set -A args "" "-?" "-f" "-o" \
+	"-o fakeproperty" "-o name,size,fakeproperty"
+
+log_assert "Executing 'zpool list' with bad options fails"
+
+typeset -i i=1
+while [[ $i -lt ${#args[*]} ]]; do
+	log_mustnot $ZPOOL list ${args[i]}
+	((i = i + 1))
+done
+
+log_pass "Executing 'zpool list' with bad options fails"
--- /dev/null	Fri Nov 22 15:19:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/Makefile	Fri Nov 22 15:19:56 2013
@@ -0,0 +1,46 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/compression
+
+PROGS = cleanup \
+	setup \
+	compress_001_pos \
+	compress_002_pos \
+	compress_003_pos \
+	compress_004_pos
+
+FILES = compress.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:19:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/cleanup.ksh	Fri Nov 22 15:19:56 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+
+default_container_cleanup
--- /dev/null	Fri Nov 22 15:19:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/compress.cfg	Fri Nov 22 15:19:57 2013
@@ -0,0 +1,33 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BLOCKSZ=8192
+export NUM_WRITES=65536
+export DATA=13
--- /dev/null	Fri Nov 22 15:19:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/compress_001_pos.ksh	Fri Nov 22 15:19:57 2013
@@ -0,0 +1,74 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/compression/compress.cfg
+
+#
+# DESCRIPTION:
+# Create two files of exactly the same size. One with compression
+# and one without. Ensure the compressed file is smaller.
+#
+# STRATEGY:
+# Use "zfs set" to turn on compression and create files before
+# and after the set call. The compressed file should be smaller.
+#
+
+verify_runnable "both"
+
+typeset OP=create
+
+log_assert "Ensure that compressed files are smaller."
+
+log_note "Ensure compression is off"
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+
+log_note "Writing file without compression..."
+log_must $FILE_WRITE -o $OP -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Add compression property to the dataset and write another file"
+log_must $ZFS set compression=on $TESTPOOL/$TESTFS
+
+log_must $FILE_WRITE -o $OP -f $TESTDIR/$TESTFILE1 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+$SLEEP 60
+
+FILE0_BLKS=`$DU -k $TESTDIR/$TESTFILE0 | $AWK '{ print $1}'`
+FILE1_BLKS=`$DU -k $TESTDIR/$TESTFILE1 | $AWK '{ print $1}'`
+
+if [[ $FILE0_BLKS -le $FILE1_BLKS ]]; then
+	log_fail "$TESTFILE0 is smaller than $TESTFILE1" \
+			"($FILE0_BLKS <= $FILE1_BLKS)"
+fi
+
+log_pass "$TESTFILE0 is bigger than $TESTFILE1 ($FILE0_BLKS > $FILE1_BLKS)"
--- /dev/null	Fri Nov 22 15:19:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/compress_002_pos.ksh	Fri Nov 22 15:19:58 2013
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/compression/compress.cfg
+
+#
+# DESCRIPTION:
+# Create two files of exactly the same size. One with compression
+# and one without. Ensure the compressed file is smaller.
+#
+# NOTE: This test uses a dataset rather than a simple file system.
+#
+# STRATEGY:
+# Create a dataset, turn on compression and create files before
+# and after the property change. The compressed file should be smaller.
+#
+
+verify_runnable "both"
+
+typeset OP=create
+
+log_assert "Ensure that compressed files in a dataset are smaller."
+
+log_note "Ensure compression is off"
+log_must $ZFS set compression=off $TESTPOOL/$TESTCTR
+
+log_note "Writing file without compression..."
+log_must $FILE_WRITE -o $OP -f $TESTDIR1/$TESTFILE0 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Add compression property to the dataset and write another file"
+log_must $ZFS set compression=on $TESTPOOL/$TESTCTR
+
+log_must $FILE_WRITE -o $OP -f $TESTDIR1/$TESTFILE1 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+$SLEEP 60
+
+FILE0_BLKS=`$DU -k $TESTDIR1/$TESTFILE0 | $AWK '{ print $1}'`
+FILE1_BLKS=`$DU -k $TESTDIR1/$TESTFILE1 | $AWK '{ print $1}'`
+
+if [[ $FILE0_BLKS -le $FILE1_BLKS ]]; then
+	log_fail "$TESTFILE0 is smaller than $TESTFILE1" \
+			"($FILE0_BLKS <= $FILE1_BLKS)"
+fi
+
+log_pass "$TESTFILE0 is bigger than $TESTFILE1 ($FILE0_BLKS > $FILE1_BLKS)"
--- /dev/null	Fri Nov 22 15:19:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/compress_003_pos.ksh	Fri Nov 22 15:19:58 2013
@@ -0,0 +1,96 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# With 'compression' or 'compress'  set, changing filesystem blocksize cannot
+# cause system panic
+#
+# STRATEGY:
+#	1. Set 'compression' or "compress" to on
+#	2. Set different blocksize with ZFS filesystem
+#	3. Use 'mkfile' create single block and multi-block files
+#	4. Verify the system continued work
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -f $TESTDIR/*
+}
+
+log_assert "Changing blocksize doesn't casue system panic with compression settings"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+single_blk_file=$TESTDIR/singleblkfile.$$
+multi_blk_file=$TESTDIR/multiblkfile.$$
+typeset -i blksize=512
+typeset -i fsize=0
+typeset -i offset=0
+
+for propname in "compression" "compress"
+do
+	for value in $(get_compress_opts zfs_compress)
+	do
+		log_must $ZFS set $propname=$value $fs
+		if [[ $value == "gzip-6" ]]; then
+			value="gzip"
+		fi
+		real_val=$(get_prop $propname $fs)
+		[[ $real_val != $value ]] && \
+			log_fail "Set property $propname=$value failed."
+
+		(( blksize = 512 ))
+		while (( blksize <= 131072 )); do
+			log_must $ZFS set recordsize=$blksize $fs
+			(( offset = $RANDOM ))
+			if (( offset > blksize )); then
+				(( offset = offset % blksize ))
+			fi
+			if (( (offset % 2) == 0 )); then
+				#keep offset as non-power-of-2
+				(( offset = offset + 1 ))
+			fi
+			(( fsize = offset ))
+			log_must $MKFILE $fsize $single_blk_file
+			(( fsize = blksize + offset ))
+			log_must $MKFILE $fsize $multi_blk_file
+
+			(( blksize = blksize * 2 ))
+		done
+	done
+done
+
+log_pass "The system works as expected while changing blocksize with compression settings"
--- /dev/null	Fri Nov 22 15:19:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/compress_004_pos.ksh	Fri Nov 22 15:19:58 2013
@@ -0,0 +1,133 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# With 'compression' set, a file with non-power-of-2 blocksize storage space
+# can be freed as will normally.
+#
+# STRATEGY:
+#	1. Set 'compression' or 'compress' to on or lzjb
+#	2. Set different recordsize with ZFS filesystem
+#	3. Repeatedly using 'randfree_file' to create a file and then free its
+#	   storage space with different range, the system should work normally.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -f $TESTDIR/*
+}
+
+function create_free_testing #<file size> <file>
+{
+	typeset -i fsz=$1
+	typeset file=$2
+	typeset -i start=0
+	typeset -i len=0
+	typeset -i dist=0
+
+	for start in 0 `expr $RANDOM % $fsz`
+	do
+		(( dist = fsz - start ))
+		for len in `expr $RANDOM % $dist` $dist \
+			`expr $start + $dist`; do
+			log_must $RANDFREE_FILE -l fsz -s $start \
+				-n $len $file
+			[[ -e $file ]] && \
+				log_must $RM -f $file
+		done
+	done
+}
+
+
+log_assert "Creating non-power-of-2 blocksize file and freeing the file \
+	storage space at will should work normally with compression setting"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+single_blk_file=$TESTDIR/singleblkfile.$$
+multi_blk_file=$TESTDIR/multiblkfile.$$
+typeset -i blksize=512
+typeset -i fsize=0
+typeset -i avail=0
+typeset -i blknum=0
+
+for propname in "compression" "compress"
+do
+	for value in $(get_compress_opts zfs_compress)
+	do
+		log_must $ZFS set compression=$value $fs
+		real_val=$(get_prop $propname $fs)
+		if [[ $value == "gzip-6" ]]; then
+			value="gzip"
+		fi
+                [[ $real_val != $value ]] && \
+                        log_fail "Set property $propname=$value failed."
+
+		(( blksize = 512 ))
+		while (( blksize <= 131072 )); do
+			log_must $ZFS set recordsize=$blksize $fs
+
+			# doing single block testing
+			(( fsize = $RANDOM ))
+			if (( fsize > blksize )); then
+				(( fsize = fsize % blksize ))
+			fi
+			if (( (fsize % 2) == 0 )); then
+				#make sure fsize is non-power-of-2
+				(( fsize = fsize + 1 ))
+			fi
+			create_free_testing $fsize $single_blk_file
+
+			# doing multiple blocks testing
+			avail=$(get_prop available $fs)
+			(( blknum = avail / blksize ))
+			# we just test <10 multi-blocks to limit testing time
+			(( blknum = blknum % 9 ))
+			while (( blknum < 2 )); do
+				(( blknum = blknum + $RANDOM % 9 ))
+			done
+			if (( (blknum % 2) == 0 )); then
+				(( blknum = blknum + 1 )) # keep blknum as odd
+			fi
+			(( fsize = blknum * blksize ))
+			create_free_testing $fsize $multi_blk_file
+
+			(( blksize = blksize * 2 ))
+		done
+	done
+done
+
+log_pass "Creating and freeing non-power-of-2 blocksize file work as expected."
--- /dev/null	Fri Nov 22 15:19:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/compression/setup.ksh	Fri Nov 22 15:19:59 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_setup $DISK
--- /dev/null	Fri Nov 22 15:19:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/ctime/Makefile	Fri Nov 22 15:19:59 2013
@@ -0,0 +1,67 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/ctime
+
+PROG = ctime_001_pos
+
+SCRIPTS = cleanup \
+	setup
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+
+OBJS = $(PROG:%=%.o)
+SRCS = $(OBJS:%.o=%.c)
+
+CMDS = $(PROG:%=$(TESTDIR)/%) $(SCRIPTS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+	$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+	$(POST_PROCESS)
+
+%.o: ../%.c
+	$(COMPILE.c) $<
+
+install: all $(CMDS)
+
+lint: lint_SRCS
+
+clobber: clean
+	-$(RM) $(PROG)
+
+clean:
+	-$(RM) $(OBJS)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:19:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/ctime/cleanup.ksh	Fri Nov 22 15:19:59 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/ctime/ctime_001_pos.c	Fri Nov 22 15:20:00 2013
@@ -0,0 +1,349 @@
+/*
+ * 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 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <utime.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <strings.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libgen.h>
+
+#define	ST_ATIME 0
+#define	ST_CTIME 1
+#define	ST_MTIME 2
+
+#define	ALL_MODE (mode_t)(S_IRWXU|S_IRWXG|S_IRWXO)
+
+typedef struct timetest {
+	int	type;
+	char	*name;
+	int	(*func)(const char *pfile);
+} timetest_t;
+
+static char tfile[BUFSIZ] = { 0 };
+
+extern int errno;
+
+/*
+ * DESCRIPTION:
+ * 	Verify time will be changed correctly after each operation.
+ *
+ * STRATEGY:
+ *	1. Define time test array.
+ *	2. Loop through each item in this array.
+ *	3. Verify the time is changed after each operation.
+ *
+ */
+
+static int
+get_file_time(const char *pfile, int what, time_t *ptr)
+{
+	struct stat stat_buf;
+
+	if (pfile == NULL || ptr == NULL) {
+		return (-1);
+	}
+
+	if (stat(pfile, &stat_buf) == -1) {
+		return (-1);
+	}
+
+	switch (what) {
+		case ST_ATIME:
+			*ptr = stat_buf.st_atime;
+			return (0);
+		case ST_CTIME:
+			*ptr = stat_buf.st_ctime;
+			return (0);
+		case ST_MTIME:
+			*ptr = stat_buf.st_mtime;
+			return (0);
+		default:
+			return (-1);
+	}
+}
+
+static int
+do_read(const char *pfile)
+{
+	int fd, ret = 0;
+	char buf[BUFSIZ] = { 0 };
+
+	if (pfile == NULL) {
+		return (-1);
+	}
+
+	if ((fd = open(pfile, O_RDONLY, ALL_MODE)) == -1) {
+		return (-1);
+	}
+	if (read(fd, buf, sizeof (buf)) == -1) {
+		(void) fprintf(stderr, "read(%d, buf, %d) failed with errno "
+		    "%d\n", fd, sizeof (buf), errno);
+		return (1);
+	}
+	(void) close(fd);
+
+	return (ret);
+}
+
+static int
+do_write(const char *pfile)
+{
+	int fd, ret = 0;
+	char buf[BUFSIZ] = "call function do_write()";
+
+	if (pfile == NULL) {
+		return (-1);
+	}
+
+	if ((fd = open(pfile, O_WRONLY, ALL_MODE)) == -1) {
+		return (-1);
+	}
+	if (write(fd, buf, strlen(buf)) == -1) {
+		(void) fprintf(stderr, "write(%d, buf, %d) failed with errno "
+		    "%d\n", fd, strlen(buf), errno);
+		return (1);
+	}
+	(void) close(fd);
+
+	return (ret);
+}
+
+static int
+do_link(const char *pfile)
+{
+	int ret = 0;
+	char link_file[BUFSIZ] = { 0 };
+	char *dname;
+
+	if (pfile == NULL) {
+		return (-1);
+	}
+
+	/*
+	 * Figure out source file directory name, and create
+	 * the link file in the same directory.
+	 */
+	dname = dirname(strdup(pfile));
+	(void) snprintf(link_file, BUFSIZ, "%s/%s", dname, "link_file");
+
+	if (link(pfile, link_file) == -1) {
+		(void) fprintf(stderr, "link(%s, %s) failed with errno %d\n",
+		    pfile, link_file, errno);
+		free((void *)dirname);
+		return (1);
+	}
+
+	(void) unlink(link_file);
+	free((void *)dirname);
+	return (ret);
+}
+
+static int
+do_creat(const char *pfile)
+{
+	int fd, ret = 0;
+
+	if (pfile == NULL) {
+		return (-1);
+	}
+
+	if ((fd = creat(pfile, ALL_MODE)) == -1) {
+		(void) fprintf(stderr, "creat(%s, ALL_MODE) failed with errno "
+		    "%d\n", pfile, errno);
+		return (1);
+	}
+	(void) close(fd);
+
+	return (ret);
+}
+
+static int
+do_utime(const char *pfile)
+{
+	int ret = 0;
+
+	if (pfile == NULL) {
+		return (-1);
+	}
+
+	/*
+	 * Times of the file are set to the current time
+	 */
+	if (utime(pfile, NULL) == -1) {
+		(void) fprintf(stderr, "utime(%s, NULL) failed with errno "
+		    "%d\n", pfile, errno);
+		return (1);
+	}
+
+	return (ret);
+}
+
+static int
+do_chmod(const char *pfile)
+{
+	int ret = 0;
+
+	if (pfile == NULL) {
+		return (-1);
+	}
+
+	if (chmod(pfile, ALL_MODE) == -1) {
+		(void) fprintf(stderr, "chmod(%s, ALL_MODE) failed with "
+		    "errno %d\n", pfile, errno);
+		return (1);
+	}
+
+	return (ret);
+}
+
+static int
+do_chown(const char *pfile)
+{
+	int ret = 0;
+
+	if (pfile == NULL) {
+		return (-1);
+	}
+
+	if (chown(pfile, getuid(), getgid()) == -1) {
+		(void) fprintf(stderr, "chown(%s, %d, %d) failed with errno "
+		    "%d\n", pfile, (int)getuid(), (int)getgid(), errno);
+		return (1);
+	}
+
+	return (ret);
+}
+
+static void
+cleanup(void)
+{
+	if ((strlen(tfile) != 0) && (access(tfile, F_OK) == 0)) {
+		(void) unlink(tfile);
+	}
+}
+
+static timetest_t timetest_table[] = {
+	{ ST_ATIME,	"st_atime",	do_read		},
+	{ ST_ATIME,	"st_atime",	do_utime	},
+	{ ST_MTIME,	"st_mtime",	do_creat	},
+	{ ST_MTIME,	"st_mtime",	do_write	},
+	{ ST_MTIME,	"st_mtime",	do_utime	},
+	{ ST_CTIME,	"st_ctime",	do_creat	},
+	{ ST_CTIME,	"st_ctime",	do_write	},
+	{ ST_CTIME,	"st_ctime",	do_chmod	},
+	{ ST_CTIME,	"st_ctime",	do_chown 	},
+	{ ST_CTIME,	"st_ctime",	do_link		},
+	{ ST_CTIME,	"st_ctime",	do_utime	},
+};
+
+#define	NCOMMAND (sizeof (timetest_table) / sizeof (timetest_table[0]))
+
+/* ARGSUSED */
+int
+main(int argc, char *argv[])
+{
+	int i, ret, fd;
+	char *penv[] = {"TESTDIR", "TESTFILE0"};
+
+	(void) fprintf(stdout, "Verify [acm]time is modified appropriately.\n");
+	(void) atexit(cleanup);
+
+	/*
+	 * Get the environment variable values.
+	 */
+	for (i = 0; i < sizeof (penv) / sizeof (char *); i++) {
+		if ((penv[i] = getenv(penv[i])) == NULL) {
+			(void) fprintf(stderr, "getenv(penv[%d])\n", i);
+			return (1);
+		}
+	}
+	(void) snprintf(tfile, sizeof (tfile), "%s/%s", penv[0], penv[1]);
+
+	/*
+	 * If the test file is exists, remove it first.
+	 */
+	if (access(tfile, F_OK) == 0) {
+		(void) unlink(tfile);
+	}
+	ret = 0;
+	if ((fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE)) == -1) {
+		(void) fprintf(stderr, "open(%s) failed: %d\n", tfile, errno);
+		return (1);
+	}
+	(void) close(fd);
+
+	for (i = 0; i < NCOMMAND; i++) {
+		time_t t1, t2;
+
+		/*
+		 * Get original time before operating.
+		 */
+		ret = get_file_time(tfile, timetest_table[i].type, &t1);
+		if (ret != 0) {
+			(void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
+			    tfile, timetest_table[i].type, ret);
+			return (1);
+		}
+
+		/*
+		 * Sleep 2 seconds, then invoke command on given file
+		 */
+		(void) sleep(2);
+		timetest_table[i].func(tfile);
+
+		/*
+		 * Get time after operating.
+		 */
+		ret = get_file_time(tfile, timetest_table[i].type, &t2);
+		if (ret != 0) {
+			(void) fprintf(stderr, "get_file_time(%s %d) = %d\n",
+			    tfile, timetest_table[i].type, ret);
+			return (1);
+		}
+
+		if (t1 == t2) {
+			(void) fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n",
+			    timetest_table[i].name, (long)t1, (long)t2);
+			return (1);
+		} else {
+			(void) fprintf(stderr, "%s: t1(%ld) != t2(%ld)\n",
+			    timetest_table[i].name, (long)t1, (long)t2);
+		}
+	}
+
+	(void) fprintf(stdout, "PASS\n");
+	return (0);
+}
--- /dev/null	Fri Nov 22 15:20:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/ctime/setup.ksh	Fri Nov 22 15:20:00 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:20:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/Makefile	Fri Nov 22 15:20:00 2013
@@ -0,0 +1,63 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/delegate
+
+PROGS = cleanup \
+	setup \
+	zfs_allow_001_pos \
+	zfs_allow_002_pos \
+	zfs_allow_003_pos \
+	zfs_allow_004_pos \
+	zfs_allow_005_pos \
+	zfs_allow_006_pos \
+	zfs_allow_007_pos \
+	zfs_allow_008_pos \
+	zfs_allow_009_neg \
+	zfs_allow_010_pos \
+	zfs_allow_011_neg \
+	zfs_allow_012_neg \
+	zfs_unallow_001_pos \
+	zfs_unallow_002_pos \
+	zfs_unallow_003_pos \
+	zfs_unallow_004_pos \
+	zfs_unallow_005_pos \
+	zfs_unallow_006_pos \
+	zfs_unallow_007_neg \
+	zfs_unallow_008_neg
+
+FILES = delegate.cfg \
+	delegate_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/cleanup.ksh	Fri Nov 22 15:20:01 2013
@@ -0,0 +1,44 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+cleanup_user_group
+
+# restore the state of svc:/network/nis/client:default
+if [[ -e $NISSTAFILE ]]; then
+	log_must $SVCADM enable svc:/network/nis/client:default
+	log_must $RM -f $NISSTAFILE
+fi
+
+default_cleanup
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/delegate.cfg	Fri Nov 22 15:20:01 2013
@@ -0,0 +1,59 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export NISSTAFILE=/var/tmp/nis_state
+
+export STAFF_GROUP=zfsgrp
+export STAFF1=staff1
+export STAFF2=staff2
+
+export OTHER_GROUP=othergrp
+export OTHER1=other1
+export OTHER2=other2
+
+export EVERYONE="$STAFF1 $STAFF2 $OTHER1 $OTHER2"
+
+export LOCAL_SET="snapshot"
+export LOCAL_DESC_SET="readonly,checksum"
+export DESC_SET="compression"
+
+export TESTVOL=testvol.delegate
+export VOLSIZE=150m
+
+export ROOT_TESTVOL=$TESTPOOL/$TESTVOL
+export ROOT_TESTFS=$TESTPOOL/$TESTFS
+export SUBFS=$ROOT_TESTFS/SUBFS
+export SUBFS2=$ROOT_TESTFS/SUBFS2
+
+DATASETS="$ROOT_TESTFS"
+if is_global_zone ; then
+	DATASETS=$DATASETS
+fi
+export DATASETS
--- /dev/null	Fri Nov 22 15:20:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/delegate_common.kshlib	Fri Nov 22 15:20:01 2013
@@ -0,0 +1,1742 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/delegate/delegate.cfg
+
+#
+# Cleanup exist user/group.
+#
+function cleanup_user_group
+{
+	typeset i
+	for i in $STAFF1 $STAFF2 $OTHER1 $OTHER2 ; do
+		del_user $i
+	done
+	for i in $STAFF_GROUP $OTHER_GROUP ; do
+		del_group $i
+	done
+
+	return 0
+}
+
+#
+# Restore test file system to the original status.
+#
+function restore_root_datasets
+{
+	if datasetexists $ROOT_TESTFS ; then
+		log_must $ZFS destroy -Rf $ROOT_TESTFS
+	fi
+	log_must $ZFS create $ROOT_TESTFS
+
+	if is_global_zone ; then
+		if datasetexists $ROOT_TESTVOL ; then
+			log_must $ZFS destroy -Rf $ROOT_TESTVOL
+		fi
+		log_must $ZFS create -V $VOLSIZE $ROOT_TESTVOL
+	fi
+
+	return 0
+}
+
+#
+# Verify the specified user have permission on the dataset
+#
+# $1 dataset
+# $2 permissions which are separated by comma(,)
+# $3-n users
+#
+function verify_perm
+{
+	typeset dtst=$1
+	typeset permissions=$2
+	shift 2
+
+	if [[ -z $@ || -z $permissions || -z $dtst ]]; then
+		return 1
+	fi
+
+	typeset type=$(get_prop type $dtst)
+	permissions=$($ECHO $permissions | $TR -s "," " ")
+
+	typeset user
+	for user in $@; do
+		typeset perm
+		for perm in $permissions; do
+			typeset -i ret=1
+			if [[ $type == "filesystem" ]]; then
+				check_fs_perm $user $perm $dtst
+				ret=$?
+			elif [[ $type == "volume" ]]; then
+				check_vol_perm $user $perm $dtst
+				ret=$?
+			fi
+
+			if ((ret != 0)) ; then
+				log_note "Fail: $user should have $perm " \
+					"on $dtst"
+				return 1
+			fi
+		done
+	done
+
+	return 0
+}
+
+#
+# Verify the specified user have no permission on the dataset
+#
+# $1 dataset
+# $2 permissions which are separated by comma(,)
+# $3-n users
+#
+function verify_noperm
+{
+	typeset dtst=$1
+	typeset permissions=$2
+	shift 2
+
+	if [[ -z $@ || -z $permissions || -z $dtst ]]; then
+		return 1
+	fi
+
+	typeset type=$(get_prop type $dtst)
+	permissions=$($ECHO $permissions | $TR -s "," " ")
+
+	typeset user
+	for user in $@; do
+		typeset perm
+		for perm in $permissions; do
+			typeset -i ret=1
+			if [[ $type == "filesystem" ]]; then
+				check_fs_perm $user $perm $dtst
+				ret=$?
+			elif [[ $type == "volume" ]]; then
+				check_vol_perm $user $perm $dtst
+				ret=$?
+			fi
+
+			if ((ret == 0)) ; then
+				log_note "Fail: $user should not have $perm " \
+					"on $dtst"
+				return 1
+			fi
+		done
+	done
+
+	return 0
+}
+
+function common_perm
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset dtst=$3
+
+	typeset -i ret=1
+	case $perm in
+		send)
+			verify_send $user $perm $dtst
+			ret=$?
+			;;
+		allow)
+			verify_allow $user $perm $dtst
+			ret=$?
+			;;
+		userprop)
+			verify_userprop $user $perm $dtst
+			ret=$?
+			;;
+		compression|checksum|readonly)
+			verify_ccr $user $perm $dtst
+			ret=$?
+			;;
+		copies)
+			verify_copies $user $perm $dtst
+			ret=$?
+			;;
+		reservation)
+			verify_reservation $user $perm $dtst
+			ret=$?
+			;;
+		*)
+			ret=1
+			;;
+	esac
+
+	return $ret
+}
+
+function check_fs_perm
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset -i ret=1
+	case $perm in
+		create)
+			verify_fs_create $user $perm $fs
+			ret=$?
+			;;
+		destroy)
+			verify_fs_destroy $user $perm $fs
+			ret=$?
+			;;
+		snapshot)
+			verify_fs_snapshot $user $perm $fs
+			ret=$?
+			;;
+		rollback)
+			verify_fs_rollback $user $perm $fs
+			ret=$?
+			;;
+		clone)
+			verify_fs_clone $user $perm $fs
+			ret=$?
+			;;
+		rename)
+			verify_fs_rename $user $perm $fs
+			ret=$?
+			;;
+		mount)
+			verify_fs_mount $user $perm $fs
+			ret=$?
+			;;
+		share)
+			verify_fs_share $user $perm $fs
+			ret=$?
+			;;
+		mountpoint)
+			verify_fs_mountpoint $user $perm $fs
+			ret=$?
+			;;
+		promote)
+			verify_fs_promote $user $perm $fs
+			ret=$?
+			;;
+		canmount)
+			verify_fs_canmount $user $perm $fs
+			ret=$?
+			;;
+		recordsize)
+			verify_fs_recordsize $user $perm $fs
+			ret=$?
+			;;
+		quota)
+			verify_fs_quota $user $perm $fs
+			ret=$?
+			;;
+		aclmode)
+			verify_fs_aclmode $user $perm $fs
+			ret=$?
+			;;
+		aclinherit)
+			verify_fs_aclinherit $user $perm $fs
+			ret=$?
+			;;
+		snapdir)
+			verify_fs_snapdir $user $perm $fs
+			ret=$?
+			;;
+		atime|exec|devices|setuid|xattr)
+			verify_fs_aedsx $user $perm $fs
+			ret=$?
+			;;
+		zoned)
+			verify_fs_zoned $user $perm $fs
+			ret=$?
+			;;
+		sharenfs)
+			verify_fs_sharenfs $user $perm $fs
+			ret=$?
+			;;
+		receive)
+			verify_fs_receive $user $perm $fs
+			ret=$?
+			;;
+		*)
+			common_perm $user $perm $fs
+			ret=$?
+			;;
+	esac
+
+	return $ret
+}
+
+function check_vol_perm
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	typeset -i ret=1
+	case $perm in
+		destroy)
+			verify_vol_destroy $user $perm $vol
+			ret=$?
+			;;
+		snapshot)
+			verify_vol_snapshot $user $perm $vol
+			ret=$?
+			;;
+		rollback)
+			verify_vol_rollback $user $perm $vol
+			ret=$?
+			;;
+		clone)
+			verify_vol_clone $user $perm $vol
+			ret=$?
+			;;
+		rename)
+			verify_vol_rename $user $perm $vol
+			ret=$?
+			;;
+		promote)
+			verify_vol_promote $user $perm $vol
+			ret=$?
+			;;
+		volsize)
+			verify_vol_volsize $user $perm $vol
+			ret=$?
+			;;
+		*)
+			common_perm $user $perm $vol
+			ret=$?
+			;;
+	esac
+
+	return $ret
+}
+
+function setup_unallow_testenv
+{
+	log_must restore_root_datasets
+
+	log_must $ZFS create $SUBFS
+
+	for dtst in $DATASETS ; do
+		log_must $ZFS allow -l $STAFF1 $LOCAL_SET $dtst
+		log_must $ZFS allow -d $STAFF2 $DESC_SET  $dtst
+		log_must $ZFS allow $OTHER1 $LOCAL_DESC_SET $dtst
+		log_must $ZFS allow $OTHER2 $LOCAL_DESC_SET $dtst
+
+		log_must verify_perm $dtst $LOCAL_SET $STAFF1
+		log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER1
+		log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER2
+		if [[ $dtst == $ROOT_TESTFS ]]; then
+			log_must verify_perm $SUBFS $DESC_SET $STAFF2
+			log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER1
+			log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER2
+		fi
+	done
+
+	return 0
+}
+
+#
+# Verify permission send for specified user on the dataset
+# $1 user
+# $2 permission
+# $3 dataset
+#
+function verify_send
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset dtst=$3
+
+	typeset oldval
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset snap=$dtst@snap.$stamp
+
+	typeset -i ret=1
+
+	log_must $ZFS snapshot $snap
+	typeset bak_user=/tmp/bak.$user.$stamp
+	typeset bak_root=/tmp/bak.root.$stamp
+
+	user_run $user eval "$ZFS send $snap > $bak_user"
+	log_must eval "$ZFS send $snap > $bak_root"
+
+	if [[ $(checksum $bak_user) == $(checksum $bak_root) ]]; then
+		ret=0
+	fi
+
+	$RM -rf $bak_user > /dev/null
+	$RM -rf $bak_root > /dev/null
+
+	return $ret
+}
+
+function verify_fs_receive
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset dtst
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset newfs=$fs/newfs.$stamp
+	typeset newvol=$fs/newvol.$stamp
+	typeset bak_user=/tmp/bak.$user.$stamp
+	typeset bak_root=/tmp/bak.root.$stamp
+
+	log_must $ZFS create $newfs
+	typeset datasets="$newfs"
+	if is_global_zone ; then
+		log_must $ZFS create -V $VOLSIZE $newvol
+		datasets="$newfs $newvol"
+	fi
+
+	for dtst in $datasets ; do
+
+		typeset dtstsnap=$dtst@snap.$stamp
+		log_must $ZFS snapshot $dtstsnap
+
+		log_must eval "$ZFS send $dtstsnap > $bak_root"
+		log_must $ZFS destroy -rf $dtst
+
+		user_run $user eval "$ZFS receive $dtst < $bak_root"
+		if datasetexists $dtstsnap ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user create $fs
+		user_run $user eval "$ZFS receive $dtst < $bak_root"
+		log_must $ZFS unallow $user create $fs
+		if datasetexists $dtstsnap ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user mount $fs
+		user_run $user eval "$ZFS receive $dtst < $bak_root"
+		log_must $ZFS unallow $user mount $fs
+		if datasetexists $dtstsnap ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user mount,create $fs
+		user_run $user eval "$ZFS receive $dtst < $bak_root"
+		log_must $ZFS unallow $user mount,create $fs
+		if ! datasetexists $dtstsnap ; then
+			return 1
+		fi
+
+		# check the data integrity
+		log_must eval "$ZFS send $dtstsnap > $bak_user"
+		log_must $ZFS destroy -rf $dtst
+		log_must eval "$ZFS receive $dtst < $bak_root"
+		log_must eval "$ZFS send $dtstsnap > $bak_root"
+		log_must $ZFS destroy -rf $dtst
+		if [[ $(checksum $bak_user) != $(checksum $bak_root) ]]; then
+			return 1
+		fi
+
+		$RM -rf $bak_user > /dev/null
+		$RM -rf $bak_root > /dev/null
+
+	done
+
+	return 0
+}
+
+function verify_userprop
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset dtst=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+
+	user_run $user $ZFS set "$user:ts=$stamp" $dtst
+	if [[ $stamp != $(get_prop "$user:ts" $dtst) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_ccr
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset dtst=$3
+
+	typeset oldval
+
+	set -A modes "on" "off"
+	oldval=$(get_prop $perm $dtst)
+	if [[ $oldval == "on" ]]; then
+		n=1
+	elif [[ $oldval == "off" ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set $perm=${modes[$n]} $dtst"
+	user_run $user $ZFS set $perm=${modes[$n]} $dtst
+	if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_copies
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset dtst=$3
+
+	typeset oldval
+
+	set -A modes 1 2 3
+	oldval=$(get_prop $perm $dtst)
+	if [[ $oldval -eq 1 ]]; then
+		n=1
+	elif [[ $oldval -eq 2 ]]; then
+		n=2
+	elif [[ $oldval -eq 3 ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set $perm=${modes[$n]} $dtst"
+	user_run $user $ZFS set $perm=${modes[$n]} $dtst
+	if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_reservation
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset dtst=$3
+
+	typeset value32m=$(( 1024 * 1024 * 32 ))
+	typeset oldval=$(get_prop reservation $dtst)
+	user_run $user $ZFS set reservation=$value32m $dtst
+	if [[ $value32m != $(get_prop reservation $dtst) ]]; then
+		log_must $ZFS set reservation=$oldval $dtst
+		return 1
+	fi
+
+	log_must $ZFS set reservation=$oldval $dtst
+	return 0
+}
+
+function verify_fs_create
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset newfs=$fs/nfs.$stamp
+	typeset newvol=$fs/nvol.$stamp
+
+	user_run $user $ZFS create $newfs
+	if datasetexists $newfs ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $fs
+	user_run $user $ZFS create $newfs
+	log_must $ZFS unallow $user mount $fs
+	if ! datasetexists $newfs ; then
+		return 1
+	fi
+
+	log_must $ZFS destroy $newfs
+
+	if is_global_zone ; then
+		# mount permission is required for sparse volume
+		user_run $user $ZFS create -V 150m -s $newvol
+		if datasetexists $newvol ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user mount $fs
+		user_run $user $ZFS create -V 150m -s $newvol
+		log_must $ZFS unallow $user mount $fs
+		if ! datasetexists $newvol ; then
+			return 1
+		fi
+		log_must $ZFS destroy $newvol
+
+		# mount and reserveration permission are
+		# required for normal volume
+		user_run $user $ZFS create -V 150m $newvol
+		if datasetexists $newvol ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user mount $fs
+		user_run $user $ZFS create -V 150m $newvol
+		log_must $ZFS unallow $user mount $fs
+		if datasetexists $newvol ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user reservation $fs
+		user_run $user $ZFS create -V 150m $newvol
+		log_must $ZFS unallow $user reservation $fs
+		if datasetexists $newvol ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user refreservation $fs
+		user_run $user $ZFS create -V 150m $newvol
+		log_must $ZFS unallow $user refreservation $fs
+		if datasetexists $newvol ; then
+			return 1
+		fi
+
+		log_must $ZFS allow $user mount $fs
+		log_must $ZFS allow $user reservation $fs
+		log_must $ZFS allow $user refreservation $fs
+		user_run $user $ZFS create -V 150m $newvol
+		log_must $ZFS unallow $user mount $fs
+		log_must $ZFS unallow $user reservation $fs
+		log_must $ZFS unallow $user refreservation $fs
+		if ! datasetexists $newvol ; then
+			return 1
+		fi
+		log_must $ZFS destroy $newvol
+	fi
+
+	return 0
+}
+
+function verify_fs_destroy
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	if ! ismounted $fs ; then
+		user_run $user $ZFS destroy $fs
+		if datasetexists $fs ; then
+			return 1
+		fi
+	fi
+
+	if ismounted $fs ; then
+		user_run $user $ZFS destroy $fs
+		if ! datasetexists $fs ; then
+			return 1
+		fi
+
+		# mount permission is required
+		log_must $ZFS allow $user mount $fs
+		user_run $user $ZFS destroy $fs
+		if datasetexists $fs ; then
+			return 1
+		fi
+	fi
+
+	return 0
+}
+
+# Verify that given the correct delegation, a regular user can:
+#	Take a snapshot of an unmounted dataset
+#	Take a snapshot of an mounted dataset
+#	Create a snapshot by making a directory in the .zfs/snapshot directory
+function verify_fs_snapshot
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset snap=$fs@snap.$stamp
+	typeset mntpt=$(get_prop mountpoint $fs)
+
+	if [[ "yes" == $(get_prop mounted $fs) ]]; then
+		log_must $ZFS umount $fs
+	fi
+
+	user_run $user $ZFS snapshot $snap
+	if ! datasetexists $snap ; then
+		return 1
+	fi
+	log_must $ZFS destroy $snap
+
+	if [[ "no" == $(get_prop mounted $fs) ]]; then
+		log_must $ZFS mount $fs
+	fi
+
+	user_run $user $ZFS snapshot $snap
+	if ! datasetexists $snap ; then
+		return 1
+	fi
+	log_must $ZFS destroy $snap
+
+	typeset snapdir=${mntpt}/.zfs/snapshot/snap.$stamp
+	user_run $user $MKDIR $snapdir
+	if ! datasetexists $snap ; then
+		return 1
+	fi
+	log_must $ZFS destroy $snap
+
+	return 0
+}
+
+function verify_fs_rollback
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset oldval
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset snap=$fs@snap.$stamp
+	typeset mntpt=$(get_prop mountpoint $fs)
+
+	oldval=$(datasetcksum $fs)
+	log_must $ZFS snapshot $snap
+
+	if ! ismounted $fs; then
+		log_must $ZFS mount $fs
+	fi
+	log_must $TOUCH $mntpt/testfile.$stamp
+
+	user_run $user $ZFS rollback -R $snap
+	if is_global_zone ; then
+		if [[ $oldval != $(datasetcksum $fs) ]]; then
+			return 1
+		fi
+	else
+		# datasetcksum can not be used in local zone
+		if [[ -e $mntpt/testfile.$stamp ]]; then
+			return 1
+		fi
+	fi
+
+	return 0
+}
+
+function verify_fs_clone
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basefs=${fs%/*}
+	typeset snap=$fs@snap.$stamp
+	typeset clone=$basefs/cfs.$stamp
+
+	log_must $ZFS snapshot $snap
+	user_run $user $ZFS clone $snap $clone
+	if datasetexists $clone ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user create $basefs
+	user_run $user $ZFS clone $snap $clone
+	log_must $ZFS unallow $user create $basefs
+	if datasetexists $clone ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $basefs
+	user_run $user $ZFS clone $snap $clone
+	log_must $ZFS unallow $user mount $basefs
+	if datasetexists $clone ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $basefs
+	log_must $ZFS allow $user create $basefs
+	user_run $user $ZFS clone $snap $clone
+	log_must $ZFS unallow $user create $basefs
+	log_must $ZFS unallow $user mount $basefs
+	if ! datasetexists $clone ; then
+		return 1
+	fi
+
+	log_must $ZFS destroy -R $snap
+
+	return 0
+}
+
+function verify_fs_rename
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basefs=${fs%/*}
+	typeset snap=$fs@snap.$stamp
+	typeset renamefs=$basefs/nfs.$stamp
+
+	if ! ismounted $fs; then
+		log_must $ZFS mount $fs
+	fi
+
+	# case 1
+	user_run $user $ZFS rename $fs $renamefs
+	if datasetexists $renamefs ; then
+		return 1
+	fi
+
+	# case 2
+	log_must $ZFS allow $user create $basefs
+	user_run $user $ZFS rename $fs $renamefs
+	log_must $ZFS unallow $user create $basefs
+	if datasetexists $renamefs ; then
+		return 1
+	fi
+
+	# case 3
+	log_must $ZFS allow $user mount $basefs
+	user_run $user $ZFS rename $fs $renamefs
+	log_must $ZFS unallow $user mount $basefs
+	if datasetexists $renamefs ; then
+		return 1
+	fi
+
+	# case 4
+	log_must $ZFS allow $user mount $fs
+	user_run $user $ZFS rename $fs $renamefs
+	if datasetexists $renamefs ; then
+		log_must $ZFS unallow $user mount $renamefs
+		return 1
+	fi
+	log_must $ZFS unallow $user mount $fs
+
+	# case 5
+	log_must $ZFS allow $user create $basefs
+	log_must $ZFS allow $user mount $fs
+	user_run $user $ZFS rename $fs $renamefs
+	log_must $ZFS unallow $user create $basefs
+	if datasetexists $renamefs ; then
+		log_must $ZFS unallow $user mount $renamefs
+		return 1
+	fi
+	log_must $ZFS unallow $user mount $fs
+
+	# case 6
+	log_must $ZFS allow $user mount $basefs
+	log_must $ZFS allow $user mount $fs
+	user_run $user $ZFS rename $fs $renamefs
+	log_must $ZFS unallow $user mount $basefs
+	if datasetexists $renamefs ; then
+		log_must $ZFS unallow $user mount $renamefs
+		return 1
+	fi
+	log_must $ZFS unallow $user mount $fs
+
+	# case 7
+	log_must $ZFS allow $user create $basefs
+	log_must $ZFS allow $user mount $basefs
+	user_run $user $ZFS rename $fs $renamefs
+	log_must $ZFS unallow $user mount $basefs
+	log_must $ZFS unallow $user create $basefs
+	if ! datasetexists $renamefs ; then
+		return 1
+	fi
+
+	log_must $ZFS rename $renamefs $fs
+
+	return 0
+}
+
+function verify_fs_mount
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset mntpt=$(get_prop mountpoint $fs)
+	typeset newmntpt=/tmp/mnt.$stamp
+
+	if ismounted $fs ; then
+		user_run $user $ZFS unmount $fs
+		if ismounted $fs ; then
+			return 1
+		fi
+	fi
+
+	if ! ismounted $fs ; then
+		log_must $ZFS set mountpoint=$newmntpt $fs
+		log_must $RM -rf $newmntpt
+		log_must $MKDIR $newmntpt
+
+		user_run $user $ZFS mount $fs
+		if ismounted $fs ; then
+			return 1
+		fi
+
+		# mountpoint's owner must be the user
+		log_must $CHOWN $user $newmntpt
+		user_run $user $ZFS mount $fs
+		if ! ismounted $fs ; then
+			return 1
+		fi
+		log_must $ZFS umount $fs
+		log_must $RM -rf $newmntpt
+		log_must $ZFS set mountpoint=$mntpt $fs
+	fi
+
+	return 0
+}
+
+function verify_fs_share
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset mntpt=$(get_prop mountpoint $fs)
+
+	typeset stat=$($SVCS -H -o STA nfs/server:default)
+	if [[ $stat != "ON" ]]; then
+		log_note "Current nfs/server status: $stat"
+		# legacy share
+		user_run $user $SHARE $mntpt
+		if is_shared $fs; then
+			return 1
+		fi
+
+		# sharenfs=on
+		log_must $ZFS set sharenfs=on $fs
+		user_run $user $ZFS share $fs
+		if is_shared $fs; then
+			log_must $ZFS set sharenfs=off $fs
+			return 1
+		fi
+		log_must $ZFS set sharenfs=off $fs
+	fi
+
+	# turn on nfs/server service if it is not enabled
+	typeset tmpshare=/var/tmp/a.$$
+	$RM -rf $tmpshare
+
+	log_must $MKDIR -p $tmpshare
+	log_must $SHARE $tmpshare
+
+	# legacy share
+	user_run $user $SHARE $mntpt
+	if ! is_shared $fs ; then
+		log_must $UNSHARE $tmpshare
+		log_must $RM -rf $tmpshare
+		return 1
+	fi
+	log_must $UNSHARE $mntpt
+
+	# sharenfs=on
+	log_must $ZFS set sharenfs=on $fs
+	user_run $user $ZFS share $fs
+	if ! is_shared $fs; then
+		log_must $UNSHARE $tmpshare
+		log_must $RM -rf $tmpshare
+		return 1
+	fi
+
+	log_must $UNSHARE $tmpshare
+	log_must $RM -rf $tmpshare
+
+	return 0
+}
+
+function verify_fs_mountpoint
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+	typeset mntpt=$(get_prop mountpoint $fs)
+	typeset newmntpt=/tmp/mnt.$stamp
+
+	if ! ismounted $fs ; then
+		user_run $user $ZFS set mountpoint=$newmntpt $fs
+		if [[ $newmntpt != \
+			$(get_prop mountpoint $fs) ]] ; then
+			return 1
+		fi
+		log_must $ZFS set mountpoint=$mntpt $fs
+	fi
+
+	if ismounted $fs ; then
+		user_run $user $ZFS set mountpoint=$newmntpt $fs
+		if [[ $mntpt != $(get_prop mountpoint $fs) ]]; then
+			return 1
+		fi
+
+		# require mount permission when fs is mounted
+		log_must $ZFS allow $user mount $fs
+		user_run $user $ZFS set mountpoint=$newmntpt $fs
+		log_must $ZFS unallow $user mount $fs
+		if [[ $newmntpt != \
+			$(get_prop mountpoint $fs) ]] ; then
+			return 1
+		fi
+		log_must $ZFS set mountpoint=$mntpt $fs
+	fi
+
+	return 0
+}
+
+function verify_fs_promote
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basefs=${fs%/*}
+	typeset snap=$fs@snap.$stamp
+	typeset clone=$basefs/cfs.$stamp
+
+	log_must $ZFS snapshot $snap
+	log_must $ZFS clone $snap $clone
+	log_must $ZFS promote $clone
+
+	typeset fs_orig=$(get_prop origin $fs)
+	typeset clone_orig=$(get_prop origin $clone)
+
+	user_run $user $ZFS promote $fs
+	# promote should fail if original fs does not have
+	# promote permission
+	if [[ $fs_orig != $(get_prop origin $fs) || \
+		$clone_orig != $(get_prop origin $clone) ]]; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user promote $clone
+	user_run $user $ZFS promote $fs
+	log_must $ZFS unallow $user promote $clone
+	if [[ $fs_orig != $(get_prop origin $fs) || \
+		$clone_orig != $(get_prop origin $clone) ]]; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $fs
+	user_run $user $ZFS promote $fs
+	log_must $ZFS unallow $user mount $fs
+	if [[ $fs_orig != $(get_prop origin $fs) || \
+		$clone_orig != $(get_prop origin $clone) ]]; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $fs
+	log_must $ZFS allow $user promote $clone
+	user_run $user $ZFS promote $fs
+	log_must $ZFS unallow $user promote $clone
+	log_must $ZFS unallow $user mount $fs
+	if [[ $snap != $(get_prop origin $clone) || \
+		$clone_orig != $(get_prop origin $fs) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_fs_canmount
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset oldval
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+
+	if ! ismounted $fs ; then
+		set -A modes "on" "off"
+		oldval=$(get_prop $perm $fs)
+		if [[ $oldval == "on" ]]; then
+			n=1
+		elif [[ $oldval == "off" ]]; then
+			n=0
+		fi
+		log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+		user_run $user $ZFS set $perm=${modes[$n]} $fs
+		if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+			return 1
+		fi
+	fi
+
+
+	# fs is mounted
+	if ismounted $fs ; then
+		# property value does not change if
+		# no mount permission
+		set -A modes "on" "off"
+		oldval=$(get_prop $perm $fs)
+		if [[ $oldval == "on" ]]; then
+			n=1
+		elif [[ $oldval == "off" ]]; then
+			n=0
+		fi
+		log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+		log_must $ZFS allow $user mount $fs
+		user_run $user $ZFS set $perm=${modes[$n]} $fs
+		log_must $ZFS unallow $user mount $fs
+		if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+			return 1
+		fi
+	fi
+
+	return 0
+}
+
+function verify_fs_recordsize
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset value8k=$(( 1024 * 8 ))
+	user_run $user $ZFS set recordsize=$value8k $fs
+	if [[ $value8k != $(get_prop recordsize $fs) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_fs_quota
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset value32m=$(( 1024 * 1024 * 32 ))
+	user_run $user $ZFS set quota=$value32m $fs
+	if [[ $value32m != $(get_prop quota $fs) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_fs_aclmode
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset oldval
+	set -A modes "discard" "groupmask" "passthrough"
+	oldval=$(get_prop $perm $fs)
+	if [[ $oldval == "discard" ]]; then
+		n=1
+	elif [[ $oldval == "groupmask" ]]; then
+		n=2
+	elif [[ $oldval == "passthrough" ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set aclmode=${modes[$n]} $fs"
+	user_run $user $ZFS set aclmode=${modes[$n]} $fs
+	if [[ ${modes[$n]} != $(get_prop aclmode $fs) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_fs_aclinherit
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	#
+	# PSARC/2008/231 change the default value of aclinherit to "restricted"
+	# but still keep the old interface of "secure"
+	#
+
+	typeset oldval
+	set -A modes "discard" "noallow" "secure" "passthrough"
+	oldval=$(get_prop $perm $fs)
+	if [[ $oldval == "discard" ]]; then
+		n=1
+	elif [[ $oldval == "noallow" ]]; then
+		n=2
+	elif [[ $oldval == "secure" || $oldval == "restricted" ]]; then
+		n=3
+	elif [[ $oldval == "passthrough" ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set aclinherit=${modes[$n]} $fs"
+	user_run $user $ZFS set aclinherit=${modes[$n]} $fs
+
+	typeset newval=$(get_prop aclinherit $fs)
+	if [[ ${modes[$n]} == "secure" && $newval == "restricted" ]]; then
+		return 0
+	elif [[ ${modes[$n]} != $(get_prop aclinherit $fs) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_fs_snapdir
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset oldval
+	set -A modes "visible" "hidden"
+	oldval=$(get_prop $perm $fs)
+	if [[ $oldval == "visible" ]]; then
+		n=1
+	elif [[ $oldval == "hidden" ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set snapdir=${modes[$n]} $fs"
+	user_run $user $ZFS set snapdir=${modes[$n]} $fs
+	if [[ ${modes[$n]} != $(get_prop snapdir $fs) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_fs_aedsx
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset oldval
+	set -A modes "on" "off"
+	oldval=$(get_prop $perm $fs)
+	if [[ $oldval == "on" ]]; then
+		n=1
+	elif [[ $oldval == "off" ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+	user_run $user $ZFS set $perm=${modes[$n]} $fs
+	if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_fs_zoned
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset oldval
+	set -A modes "on" "off"
+	oldval=$(get_prop $perm $fs)
+	if [[ $oldval == "on" ]]; then
+		n=1
+	elif [[ $oldval == "off" ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+	if is_global_zone ; then
+		if ! ismounted $fs ; then
+			user_run $user $ZFS set \
+				$perm=${modes[$n]} $fs
+			if [[ ${modes[$n]} != \
+				$(get_prop $perm $fs) ]]; then
+				return 1
+			fi
+			if [[ $n -eq 0 ]]; then
+				log_mustnot $ZFS mount $fs
+			else
+				log_must $ZFS mount $fs
+			fi
+		fi
+
+		if ismounted $fs; then
+			# n always is 1 in this case
+			user_run $user $ZFS set \
+				$perm=${modes[$n]} $fs
+			if [[ $oldval != \
+				$(get_prop $perm $fs) ]]; then
+				return 1
+			fi
+
+			# mount permission is needed
+			# to make zoned=on
+			log_must $ZFS allow $user mount $fs
+			user_run $user $ZFS set \
+				$perm=${modes[$n]} $fs
+			log_must $ZFS unallow $user mount $fs
+			if [[ ${modes[$n]} != \
+				$(get_prop $perm $fs) ]]; then
+				return 1
+			fi
+		fi
+	fi
+
+	if ! is_global_zone; then
+		user_run $user $ZFS set $perm=${modes[$n]} $fs
+		if [[ $oldval != $(get_prop $perm $fs) ]]; then
+			return 1
+		fi
+	fi
+
+	return 0
+}
+
+function verify_fs_sharenfs
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset fs=$3
+
+	typeset oldval
+	set -A modes "on" "off"
+	oldval=$(get_prop $perm $fs)
+	if [[ $oldval == "on" ]]; then
+		n=1
+	elif [[ $oldval == "off" ]]; then
+		n=0
+	fi
+	log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+	user_run $user $ZFS set $perm=${modes[$n]} $fs
+	if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+		return 1
+	fi
+	log_must $ZFS set $perm=$oldval $fs
+
+	# turn on nfs/server service if it is not enabled
+	typeset tmpshare=/var/tmp/a.$$
+	$RM -rf $tmpshare
+	log_must $MKDIR -p $tmpshare
+	log_must $SHARE $tmpshare
+
+	log_note "$user $ZFS set $perm=${modes[$n]} $fs"
+	user_run $user $ZFS set $perm=${modes[$n]} $fs
+	if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
+		return 1
+	fi
+
+	user_run $user $ZFS share $fs
+	if is_shared $fs; then
+		return 1
+	fi
+
+	# share permission is needed
+	log_must $ZFS allow $user share $fs
+	user_run $user $ZFS share $fs
+	log_must $ZFS unallow $user share $fs
+
+	if [[ $n -eq 0 ]] && ! is_shared $fs ; then
+		log_must $UNSHARE $tmpshare
+		log_must $RM -rf $tmpshare
+		return 1
+	fi
+
+	if [[ $n -eq 1 ]] && is_shared $fs ; then
+		log_must $UNSHARE $tmpshare
+		log_must $RM -rf $tmpshare
+		return 1
+	fi
+
+	log_must $UNSHARE $tmpshare
+	log_must $RM -rf $tmpshare
+
+	return 0
+}
+
+function verify_vol_destroy
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	user_run $user $ZFS destroy $vol
+	if ! datasetexists $vol ; then
+		return 1
+	fi
+
+	# mount permission is required
+	log_must $ZFS allow $user mount $vol
+	user_run $user $ZFS destroy $vol
+	if datasetexists $vol ; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_vol_snapshot
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+	typeset snap=$vol@snap.$stamp
+
+	user_run $user $ZFS snapshot $snap
+	if datasetexists $snap ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $vol
+	user_run $user $ZFS snapshot $snap
+	log_must $ZFS unallow $user mount $vol
+	if ! datasetexists $snap ; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_vol_rollback
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+	typeset snap=$vol@snap.$stamp
+
+	typeset oldval
+	log_must $ZFS snapshot $snap
+	oldval=$(datasetcksum $vol)
+
+	log_must $DD if=/dev/random of=/dev/zvol/rdsk/$vol \
+		bs=512 count=1
+
+	user_run $user $ZFS rollback -R $snap
+	$SLEEP 10
+	if [[ $oldval == $(datasetcksum $vol) ]]; then
+		return 1
+	fi
+
+	# rollback on volume has to be with mount permission
+	log_must $ZFS allow $user mount $vol
+	user_run $user $ZFS rollback -R $snap
+	$SLEEP 10
+	log_must $ZFS unallow $user mount $vol
+	if [[ $oldval != $(datasetcksum $vol) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_vol_clone
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+	typeset snap=$vol@snap.$stamp
+	typeset clone=$basevol/cvol.$stamp
+
+	log_must $ZFS snapshot $snap
+
+	user_run $user $ZFS clone $snap $clone
+	if datasetexists $clone ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user create $basevol
+	user_run $user $ZFS clone $snap $clone
+	log_must $ZFS unallow $user create $basevol
+	if datasetexists $clone ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $basevol
+	user_run $user $ZFS clone $snap $clone
+	log_must $ZFS unallow $user mount $basevol
+	if datasetexists $clone ; then
+		return 1
+	fi
+
+	# require create permission on parent and
+	# mount permission on itself as well
+	log_must $ZFS allow $user mount $basevol
+	log_must $ZFS allow $user create $basevol
+	user_run $user $ZFS clone $snap $clone
+	log_must $ZFS unallow $user create $basevol
+	log_must $ZFS unallow $user mount $basevol
+	if ! datasetexists $clone ; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_vol_rename
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+	typeset snap=$vol@snap.$stamp
+	typeset clone=$basevol/cvol.$stamp
+	typeset renamevol=$basevol/nvol.$stamp
+
+	user_run $user $ZFS rename $vol $renamevol
+	if datasetexists $renamevol ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user create $basevol
+	user_run $user $ZFS rename $vol $renamevol
+	log_must $ZFS unallow $user create $basevol
+	if datasetexists $renamevol ; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user mount $basevol
+	user_run $user $ZFS rename $vol $renamevol
+	log_must $ZFS unallow $user mount $basevol
+	if datasetexists $renamevol ; then
+		return 1
+	fi
+
+	# require both create permission on parent and
+	# mount permission on parent as well
+	log_must $ZFS allow $user mount $basevol
+	log_must $ZFS allow $user create $basevol
+	user_run $user $ZFS rename $vol $renamevol
+	log_must $ZFS unallow $user mount $basevol
+	log_must $ZFS unallow $user create $basevol
+	if ! datasetexists $renamevol ; then
+		return 1
+	fi
+
+	log_must $ZFS rename $renamevol $vol
+
+	return 0
+}
+
+function verify_vol_promote
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	typeset stamp=${perm}.${user}.$($DATE +'%F-%H%M%S')
+        typeset basevol=${vol%/*}
+	typeset snap=$vol@snap.$stamp
+	typeset clone=$basevol/cvol.$stamp
+
+	log_must $ZFS snapshot $snap
+	log_must $ZFS clone $snap $clone
+	log_must $ZFS promote $clone
+
+	typeset vol_orig=$(get_prop origin $vol)
+	typeset clone_orig=$(get_prop origin $clone)
+
+	# promote should fail if $vol and $clone
+	# miss either mount or promote permission
+	# case 1
+	user_run $user $ZFS promote $vol
+	if [[ $vol_orig != $(get_prop origin $vol) || \
+		$clone_orig != $(get_prop origin $clone) ]];
+	then
+		return 1
+	fi
+
+	# promote should fail if $vol and $clone
+	# miss either mount or promote permission
+	# case 2
+	log_must $ZFS allow $user promote $clone
+	user_run $user $ZFS promote $vol
+	log_must $ZFS unallow $user promote $clone
+	if [[ $vol_orig != $(get_prop origin $vol) || \
+		$clone_orig != $(get_prop origin $clone) ]];
+	then
+		return 1
+	fi
+
+	# promote should fail if $vol and $clone
+	# miss either mount or promote permission
+	# case 3
+	log_must $ZFS allow $user mount $vol
+	user_run $user $ZFS promote $vol
+	log_must $ZFS unallow $user mount $vol
+	if [[ $vol_orig != $(get_prop origin $vol) || \
+		$clone_orig != $(get_prop origin $clone) ]];
+	then
+		return 1
+	fi
+
+	# promote should fail if $vol and $clone
+	# miss either mount or promote permission
+	# case 4
+	log_must $ZFS allow $user mount $clone
+	user_run $user $ZFS promote $vol
+	log_must $ZFS unallow $user mount $clone
+	if [[ $vol_orig != $(get_prop origin $vol) || \
+		$clone_orig != $(get_prop origin $clone) ]];
+	then
+		return 1
+	fi
+
+	# promote should fail if $vol and $clone
+	# miss either mount or promote permission
+	# case 5
+	log_must $ZFS allow $user promote $clone
+	log_must $ZFS allow $user mount $vol
+	user_run $user $ZFS promote $vol
+	log_must $ZFS unallow $user promote $clone
+	log_must $ZFS unallow $user mount $vol
+	if [[ $vol_orig != $(get_prop origin $vol) || \
+		$clone_orig != $(get_prop origin $clone) ]];
+	then
+		return 1
+	fi
+
+	# promote should fail if $vol and $clone
+	# miss either mount or promote permission
+	# case 6
+	log_must $ZFS allow $user promote $clone
+	log_must $ZFS allow $user mount $clone
+	user_run $user $ZFS promote $vol
+	log_must $ZFS unallow $user promote $clone
+	log_must $ZFS unallow $user mount $vol
+	if [[ $vol_orig != $(get_prop origin $vol) || \
+		$clone_orig != $(get_prop origin $clone) ]];
+	then
+		return 1
+	fi
+
+	# promote should fail if $vol and $clone
+	# miss either mount or promote permission
+	# case 7
+	log_must $ZFS allow $user mount $vol
+	log_must $ZFS allow $user mount $clone
+	user_run $user $ZFS promote $vol
+	log_must $ZFS unallow $user mount $vol
+	log_must $ZFS unallow $user mount $clone
+	if [[ $vol_orig != $(get_prop origin $vol) || \
+		$clone_orig != $(get_prop origin $clone) ]];
+	then
+		return 1
+	fi
+
+	# promote only succeeds when $vol and $clone
+	# have both mount and promote permission
+	# case 8
+	log_must $ZFS allow $user promote $clone
+	log_must $ZFS allow $user mount $vol
+	log_must $ZFS allow $user mount $clone
+	user_run $user $ZFS promote $vol
+	log_must $ZFS unallow $user promote $clone
+	log_must $ZFS unallow $user mount $vol
+	log_must $ZFS unallow $user mount $clone
+	if [[ $snap != $(get_prop origin $clone) || \
+		$clone_orig != $(get_prop origin $vol) ]]; then
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_vol_volsize
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset vol=$3
+
+	typeset oldval
+	oldval=$(get_prop volsize $vol)
+	(( newval = oldval * 2 ))
+
+	reserv_size=$(get_prop refreservation $vol)
+
+	if [[ "0" == $reserv_size ]]; then
+		# sparse volume
+		user_run $user $ZFS set volsize=$newval $vol
+		if [[ $oldval == $(get_prop volsize $vol) ]];
+		then
+			return 1
+		fi
+
+	else
+		# normal volume, reservation permission
+		# is required
+		user_run $user $ZFS set volsize=$newval $vol
+		if [[ $newval == $(get_prop volsize $vol) ]];
+		then
+			return 1
+		fi
+
+		log_must $ZFS allow $user reservation $vol
+		log_must $ZFS allow $user refreservation $vol
+		user_run $user $ZFS set volsize=$newval $vol
+		log_must $ZFS unallow $user reservation $vol
+		log_must $ZFS unallow $user refreservation $vol
+		if [[ $oldval == $(get_prop volsize $vol) ]];
+		then
+			return 1
+		fi
+	fi
+
+	return 0
+}
+
+function verify_allow
+{
+	typeset user=$1
+	typeset perm=$2
+	typeset dtst=$3
+
+	typeset -i ret
+
+	user_run $user $ZFS allow $user allow $dtst
+	ret=$?
+	if [[ $ret -eq 0 ]]; then
+		return 1
+	fi
+
+	log_must $ZFS allow $user copies $dtst
+	user_run $user $ZFS allow $user copies $dtst
+	ret=$?
+	log_must $ZFS unallow $user copies $dtst
+	if [[ $ret -eq 1 ]]; then
+		return 1
+	fi
+
+	return 0
+
+}
--- /dev/null	Fri Nov 22 15:20:02 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/setup.ksh	Fri Nov 22 15:20:02 2013
@@ -0,0 +1,59 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+# check svc:/network/nis/client:default state
+# disable it if the state is ON
+# and the state will be restored during cleanup.ksh
+log_must $RM -f $NISSTAFILE
+if [[ "ON" == $($SVCS -H -o sta svc:/network/nis/client:default) ]]; then
+	log_must $SVCADM disable -t svc:/network/nis/client:default
+	log_must $TOUCH $NISSTAFILE
+fi
+
+cleanup_user_group
+
+# Create staff group and add two user to it
+log_must add_group $STAFF_GROUP
+log_must add_user $STAFF_GROUP $STAFF1
+log_must add_user $STAFF_GROUP $STAFF2
+
+# Create other group and add two user to it
+log_must add_group $OTHER_GROUP
+log_must add_user $OTHER_GROUP $OTHER1
+log_must add_user $OTHER_GROUP $OTHER2
+
+DISK=${DISKS%% *}
+default_volume_setup $DISK
+log_must $CHMOD 777 $TESTDIR
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:02 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh	Fri Nov 22 15:20:02 2013
@@ -0,0 +1,98 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+# 	"everyone" is interpreted as the keyword "everyone" whatever the same
+# 	name user or group is existing.
+#
+# STRATEGY:
+#	1. Create user 'everyone'.
+#	2. Verify 'everyone' is interpreted as keywords.
+#	3. Create group 'everyone'.
+#	4. Verify 'everyone' is interpreted as keywords.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ $user_added == "TRUE" ]] ; then
+		del_user everyone
+	fi
+	if [[ $group_added == "TRUE" ]] ; then
+		del_group everyone
+	fi
+
+	restore_root_datasets
+}
+
+log_assert "everyone' is interpreted as a keyword even if a user " \
+	"or group named 'everyone' exists."
+log_onexit cleanup
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,send,userprop"
+
+log_note "Create a user called 'everyone'."
+if ! $ID everyone > /dev/null 2>&1; then
+	user_added="TRUE"
+	log_must $USERADD everyone
+fi
+for dtst in $DATASETS ; do
+	log_must $ZFS allow everyone $perms $dtst
+	log_must verify_perm $dtst $perms $EVERYONE "everyone"
+done
+log_must restore_root_datasets
+if [[ $user_added == "TRUE" ]]; then
+	log_must $USERDEL everyone
+fi
+
+log_note "Created a group called 'everyone'."
+if ! $CAT /etc/group | $AWK -F: '{print $1}' | \
+	$GREP -w 'everyone' > /dev/null 2>&1
+then
+	group_added="TRUE"
+	log_must $GROUPADD everyone
+fi
+
+for dtst in $DATASETS ; do
+	log_must $ZFS allow everyone $perms $dtst
+	log_must verify_perm $dtst $perms $EVERYONE
+done
+log_must restore_root_datasets
+if [[ $group_added == "TRUE" ]]; then
+	log_must $GROUPDEL everyone
+fi
+
+log_pass "everyone is always interpreted as keyword passed."
--- /dev/null	Fri Nov 22 15:20:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_002_pos.ksh	Fri Nov 22 15:20:03 2013
@@ -0,0 +1,79 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+# <user|group> argument is interpreted as a user if possible, then as a group as
+# possible.
+#
+# STRATEGY:
+#	1. Create user $STAFF_GROUP
+#	2. Delegate permissions to $STAFF_GROUP
+#	3. Verify user $STAFF_GROUP has the permissions.
+#	4. Delete user $STAFF_GROUP and allow the permission to $STAFF_GROUP
+#	5. Verify $STAFF_GROUP is interpreted as group.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if $ID $STAFF_GROUP > /dev/null 2>&1; then
+		log_must del_user $STAFF_GROUP
+	fi
+
+	restore_root_datasets
+}
+
+log_assert "<user|group> is interpreted as user if possible, then as group."
+log_onexit cleanup
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,send,userprop"
+
+log_must $USERADD $STAFF_GROUP
+for dtst in $DATASETS ; do
+	log_must $ZFS allow $STAFF_GROUP $perms $dtst
+	log_must verify_perm $dtst $perms $STAFF_GROUP
+	log_must verify_noperm $dtst $perms $STAFF1 $STAFF2
+done
+
+log_must restore_root_datasets
+
+log_must del_user $STAFF_GROUP
+for dtst in $datasets ; do
+	log_must $ZFS allow $STAFF_GROUP $perms $dtst
+	log_must verify_perm $dtst $perms $STAFF1 $STAFF2
+done
+
+log_pass "<user|group> is interpreted as user if possible, then as group passed."
--- /dev/null	Fri Nov 22 15:20:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_003_pos.ksh	Fri Nov 22 15:20:03 2013
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify option '-l' only allow permission to the dataset itself.
+#
+# STRATEGY:
+#	1. Create descendent datasets of $ROOT_TESTFS
+#	2. Select user, group and everyone and set local permission separately.
+#	3. Set locally permissions to $ROOT_TESTFS or $ROOT_TESTVOL.
+#	4. Verify the permissions are only allow on $ROOT_TESTFS or
+#	   $ROOT_TESTVOL.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-l' only allow permission to the dataset itself."
+log_onexit restore_root_datasets
+
+childfs=$ROOT_TESTFS/childfs
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,userprop"
+
+log_must $ZFS create $childfs
+
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -l $STAFF1 $perms $dtst
+	log_must verify_perm $dtst $perms $STAFF1
+	if [[ $dtst == $ROOT_TESTFS ]] ; then
+		log_must verify_noperm $childfs $perms \
+			$STAFF1 $STAFF2 $OTHER1 $OTHER2
+	fi
+done
+
+log_must restore_root_datasets
+
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -l -g $STAFF_GROUP $perms $dtst
+	log_must verify_perm $dtst $perms $STAFF1 $STAFF2
+	if [[ $dtst == $ROOT_TESTFS ]] ; then
+		log_must verify_noperm $childfs $perms \
+			$STAFF1 $STAFF2 $OTHER1 $OTHER2
+	fi
+done
+
+log_must restore_root_datasets
+
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -l -e $perms $dtst
+	log_must verify_perm $dtst $perms $STAFF1 $STAFF2 $OTHER1 $OTHER2
+	if [[ $dtst == $ROOT_TESTFS ]] ; then
+		log_must verify_noperm $childfs $perms \
+			$STAFF1 $STAFF2 $OTHER1 $OTHER2
+	fi
+done
+
+log_must restore_root_datasets
+
+log_pass "Verify option '-l' only allow permission to the dataset itself pass."
--- /dev/null	Fri Nov 22 15:20:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_004_pos.ksh	Fri Nov 22 15:20:03 2013
@@ -0,0 +1,96 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify option '-d' allow permission to the descendent datasets, and not
+#	for this dataset itself.
+#
+# STRATEGY:
+#	1. Create descendent datasets of $ROOT_TESTFS
+#	2. Select user, group and everyone and set descendent permission
+#	   separately.
+#	3. Set descendent permissions to $ROOT_TESTFS or $ROOT_TESTVOL.
+#	4. Verify those permissions are allowed to $ROOT_TESTFS's
+#	   descendent dataset.
+#	5. Verify the permissions are not allowed to $ROOT_TESTFS or
+#	   $ROOT_TESTVOL.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-d' allow permission to the descendent datasets."
+log_onexit restore_root_datasets
+
+childfs=$ROOT_TESTFS/childfs
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,userprop"
+
+# Verify option '-d' only affect sub-datasets
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -d $STAFF1 $perms $dtst
+	log_must verify_noperm $dtst $perms $STAFF1
+	if [[ $dtst == $ROOT_TESTFS ]]; then
+		log_must verify_perm $childfs $perms $STAFF1
+	fi
+done
+
+log_must restore_root_datasets
+
+# Verify option '-d + -g' affect group in sub-datasets.
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -d -g $STAFF_GROUP $perms $dtst
+	log_must verify_noperm $dtst $perms $STAFF2
+	if [[ $dtst == $ROOT_TESTFS ]]; then
+		log_must verify_perm $childfs $perms $STAFF2
+	fi
+done
+
+log_must restore_root_datasets
+
+# Verify option '-d + -e' affect everyone in sub-datasets.
+log_must $ZFS create $childfs
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -d -e $perms $dtst
+	log_must verify_noperm $dtst $perms $OTHER1 $OTHER2
+	if [[ $dtst == $ROOT_TESTFS ]]; then
+		log_must verify_perm $childfs $perms $OTHER1 $OTHER2
+	fi
+done
+
+log_must restore_root_datasets
+
+log_pass "Verify option '-d' allow permission to the descendent datasets pass."
--- /dev/null	Fri Nov 22 15:20:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_005_pos.ksh	Fri Nov 22 15:20:04 2013
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify option '-c' will be granted locally to the creator on any
+#	newly-created descendent file systems.
+#
+# STRATEGY:
+#	1. Allow create permissions to everyone on $ROOT_TESTFS locally.
+#	2. Allow '-c' create to $ROOT_TESTFS.
+#	3. chmod 777 the mountpoint of $ROOT_TESTFS
+#	4. Verify only creator can create descendent dataset on
+#	   $ROOT_TESTFS/$user.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-c' will be granted locally to the creator."
+log_onexit restore_root_datasets
+
+eval set -A dataset $DATASETS
+typeset perms="snapshot,reservation,compression,checksum,userprop"
+
+log_must $ZFS allow -l everyone create,mount $ROOT_TESTFS
+log_must $ZFS allow -c $perms $ROOT_TESTFS
+
+mntpnt=$(get_prop mountpoint $ROOT_TESTFS)
+log_must $CHMOD 777 $mntpnt
+
+for user in $EVERYONE; do
+	childfs=$ROOT_TESTFS/$user
+
+	user_run $user $ZFS create $childfs
+
+	for other in $EVERYONE; do
+		#
+		# Verify only the creator has the $perm time permissions.
+		#
+		if [[ $other == $user ]]; then
+			log_must verify_perm $childfs $perms $user
+		else
+			log_must verify_noperm $childfs $perms $other
+		fi
+	done
+done
+
+log_pass "Verify option '-c' will be granted locally to the creator passed."
--- /dev/null	Fri Nov 22 15:20:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_006_pos.ksh	Fri Nov 22 15:20:04 2013
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Changing permissions in a set will change what is allowed wherever the
+#	set is used.
+#
+# STRATEGY:
+#	1. Set create as set @basic.
+#	2. Allow set @basic to $STAFF1 on $ROOT_TESTFS or $ROOT_TESTVOL
+#	3. Verify $STAFF1 has create permissions.
+#	4. Reset snapshot,allow to $basic
+#	5. Verify now $STAFF1 have create,allow,destroy permissions.
+#
+
+verify_runnable "both"
+
+log_assert "Changing permissions in a set will change what is allowed " \
+	"wherever the set is used."
+log_onexit restore_root_datasets
+
+fs1=$ROOT_TESTFS/fs1; fs2=$ROOT_TESTFS/fs2
+log_must $ZFS create $fs1
+log_must $ZFS create $fs2
+
+eval set -A dataset $DATASETS
+perms1="snapshot,checksum,reservation"
+
+for dtst in $DATASETS $fs1 $fs2; do
+	log_must $ZFS allow -s @basic $perms1 $dtst
+	log_must $ZFS allow $STAFF1 @basic $dtst
+	log_must verify_perm $dtst $perms1 $STAFF1
+done
+
+perms2="send,compression,userprop"
+for dtst in $DATASETS $fs1 $fs2; do
+	log_must $ZFS allow -s @basic $perms2 $dtst
+	log_must verify_perm $dtst ${perms1},${perms2} $STAFF1
+done
+
+log_pass "Changing permissions in a set will change what is allowed passed."
--- /dev/null	Fri Nov 22 15:20:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_007_pos.ksh	Fri Nov 22 15:20:04 2013
@@ -0,0 +1,103 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify the permissions set will be masked on its descendent
+#	datasets by same name set.
+#
+# STRATEGY:
+#	1. Create $ROOT_TESTFS/childfs
+#	2. Set permission $perms1 to @set on $ROOT_TESTFS
+#	3. Reset permission $perms2 to @set on $ROOT_TESTFS/childfs
+#	4. Allow @set to $STAFF1 on $ROOT_TESTFS/childfs
+#	5. Verify $perms2 is delegated on $ROOT_TESTFS/childfs and its
+#	   descendent.
+#	6. Allow @set to $STAFF1 on $ROOT_TESTFS
+#	7. Verify $perms1 is not appended to $STAFF1 on $ROOT_TESTFS/childfs and
+#	   its descendent since it is masked
+#
+
+verify_runnable "both"
+
+log_assert "Verify permission set can be masked on descendent dataset."
+log_onexit restore_root_datasets
+
+typeset perms1="snapshot,reservation,compression"
+eval set -A dataset $DATASETS
+typeset perms2="checksum,send,userprop"
+
+#
+# Define three level filesystems
+#
+childfs=$ROOT_TESTFS/childfs
+grandchild=$childfs/grandchild
+log_must $ZFS create $childfs
+log_must $ZFS create $grandchild
+
+#
+# Setting different permissions to the same set on two level.
+# But only assign the user at one level.
+#
+log_must $ZFS allow -s @set $perms1 $ROOT_TESTFS
+log_must $ZFS allow -s @set $perms2 $childfs
+log_must $ZFS allow $STAFF1 @set $childfs
+
+#
+# Verify only perms2 is valid to user on the level which he was assigned.
+#
+log_must verify_noperm $ROOT_TESTFS $perms1 $STAFF1
+for fs in $childfs $grandchild ; do
+	log_must verify_noperm $fs $perms1 $STAFF1
+	log_must verify_perm $fs $perms2 $STAFF1
+done
+
+#
+# Delegate @set to STAFF1 on ROOT_TESTFS, verify $perms1 will not be appended
+# to its descendent datasets since it is masked
+#
+log_must $ZFS allow $STAFF1 @set $ROOT_TESTFS
+log_must verify_perm $ROOT_TESTFS $perms1 $STAFF1
+for fs in $childfs $grandchild ; do
+	log_must verify_noperm $fs $perms1 $STAFF1
+	log_must verify_perm $fs $perms2 $STAFF1
+done
+
+# Remove the mask, $perms1 will be allowed to its descendent datasets
+log_must $ZFS unallow -s @set $childfs
+for fs in $childfs $grandchild ; do
+	log_must verify_noperm $fs $perms2 $STAFF1
+	log_must verify_perm $fs $perms1 $STAFF1
+done
+
+log_pass "Verify permission set can be masked on descendent dataset pass."
--- /dev/null	Fri Nov 22 15:20:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_008_pos.ksh	Fri Nov 22 15:20:05 2013
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	non-root user can allow any permissions which he is holding to
+#	other else user when it get 'allow' permission.
+#
+# STRATEGY:
+#	1. Set two set permissions to two datasets locally.
+#	2. Verify the non-root user can allow permission if he has allow
+#	   permission.
+#
+
+verify_runnable "both"
+
+log_assert "Verify non-root user can allow permissions."
+log_onexit restore_root_datasets
+
+perms1="snapshot,reservation"
+perms2="send,compression,checksum,userprop"
+childfs=$ROOT_TESTFS/childfs
+
+log_must $ZFS create $childfs
+
+for dtst in $DATASETS ; do
+	# Delegate local permission to $STAFF1
+	log_must $ZFS allow -l $STAFF1 $perms1 $dtst
+	log_must $ZFS allow -l $STAFF1 allow $dtst
+
+	if [[ $dtst == $ROOT_TESTFS ]]; then
+		log_must $ZFS allow -l $STAFF1 $perms2 $childfs
+		# $perms1 is local permission in $ROOT_TESTFS
+		log_mustnot user_run $STAFF1 $ZFS allow $OTHER1 $perms1 $childfs
+		log_must verify_noperm $childfs $perms1 $OTHER1
+	fi
+
+	# Verify 'allow' give non-privilege user delegated permission.
+	log_must user_run $STAFF1 $ZFS allow -l $OTHER1 $perms1 $dtst
+	log_must verify_perm $dtst $perms1 $OTHER1
+
+	# $perms2 was not allow to $STAFF1, so he have no permission to
+	# delegate permission to other else.
+	log_mustnot user_run $STAFF1 $ZFS allow $OTHER1 $perms2 $dtst
+	log_must verify_noperm $dtst $perms2 $OTHER1
+done
+
+log_pass "Verify non-root user can allow permissions passed."
--- /dev/null	Fri Nov 22 15:20:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_009_neg.ksh	Fri Nov 22 15:20:05 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	zfs allow can deal with invalid arguments.(Invalid options or combination)
+#
+# STRATEGY:
+#	1. Verify invalid argumets will cause error.
+#	2. Verify non-optional argument was missing will cause error.
+#	3. Verify invalid options cause error.
+#
+
+verify_runnable "both"
+
+log_assert "Verify invalid arguments are handled correctly."
+log_onexit restore_root_datasets
+
+# Permission sets are limited to 64 characters in length.
+longset="set123456789012345678901234567890123456789012345678901234567890123"
+for dtst in $DATASETS ; do
+	log_mustnot eval "$ZFS allow -s @$longset $dtst"
+	# Create non-existent permission set
+	typeset timestamp=$($DATE +'%F-%R:%S')
+	log_mustnot $ZFS allow -s @non-existent $dtst
+	log_mustnot $ZFS allow $STAFF "atime,created,mounted" $dtst
+	log_mustnot $ZFS allow $dtst $TESTPOOL
+	log_mustnot $ZFS allow -c $dtst
+	log_mustnot $ZFS allow -u $STAFF1 $dtst
+	log_mustnot $ZFS allow -u $STAFF1 -g $STAFF_GROUP "create,destroy" $dtst
+	log_mustnot $ZFS allow -u $STAFF1 -e "mountpoint" $dtst
+done
+
+log_pass "Invalid arguments are handled correctly."
--- /dev/null	Fri Nov 22 15:20:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh	Fri Nov 22 15:20:05 2013
@@ -0,0 +1,113 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Scan the following permissions one by one to verify privileged user
+#	has correct permission delegation in datasets.
+#
+# STRATEGY:
+#	1. Delegate all the permission one by one to user on dataset.
+#	2. Verify privileged user has correct permission without any other
+#	   permissions allowed.
+#
+
+verify_runnable "both"
+
+log_assert "Verify privileged user has correct permissions once which was "\
+	"delegated to him in datasets"
+log_onexit restore_root_datasets
+
+#
+#				Results in	Results in
+#		Permission	Filesystem	Volume
+#
+set -A perms	create		true		false	\
+		snapshot	true		true	\
+		mount		true		false	\
+		send		true		true	\
+		allow		true		true	\
+		quota		true		false	\
+		reservation	true		true	\
+		recordsize	true		false	\
+		mountpoint	true		false	\
+		checksum	true		true	\
+		compression	true		true	\
+		canmount	true		false	\
+		atime		true		false	\
+		devices		true		false	\
+		exec		true		false	\
+		volsize		false		true	\
+		setuid		true		false	\
+		readonly	true		true	\
+		snapdir		true		false	\
+		userprop	true		true	\
+		aclmode		true		false	\
+		aclinherit	true		false	\
+		rollback	true		true	\
+		clone		true		true	\
+		rename		true		true	\
+		promote		true		true	\
+		zoned		true		false	\
+		xattr		true		false	\
+		receive		true		false	\
+		destroy		true		true
+if is_global_zone; then
+	typeset -i n=${#perms[@]}
+	perms[((n))]="sharenfs"; perms[((n+1))]="true"; perms[((n+2))]="false"
+	perms[((n+3))]="share"; perms[((n+4))]="true"; perms[((n+5))]="false"
+fi
+
+for dtst in $DATASETS; do
+	typeset -i k=1
+	typeset type=$(get_prop type $dtst)
+	[[ $type == "volume" ]] && k=2
+
+	typeset -i i=0
+	while (( i < ${#perms[@]} )); do
+		log_must $ZFS allow $STAFF1 ${perms[$i]} $dtst
+
+		if [[ ${perms[((i+k))]} == "true" ]]; then
+			log_must verify_perm $dtst ${perms[$i]} $STAFF1
+		else
+			log_must verify_noperm $dtst ${perms[$i]} $STAFF1
+		fi
+
+		log_must restore_root_datasets
+
+		((i += 3))
+	done
+done
+
+log_pass "Verify privileged user has correct permissions " \
+	"in datasets passed."
--- /dev/null	Fri Nov 22 15:20:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_011_neg.ksh	Fri Nov 22 15:20:06 2013
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify zpool subcmds and system readonly properties can't be delegated.
+#
+# STRATEGY:
+#	1. Loop all the zpool subcmds and readonly properties, except permission
+#	   'create' & 'destroy'.
+#	2. Verify those subcmd or properties can't be delegated.
+#
+
+verify_runnable "both"
+
+log_assert "Verify zpool subcmds and system readonly properties can't be " \
+	"delegated."
+log_onexit restore_root_datasets
+
+set -A invalid_perms	\
+	add		remove		list		iostat		\
+	status		offline		online 		clear		\
+	attach		detach		replace		scrub		\
+	export		import		upgrade				\
+	type		creation	used		available	\
+	referenced	compressratio	mounted
+
+for dtst in $DATASETS ; do
+	typeset -i i=0
+
+	while ((i < ${#invalid_perms[@]})); do
+		log_mustnot $ZFS allow $STAFF1 ${invalid_perms[$i]} $dtst
+
+		((i += 1))
+	done
+done
+
+log_pass "Verify zpool subcmds and system readonly properties passed."
--- /dev/null	Fri Nov 22 15:20:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh	Fri Nov 22 15:20:06 2013
@@ -0,0 +1,79 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Scan all permissions one by one to verify privileged user
+#	can not use permissions properly when delegation property is set off
+#
+# STRATEGY:
+#	1. Delegate all the permission one by one to user on dataset.
+#	2. Verify privileged user can not use permissions properly when
+#	delegation property is off
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	log_must $ZPOOL set delegation=on $TESTPOOL
+	log_must restore_root_datasets
+}
+
+log_assert "Verify privileged user can not use permissions properly when " \
+	"delegation property is set off"
+log_onexit cleanup
+
+
+set -A perms	create snapshot mount send allow quota reservation \
+		recordsize mountpoint checksum compression canmount atime \
+		devices exec volsize setuid readonly snapdir userprop \
+		aclmode aclinherit rollback clone rename promote \
+		zoned xattr receive destroy sharenfs share
+
+log_must $ZPOOL set delegation=off $TESTPOOL
+
+for dtst in $DATASETS; do
+	typeset -i i=0
+	while (( i < ${#perms[@]} )); do
+
+		log_must $ZFS allow $STAFF1 ${perms[$i]} $dtst
+		log_must verify_noperm $dtst ${perms[$i]} $STAFF1
+
+		log_must restore_root_datasets
+		((i += 1))
+	done
+done
+
+log_pass "Verify privileged user can not use permissions properly when " \
+	"delegation property is set off"
--- /dev/null	Fri Nov 22 15:20:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_001_pos.ksh	Fri Nov 22 15:20:06 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify '-l' only removed the local permissions.
+#
+# STRATEGY:
+#	1. Set up unallow test model.
+#	2. Implement unallow -l to $ROOT_TESTFS or $TESTVOL
+#	3. Verify '-l' only remove the local permissions.
+#
+
+verify_runnable "both"
+
+log_assert "Verify '-l' only removed the local permissions."
+log_onexit restore_root_datasets
+
+log_must setup_unallow_testenv
+
+for dtst in $DATASETS ; do
+	log_must $ZFS unallow -l $STAFF1 $dtst
+	log_must verify_noperm $dtst $LOCAL_SET $STAFF1
+
+	log_must $ZFS unallow -l $OTHER1 $dtst
+	log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1
+
+	log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER2
+	if [[ $dtst == $ROOT_TESTFS ]]; then
+		log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER1 $OTHER2
+		log_must verify_perm $SUBFS $DESC_SET $STAFF2
+	fi
+done
+
+log_pass "Verify '-l' only removed the local permissions passed."
--- /dev/null	Fri Nov 22 15:20:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_002_pos.ksh	Fri Nov 22 15:20:07 2013
@@ -0,0 +1,61 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify '-d' only remove the permissions on descendent filesystem.
+#
+# STRATEGY:
+#	1. Set up unallow test model.
+#	2. Implement unallow -d to $ROOT_TESTFS
+#	3. Verify '-d' only remove the permissions on descendent filesystem.
+#
+
+verify_runnable "both"
+
+log_assert "Verify '-d' only removed the descendent permissions."
+log_onexit restore_root_datasets
+
+log_must setup_unallow_testenv
+
+log_must $ZFS unallow -d $STAFF2 $ROOT_TESTFS
+log_must verify_noperm $SUBFS $DESC_SET $STAFF2
+
+log_must $ZFS unallow -d $OTHER1 $ROOT_TESTFS
+log_must verify_noperm $SUBFS $LOCAL_DESC_SET $OTHER1
+log_must verify_perm $ROOT_TESTFS $LOCAL_DESC_SET $OTHER1
+
+log_must verify_perm $ROOT_TESTFS $LOCAL_DESC_SET $OTHER2
+log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER2
+
+log_pass "Verify '-d' only removed the descendent permissions passed"
--- /dev/null	Fri Nov 22 15:20:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_003_pos.ksh	Fri Nov 22 15:20:07 2013
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify options '-r' or '-l' + '-d' will unallow permission to this
+#	dataset and the descendent datasets.
+#
+# STRATEGY:
+#	1. Set up unallow test model.
+#	2. Implement unallow -l -d to $ROOT_TESTFS or $ROOT_TESTVOL without
+#	   options.
+#	3. Verify '-l' + '-d' will unallow local + descendent permission.
+#	4. Verify '-r' will unallow local + descendent permission.
+#
+
+verify_runnable "both"
+
+log_assert "Verify options '-r' and '-l'+'-d' will unallow permission to " \
+	"this dataset and the descendent datasets."
+log_onexit restore_root_datasets
+
+log_must setup_unallow_testenv
+
+for dtst in $DATASETS ; do
+	log_must $ZFS unallow $STAFF1 $dtst
+	log_must $ZFS unallow -l -d $STAFF2 $dtst
+	log_must verify_noperm $dtst $LOCAL_SET $STAFF1
+	if [[ $dtst == $ROOT_TESTFS ]]; then
+		log_must verify_noperm $SUBFS $DESC_SET $STAFF2
+	fi
+
+	log_must $ZFS unallow -l -d $OTHER1 $dtst
+	log_must $ZFS unallow -r $OTHER2 $dtst
+	log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1 $OTHER2
+	if [[ $dtst == $ROOT_TESTFS ]]; then
+		log_must verify_noperm $SUBFS $LOCAL_DESC_SET $OTHER1 $OTHER2
+	fi
+done
+
+log_pass "Verify options '-r' and '-l'+'-d' function passed."
--- /dev/null	Fri Nov 22 15:20:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_004_pos.ksh	Fri Nov 22 15:20:08 2013
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify '-s' will remove permissions from the named set.
+#
+# STRATEGY:
+#	1. Set @basic set to $ROOT_TESTFS or $ROOT_TESTVOL and allow @basic
+#	   to $STAFF1
+#	2. Verify $STAFF1 have @basic permissions.
+#	3. Verify '-s' will remove permission from the named set.
+#
+
+verify_runnable "both"
+
+log_assert "Verify '-s' will remove permissions from the named set."
+log_onexit restore_root_datasets
+
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -s @basic $LOCAL_DESC_SET $dtst
+	log_must $ZFS allow -u $STAFF1 @basic $dtst
+
+	log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1
+	log_must $ZFS unallow -s @basic $LOCAL_DESC_SET $dtst
+	log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF1
+done
+
+log_pass "Verify '-s' will remove permissions from the named set passed."
--- /dev/null	Fri Nov 22 15:20:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_005_pos.ksh	Fri Nov 22 15:20:08 2013
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify option '-c' will remove the created permission set.
+#
+# STRATEGY:
+#	1. Set created time set to $ROOT_TESTFS.
+#	2. Allow permission create to $STAFF1 on $ROOT_TESTFS.
+#	3. Create $SUBFS and verify $STAFF1 have created time permissions.
+#	4. Verify $STAFF1 has created time permission.
+#	5. Unallow created time permission with option '-c'.
+#	6. Created $SUBFS and verify $STAFF1 have not created time permissions.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-c' will remove the created permission set."
+log_onexit restore_root_datasets
+
+log_must $ZFS allow -c $LOCAL_SET $ROOT_TESTFS
+log_must $ZFS allow -l $STAFF1 create,mount $ROOT_TESTFS
+
+# Create $SUBFS and verify $SUBFS has created time permissions.
+user_run $STAFF1 $ZFS create $SUBFS
+if ! datasetexists $SUBFS ; then
+	log_fail "ERROR: ($STAFF1): $ZFS create $SUBFS"
+fi
+log_must verify_perm $SUBFS $LOCAL_SET $STAFF1
+
+#
+# After unallow -c, create $SUBFS2 and verify $SUBFS2 has not created time
+# permissions any more.
+#
+log_must $ZFS unallow -c $LOCAL_SET $ROOT_TESTFS
+user_run $STAFF1 $ZFS create $SUBFS2
+if ! datasetexists $SUBFS2 ; then
+	log_fail "ERROR: ($STAFF1): $ZFS create $SUBFS2"
+fi
+log_must verify_noperm $SUBFS2 $LOCAL_SET $STAFF1
+
+log_pass "Verify option '-c' will remove the created permission set passed."
--- /dev/null	Fri Nov 22 15:20:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_006_pos.ksh	Fri Nov 22 15:20:08 2013
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify option '-u', '-g' and '-e' only removed the specified type
+#	permissions set.
+#
+# STRATEGY:
+#	1. Allow '-u' '-g' & '-e' to $STAFF1 on ROOT_TESTFS or $ROOT_TESTVOL.
+#	2. Unallow '-u' '-g' & '-e' on $ROOT_TESTFS or $ROOT_TESTVOL separately.
+#	3. Verify permissions on $ROOT_TESTFS or $ROOT_TESTVOL separately.
+#
+
+verify_runnable "both"
+
+log_assert "Verify option '-u', '-g' and '-e' only removed the specified type "\
+	"permissions set."
+log_onexit restore_root_datasets
+
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -u $STAFF1 $LOCAL_DESC_SET $dtst
+	log_must $ZFS allow -g $STAFF_GROUP $LOCAL_DESC_SET $dtst
+	log_must $ZFS allow -e $LOCAL_DESC_SET $dtst
+
+	log_must verify_perm $dtst $LOCAL_DESC_SET \
+		$STAFF1 $STAFF2 $OTHER1 $OTHER2
+
+	log_must $ZFS unallow -e $dtst
+	log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1 $STAFF2
+	log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1 $OTHER2
+
+	log_must $ZFS unallow -g $STAFF_GROUP $dtst
+	log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1
+	log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF2
+
+	log_must $ZFS unallow -u $STAFF1 $dtst
+	log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF1
+done
+
+log_pass "Verify option '-u', '-g' and '-e' passed."
--- /dev/null	Fri Nov 22 15:20:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_007_neg.ksh	Fri Nov 22 15:20:09 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	zfs unallow will not remove those permissions which inherited from
+#	its parent filesystem.
+#
+# STRATEGY:
+#	1. Assign perm1 to $ROOT_TESTFS
+#	2. Create $SUBFS and assign perm2 to it.
+#	3. Verify unallow can not affect perm1 on $SUBFS
+#
+
+verify_runnable "both"
+
+log_assert "zfs unallow won't remove those permissions which inherited from " \
+	"its parent dataset."
+log_onexit restore_root_datasets
+
+perm1="atime,devices"; perm2="compression,checksum"
+log_must $ZFS create $SUBFS
+log_must $ZFS allow $STAFF1 $perm1 $ROOT_TESTFS
+log_must $ZFS allow $STAFF1 $perm2 $SUBFS
+
+log_must verify_perm $SUBFS ${perm1},${perm2} $STAFF1
+#
+# Athrough unallow the permissions which don't exists on the specific dataset
+# return 0, the inherited permissions can't be removed in fact.
+#
+log_must $ZFS unallow -u $STAFF1 $perm1 $SUBFS
+log_must verify_perm $SUBFS ${perm1},${perm2} $STAFF1
+
+log_pass "Verify zfs unallow won't remove inherited permissions passed."
--- /dev/null	Fri Nov 22 15:20:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/delegate/zfs_unallow_008_neg.ksh	Fri Nov 22 15:20:09 2013
@@ -0,0 +1,75 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
+
+#
+# DESCRIPTION:
+#	zfs unallow can handle invalid arguments.
+#
+# STRATEGY:
+#	1. Set up basic test environment.
+#	2. Verify zfs unallow handle invalid arguments correctly.
+#
+
+verify_runnable "both"
+
+log_assert "zfs unallow can handle invalid arguments."
+log_onexit restore_root_datasets
+
+function neg_test
+{
+	log_mustnot eval "$@ >/dev/null 2>&1"
+}
+
+# Options that cause this test to fail:
+# "-r"
+set -A badopts "everyone -e" "everyone -u $STAFF1" "everyone everyone" \
+	"-c -l" "-c -d" "-c -e" "-c -s" "-u -e" "-s -e" "-s -l -d" \
+	"-s @non-exist-set -l" "-s @non-existen-set -d" \
+	"-s @non-existen-set -e" "-r -u $STAFF1 $STAFF1" \
+	"-u $STAFF1 -g $STAFF_GROUP" "-u $STAFF1 -e"
+
+log_must setup_unallow_testenv
+
+for dtst in $DATASETS ; do
+	log_must $ZFS allow -c create $dtst
+
+	typeset -i i=0
+	while ((i < ${#badopts[@]})); do
+		neg_test $ZFS unallow ${badopts[$i]} $dtst
+		((i += 1))
+	done
+
+	# Causes test failure: neg_test user_run $STAFF1 $ZFS unallow $dtst
+done
+
+log_pass "zfs unallow can handle invalid arguments passed."
--- /dev/null	Fri Nov 22 15:20:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/Makefile	Fri Nov 22 15:20:09 2013
@@ -0,0 +1,46 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/devices
+
+PROGS = cleanup \
+	devices_001_pos \
+	devices_002_neg \
+	devices_003_pos \
+	setup
+
+FILES = devices.cfg \
+	devices_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/cleanup.ksh	Fri Nov 22 15:20:10 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/devices.cfg	Fri Nov 22 15:20:10 2013
@@ -0,0 +1,32 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE1=testfile1$$
+export TESTFILE2=testfile2$$
--- /dev/null	Fri Nov 22 15:20:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/devices_001_pos.ksh	Fri Nov 22 15:20:10 2013
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/devices/devices.cfg
+. $STF_SUITE/tests/functional/devices/devices_common.kshlib
+
+#
+# DESCRIPTION:
+# When set property devices=on on file system, devices files can be used in
+# this file system.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Set devices=on on this file system.
+# 3. Separately create block device file and character file.
+# 4. Separately read from those two device files.
+# 5. Check the return value, and make sure it succeeds.
+#
+
+verify_runnable "global"
+
+log_assert "Setting devices=on on file system, the devices files in this file" \
+	"system can be used."
+log_onexit cleanup
+
+log_must $ZFS set devices=on $TESTPOOL/$TESTFS
+
+#
+# Separately create block device file and character device file, then try to
+# open them and make sure it succeed.
+#
+create_dev_file b $TESTDIR/$TESTFILE1
+log_must $DD if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1
+create_dev_file c $TESTDIR/$TESTFILE2
+log_must $DD if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1
+
+log_pass "Setting devices=on on file system and testing it pass."
--- /dev/null	Fri Nov 22 15:20:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/devices_002_neg.ksh	Fri Nov 22 15:20:11 2013
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/devices/devices.cfg
+. $STF_SUITE/tests/functional/devices/devices_common.kshlib
+
+#
+# DESCRIPTION:
+# When set property devices=off on file system, device files cannot be used
+# in this file system.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Set devices=off on this file system.
+# 3. Separately create block device file and character file.
+# 4. Separately read from those two device files.
+# 5. Check the return value, and make sure it failed.
+#
+
+verify_runnable "global"
+
+log_assert "Setting devices=off on file system, the devices files in this file"\
+	"system can not be used."
+log_onexit cleanup
+
+log_must $ZFS set devices=off $TESTPOOL/$TESTFS
+
+#
+# Separately create block device file and character device file, then try to
+# open them and make sure it failed.
+#
+create_dev_file b $TESTDIR/$TESTFILE1
+log_mustnot $DD if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1
+create_dev_file c $TESTDIR/$TESTFILE2
+log_mustnot $DD if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1
+
+log_pass "Setting devices=off on file system and testing it pass."
--- /dev/null	Fri Nov 22 15:20:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/devices_003_pos.ksh	Fri Nov 22 15:20:11 2013
@@ -0,0 +1,49 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Writing random data into /dev/zfs should do no harm.
+#
+# STRATEGY:
+# 1. Write some random data into /dev/zfs
+# 2. Verify that this should fail.
+#
+#
+
+log_assert "Writing random data into /dev/zfs should do no harm."
+
+log_mustnot $DD if=/dev/urandom of=/dev/zfs count=1024
+
+log_pass "Writing random data into /dev/zfs should do no harm."
--- /dev/null	Fri Nov 22 15:20:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/devices_common.kshlib	Fri Nov 22 15:20:11 2013
@@ -0,0 +1,119 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/devices/devices.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# Create block file or charactor file according to parameter.
+#
+# $1 device file type
+# $2 file name
+#
+function create_dev_file
+{
+	typeset filetype=$1
+	typeset filename=$2
+
+	case $filetype in
+		b)
+			devtype=$($DF -n / | $AWK '{print $3}')
+			case $devtype in
+				zfs)
+					rootpool=$($DF / | \
+						$AWK '{print $2}')
+					rootpool=${rootpool#\(}
+					rootpool=${rootpool%%/*}
+
+					devstr=$(get_disklist $rootpool)
+					devstr=$($ECHO "$devstr" | \
+						$AWK '{print $1}')
+					[[ -z $devstr ]] && \
+						log_fail "Can not get block device file."
+					devstr=/dev/dsk/${devstr}
+					;;
+				ufs)
+			#
+			# Get the existing block device file in current system.
+			# And bring out the first one.
+			#
+					devstr=$($DF -lhF ufs | \
+						$GREP "^/dev/dsk" | \
+						$AWK '{print $1}')
+					devstr=$($ECHO "$devstr" | \
+						$AWK '{print $1}')
+					[[ -z $devstr ]] && \
+						log_fail "Can not get block device file."
+					;;
+				*)
+					log_unsupported "Unsupported fstype " \
+						"for / ($devtype)," \
+						"only ufs|zfs is supported."
+					;;
+			esac
+
+			#
+			# Get the device file information. i.e:
+			# /dev/dsk/c0t0d0s0:      block special (28/768)
+			#
+			devstr=$($FILE $devstr)
+
+			#
+			# Bring out major and minor number.
+			#
+			major=${devstr##*\(}
+			major=${major%%/*}
+			minor=${devstr##*/}
+			minor=${minor%\)}
+
+			log_must $MKNOD $filename b $major $minor
+			;;
+		c)
+			#
+			# Create device file '/dev/null'
+			#
+			log_must $MKNOD $filename c $($GETMAJOR mm) 2
+			;;
+		*)
+			log_fail "'$filetype' is wrong."
+			;;
+	esac
+
+	return 0
+}
+
+function cleanup
+{
+	log_must $ZFS set devices=on $TESTPOOL/$TESTFS
+	log_must $RM -f $TESTDIR/$TESTFILE1
+	log_must $RM -f $TESTDIR/$TESTFILE2
+	log_must $RM -f $TESTDIR/$TESTFILE1.out
+	log_must $RM -f $TESTDIR/$TESTFILE2.out
+}
--- /dev/null	Fri Nov 22 15:20:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/devices/setup.ksh	Fri Nov 22 15:20:12 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:20:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/exec/Makefile	Fri Nov 22 15:20:12 2013
@@ -0,0 +1,69 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/exec
+
+PROG = mmap_exec
+
+SCRIPTS = cleanup \
+	exec_001_pos \
+	exec_002_neg \
+	setup
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+
+OBJS = $(PROG:%=%.o)
+SRCS = $(OBJS:%.o=%.c)
+
+CMDS = $(PROG:%=$(TESTDIR)/%) $(SCRIPTS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+	$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+	$(POST_PROCESS)
+
+%.o: ../%.c
+	$(COMPILE.c) $<
+
+install: all $(CMDS)
+
+lint: lint_SRCS
+
+clobber: clean
+	-$(RM) $(PROG)
+
+clean:
+	-$(RM) $(OBJS)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:20:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/exec/cleanup.ksh	Fri Nov 22 15:20:13 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/exec/exec_001_pos.ksh	Fri Nov 22 15:20:13 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# When set property exec=on on a filesystem, processes can be executed from
+# this filesystem.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Copy '/usr/bin/ls' to the ZFS file system.
+# 3. Setting exec=on on this file system.
+# 4. Make sure '/usr/bin/ls' can work in this ZFS file system.
+# 5. Make sure mmap which is using the PROT_EXEC calls succeed.
+#
+
+verify_runnable "both"
+MMAP_EXEC=$STF_SUITE/tests/functional/exec/mmap_exec
+
+function cleanup
+{
+	log_must $RM $TESTDIR/myls
+}
+
+log_assert "Setting exec=on on a filesystem, processes can be executed from " \
+	"this file system."
+log_onexit cleanup
+
+log_must $CP $LS $TESTDIR/myls
+log_must $ZFS set exec=on $TESTPOOL/$TESTFS
+log_must $TESTDIR/myls
+log_must $MMAP_EXEC $TESTDIR/myls
+
+log_pass "Setting exec=on on filesystem testing passed."
--- /dev/null	Fri Nov 22 15:20:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/exec/exec_002_neg.ksh	Fri Nov 22 15:20:13 2013
@@ -0,0 +1,85 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# When set property exec=off on a filesystem, processes can not be executed from
+# this filesystem.
+#
+# STRATEGY:
+# 1. Create pool and file system.
+# 2. Copy '/usr/bin/ls' to the ZFS file system.
+# 3. Setting exec=off on this file system.
+# 4. Make sure '/usr/bin/ls' can not work in this ZFS file system.
+# 5. Make sure mmap which is using the PROT_EXEC calls failed.
+#
+
+verify_runnable "both"
+MMAP_EXEC=$STF_SUITE/tests/functional/exec/mmap_exec
+
+function cleanup
+{
+	log_must $RM $TESTDIR/myls
+}
+
+#
+# Execute and check if the return value is equal to expected.
+#
+# $1 expected value
+# $2..$n executed item
+#
+function exec_n_check
+{
+	typeset expect_value=$1
+
+	shift
+	$@
+	ret=$?
+	if [[ $ret != $expect_value ]]; then
+		log_fail "Unexpected return code: '$ret'"
+	fi
+
+	return 0
+}
+
+log_assert "Setting exec=off on a filesystem, processes can not be executed " \
+	"from this file system."
+log_onexit cleanup
+
+log_must $CP $LS $TESTDIR/myls
+log_must $ZFS set exec=off $TESTPOOL/$TESTFS
+
+log_must exec_n_check 126 $TESTDIR/myls
+log_must exec_n_check 13 $MMAP_EXEC $TESTDIR/myls
+
+log_pass "Setting exec=off on filesystem testing passed."
--- /dev/null	Fri Nov 22 15:20:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/exec/mmap_exec.c	Fri Nov 22 15:20:14 2013
@@ -0,0 +1,71 @@
+/*
+ * 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 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+extern int errno;
+
+int
+main(int argc, char *argv[])
+{
+	int fd;
+	struct stat statbuf;
+
+	if (argc != 2) {
+		(void) printf("Error: missing binary name.\n");
+		(void) printf("Usage:\n\t%s <binary name>\n",
+		    argv[0]);
+		return (1);
+	}
+
+	errno = 0;
+
+	if ((fd = open(argv[1], O_RDONLY)) < 0) {
+		perror("open");
+		return (errno);
+	}
+	if (fstat(fd, &statbuf) < 0) {
+		perror("fstat");
+		return (errno);
+	}
+
+	if (mmap(0, statbuf.st_size,
+	    PROT_EXEC, MAP_SHARED, fd, 0) == MAP_FAILED) {
+		perror("mmap");
+		return (errno);
+	}
+
+	return (0);
+}
--- /dev/null	Fri Nov 22 15:20:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/exec/setup.ksh	Fri Nov 22 15:20:14 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:20:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/features/Makefile	Fri Nov 22 15:20:14 2013
@@ -0,0 +1,27 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/features/async_destroy
+
+all install lint clean clobber:
+
+SUBDIRS = async_destroy
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Fri Nov 22 15:20:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/features/async_destroy/Makefile	Fri Nov 22 15:20:15 2013
@@ -0,0 +1,38 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/features/async_destroy
+
+PROGS = async_destroy_001_pos \
+	cleanup \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:20:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh	Fri Nov 22 15:20:15 2013
@@ -0,0 +1,84 @@
+#!/bin/ksh -p
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Exercise the traversal suspend/resume code in async_destroy by
+# destroying a file system that has more blocks than we can free
+# in a single txg.
+#
+# STRATEGY:
+# 1. Create a file system
+# 2. Set recordsize to 512 to create the maximum number of blocks
+# 3. Set compression to off to force zero-ed blocks to be written
+# 4. dd a lot of data from /dev/zero to the file system
+# 5. Destroy the file system
+# 6. Wait for the freeing property to go to 0
+# 7. Use zdb to check for leaked blocks
+#
+
+TEST_FS=$TESTPOOL/async_destroy
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $TEST_FS && log_must $ZFS destroy $TEST_FS
+}
+
+log_onexit cleanup
+log_assert "async_destroy can suspend and resume traversal"
+
+log_must $ZFS create -o recordsize=512 -o compression=off $TEST_FS
+
+#
+# Fill with 2G
+#
+log_must $DD bs=1024k count=2048 if=/dev/zero of=/$TEST_FS/file
+
+log_must $ZFS destroy $TEST_FS
+
+count=0
+while [[ "0" != "$($ZPOOL list -Ho freeing $TESTPOOL)" ]]; do
+	count=$((count + 1))
+	sleep 1
+done
+
+#
+# We assert that the data took a few seconds to free to make sure that
+# we actually exercised the suspend/resume code. The destroy should
+# actually take much longer than this, so false positives are not likely.
+#
+log_must test $count -gt 5
+
+#
+# Check for leaked blocks.
+#
+log_must $ZDB -b $TESTPOOL
+
+log_pass "async_destroy can suspend and resume traversal"
--- /dev/null	Fri Nov 22 15:20:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/features/async_destroy/cleanup.ksh	Fri Nov 22 15:20:15 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/features/async_destroy/setup.ksh	Fri Nov 22 15:20:16 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:20:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_pool/Makefile	Fri Nov 22 15:20:16 2013
@@ -0,0 +1,43 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/grow_pool
+
+PROGS = cleanup \
+	grow_pool_001_pos \
+	setup
+
+FILES = grow_pool.cfg \
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:17 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_pool/cleanup.ksh	Fri Nov 22 15:20:17 2013
@@ -0,0 +1,53 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/grow_pool/grow_pool.cfg
+
+verify_runnable "global"
+
+ismounted $TESTFS && \
+        log_must $ZFS umount $TESTDIR
+destroy_pool "$TESTPOOL"
+
+#
+# Here we create & destroy a zpool using the disks
+# because this resets the partitions to normal
+#
+if [[ -z $DISK ]]; then
+        create_pool ZZZ "$DISK0 $DISK1"
+        destroy_pool ZZZ
+else
+        create_pool ZZZ "$DISK"
+        destroy_pool ZZZ
+fi
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:17 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_pool/grow_pool.cfg	Fri Nov 22 15:20:17 2013
@@ -0,0 +1,63 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function set_disks
+{
+	set -A disk_array $(find_disks $DISKS)
+	typeset -i i=0
+	typeset -i limit=2
+	while  (( i < limit )); do
+		if [[ -n ${disk_array[$i]} ]]; then
+			export DISK${i}="${disk_array[$i]}"
+		else
+			export DISK=${DISKS%% *}
+			return
+		fi
+		((i = i + 1))
+	done
+	export DISK=""
+}
+
+export BLOCK_SIZE=8192
+set_disks
+#
+# Do not make SIZE too large as the three slices may exceed
+# the size of the disk, and also slow down the test
+# which involves filling until ENOSPC
+#
+export SIZE="100mb"
+export SLICE=0
+export SLICE0=0
+export SLICE1=1
+export SMALL_WRITE_COUNT=100
+export TESTFILE1=file$$.1
+export WRITE_COUNT=65536000
--- /dev/null	Fri Nov 22 15:20:17 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_pool/grow_pool_001_pos.ksh	Fri Nov 22 15:20:17 2013
@@ -0,0 +1,74 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/grow_pool/grow_pool.cfg
+
+#
+# DESCRIPTION:
+# A ZFS file system is limited by the amount of disk space
+# available to the pool. Growing the pool by adding a disk
+# increases the amount of space.
+#
+# STRATEGY:
+# 1) Fill a ZFS filesystem until ENOSPC by creating a large file
+# 2) Grow the pool by adding a disk
+# 3) Verify that more data can now be written to the file system
+#
+
+verify_runnable "global"
+
+log_assert "A zpool may be increased in capacity by adding a disk"
+
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 \
+	-b $BLOCK_SIZE -c $WRITE_COUNT -d 0
+typeset -i zret=$?
+readonly ENOSPC=28
+if [[ $zret -ne $ENOSPC ]]; then
+	log_fail "file_write completed w/o ENOSPC, aborting!!!"
+fi
+
+if [[ ! -s $TESTDIR/$TESTFILE1 ]]; then
+	log_fail "$TESTDIR/$TESTFILE1 was not created"
+fi
+
+if [[ -n $DISK ]]; then
+	log_must $ZPOOL add $TESTPOOL $DISK"s"$SLICE1
+else
+	log_must $ZPOOL add $TESTPOOL $DISK1
+fi
+
+log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE1 \
+	-b $BLOCK_SIZE -c $SMALL_WRITE_COUNT -d 0
+
+log_must $ZFS inherit compression $TESTPOOL/$TESTFS
+log_pass "TESTPOOL successfully grown"
--- /dev/null	Fri Nov 22 15:20:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_pool/setup.ksh	Fri Nov 22 15:20:18 2013
@@ -0,0 +1,54 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/grow_pool/grow_pool.cfg
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+if [[ -n $DISK ]]; then
+        log_note "No spare disks available. Using slices on $DISK"
+	for i in $SLICE0 $SLICE1 ; do
+		log_must set_partition $i "$cyl" $SIZE $DISK
+		cyl=$(get_endslice $DISK $i)
+	done
+        tmp=$DISK"s"$SLICE0
+else
+        log_must set_partition $SLICE "" $SIZE $DISK0
+        log_must set_partition $SLICE "" $SIZE $DISK1
+	tmp=$DISK0"s"$SLICE
+fi
+
+default_setup $tmp
--- /dev/null	Fri Nov 22 15:20:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_replicas/Makefile	Fri Nov 22 15:20:18 2013
@@ -0,0 +1,43 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/grow_replicas
+
+PROGS = cleanup \
+	grow_replicas_001_pos \
+	setup
+
+FILES = grow_replicas.cfg \
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_replicas/cleanup.ksh	Fri Nov 22 15:20:18 2013
@@ -0,0 +1,53 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/grow_replicas/grow_replicas.cfg
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+ismounted $TESTFS && \
+        log_must $ZFS umount $TESTDIR
+destroy_pool "$TESTPOOL"
+
+#
+# Here we create & destroy a zpool using the disks
+# because this resets the partitions to normal
+#
+if [[ -z $DISK ]]; then
+        create_pool "ZZZ" "$DISK0 $DISK1"
+        destroy_pool "ZZZ"
+else
+        create_pool "ZZZ" "$DISK"
+        destroy_pool "ZZZ"
+fi
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_replicas/grow_replicas.cfg	Fri Nov 22 15:20:19 2013
@@ -0,0 +1,78 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+function set_disks
+{
+	set -A disk_array $(find_disks $DISKS)
+	typeset -i i=0
+	typeset -i limit=4
+	while  (( i < limit )); do
+		if [[ -n ${disk_array[$i]} ]]; then
+			export DISK${i}="${disk_array[$i]}"
+		else
+			export DISK=${DISKS%% *}
+			return
+		fi
+		((i = i + 1))
+	done
+	export DISK=""
+}
+
+typeset -i index=`expr $RANDOM % 2`
+if (( $index == 0 )); then
+        POOLTYPE="mirror"
+else
+        POOLTYPE="raidz"
+fi
+export POOLTYPE
+
+export BLOCK_SIZE=8192
+set_disks
+#
+# Do not make SIZE too large as the three slices may exceed
+# the size of the disk, and also slow down the test
+# which involves filling until ENOSPC
+#
+export SIZE="100mb"
+if [[ $WRAPPER != *"smi"* ]]; then
+	export SLICE=0
+else
+	export SLICE=2
+fi
+export SLICE0=0
+export SLICE1=1
+export SLICE2=2
+export SLICE3=3
+export SLICE4=4
+export SMALL_WRITE_COUNT=100
+export TESTFILE1=file$$.1
+export WRITE_COUNT=65536000
--- /dev/null	Fri Nov 22 15:20:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_replicas/grow_replicas_001_pos.ksh	Fri Nov 22 15:20:19 2013
@@ -0,0 +1,83 @@
+#! /bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/grow_replicas/grow_replicas.cfg
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# A ZFS file system is limited by the amount of disk space
+# available to the pool. Growing the pool by adding a disk
+# increases the amount of space.
+#
+# STRATEGY:
+# 1) Fill a ZFS filesystem mirror/raidz until ENOSPC by creating lots
+# of files
+# 2) Grow the mirror/raidz by adding a disk
+# 3) Verify that more data can now be written to the file system
+#
+
+verify_runnable "global"
+
+log_assert "A zpool mirror/raidz may be increased in capacity by adding a disk."
+
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 \
+        -b $BLOCK_SIZE -c $WRITE_COUNT -d 0
+
+typeset -i zret=$?
+readonly ENOSPC=28
+if [[ $zret -ne $ENOSPC ]]; then
+        log_fail "file_write completed w/o ENOSPC, aborting!!!"
+fi
+
+if [[ ! -s $TESTDIR/$TESTFILE1 ]]; then
+        log_fail "$TESTDIR/$TESTFILE1 was not created"
+fi
+
+#
+# $DISK will be set if we're using slices on one disk
+#
+if [[ -n $DISK ]]; then
+        log_must $ZPOOL add $TESTPOOL $POOLTYPE $DISK"s"$SLICE3 \
+            $DISK"s"$SLICE4
+else
+        [[ -z $DISK2 || -z $DISK3 ]] && \
+            log_unsupported "No spare disks available."
+        log_must $ZPOOL add -f $TESTPOOL $POOLTYPE $DISK2"s"$SLICE \
+	    $DISK3"s"$SLICE
+fi
+
+log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE1 \
+        -b $BLOCK_SIZE -c $SMALL_WRITE_COUNT -d 0
+
+log_must $ZFS inherit compression $TESTPOOL/$TESTFS
+log_pass "TESTPOOL mirror/raidz successfully grown"
--- /dev/null	Fri Nov 22 15:20:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/grow_replicas/setup.ksh	Fri Nov 22 15:20:19 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/grow_replicas/grow_replicas.cfg
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+log_note "Creating pool type: $POOLTYPE"
+
+if [[ -n $DISK ]]; then
+        log_note "No spare disks available. Using slices on $DISK"
+	for i in $SLICE0 $SLICE1 $SLICE3 $SLICE4 ; do
+		log_must set_partition $i "$cyl" $SIZE $DISK
+		cyl=$(get_endslice $DISK $i)
+	done
+        create_pool $TESTPOOL $POOLTYPE ${DISK}s$SLICE0 \
+	    ${DISK}s$SLICE1
+else
+        log_must set_partition $SLICE "" $SIZE $DISK0
+        log_must set_partition $SLICE "" $SIZE $DISK1
+        create_pool $TESTPOOL $POOLTYPE ${DISK0}s${SLICE} \
+	    ${DISK1}s$SLICE
+fi
+
+$RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
+$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/Makefile	Fri Nov 22 15:20:20 2013
@@ -0,0 +1,64 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/history
+
+PROGS = cleanup \
+	history_001_pos \
+	history_002_pos \
+	history_003_pos \
+	history_004_pos \
+	history_005_neg \
+	history_006_neg \
+	history_007_pos \
+	history_008_pos \
+	history_009_pos \
+	history_010_pos \
+	setup
+
+FILES = history.cfg \
+	history_common.kshlib
+
+DATAFILES = i386.migratedpool.DAT.Z \
+	i386.orig_history.txt \
+	sparc.migratedpool.DAT.Z \
+	sparc.orig_history.txt \
+	zfs-pool-v4.dat.Z
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all lint clean clobber:
+
+install: $(CMDS) $(DATA)
+
+$(CMDS): $(TESTDIR)
+
+$(DATA): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/cleanup.ksh	Fri Nov 22 15:20:20 2013
@@ -0,0 +1,38 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+[[ -f $OLD_HISTORY ]] && $RM -f $OLD_HISTORY
+[[ -f $TMP_HISTORY ]] && $RM -f $TMP_HISTORY
+[[ -f $NEW_HISTORY ]] && $RM -f $NEW_HISTORY
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history.cfg	Fri Nov 22 15:20:21 2013
@@ -0,0 +1,45 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export ZFSROOT=
+
+export MPOOL=mpool.$$
+
+export OLD_HISTORY=/tmp/old_history.$$
+export TMP_HISTORY=/tmp/tmp_history.$$
+export NEW_HISTORY=/tmp/new_history.$$
+
+export MIGRATEDPOOLNAME=${MIGRATEDPOOLNAME:-history_pool}
+export TIMEZONE=${TIMEZONE:-US/Mountain}
+
+export HIST_USER="huser"
+export HIST_GROUP="hgroup"
+
+export TESTVOL=testvol.$$
--- /dev/null	Fri Nov 22 15:20:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_001_pos.ksh	Fri Nov 22 15:20:21 2013
@@ -0,0 +1,111 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#	Create a scenario to verify the following zpool subcommands are logged.
+#	create, destroy, add, remove, offline, online, attach, detach, replace,
+#	scrub, export, import, clear, upgrade.
+#
+# STRATEGY:
+#	1. Create three virtual disk files and create a mirror.
+#	2. Run and verify pool commands, with special casing for destroy/export.
+#	3. Import a pool and upgrade it, verifying 'upgrade' was logged.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	destroy_pool $MPOOL
+	destroy_pool $upgrade_pool
+
+	[[ -d $import_dir ]] && $RM -rf $import_dir
+	for file in $VDEV1 $VDEV2 $VDEV3 $VDEV4; do
+		[[ -f $file ]] && $RM -f $file
+	done
+}
+
+log_assert "Verify zpool sub-commands which modify state are logged."
+log_onexit cleanup
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+(( $? != 0)) && log_fail "get_prop($TESTPOOL mountpoint)"
+VDEV1=$mntpnt/vdev1; VDEV2=$mntpnt/vdev2;
+VDEV3=$mntpnt/vdev3; VDEV4=$mntpnt/vdev4;
+
+log_must $MKFILE 64m $VDEV1 $VDEV2 $VDEV3
+log_must $MKFILE 100m $VDEV4
+
+run_and_verify -p "$MPOOL" "$ZPOOL create $MPOOL mirror $VDEV1 $VDEV2"
+run_and_verify -p "$MPOOL" "$ZPOOL add -f $MPOOL spare $VDEV3"
+run_and_verify -p "$MPOOL" "$ZPOOL remove $MPOOL $VDEV3"
+run_and_verify -p "$MPOOL" "$ZPOOL offline $MPOOL $VDEV1"
+run_and_verify -p "$MPOOL" "$ZPOOL online $MPOOL $VDEV1"
+run_and_verify -p "$MPOOL" "$ZPOOL attach $MPOOL $VDEV1 $VDEV4"
+run_and_verify -p "$MPOOL" "$ZPOOL detach $MPOOL $VDEV4"
+run_and_verify -p "$MPOOL" "$ZPOOL replace -f $MPOOL $VDEV1 $VDEV4"
+run_and_verify -p "$MPOOL" "$ZPOOL scrub $MPOOL"
+run_and_verify -p "$MPOOL" "$ZPOOL clear $MPOOL"
+
+# For export and destroy, mimic the behavior of run_and_verify using two
+# commands since the history will be unavailable until the pool is imported
+# again.
+commands=("$ZPOOL export $MPOOL" "$ZPOOL import -d $mntpnt $MPOOL"
+    "$ZPOOL destroy $MPOOL" "$ZPOOL import -D -f -d $mntpnt $MPOOL")
+for i in 0 2; do
+	cmd1="${commands[$i]}"
+	cmd2="${commands[(($i + 1 ))]}"
+
+	$ZPOOL history $MPOOL > $OLD_HISTORY 2>/dev/null
+	log_must $cmd1
+	log_must $cmd2
+	$ZPOOL history $MPOOL > $TMP_HISTORY 2>/dev/null
+	$DIFF $OLD_HISTORY $TMP_HISTORY | $GREP "^> " | $SED 's/^> //g' > \
+	    $NEW_HISTORY
+	$GREP "$($ECHO "$cmd1" | $SED 's/\/usr\/sbin\///g')" $NEW_HISTORY \
+	    >/dev/null 2>&1 || log_fail "Didn't find \"$cmd1\" in pool history"
+	$GREP "$($ECHO "$cmd2" | $SED 's/\/usr\/sbin\///g')" $NEW_HISTORY \
+	    >/dev/null 2>&1 || log_fail "Didn't find \"$cmd2\" in pool history"
+done
+
+run_and_verify -p "$MPOOL" "$ZPOOL split $MPOOL ${MPOOL}_split"
+
+import_dir=/var/tmp/import_dir.$$
+log_must $MKDIR $import_dir
+log_must $CP $STF_SUITE/tests/functional/history/zfs-pool-v4.dat.Z $import_dir
+log_must $UNCOMPRESS $import_dir/zfs-pool-v4.dat.Z
+upgrade_pool=$($ZPOOL import -d $import_dir | $GREP "pool:" | $AWK '{print $2}')
+log_must $ZPOOL import -d $import_dir $upgrade_pool
+run_and_verify -p "$upgrade_pool" "$ZPOOL upgrade $upgrade_pool"
+
+log_pass "zpool sub-commands which modify state are logged passed. "
--- /dev/null	Fri Nov 22 15:20:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_002_pos.ksh	Fri Nov 22 15:20:21 2013
@@ -0,0 +1,142 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#	Create a  scenario to verify the following zfs subcommands are logged.
+#	create, destroy, clone, rename, snapshot, rollback, set, inherit,
+#	receive, promote, hold and release.
+#
+# STRATEGY:
+#	1. Verify that all the zfs commands listed (barring send) produce an
+#	   entry in the pool history.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+
+	[[ -f $tmpfile ]] && $RM -f $tmpfile
+	[[ -f $tmpfile2 ]] && $RM -f $tmpfile2
+	for dataset in $fs $newfs $fsclone $vol $newvol $volclone; do
+		datasetexists $dataset && $ZFS destroy -Rf $dataset
+	done
+	$RM -rf /history.$$
+}
+
+log_assert "Verify zfs sub-commands which modify state are logged."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS1; newfs=$TESTPOOL/newfs; fsclone=$TESTPOOL/clone
+vol=$TESTPOOL/$TESTVOL ; newvol=$TESTPOOL/newvol; volclone=$TESTPOOL/volclone
+fssnap=$fs@fssnap; fssnap2=$fs@fssnap2
+volsnap=$vol@volsnap; volsnap2=$vol@volsnap2
+tmpfile=/tmp/tmpfile.$$ ; tmpfile2=/tmp/tmpfile2.$$
+
+#	property	value		property	value
+#
+props=(
+	quota		64M		recordsize	512
+	reservation	32M		reservation	none
+	mountpoint	/history.$$	mountpoint	legacy
+	mountpoint	none		sharenfs	on
+	sharenfs	off
+	compression	on		compression	off
+	compression	lzjb		aclmode		discard
+	aclmode		groupmask	aclmode		passthrough
+	atime		on		atime		off
+	devices		on		devices		off
+	exec		on		exec		off
+	setuid		on		setuid		off
+	readonly	on		readonly	off
+	zoned		on		zoned		off
+	snapdir		hidden		snapdir		visible
+	aclinherit	discard		aclinherit	noallow
+	aclinherit	secure		aclinherit	passthrough
+	canmount	off		canmount	on
+	xattr		on		xattr		off
+	compression	gzip		compression	gzip-$((RANDOM%9 + 1))
+	copies		$((RANDOM%3 + 1))
+)
+
+run_and_verify "$ZFS create $fs"
+# Set all the property for filesystem
+typeset -i i=0
+while ((i < ${#props[@]})) ; do
+	run_and_verify "$ZFS set ${props[$i]}=${props[((i+1))]} $fs"
+
+	# quota, reservation, canmount can not be inherited.
+	#
+	if [[ ${props[$i]} != "quota" && ${props[$i]} != "reservation" && \
+	    ${props[$i]} != "canmount" ]];
+	then
+		run_and_verify "$ZFS inherit ${props[$i]} $fs"
+	fi
+
+	((i += 2))
+done
+
+run_and_verify "$ZFS create -V 64M $vol"
+run_and_verify "$ZFS set volsize=32M $vol"
+run_and_verify "$ZFS snapshot $fssnap"
+run_and_verify "$ZFS hold tag $fssnap"
+run_and_verify "$ZFS release tag $fssnap"
+run_and_verify "$ZFS snapshot $volsnap"
+run_and_verify "$ZFS snapshot $fssnap2"
+run_and_verify "$ZFS snapshot $volsnap2"
+
+# Send isn't logged...
+log_must $ZFS send -i $fssnap $fssnap2 > $tmpfile
+log_must $ZFS send -i $volsnap $volsnap2 > $tmpfile2
+# Verify that's true
+$ZPOOL history $TESTPOOL | $GREP 'zfs send' >/dev/null 2>&1 && \
+    log_fail "'zfs send' found in history of \"$TESTPOOL\""
+
+run_and_verify "$ZFS destroy $fssnap2"
+run_and_verify "$ZFS destroy $volsnap2"
+run_and_verify "$ZFS receive $fs < $tmpfile"
+run_and_verify "$ZFS receive $vol < $tmpfile2"
+run_and_verify "$ZFS rollback -r $fssnap"
+run_and_verify "$ZFS rollback -r $volsnap"
+run_and_verify "$ZFS clone $fssnap $fsclone"
+run_and_verify "$ZFS clone $volsnap $volclone"
+run_and_verify "$ZFS rename $fs $newfs"
+run_and_verify "$ZFS rename $vol $newvol"
+run_and_verify "$ZFS promote $fsclone"
+run_and_verify "$ZFS promote $volclone"
+run_and_verify "$ZFS destroy $newfs"
+run_and_verify "$ZFS destroy $newvol"
+run_and_verify "$ZFS destroy -rf $fsclone"
+run_and_verify "$ZFS destroy -rf $volclone"
+
+log_pass "zfs sub-commands which modify state are logged passed."
--- /dev/null	Fri Nov 22 15:20:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_003_pos.ksh	Fri Nov 22 15:20:22 2013
@@ -0,0 +1,103 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	zpool history will truncate on small pools, leaving pool creation intact
+#
+# STRATEGY:
+#	1. Create two 100M virtual disk files.
+#	2. Create test pool using the two virtual files.
+#	3. Loop 100 times to set and remove compression to test dataset.
+#	4. Make sure 'zpool history' output is truncated
+#	5. Verify that the initial pool creation is preserved.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $spool && log_must $ZPOOL destroy $spool
+	[[ -f $VDEV0 ]] && log_must $RM -f $VDEV0
+	[[ -f $VDEV1 ]] && log_must $RM -f $VDEV1
+	[[ -f $TMPFILE ]] && log_must $RM -f $TMPFILE
+}
+
+log_assert "zpool history limitation test."
+log_onexit cleanup
+
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+(( $? != 0 )) && log_fail "get_prop mountpoint $TESTPOOL"
+
+VDEV0=$mntpnt/vdev0; VDEV1=$mntpnt/vdev1
+log_must $MKFILE 100m $VDEV0 $VDEV1
+
+spool=smallpool.$$; sfs=smallfs.$$
+log_must $ZPOOL create $spool $VDEV0 $VDEV1
+log_must $ZFS create $spool/$sfs
+
+typeset -i orig_count=$($ZPOOL history $spool | $WC -l)
+typeset orig_md5=$($ZPOOL history $spool | $HEAD -2 | $MD5SUM | \
+    $AWK '{print $1}')
+
+typeset -i i=0
+while ((i < 100)); do
+	$ZFS set compression=off $spool/$sfs
+	$ZFS set compression=on $spool/$sfs
+	$ZFS set compression=off $spool/$sfs
+	$ZFS set compression=on $spool/$sfs
+	$ZFS set compression=off $spool/$sfs
+
+	((i += 1))
+done
+
+TMPFILE=/tmp/spool.$$
+$ZPOOL history $spool >$TMPFILE
+typeset -i entry_count=$($WC -l $TMPFILE | $AWK '{print $1}')
+typeset final_md5=$($HEAD -2 $TMPFILE | $MD5SUM | $AWK '{print $1}')
+
+$GREP 'zpool create' $TMPFILE >/dev/null 2>&1 ||
+    log_fail "'zpool create' was not found in pool history"
+
+$GREP 'zfs create' $TMPFILE >/dev/null 2>&1 &&
+    log_fail "'zfs create' was found in pool history"
+
+$GREP 'zfs set compress' $TMPFILE >/dev/null 2>&1 ||
+    log_fail "'zfs set compress' was found in pool history"
+
+# Verify that the creation of the pool was preserved in the history.
+if [[ $orig_md5 != $final_md5 ]]; then
+	log_fail "zpool creation history was not preserved."
+fi
+
+log_pass "zpool history limitation test passed."
--- /dev/null	Fri Nov 22 15:20:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_004_pos.ksh	Fri Nov 22 15:20:22 2013
@@ -0,0 +1,100 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zpool history' can cope with simultaneous commands.
+#
+# STRATEGY:
+#	1. Create test pool and test fs.
+#	2. Loop 100 times, set properties to test fs simultaneously.
+#	3. Wait for all the command execution complete.
+#	4. Make sure all the commands was logged by 'zpool history'.
+#
+
+verify_runnable "global"
+
+log_assert "'zpool history' can cope with simultaneous commands."
+
+typeset -i orig_count=$($ZPOOL history $spool | $WC -l | $AWK '{print $1}')
+
+typeset -i i=0
+while ((i < 10)); do
+	$ZFS set compression=off $TESTPOOL/$TESTFS &
+	$ZFS set atime=off $TESTPOOL/$TESTFS &
+	$ZFS create $TESTPOOL/$TESTFS1 &
+	$ZFS create $TESTPOOL/$TESTFS2 &
+	$ZFS create $TESTPOOL/$TESTFS3 &
+
+	wait
+
+	$ZFS snapshot $TESTPOOL/$TESTFS1@snap &
+	$ZFS snapshot $TESTPOOL/$TESTFS2@snap &
+	$ZFS snapshot $TESTPOOL/$TESTFS3@snap &
+
+	wait
+
+	$ZFS clone $TESTPOOL/$TESTFS1@snap $TESTPOOL/clone1 &
+	$ZFS clone $TESTPOOL/$TESTFS2@snap $TESTPOOL/clone2 &
+	$ZFS clone $TESTPOOL/$TESTFS3@snap $TESTPOOL/clone3 &
+
+	wait
+
+	$ZFS promote $TESTPOOL/clone1 &
+	$ZFS promote $TESTPOOL/clone2 &
+	$ZFS promote $TESTPOOL/clone3 &
+
+	wait
+
+	$ZFS destroy $TESTPOOL/$TESTFS1 &
+	$ZFS destroy $TESTPOOL/$TESTFS2 &
+	$ZFS destroy $TESTPOOL/$TESTFS3 &
+
+	wait
+
+	$ZFS destroy -Rf $TESTPOOL/clone1 &
+	$ZFS destroy -Rf $TESTPOOL/clone2 &
+	$ZFS destroy -Rf $TESTPOOL/clone3 &
+
+	wait
+	((i += 1))
+done
+
+typeset -i entry_count=$($ZPOOL history $spool | $WC -l | $AWK '{print $1}')
+
+if ((entry_count - orig_count != 200)); then
+	log_fail "The entries count error: entry_count=$entry_count " \
+		 "orig_count = $orig_count"
+fi
+
+log_pass "'zpool history' can cope with simultaneous commands."
--- /dev/null	Fri Nov 22 15:20:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_005_neg.ksh	Fri Nov 22 15:20:22 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify the following zpool subcommands are not logged.
+#		zpool get
+#		zpool history
+#		zpool list
+#		zpool status
+#		zpool iostat
+#
+# STRATEGY:
+#	1. Create a test pool.
+#	2. Separately invoke zpool list|status|iostat
+#	3. Verify they was not recored in pool history.
+#
+
+verify_runnable "global"
+
+log_assert "Verify 'zpool get|history|list|status|iostat' will not be logged."
+
+# Save initial TESTPOOL history
+log_must eval "$ZPOOL history $TESTPOOL >$OLD_HISTORY"
+
+log_must $ZPOOL get all $TESTPOOL >/dev/null
+log_must $ZPOOL list $TESTPOOL >/dev/null
+log_must $ZPOOL status $TESTPOOL >/dev/null
+log_must $ZPOOL iostat $TESTPOOL >/dev/null
+
+log_must eval "$ZPOOL history $TESTPOOL >$NEW_HISTORY"
+log_must $DIFF $OLD_HISTORY $NEW_HISTORY
+
+log_pass "Verify 'zpool get|history|list|status|iostat' will not be logged."
--- /dev/null	Fri Nov 22 15:20:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_006_neg.ksh	Fri Nov 22 15:20:23 2013
@@ -0,0 +1,84 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify the following zfs subcommands are not logged.
+#	list, get, holds, mount, unmount, share, unshare, send
+#
+# STRATEGY:
+#	1. Create a test pool.
+#	2. Separately invoke zfs list|get|holds|mount|unmount|share|unshare|send
+#	3. Verify they were not recored in pool history.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if datasetexists $fs ; then
+		log_must $ZFS destroy -rf $fs
+	fi
+	log_must $ZFS create $fs
+}
+
+log_assert "Verify 'zfs list|get|holds|mount|unmount|share|unshare|send' " \
+    "will not be logged."
+log_onexit cleanup
+
+# Create initial test environment
+fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2
+log_must $ZFS set sharenfs=on $fs
+log_must $ZFS snapshot $snap1
+log_must $ZFS hold tag $snap1
+log_must $ZFS snapshot $snap2
+
+# Save initial TESTPOOL history
+log_must eval "$ZPOOL history $TESTPOOL > $OLD_HISTORY"
+
+log_must $ZFS list $fs > /dev/null
+log_must $ZFS get mountpoint $fs > /dev/null
+log_must $ZFS unmount $fs
+log_must $ZFS mount $fs
+log_must $ZFS share $fs
+log_must $ZFS unshare $fs
+log_must $ZFS send -i $snap1 $snap2 > /dev/null
+log_must $ZFS holds $snap1
+
+log_must eval "$ZPOOL history $TESTPOOL > $NEW_HISTORY"
+log_must $DIFF $OLD_HISTORY $NEW_HISTORY
+
+log_must $ZFS release tag $snap1
+
+log_pass "Verify 'zfs list|get|mount|unmount|share|unshare|send' passed."
--- /dev/null	Fri Nov 22 15:20:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_007_pos.ksh	Fri Nov 22 15:20:23 2013
@@ -0,0 +1,112 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify command history moves with pool while pool being migrated
+#
+# STRATEGY:
+#	1. Import uniform platform and cross platform pools
+#	2. Contract the command history of the imported pool
+#	3. Compare imported history log with the previous log.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $migratedpoolname &&  \
+		log_must $ZPOOL destroy -f $migratedpoolname
+
+	[[ -d $import_dir ]] && $RM -rf $import_dir
+}
+
+log_assert "Verify command history moves with migrated pool."
+log_onexit cleanup
+
+tst_dir=$STF_SUITE/tests/functional/history
+import_dir=$TESTDIR/importdir.$$
+migrated_cmds_f=$import_dir/migrated_history.$$
+migratedpoolname=$MIGRATEDPOOLNAME
+typeset -i RET=1
+typeset -i linenum=0
+
+[[ ! -d $import_dir ]] && log_must $MKDIR $import_dir
+
+# We test the migrations on both uniform platform and cross platform
+for arch in "i386" "sparc"; do
+	log_must $CP $tst_dir/${arch}.orig_history.txt $import_dir
+	orig_cmds_f=$import_dir/${arch}.orig_history.txt
+	# remove blank line
+	orig_cmds_f1=$import_dir/${arch}.orig_history_1.txt
+	$CAT $orig_cmds_f | $GREP -v "^$" > $orig_cmds_f1
+
+	log_must $CP $tst_dir/${arch}.migratedpool.DAT.Z $import_dir
+	log_must $UNCOMPRESS $import_dir/${arch}.migratedpool.DAT.Z
+
+	# destroy the pool with same name, so that import operation succeeds.
+	poolexists $migratedpoolname && \
+	    log_must $ZPOOL destroy -f $migratedpoolname
+
+	log_must $ZPOOL import -d $import_dir $migratedpoolname
+	TZ=$TIMEZONE $ZPOOL history $migratedpoolname | $GREP -v "^$" \
+	    >$migrated_cmds_f
+	RET=$?
+	(( $RET != 0 )) && log_fail "$ZPOOL histroy $migratedpoolname fails."
+
+	# The migrated history file should differ with original history file on
+	# two commands -- 'export' and 'import', which are included in migrated
+	# history file but not in original history file. so, check the two
+	# commands firstly in migrated history file and then delete them, and
+	# then compare this filtered file with the original history file. They
+	# should be identical at this time.
+	for subcmd in "export" "import"; do
+		$GREP "$subcmd" $migrated_cmds_f >/dev/null 2>&1
+		RET=$?
+		(( $RET != 0 )) && log_fail "zpool $subcmd is not logged for" \
+		    "the imported pool $migratedpoolname."
+	done
+
+	tmpfile=$import_dir/cmds_tmp.$$
+	linenum=`$CAT $migrated_cmds_f | $WC -l`
+	(( linenum = linenum - 2 ))
+	$HEAD -n $linenum $migrated_cmds_f > $tmpfile
+	log_must $DIFF $tmpfile $orig_cmds_f1
+
+	# cleanup for next loop testing
+	log_must $ZPOOL destroy -f $migratedpoolname
+	log_must $RM -f `$LS $import_dir`
+done
+
+log_pass "Verify command history moves with migrated pool."
--- /dev/null	Fri Nov 22 15:20:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_008_pos.ksh	Fri Nov 22 15:20:23 2013
@@ -0,0 +1,74 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#	Pool history records all recursive operations.
+#
+# STRATEGY:
+#	1. Create a filesystem and several sub-filesystems in it.
+#	2. Make a recursive snapshot.
+#	3. Verify pool history records all the recursive operations.
+#	4. Do the same verification for hold, release, inherit, rollback and
+#	   destroy.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if datasetexists $root_testfs; then
+		log_must $ZFS destroy -rf $root_testfs
+	fi
+	log_must $ZFS create $root_testfs
+}
+
+log_assert "Pool history records all recursive operations."
+log_onexit cleanup
+
+root_testfs=$TESTPOOL/$TESTFS
+fs1=$root_testfs/fs1; fs2=$root_testfs/fs2; fs3=$root_testfs/fs3
+for fs in $fs1 $fs2 $fs3; do
+	log_must $ZFS create $fs
+done
+
+run_and_verify "$ZFS snapshot -r $root_testfs@snap" "-i"
+run_and_verify "$ZFS hold -r tag $root_testfs@snap" "-i"
+run_and_verify "$ZFS release -r tag $root_testfs@snap" "-i"
+log_must $ZFS snapshot $root_testfs@snap2
+log_must $ZFS snapshot $root_testfs@snap3
+run_and_verify "$ZFS rollback -r $root_testfs@snap" "-i"
+run_and_verify "$ZFS inherit -r mountpoint $root_testfs" "-i"
+run_and_verify "$ZFS destroy -r $root_testfs" "-i"
+
+log_pass "Pool history records all recursive operations."
--- /dev/null	Fri Nov 22 15:20:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_009_pos.ksh	Fri Nov 22 15:20:24 2013
@@ -0,0 +1,114 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify the delegation internal history are correctly.
+#
+# STRATEGY:
+#	1. Create test group and user.
+#	2. Define permission sets and verify the internal history correctly.
+#	3. Separately verify the internal history above is correct.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	del_user $HIST_USER
+	del_group $HIST_GROUP
+}
+
+log_assert "Verify delegated commands are logged in the pool history."
+log_onexit cleanup
+
+testfs=$TESTPOOL/$TESTFS
+# Create history test group and user and get user id and group id
+add_group $HIST_GROUP
+add_user $HIST_GROUP $HIST_USER
+
+#	subcmd		allow_options
+array=(	"allow"		"-s @basic snapshot"
+	"allow"		"-s @set @basic"
+	"allow"		"-c create"
+	"unallow"	"-c create"
+	"allow"		"-c @set"
+	"unallow"	"-c @set"
+	"allow"		"-l -u $HIST_USER snapshot"
+	"allow"		"-u $HIST_USER snapshot"
+	"unallow"	"-u $HIST_USER snapshot"
+	"allow"		"-l -u $HIST_USER @set"
+	"allow"		"-u $HIST_USER @set"
+	"unallow"	"-u $HIST_USER @set"
+	"allow"		"-d -u $HIST_USER snapshot"
+	"allow"		"-u $HIST_USER snapshot"
+	"unallow"	"-u $HIST_USER snapshot"
+	"allow"		"-d -u $HIST_USER @set"
+	"allow"		"-u $HIST_USER @set"
+	"unallow"	"-u $HIST_USER @set"
+	"allow"		"-l -g $HIST_GROUP snapshot"
+	"allow"		"-g $HIST_GROUP snapshot"
+	"unallow"	"-g $HIST_GROUP snapshot"
+	"allow"		"-l -g $HIST_GROUP @set"
+	"allow"		"-g $HIST_GROUP @set"
+	"unallow"	"-g $HIST_GROUP @set"
+	"allow"		"-d -g $HIST_GROUP snapshot"
+	"allow"		"-g $HIST_GROUP snapshot"
+	"unallow"	"-g $HIST_GROUP snapshot"
+	"allow"		"-d -g $HIST_GROUP @set"
+	"allow"		"-g $HIST_GROUP @set"
+	"unallow"	"-g $HIST_GROUP @set"
+	"allow"		"-l -e snapshot"
+	"allow"		"-e snapshot"
+	"unallow"	"-e snapshot"
+	"allow"		"-l -e @set"
+	"allow"		"-e @set"
+	"unallow"	"-e @set"
+	"allow"		"-d -e snapshot"
+	"allow"		"-e snapshot"
+	"unallow"	"-e snapshot"
+	"allow"		"-d -e @set"
+	"allow"		"-e @set"
+	"unallow"	"-e @set"
+)
+
+typeset -i i=0
+while ((i < ${#array[@]})); do
+	subcmd=${array[$i]}
+	options=${array[((i + 1))]}
+
+	run_and_verify "$ZFS $subcmd $options $testfs" "-i"
+	((i += 2))
+done
+
+log_pass "Verify delegated commands are logged in the pool history."
--- /dev/null	Fri Nov 22 15:20:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_010_pos.ksh	Fri Nov 22 15:20:24 2013
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/history/history_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify internal long history information are correct.
+#
+# STRATEGY:
+#	1. Create non-root test user and group.
+#	2. Do some zfs operations as a root and non-root user.
+#	3. Verify the long history information is correct.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	del_user $HIST_USER
+	del_group $HIST_GROUP
+	datasetexists $root_testfs && log_must $ZFS destroy -rf $root_testfs
+}
+
+log_assert "Verify internal long history information are correct."
+log_onexit cleanup
+
+root_testfs=$TESTPOOL/$TESTFS1
+
+# Create history test group and user and get user id and group id
+add_group $HIST_GROUP
+add_user $HIST_GROUP $HIST_USER
+
+run_and_verify "$ZFS create $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_GROUP snapshot,mount $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_USER destroy,mount $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_USER reservation $root_testfs" "-l"
+run_and_verify "$ZFS allow $HIST_USER allow $root_testfs" "-l"
+run_and_verify -u "$HIST_USER" "$ZFS snapshot $root_testfs@snap" "-l"
+run_and_verify -u "$HIST_USER" "$ZFS destroy $root_testfs@snap" "-l"
+run_and_verify -u "$HIST_USER" "$ZFS set reservation=64M $root_testfs" "-l"
+run_and_verify -u "$HIST_USER" \
+    "$ZFS allow $HIST_USER reservation $root_testfs" "-l"
+run_and_verify "$ZFS unallow $HIST_USER create $root_testfs" "-l"
+run_and_verify "$ZFS unallow $HIST_GROUP snapshot $root_testfs" "-l"
+run_and_verify "$ZFS destroy -r $root_testfs" "-l"
+
+log_pass "Verify internal long history information pass."
--- /dev/null	Fri Nov 22 15:20:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/history_common.kshlib	Fri Nov 22 15:20:24 2013
@@ -0,0 +1,410 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/history/history.cfg
+
+function run_and_verify
+{
+	typeset user pool
+	while getopts "p:u:" opt; do
+		case $opt in
+		p)
+			pool=$OPTARG
+			;;
+		u)
+			user=$OPTARG
+			;;
+		esac
+	done
+	shift $(($OPTIND - 1))
+
+	pool=${pool:-$TESTPOOL}
+	user=${user:-"root"}
+	fullcmd="$1"
+	flags="$2"
+
+	histcmd=$($ECHO $fullcmd | $SED 's/\/usr\/sbin\///g')
+	cmd=$($ECHO $histcmd | $AWK '{print $1}')
+	subcmd=$($ECHO $histcmd | $AWK '{print $2}')
+
+	# If we aren't running zpool or zfs, something is wrong
+	[[ $cmd == "zpool" || $cmd == "zfs" ]] || \
+	    log_fail "run_and_verify called with \"$cmd ($fullcmd)\""
+
+	# If this is a 'zfs receive' truncate the stdin redirect
+	[[ $subcmd == "receive" || $subcmd == "recv" ]] && \
+	    histcmd=${histcmd%% <*}
+
+	# Run the command as the specified user, and find the new history.
+	$ZPOOL history $flags $pool > $OLD_HISTORY 2>/dev/null
+	if [[ $user == "root" ]]; then
+		log_must eval "$fullcmd"
+	else
+		log_must $SU $user -c "eval $fullcmd"
+	fi
+	$ZPOOL history $flags $pool > $TMP_HISTORY 2>/dev/null
+	$DIFF $OLD_HISTORY $TMP_HISTORY | $GREP "^> " | $SED 's/^> //g' \
+	    > $NEW_HISTORY
+
+	# Verify what's common to every case, regardless of zpool history flags.
+	$GREP "$histcmd" $NEW_HISTORY >/dev/null 2>&1 || \
+	    log_fail "Didn't find \"$histcmd\" in pool history"
+
+	# If 'zpool history' was called without any flags, then we're done.
+	[[ -z $flags ]] && return
+
+	# Verify the new history in cases that are more interesting because
+	# additional information is logged with -i or -l.
+
+	[[ $flags =~ "i" ]] && log_must verify_$subcmd "$histcmd" "$subcmd" \
+	    "$flags"
+	[[ $flags =~ "l" ]] && log_must verify_long "$histcmd" "$user" "$flags"
+}
+
+function verify_long
+{
+	typeset cmd=$1
+	typeset user=$2
+	typeset flags=$3
+
+	[[ $flags =~ "l" ]] || return 1
+
+	typeset uid=$($ID -u $user)
+	typeset hname=$($HOSTNAME)
+	if ! is_global_zone; then
+		hname=$hname:$($ZONENAME)
+	fi
+
+	$GREP "$cmd \[user $uid ($user) on $hname\]" $NEW_HISTORY >/dev/null \
+	    2>&1
+	if [[ $? != 0 ]]; then
+		log_note "Couldn't find long information for \"$cmd\""
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_hold
+{
+	typeset cmd=$1
+	typeset subcmd=$2
+	typeset flags=$3
+
+	[[ $flags =~ "i" ]] || return 1
+
+	typeset tag=$($ECHO $cmd | $AWK '{print $4}')
+	typeset fullname=${cmd##* }
+	typeset dsname=${fullname%%@*}
+	typeset snapname=${fullname##*@}
+
+	# This works whether or not the hold was recursive
+	for ds in $($ZFS list -r -Ho name -t snapshot $dsname | \
+	    $GREP "@$snapname"); do
+		$GREP "$subcmd $ds ([0-9]*) tag=$tag" $NEW_HISTORY \
+		    >/dev/null 2>&1
+		if [[ $? != 0 ]]; then
+			log_note "Didn't find hold on $ds with $tag"
+			return 1
+		fi
+	done
+
+	return 0
+}
+
+function verify_release
+{
+	# hold and release formats only differ by the subcommand name, so
+	# simply reuse the hold function.
+	verify_hold "$1" "release" "$3"
+}
+
+function verify_rollback
+{
+	typeset cmd=$1
+	typeset flags=$3
+
+	[[ $flags =~ "i" ]] || return 1
+
+	typeset fullname=${cmd##* }
+	typeset dsname=${fullname%%@*}
+	typeset parent_fs=${dsname##*/}
+	typeset rb_fs=${dsname}/%rollback
+	typeset snapname=${fullname##*@}
+
+	$GREP "clone swap $rb_fs ([0-9]*) parent=$parent_fs" $NEW_HISTORY \
+	    >/dev/null 2>&1
+	if [[ $? != 0 ]]; then
+		log_note "Didn't find rollback clone swap in pool history"
+		return 1
+	fi
+
+	$GREP "destroy $rb_fs" $NEW_HISTORY >/dev/null 2>&1
+	if [[ $? != 0 ]]; then
+		log_note "Didn't find rollback destroy in pool history"
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_inherit
+{
+	typeset cmd=$1
+	typeset flags=$3
+
+	[[ $flags =~ "i" ]] || return 1
+
+	typeset dsname=${cmd##* }
+	typeset prop=${cmd% *}
+	prop=${prop##* }
+
+	# This works whether or not the inherit was recursive
+	for ds in $($ZFS list -r -Ho name -t filesystem $dsname); do
+		$GREP "$subcmd $ds ([0-9]*) ${prop}=" $NEW_HISTORY >/dev/null \
+		    2>&1
+		if [[ $? != 0 ]]; then
+			log_note "Didn't find inherit history for $ds"
+			return 1
+		fi
+	done
+
+	return 0
+}
+
+function verify_allow
+{
+	typeset cmd=$1
+	typeset subcmd=$2
+	typeset flags=$3
+
+	[[ $flags =~ "i" ]] || return 1
+	[[ $subcmd == "allow" ]] && subcmd="update"
+	[[ $subcmd == "unallow" ]] && subcmd="remove"
+	typeset is_set lflag dflag dsname gname gid uname uid opt str code tmp
+
+	#
+	# Here, we determine three things:
+	# - Whether we're operating on a set or an indivdual permission (which
+	#   dictates the case of the first character in the code)
+	# - The name of the dataset we're operating on.
+	# - Whether the operation applies locally or to descendent datasets (or
+	#   both)
+	#
+	$ECHO $cmd  | $AWK '{i = NF - 1; print $i}' | $GREP '@' >/dev/null \
+	    2>&1 && is_set=1
+	dsname=${cmd##* }
+	[[ $cmd =~ "-l " ]] && lflag=1
+	[[ $cmd =~ "-d " ]] && dflag=1
+	if [[ -z $lflag && -z $dflag ]]; then
+		lflag=1
+		dflag=1
+	fi
+
+	#
+	# For each of the five cases below, the operation is essentially the
+	# same. First, use the command passed in to determine what the code at
+	# the end of the pool history will be. The specifics of the code are
+	# described in a block comment at the top of dsl_deleg.c. Once that's
+	# been assembled, check for its presence in the history, and return
+	# success or failure accordingly.
+	#
+	if [[ $cmd =~ "-s " ]]; then
+		str="s-\$@"
+		[[ -n $is_set ]] && str="S-\$@"
+		tmp=${cmd#*@}
+		code="$str${tmp% *}"
+		$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+		    $NEW_HISTORY >/dev/null 2>&1
+		if [[ $? != 0 ]]; then
+			 log_note "Couldn't find $code in $NEW_HISTORY"
+			 return 1
+		 fi
+	elif [[ $cmd =~ "-c " ]]; then
+		str="c-\$"
+		[[ -n $is_set ]] && str="C-\$"
+		tmp=${cmd#*-c}
+		code="$str${tmp% *}"
+		$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+		    $NEW_HISTORY >/dev/null 2>&1
+		if [ $? != 0 ]]; then
+			 log_note "Couldn't find $code in $NEW_HISTORY"
+			 return 1
+		fi
+	elif [[ $cmd =~ "-u " ]]; then
+		str="u"
+		[[ -n $is_set ]] && str="U"
+		tmp=${cmd##*-u }
+		opt=$($ECHO $tmp | $AWK '{print $2}')
+		uid=$($ID -u ${tmp%% *})
+		if [[ -n $lflag ]]; then
+			code="${str}l\$$uid $opt"
+			$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+			    $NEW_HISTORY >/dev/null 2>&1
+			if [ $? != 0 ]]; then
+				 log_note "Couldn't find $code in $NEW_HISTORY"
+				 return 1
+			fi
+		fi
+		if [[ -n $dflag ]]; then
+			code="${str}d\$$uid $opt"
+			$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+			    $NEW_HISTORY >/dev/null 2>&1
+			if [ $? != 0 ]]; then
+				 log_note "Couldn't find $code in $NEW_HISTORY"
+				 return 1
+			fi
+		fi
+	elif [[ $cmd =~ "-g " ]]; then
+		str="g"
+		[[ -n $is_set ]] && str="G"
+		tmp=${cmd##*-g }
+		opt=$($ECHO $tmp | $AWK '{print $2}')
+		gid=$($AWK -F: "/^${tmp%% *}:/ {print \$3}" /etc/group)
+		if [[ -n $lflag ]]; then
+			code="${str}l\$$gid $opt"
+			$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+			    $NEW_HISTORY >/dev/null 2>&1
+			if [ $? != 0 ]]; then
+				 log_note "Couldn't find $code in $NEW_HISTORY"
+				 return 1
+			fi
+		fi
+		if [[ -n $dflag ]]; then
+			code="${str}d\$$gid $opt"
+			$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+			    $NEW_HISTORY >/dev/null 2>&1
+			if [ $? != 0 ]]; then
+				 log_note "Couldn't find $code in $NEW_HISTORY"
+				 return 1
+			fi
+		fi
+	elif [[ $cmd =~ "-e " ]]; then
+		str="e"
+		[[ -n $is_set ]] && str="E"
+		opt=${cmd##*-e }
+		opt=${opt%% *}
+		if [[ -n $lflag ]]; then
+			code="${str}l\$ $opt"
+			$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+			    $NEW_HISTORY >/dev/null 2>&1
+			if [ $? != 0 ]]; then
+				 log_note "Couldn't find $code in $NEW_HISTORY"
+				 return 1
+			fi
+		fi
+		if [[ -n $dflag ]]; then
+			code="${str}d\$ $opt"
+			$GREP "permission $subcmd $dsname ([0-9]*) $code" \
+			    $NEW_HISTORY >/dev/null 2>&1
+			if [ $? != 0 ]]; then
+				 log_note "Couldn't find $code in $NEW_HISTORY"
+				 return 1
+			fi
+		fi
+	else
+		log_note "Can't parse command \"$cmd\""
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_unallow
+{
+	#
+	# The unallow and allow history have the same format, except the former
+	# logs "permission removed" and the latter "permission updated" so
+	# simply reuse the allow function.
+	#
+	verify_allow "$1" "unallow" "$3"
+}
+
+function verify_destroy
+{
+	typeset cmd=$1
+	typeset flags=$3
+
+	# This function doesn't currently verifiy the zpool command.
+	[[ ${cmd%% *} == "zfs" ]] || return 1
+	[[ $flags =~ "i" ]] || return 1
+
+	typeset dsname=${cmd##* }
+	[[ $dsname =~ "@" ]] && typeset is_snap=1
+
+	if [[ -n $is_snap ]]; then
+		$GREP "ioctl destroy_snaps" $NEW_HISTORY >/dev/null 2>&1
+		if [[ $? != 0 ]]; then
+			log_note "Didn't find ioctl while destroying $dsname"
+			return 1
+		fi
+	fi
+
+	# This should be present for datasets and snapshots alike
+	$GREP "destroy $dsname" $NEW_HISTORY >/dev/null 2>&1
+	if [[ $? != 0 ]]; then
+		log_note "Didn't find \"destroy\" for $dsname"
+		return 1
+	fi
+
+	return 0
+}
+
+function verify_snapshot
+{
+	typeset cmd=$1
+	typeset flags=$3
+
+	[[ $flags =~ "i" ]] || return 1
+
+	typeset fullname=${cmd##* }
+	typeset dsname=${fullname%%@*}
+	typeset snapname=${fullname##*@}
+
+	$GREP "\[txg:[0-9]*\] $subcmd $fullname ([0-9]*)" $NEW_HISTORY \
+	    >/dev/null 2>&1
+	if [[ $? != 0 ]]; then
+		log_note "Didn't find snapshot command for $fullname"
+		return 1
+	fi
+
+	# This works whether or not the snapshot was recursive
+	for ds in $($ZFS list -r -Ho name -t snapshot $dsname | \
+	    $GREP "@$snapname"); do
+		$GREP "^[ ]* $ds$" $NEW_HISTORY >/dev/null 2>&1
+		if [[ $? != 0 ]]; then
+			log_note "Didn't find \"ioctl snapshot\" for $ds"
+			return 1
+		fi
+	done
+
+	return 0
+}
Binary files /tmp/dsraq3m and new/usr/src/test/zfs-tests/tests/functional/history/i386.migratedpool.DAT.Z differ
--- /dev/null	Fri Nov 22 15:20:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/i386.orig_history.txt	Fri Nov 22 15:20:25 2013
@@ -0,0 +1,12 @@
+History for 'history_pool':
+2006-10-20.13:18:37 zpool create history_pool /var/tmp/i386.migratedpool.DAT
+2006-10-20.13:18:37 zfs create history_pool/fs
+2006-10-20.13:18:37 zfs set compression=on history_pool/fs
+2006-10-20.13:18:37 zfs set checksum=on history_pool
+2006-10-20.13:18:37 zfs snapshot history_pool/fs@snap
+2006-10-20.13:18:37 zfs clone history_pool/fs@snap history_pool/clone
+2006-10-20.13:18:37 zfs promote history_pool/clone
+2006-10-20.13:18:37 zfs promote history_pool/fs
+2006-10-20.13:18:37 zfs destroy -r -R history_pool/fs
+2006-10-20.13:18:37 zpool export history_pool
+2007-04-05.00:05:38 zpool upgrade history_pool
--- /dev/null	Fri Nov 22 15:20:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/setup.ksh	Fri Nov 22 15:20:26 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
Binary files /tmp/dqHaWbn and new/usr/src/test/zfs-tests/tests/functional/history/sparc.migratedpool.DAT.Z differ
--- /dev/null	Fri Nov 22 15:20:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/history/sparc.orig_history.txt	Fri Nov 22 15:20:26 2013
@@ -0,0 +1,12 @@
+History for 'history_pool':
+2006-10-27.03:13:47 zpool create history_pool /var/tmp/sparc.migratedpool.DAT
+2006-10-27.03:13:48 zfs create history_pool/fs
+2006-10-27.03:13:48 zfs set compression=on history_pool/fs
+2006-10-27.03:13:48 zfs set checksum=on history_pool
+2006-10-27.03:13:48 zfs snapshot history_pool/fs@snap
+2006-10-27.03:13:48 zfs clone history_pool/fs@snap history_pool/clone
+2006-10-27.03:13:49 zfs promote history_pool/clone
+2006-10-27.03:13:49 zfs promote history_pool/fs
+2006-10-27.03:13:49 zfs destroy -r -R history_pool/fs
+2006-10-27.03:13:49 zpool export history_pool
+2007-04-05.00:41:55 zpool upgrade history_pool
Binary files /tmp/dVSaWin and new/usr/src/test/zfs-tests/tests/functional/history/zfs-pool-v4.dat.Z differ
--- /dev/null	Fri Nov 22 15:20:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/Makefile	Fri Nov 22 15:20:27 2013
@@ -0,0 +1,90 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/inheritance
+
+PROGS = cleanup \
+	inherit_001_pos
+
+FILES = config001.cfg \
+	config002.cfg \
+	config003.cfg \
+	config004.cfg \
+	config005.cfg \
+	config006.cfg \
+	config007.cfg \
+	config008.cfg \
+	config009.cfg \
+	config010.cfg \
+	config011.cfg \
+	config012.cfg \
+	config013.cfg \
+	config014.cfg \
+	config015.cfg \
+	config016.cfg \
+	config017.cfg \
+	config018.cfg \
+	config019.cfg \
+	config020.cfg \
+	config021.cfg \
+	config022.cfg \
+	config023.cfg \
+	config024.cfg \
+	inherit.kshlib \
+	state001.cfg \
+	state002.cfg \
+	state003.cfg \
+	state004.cfg \
+	state005.cfg \
+	state006.cfg \
+	state007.cfg \
+	state008.cfg \
+	state009.cfg \
+	state010.cfg \
+	state011.cfg \
+	state012.cfg \
+	state013.cfg \
+	state014.cfg \
+	state015.cfg \
+	state016.cfg \
+	state017.cfg \
+	state018.cfg \
+	state019.cfg \
+	state020.cfg \
+	state021.cfg \
+	state022.cfg \
+	state023.cfg \
+	state024.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:20:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/README.config	Fri Nov 22 15:20:27 2013
@@ -0,0 +1,67 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# The configX.cfg files describe both the dataset hierarchy to
+# be created but also the initial source values for the datasets
+# properties, i.e. whether they should be left with their default values
+# or set locally.
+#
+# Format for this file is as follows:
+#	<dataset name>	<dataset type> 	<inital property setting>
+#
+# <dataset name> - must be the full dataset name
+#
+# <dataset type> - recognised types are POOL, CTR and FS
+#
+#
+# <initial property setting> - can have one of the following
+# values:
+#
+#	default		property values are left unchanged
+#
+#	local		property values are set locally
+#
+#	  -		property values are left unchanged (has the
+#			same effect as 'default' but is used to indicate
+#			that the property 'source' field may be 'inherited
+#			from..' depending on the actions further up the
+#			dataset hierarchy.
+#
+#
+# The configuration below creates a three tier dataset layout, consisting
+# of a pool, container and filesystem.
+#
+# The top tier pool's properties being set locally, and the two
+# lower tier properties each inheriting their values from the next tier
+# up.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/README.state	Fri Nov 22 15:20:28 2013
@@ -0,0 +1,109 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+# For every configX.cfg file there must be a corresponding stateX.cfg
+# file. The state file both drives the operations to be performed on the
+# dataset hierarchy which has been specified by the corresponding
+# configX.cfg file, and also specifies the expected state of the
+# properties after the operation has been completed.
+#
+# The format of the file is:
+#       <target dataset>:<command>
+#       <property source before command>        <property src after command>
+#       <property source before command>        <property src after command>
+#       ....                                    ....
+#       ....                                    ....
+#
+# <target dataset> - dataset upon which the <command> is to be executed. Can
+#                    be any of the datasets specified in the corresponding
+#                    configX.cfg file. If no command is to be executed
+#                    then must be set to '-'
+#
+#
+# <command>        - command to be executed upon the specified dataset.
+#                    Currently the only supported commands are 'inherit'
+#                    or 'inherit -r'. If no command is to be executed,
+#                    then must be set to '-'.
+#
+# <property src before command>
+#                  - the 'source' (as reported in 'zfs get') for the
+#                    the properties before <command> is executed. This
+#                    can be 'default', 'local' or the name of a dataset
+#                    from which the property is inherited. (The code
+#                    automatically adds in the 'inherited from..' part
+#                    of the string when doing the check.
+#
+#                    This field is for informational purposes only, to
+#                    aid the user in seeing how the changes trickle down
+#                    the data hierarchy.
+#
+# <property src after command>
+#                  - the expected value of the 'source' field after the
+#                    <command> has been executed on the <target dataset>.
+#                    As above can be 'default', 'local', or the dataset
+#                    from which the property is inherited.
+#
+# Two important things to note:
+# 1) there must be a <property src..> line corresponding to each dataset
+#    line specified in the configX.cfg file.
+#
+#
+# 2) There can be as many <command>/<property src> blocks as desired, but
+#    there must be at least one, and the effect of each block is cumulative
+#    (i.e. the properties are not reset back to their default values between
+#    each block. If that is desired then each block must be placed in its
+#    own state file with its own corresponding configX.cfg file).
+#
+#
+# Below are two sample <command>/<property src> blocks.
+#
+# The first simply verifies that the properties on the top level dataset
+# were set locally, and that the middle and bottom datasets properties
+# were inherited from the top level pool (called TESTPOOL). Note the '-:-'
+# which means that no command is to be executed, but simply that the
+# properties settings are to be verified.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+-:-
+#
+local                           local
+TESTPOOL                        TESTPOOL
+TESTPOOL                        TESTPOOL
+#
+#
+# The block below describes the expected state of the properties after
+# an 'inherit -r' command has been run on the top level pool (called
+# TESTPOOL).
+#
+TESTPOOL:inherit -r
+#
+local				default
+TESTPOOL			default
+TESTPOOL			default
--- /dev/null	Fri Nov 22 15:20:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/cleanup.ksh	Fri Nov 22 15:20:28 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. ${STF_SUITE}/include/libtest.shlib
+
+$RM -rf $TESTDIR.*
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config001.cfg	Fri Nov 22 15:20:29 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config002.cfg	Fri Nov 22 15:20:29 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config003.cfg	Fri Nov 22 15:20:29 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config004.cfg	Fri Nov 22 15:20:30 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config005.cfg	Fri Nov 22 15:20:30 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config006.cfg	Fri Nov 22 15:20:30 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config007.cfg	Fri Nov 22 15:20:31 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config008.cfg	Fri Nov 22 15:20:31 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      default
--- /dev/null	Fri Nov 22 15:20:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config009.cfg	Fri Nov 22 15:20:31 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      default
--- /dev/null	Fri Nov 22 15:20:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config010.cfg	Fri Nov 22 15:20:32 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      default
--- /dev/null	Fri Nov 22 15:20:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config011.cfg	Fri Nov 22 15:20:32 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config012.cfg	Fri Nov 22 15:20:32 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     default
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config013.cfg	Fri Nov 22 15:20:33 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config014.cfg	Fri Nov 22 15:20:33 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config015.cfg	Fri Nov 22 15:20:34 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config016.cfg	Fri Nov 22 15:20:34 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    default
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config017.cfg	Fri Nov 22 15:20:34 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config018.cfg	Fri Nov 22 15:20:35 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config019.cfg	Fri Nov 22 15:20:35 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config020.cfg	Fri Nov 22 15:20:35 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      -
--- /dev/null	Fri Nov 22 15:20:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config021.cfg	Fri Nov 22 15:20:36 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config022.cfg	Fri Nov 22 15:20:36 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     -
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config023.cfg	Fri Nov 22 15:20:36 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/config024.cfg	Fri Nov 22 15:20:37 2013
@@ -0,0 +1,33 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+TESTPOOL                        POOL    local
+TESTPOOL/TESTCTR                CTR     local
+TESTPOOL/TESTCTR/TESTFS1        FS      local
--- /dev/null	Fri Nov 22 15:20:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/inherit.kshlib	Fri Nov 22 15:20:37 2013
@@ -0,0 +1,114 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+#
+# Simple function to get the source of the specified property.
+# If unable to get the property then exits.
+#
+function get_prop_src # property dataset
+{
+        typeset prop_val
+        typeset prop=$1
+        typeset dataset=$2
+
+	prop_val=`$ZFS get -H -o source $prop $dataset`
+
+        if [[ $? -ne 0 ]]; then
+                log_fail "Unable to determine the source of $prop " \
+                        "property for dataset $dataset"
+        else
+                echo $prop_val
+        fi
+}
+
+#
+# Function to check the 'source' of a property. The source can
+# either be "default", "local", or "inherited from <parent dataset>".
+#
+# The 'expected src' argument must be either "default", "local", or
+# a dataset name.
+#
+# Returns 0 on success, 1 on failure.
+#
+function verify_prop_src # child_dataset property expected_src
+{
+        typeset target=$1
+        typeset prop=$2
+        typeset expected=$3
+
+        prop_src=`get_prop_src $prop $target`
+
+	#
+	# Rather than just checking if $prop_src == $expected
+	# we first determine what value $expected should have.
+	# This allows us to catch the case where a property
+	# has a source of "local" but we expected it to be
+	# "default"
+	#
+	if [[ $expected == "default" ]]; then
+		if [[ $prop_src != $expected ]]; then
+			log_note "Property $prop of $target has source"\
+				" $prop_src rather than $expected"
+			return 1
+		fi
+	elif [[ $expected == "local" ]]; then
+		if [[ $prop_src != $expected ]]; then
+			log_note "Property $prop of $target has source"\
+				" $prop_src rather than $expected"
+			return 1
+		fi
+	elif [[ $prop_src != "inherited from $expected" ]]; then
+		log_note "Property $prop of $expected has source $prop_src"\
+			" rather than 'inherited from $expected'"
+                return 1
+	fi
+
+	return 0
+}
+
+#
+# Simple function to set a property to a
+# specified value and verify it has changed
+# correctly.
+#
+function set_n_verify_prop #property value dataset
+{
+	typeset prop=$1
+	typeset prop_val=$2
+	typeset dataset=$3
+
+	$ZFS set $prop=$prop_val $dataset
+	check_val=`get_prop $prop $dataset`
+
+	if [[ $check_val != $prop_val ]]; then
+		log_fail "Property $prop of $dataset has value $check_val"\
+			" rather than $prop_val"
+	fi
+}
--- /dev/null	Fri Nov 22 15:20:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/inherit_001_pos.ksh	Fri Nov 22 15:20:38 2013
@@ -0,0 +1,437 @@
+#! /bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inheritance/inherit.kshlib
+
+#
+# DESCRIPTION:
+# Test that properties are correctly inherited using 'zfs set',
+# 'zfs inherit' and 'zfs inherit -r'.
+#
+# STRATEGY:
+# 1) Read a configX.cfg file and create the specified datasets
+# 2) Read a stateX.cfg file and execute the commands within it
+# and verify that the properties have the correct values
+# 3) Repeat steps 1-2 for each configX and stateX files found.
+#
+
+verify_runnable "global"
+
+log_assert "Test properties are inherited correctly"
+
+#
+# Simple function to create specified datasets.
+#
+function create_dataset { #name type disks
+	typeset dataset=$1
+	typeset type=$2
+	typeset disks=$3
+
+	if [[ $type == "POOL" ]]; then
+		create_pool "$dataset" "$disks"
+	elif [[ $type == "CTR" ]]; then
+		log_must $ZFS create $dataset
+		log_must $ZFS set canmount=off $dataset
+	elif [[ $type == "FS" ]]; then
+		log_must $ZFS create $dataset
+	else
+		log_fail "Unrecognised type $type"
+	fi
+
+	list="$list $dataset"
+}
+
+#
+# Function to walk through all the properties in a
+# dataset, setting them to a 'local' value if required.
+#
+function init_props { #dataset init_code
+	typeset dataset=$1
+	typeset init_code=$2
+	typeset dir=$3
+
+	typeset -i i=0
+
+	#
+	# Though the effect of '-' and 'default' is the same we
+	# call them out via a log_note to aid in debugging the
+	# config files
+	#
+	if [[ $init_code == "-" ]]; then
+		log_note "Leaving properties for $dataset unchanged."
+		[[ $def_recordsize == 0 ]] && \
+		    update_recordsize $dataset $init_code
+		return;
+	elif [[ $init_code == "default" ]]; then
+		log_note "Leaving properties for $dataset at default values."
+		[[ $def_recordsize == 0 ]] && \
+		    update_recordsize $dataset $init_code
+		return;
+	elif [[ $init_code == "local" ]]; then
+		log_note "Setting properties for $dataset to local values."
+		while (( i <  ${#prop[*]} )); do
+			if [[ ${prop[i]} == "recordsize" ]]; then
+				update_recordsize $dataset $init_code
+			else
+				if [[ ${prop[i]} == "mountpoint" ]]; then
+					set_n_verify_prop ${prop[i]} \
+					    ${local_val[((i/2))]}.$dir $dataset
+				else
+					set_n_verify_prop ${prop[i]} \
+					    ${local_val[((i/2))]} $dataset
+				fi
+			fi
+
+			((i = i + 2))
+		done
+	else
+		log_fail "Unrecognised init code $init_code"
+	fi
+}
+
+#
+# We enter this function either to update the recordsize value
+# in the default array, or to update the local value array.
+#
+function update_recordsize { #dataset init_code
+	typeset dataset=$1
+	typeset init_code=$2
+	typeset idx=0
+	typeset record_val
+
+	#
+	# First need to find where the recordsize property is
+	# located in the arrays
+	#
+	while (( idx <  ${#prop[*]} )); do
+		[[ ${prop[idx]} == "recordsize" ]] && break
+
+		((idx = idx + 2))
+	done
+
+	((idx = idx / 2))
+	record_val=`get_prop recordsize $dataset`
+	if [[ $init_code == "-" || $init_code == "default" ]]; then
+		def_val[idx]=$record_val
+		def_recordsize=1
+	elif [[ $init_code == "local" ]]; then
+		log_must $ZFS set recordsize=$record_val $dataset
+		local_val[idx]=$record_val
+	fi
+}
+
+#
+# The mountpoint property is slightly different from other properties and
+# so is handled here. For all other properties if they are set to a specific
+# value at a higher level in the data hierarchy (i.e. checksum=on) then that
+# value propogates down the hierarchy unchanged, with the source field being
+# set to 'inherited from <higher dataset>'.
+#
+# The mountpoint property is different in that while the value propogates
+# down the hierarchy, the value at each level is determined by a combination
+# of the top-level value and the current level in the hierarchy.
+#
+# For example consider the case where we have a pool (called pool1), containing
+# a dataset (ctr) which in turn contains a filesystem (fs). If we set the
+# mountpoint of the pool to '/mnt2' then the mountpoints for the dataset and
+# filesystem are '/mnt2/ctr' and /mnt2/ctr/fs' respectively, with the 'source'
+# field being set to 'inherited from pool1'.
+#
+# So at the filesystem level to calculate what our mountpoint property should
+# be set to we walk back up the hierarchy sampling the mountpoint property at
+# each level and forming up the expected mountpoint value piece by piece until
+# we reach the level specified in the 'source' field, which in this example is
+# the top-level pool.
+#
+function get_mntpt_val #dataset src index
+{
+	typeset dataset=$1
+	typeset src=$2
+	typeset idx=$3
+	typeset new_path=""
+	typeset dset
+	typeset mntpt=""
+
+	if [[ $src == "local" ]]; then
+		# Extract mount points specific to datasets
+		if [[ $dataset == "TESTPOOL" ]]; then
+			mntpt=${local_val[idx]}.1
+		elif [[ $dataset == "TESTPOOL/TESTCTR" ]]; then
+			mntpt=${local_val[idx]}.2
+		else
+			mntpt=${local_val[idx]}.3
+		fi
+	elif [[ $src == "default" ]]; then
+		mntpt="/$dataset"
+	else
+		# Walk back up the hierarchy building up the
+		# expected mountpoint property value.
+		obj_name=${dataset##*/}
+
+		while [[ $src != $dataset ]]; do
+			dset=${dataset%/*}
+
+			mnt_val=`get_prop mountpoint $dset`
+
+			mod_prop_val=${mnt_val##*/}
+			new_path="/"$mod_prop_val$new_path
+			dataset=$dset
+		done
+
+		mntpt=$new_path"/"$obj_name
+	fi
+	echo $mntpt
+}
+
+#
+# Simple function to verify that a property has the
+# expected value.
+#
+function verify_prop_val #property dataset src index
+{
+	typeset prop=$1
+	typeset dataset=$2
+	typeset src=$3
+	typeset idx=$4
+	typeset new_path=""
+	typeset dset
+	typeset exp_val
+	typeset prop_val
+
+	prop_val=`get_prop $prop $dataset`
+
+	# mountpoint property is handled as a special case
+	if [[ $prop == "mountpoint" ]]; then
+		exp_val=`get_mntpt_val $dataset $src $idx`
+	else
+		if [[ $src == "local" ]]; then
+			exp_val=${local_val[idx]}
+		elif [[ $src == "default" ]]; then
+			exp_val=${def_val[idx]}
+		else
+			#
+			# We are inheriting the value from somewhere
+			# up the hierarchy.
+			#
+			exp_val=`get_prop $prop $src`
+		fi
+	fi
+
+	if [[ $prop_val != $exp_val ]]; then
+		# After putback PSARC/2008/231 Apr,09,2008,
+		# the default value of aclinherit has changed to be
+		# 'restricted' instead of 'secure',
+		# but the old interface of 'secure' still exist
+
+		if [[ $prop != "aclinherit" || \
+		    $exp_val != "secure" || \
+		    $prop_val != "restricted" ]]; then
+
+			log_fail "$prop of $dataset is [$prop_val] rather "\
+			    "than [$exp_val]"
+		fi
+	fi
+}
+
+#
+# Function to read the configX.cfg files and create the specified
+# dataset hierarchy
+#
+function scan_config { #config-file
+	typeset config_file=$1
+
+	DISK=${DISKS%% *}
+
+	list=""
+	typeset -i mount_dir=1
+
+	grep "^[^#]" $config_file | {
+		while read name type init ; do
+			create_dataset $name $type $DISK
+			init_props $name $init $mount_dir
+			((mount_dir = mount_dir + 1))
+		done
+	}
+}
+
+#
+# Function to check an exit flag, calling log_fail if that exit flag
+# is non-zero. Can be used from code that runs in a tight loop, which
+# would otherwise result in a lot of journal output.
+#
+function check_failure { # int status, error message to use
+
+	typeset -i exit_flag=$1
+	error_message=$2
+
+	if [[ $exit_flag -ne 0 ]]; then
+		log_fail "$error_message"
+	fi
+}
+
+
+#
+# Main function. Executes the commands specified in the stateX.cfg
+# files and then verifies that all the properties have the correct
+# values and 'source' fields.
+#
+function scan_state { #state-file
+	typeset state_file=$1
+	typeset -i i=0
+	typeset -i j=0
+
+	log_note "Reading state from $state_file"
+
+	while ((i <  ${#prop[*]})); do
+		grep "^[^#]" $state_file | {
+			while IFS=: read target op; do
+				#
+				# The user can if they wish specify that no
+				# operation be performed (by specifying '-'
+				# rather than a command). This is not as
+				# useless as it sounds as it allows us to
+				# verify that the dataset hierarchy has been
+				# set up correctly as specified in the
+				# configX.cfg file (which includes 'set'ting
+				# properties at a higher level and checking
+				# that they propogate down to the lower levels.
+				#
+				# Note in a few places here, we use
+				# check_failure, rather than log_must - this
+				# substantially reduces journal output.
+				#
+				if [[ $op == "-" ]]; then
+					log_note "No operation specified"
+				else
+					export __ZFS_POOL_RESTRICT="$TESTPOOL"
+					log_must $ZFS unmount -a
+					unset __ZFS_POOL_RESTRICT
+
+					for p in ${prop[i]} ${prop[((i+1))]}; do
+						$ZFS $op $p $target
+						ret=$?
+						check_failure $ret "$ZFS $op $p \
+						    $target"
+					done
+				fi
+				for check_obj in $list; do
+					read init_src final_src
+
+					for p in ${prop[i]} ${prop[((i+1))]}; do
+					# check_failure to keep journal small
+						verify_prop_src $check_obj $p \
+						    $final_src
+						ret=$?
+						check_failure $ret "verify" \
+						    "_prop_src $check_obj $p" \
+						    "$final_src"
+
+					# Again, to keep journal size down.
+						verify_prop_val $p $check_obj \
+						    $final_src $j
+						ret=$?
+						check_failure $ret "verify" \
+						    "_prop_val $check_obj $p" \
+						    "$final_src"
+					done
+				done
+			done
+		}
+		((i = i + 2))
+		((j = j + 1))
+	done
+}
+
+
+set -A prop "checksum" "" \
+	"compression" "compress" \
+	"atime" "" \
+	"devices" "" \
+	"exec" "" \
+	"setuid" "" \
+	"sharenfs" "" \
+	"recordsize" "recsize" \
+	"mountpoint" "" \
+	"snapdir" "" \
+	"aclmode" "" \
+	"aclinherit" "" \
+	"readonly" "rdonly"
+
+#
+# Note except for the mountpoint default value (which is handled in
+# the routine itself), each property specified in the 'prop' array
+# above must have a corresponding entry in the two arrays below.
+#
+
+set -A def_val "on" "off" "on" "on" "on" \
+	"on" "off" "" \
+	"" "hidden" "discard" "secure" \
+	"off"
+
+set -A local_val "off" "on" "off" "off" "off" \
+	"off" "on" "" \
+	"$TESTDIR" "visible" "groupmask" "discard" \
+	"off"
+
+#
+# Global flag indicating whether the default record size had been
+# read.
+#
+typeset def_recordsize=0
+
+set -A config_files $(ls $STF_SUITE/tests/functional/inheritance/config*[1-9]*.cfg)
+set -A state_files $(ls $STF_SUITE/tests/functional/inheritance/state*.cfg)
+
+#
+# Global list of datasets created.
+#
+list=""
+
+typeset -i k=0
+
+if [[ ${#config_files[*]} != ${#state_files[*]} ]]; then
+	log_fail "Must have the same number of config files " \
+	    " (${#config_files[*]}) and state files ${#state_files[*]}"
+fi
+
+while ((k < ${#config_files[*]})); do
+	default_cleanup_noexit
+	def_recordsize=0
+
+	log_note "Testing configuration ${config_files[k]}"
+
+	scan_config ${config_files[k]}
+	scan_state ${state_files[k]}
+
+	((k = k + 1))
+done
+
+log_pass "Properties correctly inherited as expected"
--- /dev/null	Fri Nov 22 15:20:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state001.cfg	Fri Nov 22 15:20:38 2013
@@ -0,0 +1,44 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that the property that was set on the top level pool
+# via the 'local' keyword (in the config1.cfg file) has correctly
+# propogated down the hierarchy.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+local                           local
+TESTPOOL                        TESTPOOL
+TESTPOOL                        TESTPOOL
--- /dev/null	Fri Nov 22 15:20:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state002.cfg	Fri Nov 22 15:20:38 2013
@@ -0,0 +1,45 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that the property that was set on the middle level
+# dataset via the 'local' keyword (in the configX.cfg file) has
+# correctly propogated down the hierarchy to the filesystem underneath,
+# while leaving the top level pools properties unchanged.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+default				default
+local                           local
+TESTPOOL/TESTCTR		TESTPOOL/TESTCTR
--- /dev/null	Fri Nov 22 15:20:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state003.cfg	Fri Nov 22 15:20:39 2013
@@ -0,0 +1,43 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that setting the filesystem's properties does not affect
+# the properties of datasets above it in the hierarchy.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+default				default
+default				default
+local                           local
--- /dev/null	Fri Nov 22 15:20:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state004.cfg	Fri Nov 22 15:20:39 2013
@@ -0,0 +1,44 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that setting a property on a middle level dataset does
+# not prevent us from setting a property on the bottom level filesystem,
+# and that neither affects the top level pools properties.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+default				default
+local                           local
+local                           local
--- /dev/null	Fri Nov 22 15:20:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state005.cfg	Fri Nov 22 15:20:39 2013
@@ -0,0 +1,45 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we set a property on a top level pool, followed
+# by a middle level dataset, that the bottom level filesystem inherits
+# the property from the middle level dataset, and not from the top level
+# pool.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+local                           local
+local                           local
+TESTPOOL/TESTCTR		TESTPOOL/TESTCTR
--- /dev/null	Fri Nov 22 15:20:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state006.cfg	Fri Nov 22 15:20:40 2013
@@ -0,0 +1,47 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we set a property on a top level pool, followed
+# by a bottom level filesystem, that the middle level dataset inherits
+# the property from the top level pool, and not from the bottom level
+# filesystem.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+# <prop src before cmd>		<prop src after cmd>
+#
+local                           local
+TESTPOOL			TESTPOOL
+local                           local
--- /dev/null	Fri Nov 22 15:20:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state007.cfg	Fri Nov 22 15:20:40 2013
@@ -0,0 +1,45 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we can set properties on each level of the
+# hierarchy independently.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+# <prop src before cmd>         <prop src after cmd>
+#
+local                           local
+local                           local
+local                           local
--- /dev/null	Fri Nov 22 15:20:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state008.cfg	Fri Nov 22 15:20:40 2013
@@ -0,0 +1,44 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# No command is actually run (hence '-:-') but rather this state file is
+# used to verify that when we create a dataset hierarchy that the
+# properties of each dataset have their default values.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+-:-
+#
+# <prop src before cmd>         <prop src after cmd>
+default				default
+default				default
+default				default
--- /dev/null	Fri Nov 22 15:20:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state009.cfg	Fri Nov 22 15:20:41 2013
@@ -0,0 +1,57 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at different levels of a
+# data hierarchy where the properties of each dataset have their
+# default values leaves the values unchanged.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+default				default
+default				default
+default				default
+#
+TESTPOOL/TESTCTR:inherit
+#
+default				default
+default				default
+default				default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state010.cfg	Fri Nov 22 15:20:41 2013
@@ -0,0 +1,56 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at different levels of a
+# data hierarchy where the properties of each dataset have their
+# default values leaves the values unchanged.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+default				default
+default				default
+default				default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default				default
+default				default
+default				default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state011.cfg	Fri Nov 22 15:20:41 2013
@@ -0,0 +1,58 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that running 'zfs inherit' at each level of the data hierarchy
+# when the bottom filesystem level properties have been set locally has
+# no effect except at the bottom level where the property values are
+# inherited from the middle level dataset.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+default				default
+default				default
+local				local
+#
+TESTPOOL/TESTCTR:inherit
+#
+default				default
+default				default
+local				local
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+local				default
+#
--- /dev/null	Fri Nov 22 15:20:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state012.cfg	Fri Nov 22 15:20:42 2013
@@ -0,0 +1,62 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that running 'zfs inherit -r' at each level of the data hierarchy
+# when the bottom filesystem level properties have been set locally results
+# in the top level property values being propogated down the data
+# hierarchy.
+#
+# Executing inherit -r at the middle level and bottom levels after
+# running it at the top level is somewhat redundant as the top level value
+# should propogate down the entire data hierarchy. Done for completeness
+# sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+default				default
+default				default
+local				default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default				default
+default				default
+default				default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state013.cfg	Fri Nov 22 15:20:42 2013
@@ -0,0 +1,56 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' on each level when the middle
+# and bottom levels properties are set locally results in the middle and
+# bottom levels inheriting values from the next level up in the hierarchy.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit
+#
+default				default
+local				local
+local				local
+#
+TESTPOOL/TESTCTR:inherit
+#
+default				default
+local				default
+local				local
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+local				default
+#
--- /dev/null	Fri Nov 22 15:20:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state014.cfg	Fri Nov 22 15:20:42 2013
@@ -0,0 +1,62 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that running 'zfs inherit -r' at each level of the data hierarchy
+# when the bottom and middle level properties have been set locally results
+# in the top level property values being propogated down the data
+# hierarchy.
+#
+# Note : executing inherit -r at the middle level and bottom levels after
+# running it at the top level is somewhat redundant as the top level value
+# should propogate down the entire data hierarchy. Done for completeness
+# sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+default				default
+local				default
+local				default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default				default
+default				default
+default				default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state015.cfg	Fri Nov 22 15:20:42 2013
@@ -0,0 +1,66 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the middle level properties are set locally, and the bottom
+# level has inherited its value from the middle level, results in no change
+# to the top level properties.
+#
+# Executing 'zfs inherit' at the middle level results in the middle level
+# inheriting its value from the top level, and passing the values down to
+# the bottom level.
+#
+# Executing 'zfs inherit' at the bottom level is somewhat redundant but
+# is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+default                         default
+local                           local
+TESTPOOL/TESTCTR                TESTPOOL/TESTCTR
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                         default
+local                           default
+TESTPOOL/TESTCTR                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                         default
+default                         default
+default                         default
--- /dev/null	Fri Nov 22 15:20:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state016.cfg	Fri Nov 22 15:20:43 2013
@@ -0,0 +1,62 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the middle level properties are set locally, and the bottom
+# level has inherited its value from the middle level, results in no change
+# to the top level properties and the middle and bottom properties changing
+# to the top level (default) values.
+#
+# Executing 'zfs inherit -r' at the bottom and middle levels after executing
+# at the top level is somewhat redundant but ss done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+default				default
+local				default
+TESTPOOL			default
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default				default
+default				default
+default				default
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state017.cfg	Fri Nov 22 15:20:43 2013
@@ -0,0 +1,67 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the top level and middle level datasets properties are set locally,
+# and the bottom level has inherited its properties from the middle
+# level, results in the top level properties reverting back to their
+# default values.
+#
+# Executing 'zfs inherit' at the middle level results in the middle level
+# inheriting its value from the top level (which is now default), and passing
+# the values down to the bottom level.
+#
+# Executing 'zfs inherit' at the bottom level is somewhat redundant but
+# is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+local                           default
+local                           local
+TESTPOOL/TESTCTR                TESTPOOL/TESTCTR
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default                         default
+local                           default
+TESTPOOL/TESTCTR                default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default                         default
+default                         default
+default                         default
--- /dev/null	Fri Nov 22 15:20:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state018.cfg	Fri Nov 22 15:20:43 2013
@@ -0,0 +1,64 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the top level and middle level datasets properties are set locally,
+# and the bottom level has inherited its properties from the middle
+# level, results in the top level properties reverting back to their
+# default values and being propogated down to the other datasets in the
+# hierarchy.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels after executing
+# it at the top level is somewhat redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+local				default
+local				default
+TESTPOOL/TESTCTR		default
+#
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default				default
+default				default
+default				default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+default				default
--- /dev/null	Fri Nov 22 15:20:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state019.cfg	Fri Nov 22 15:20:44 2013
@@ -0,0 +1,63 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the top level properties are set locally and the middle and bottom
+# datasets have inherited from the top level, results in the top level
+# properties reverting back to their default values, the middle and bottom
+# levels inheriting the changed values.
+#
+# Executing 'zfs inherit' at the middle and bottom levels is somewhat
+# redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit
+#
+local				default
+TESTPOOL			default
+TESTPOOL			default
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default				default
+default				default
+default				default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state020.cfg	Fri Nov 22 15:20:44 2013
@@ -0,0 +1,64 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the top level properties are set locally and the middle and bottom
+# datasets have inherited from the top level, results in the top level
+# properties reverting back to their default values, the middle and bottom
+# levels inheriting the changed values.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels is somewhat
+# redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+local				default
+TESTPOOL			default
+TESTPOOL			default
+#
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default				default
+default				default
+default				default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state021.cfg	Fri Nov 22 15:20:44 2013
@@ -0,0 +1,64 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when the top level and bottom level properties are set locally and the
+# middle dataset has inherited from the top level, results in the top level
+# properties reverting back to their default values, and the middle level
+# inheriting the new top level value.
+#
+# Executing 'zfs inherit' at the bottom level results in it inheriting
+# the middle level values.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+local				default
+TESTPOOL			default
+local				local
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default				default
+default				default
+local				local
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+local				default
+#
--- /dev/null	Fri Nov 22 15:20:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state022.cfg	Fri Nov 22 15:20:44 2013
@@ -0,0 +1,63 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when the top level and bottom level properties are set locally and the
+# middle dataset has inherited from the top level, results in the top level
+# properties reverting back to their default values, the middle and bottom
+# levels inheriting the changed values.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels is somewhat
+# redundant but is done for completness sake.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+TESTPOOL:inherit -r
+#
+local				default
+TESTPOOL			default
+local				default
+#
+#
+TESTPOOL/TESTCTR:inherit -r
+#
+default				default
+default				default
+default				default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit -r
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state023.cfg	Fri Nov 22 15:20:45 2013
@@ -0,0 +1,65 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit' at the top level in the hierarchy
+# when each levels properties are set locally, results in the top level
+# properties reverting back to their default values.
+#
+# Executing 'zfs inherit' at the middle level results in it inheriting
+# the top levels (now default) values
+#
+# Executing 'zfs inherit' at the bottom level results in it inheriting
+# the middle levels (now default) values
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit
+#
+local				default
+local				local
+local				local
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default				default
+local				default
+local				local
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+local				default
+#
--- /dev/null	Fri Nov 22 15:20:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inheritance/state024.cfg	Fri Nov 22 15:20:45 2013
@@ -0,0 +1,63 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+# *** ASSERTION DESCRIPTION ***
+#
+# Verify that executing 'zfs inherit -r' at the top level in the hierarchy
+# when each levels properties are set locally, results in the top level
+# properties reverting back to their default values, and the changed
+# values being propogated down the hierarchy.
+#
+# Executing 'zfs inherit -r' at the middle and bottom levels after doing so
+# at the top level is somewhat redundant but is done for completeness.
+#
+# *** ASSERTION DESCRIPTION ***
+#
+#
+TESTPOOL:inherit -r
+#
+local				default
+local				default
+local				default
+#
+#
+TESTPOOL/TESTCTR:inherit
+#
+default				default
+default				default
+default				default
+#
+#
+TESTPOOL/TESTCTR/TESTFS1:inherit
+#
+default				default
+default				default
+default				default
+#
--- /dev/null	Fri Nov 22 15:20:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/interop/Makefile	Fri Nov 22 15:20:46 2013
@@ -0,0 +1,43 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/interop
+
+PROGS = cleanup \
+	interop_001_pos \
+	setup
+
+FILES = interop.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/interop/cleanup.ksh	Fri Nov 22 15:20:46 2013
@@ -0,0 +1,73 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/interop/interop.cfg
+
+verify_runnable "global"
+
+ismounted $TESTPOOL/$TESTFS
+(( $? == 0 )) && log_must $ZFS umount -f $TESTDIR
+destroy_pool $TESTPOOL
+
+$METASTAT $META_DEVICE_ID > /dev/null 2>&1
+if (( $? == 0 )); then
+	log_note "Clearing meta device ($META_DEVICE_ID)"
+	$METACLEAR -f $META_DEVICE_ID > /dev/null 2>&1
+fi
+
+typeset metadb=""
+typeset i=""
+
+metadb=`$METADB | $CUT -f6 | $GREP dev | $UNIQ`
+for i in $metadb; do
+	log_note "Clearing meta db ($i)"
+	$METADB -fd $i > /dev/null 2>&1
+done
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+case $DISK_COUNT in
+0)
+	log_note "No disk devices to restore"
+	;;
+1)
+	log_must cleanup_devices $ZFS_DISK2
+	;;
+2)
+	log_must cleanup_devices $META_DISK0 $ZFS_DISK2
+	;;
+*)
+	log_must cleanup_devices $META_DISK0 $META_DISK1 $ZFS_DISK2
+	;;
+esac
+
+log_pass "Cleanup has been successful"
--- /dev/null	Fri Nov 22 15:20:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/interop/interop.cfg	Fri Nov 22 15:20:46 2013
@@ -0,0 +1,81 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+set -A disk_array $(find_disks $DISKS)
+case "${#disk_array[*]}" in
+0)
+	DISK_COUNT=0
+        ;;
+1)
+        # We need to repartition the single disk to two slices
+	DISK_COUNT=1
+        META_DISK0=${disk_array[0]}
+        SINGLE_DISK=$META_DISK0
+        META_DISK1=$META_DISK0
+        ZFS_DISK2=$META_DISK0
+        META_SIDE0=${SINGLE_DISK}s0
+        META_SIDE1=${SINGLE_DISK}s1
+        ZFS_SIDE2=${SINGLE_DISK}s3
+        ;;
+2)
+        # We need to repartition the single disk to two slices and allocate
+	# the 2nd disk to ZFS
+	DISK_COUNT=2
+        META_DISK0=${disk_array[0]}
+        SINGLE_DISK=$META_DISK0
+        META_DISK1=$META_DISK0
+        ZFS_DISK2=${disk_array[1]}
+        META_SIDE0=${SINGLE_DISK}s0
+        META_SIDE1=${SINGLE_DISK}s1
+        ZFS_SIDE2=${ZFS_DISK2}s0
+        ;;
+*)
+	# In this case there are at least enough disks to use.
+	DISK_COUNT=3
+        META_DISK0=${disk_array[0]}
+        META_DISK1=${disk_array[1]}
+        ZFS_DISK2=${disk_array[2]}
+        META_SIDE0=${META_DISK0}s0
+        META_SIDE1=${META_DISK1}s0
+        ZFS_SIDE2=${ZFS_DISK2}s0
+        ;;
+esac
+
+export DISK_COUNT META_DISK0 META_DISK1 ZFS_DISK2
+export META_SIDE0 META_SIDE1 ZFS_SIDE2 SINGLE_DISK
+
+export TESTFILE=testfile
+export FS_SIZE=500m
+export META_DEVICE_ID=d99
+export META_DEVICE_PATH=/dev/md/dsk/$META_DEVICE_ID
+export FILE_COUNT=20
+export FILE_SIZE=$(( 1024 * 1024 ))
--- /dev/null	Fri Nov 22 15:20:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/interop/interop_001_pos.ksh	Fri Nov 22 15:20:47 2013
@@ -0,0 +1,88 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/interop/interop.cfg
+
+#
+# DESCRIPTION:
+# Create a SVM device and add this to an existing ZFS pool
+#
+# STRATEGY:
+# 1. Create a SVM metadevice
+# 2. Create a ZFS file system
+# 3. Add SVM metadevice to the ZFS pool
+# 4. Create files and fill the pool.
+#
+
+
+function cleanup
+{
+	$RM -rf $TESTDIR/*
+}
+
+log_assert "Create a SVM device and add this to an existing ZFS pool"
+
+log_onexit cleanup
+
+# the current size of the test pool
+typeset -i oldsize=`$ZFS get -pH -o value available $TESTPOOL`
+
+log_must $ZPOOL add $TESTPOOL $META_DEVICE_PATH
+log_must $ZPOOL iostat -v | $GREP $META_DEVICE_ID
+
+# the size of the test pool after adding the extra device
+typeset -i newsize=`$ZFS get -pH -o value available $TESTPOOL`
+
+(( $oldsize >= $newsize )) && \
+    log_fail "Pool space available ($oldsize) before adding a new device was "\
+	     "larger than the space available ($newsize) afterwards."
+
+log_note "Pool space available was ($oldsize), it's now ($newsize)"
+
+typeset -i odirnum=1
+typeset -i idirnum=0
+typeset -i filenum=0
+typeset -i retval=0
+typeset bg=$TESTDIR/bigdirectory
+
+fill_fs $bg 20 25 $FILE_SIZE $FILE_COUNT
+retval=$?
+
+afterwritepoolavail=`$ZFS get -pH -o value available $TESTPOOL`
+readonly ENOSPC=28
+
+(( $retval == $ENOSPC && $afterwritepoolavail < $oldsize)) && \
+	log_pass "Successfully used ($(( $newsize - $oldsize )) bytes) in "\
+		 "pool provided by SVM metadevice"
+
+log_fail "Failed to use space in pool ($(( $newsize - $oldsize ))bytes) "\
+	 "provided by SVM metadevice"
--- /dev/null	Fri Nov 22 15:20:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/interop/setup.ksh	Fri Nov 22 15:20:47 2013
@@ -0,0 +1,83 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/interop/interop.cfg
+
+verify_runnable "global"
+
+case $DISK_COUNT in
+0)
+	log_untested "Need at least 1 disk device for test"
+	;;
+1)
+	log_note "Partitioning a single disk ($SINGLE_DISK)"
+	;;
+2)
+	log_note "Partitioning a disks ($SINGLE_DISK) and ($ZFS_DISK2)"
+	;;
+3)
+	log_note "Partitioning disks ($META_DISK0 $META_DISK1 $ZFS_DISK2)"
+	;;
+esac
+
+log_must set_partition ${META_SIDE0##*s} "" $FS_SIZE $META_DISK0
+if [[ $WRAPPER == *"smi"* && $META_DISK1 == $META_DISK0 ]]; then
+	typeset i=${META_SIDE0##*s}
+	typeset cyl=$(get_endslice $META_DISK0 $i)
+	log_must set_partition ${META_SIDE1##*s} "$cyl" $FS_SIZE $META_DISK1
+else
+	log_must set_partition ${META_SIDE1##*s} "" $FS_SIZE $META_DISK1
+fi
+if [[ $WRAPPER == *"smi"* && $ZFS_DISK2 == $META_DISK1 ]]; then
+	typeset i=${META_SIDE1##*s}
+	typeset cyl=$(get_endslice $META_DISK1 $i)
+	log_must set_partition ${ZFS_SIDE2##*s} "$cyl" $FS_SIZE $ZFS_DISK2
+else
+	log_must set_partition ${ZFS_SIDE2##*s} "" $FS_SIZE $ZFS_DISK2
+fi
+
+create_pool $TESTPOOL $ZFS_SIDE2
+
+$RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
+$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+
+log_note "Configuring metadb with $META_SIDE1"
+log_must $METADB -a -f -c 3 $META_SIDE1
+
+log_note "Configure $META_DEVICE_ID with $META_SIDE0"
+log_must $METAINIT $META_DEVICE_ID 1 1 $META_SIDE0
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/Makefile	Fri Nov 22 15:20:47 2013
@@ -0,0 +1,51 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/inuse
+
+PROGS = cleanup \
+	inuse_001_pos \
+	inuse_002_pos \
+	inuse_003_pos \
+	inuse_004_pos \
+	inuse_005_pos \
+	inuse_006_pos \
+	inuse_007_pos \
+	inuse_008_pos \
+	inuse_009_pos \
+	setup
+
+FILES = inuse.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse.cfg	Fri Nov 22 15:20:48 2013
@@ -0,0 +1,125 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_disk_count "$DISKS" 2
+set -A disk_array $(find_disks $DISKS)
+case "${#disk_array[@]}" in
+2)
+	FS_DISK0=${disk_array[0]}
+	FS_DISK1=${disk_array[1]}
+	FS_DISK2=${disk_array[0]}
+	FS_DISK3=${disk_array[1]}
+	FS_SIDE0=${FS_DISK0}s0
+	FS_SIDE1=${FS_DISK0}s1
+	FS_SIDE2=${FS_DISK1}s0
+	FS_SIDE3=${FS_DISK1}s1
+	disk0="/dev/dsk/$FS_SIDE0"
+	disk1="/dev/dsk/$FS_SIDE1"
+	disk2="/dev/dsk/$FS_SIDE2"
+	disk3="/dev/dsk/$FS_SIDE3"
+	disktargets="$disk0 $disk2"
+	rawdisk0="/dev/rdsk/$FS_SIDE0"
+	rawdisk1="/dev/rdsk/$FS_SIDE1"
+	rawdisk2="/dev/rdsk/$FS_SIDE2"
+	rawdisk3="/dev/rdsk/$FS_SIDE3"
+	rawtargets="$rawdisk0 $rawdisk2"
+	vdisks="$FS_DISK0"
+	sdisks="$FS_DISK1"
+	vslices="$FS_SIDE0 $FS_SIDE1 $FS_SIDE2"
+	sslices="$FS_SIDE3"
+	;;
+3)
+	FS_DISK0=${disk_array[0]}
+	FS_DISK1=${disk_array[1]}
+	FS_DISK2=${disk_array[2]}
+	FS_DISK3=${disk_array[0]}
+	FS_SIDE0=${FS_DISK0}s0
+	FS_SIDE1=${FS_DISK0}s1
+	FS_SIDE2=${FS_DISK1}s0
+	FS_SIDE3=${FS_DISK2}s0
+	disk0="/dev/dsk/$FS_SIDE0"
+	disk1="/dev/dsk/$FS_SIDE1"
+	disk2="/dev/dsk/$FS_SIDE2"
+	disk3="/dev/dsk/$FS_SIDE3"
+	disktargets="$disk0 $disk2 $disk3"
+	rawdisk0="/dev/rdsk/$FS_SIDE0"
+	rawdisk1="/dev/rdsk/$FS_SIDE1"
+	rawdisk2="/dev/rdsk/$FS_SIDE2"
+	rawdisk3="/dev/rdsk/$FS_SIDE3"
+	rawtargets="$rawdisk0 $rawdisk2 $rawdisk3"
+	vdisks="$FS_DISK0 $FS_DISK1"
+	sdisks="$FS_DISK2"
+	vslices="$FS_SIDE0 $FS_SIDE2 $FS_SIDE3"
+	sslices="$FS_SIDE1"
+	;;
+*)
+	FS_DISK0=${disk_array[0]}
+	FS_DISK1=${disk_array[1]}
+	FS_DISK2=${disk_array[2]}
+	FS_DISK3=${disk_array[3]}
+	FS_SIDE0=${FS_DISK0}s0
+	FS_SIDE1=${FS_DISK1}s0
+	FS_SIDE2=${FS_DISK2}s0
+	FS_SIDE3=${FS_DISK3}s0
+	disk0="/dev/dsk/$FS_SIDE0"
+	disk1="/dev/dsk/$FS_SIDE1"
+	disk2="/dev/dsk/$FS_SIDE2"
+	disk3="/dev/dsk/$FS_SIDE3"
+	disktargets="$disk0 $disk1 $disk2 $disk3"
+	rawdisk0="/dev/rdsk/$FS_SIDE0"
+	rawdisk1="/dev/rdsk/$FS_SIDE1"
+	rawdisk2="/dev/rdsk/$FS_SIDE2"
+	rawdisk3="/dev/rdsk/$FS_SIDE3"
+	rawtargets="$rawdisk0 $rawdisk1 $rawdisk2 $rawdisk3"
+	vdisks="$FS_DISK0 $FS_DISK1 $FS_DISK2"
+	sdisks="$FS_DISK3"
+	vslices="$FS_SIDE0 $FS_SIDE1 $FS_SIDE2"
+	sslices="$FS_SIDE3"
+	;;
+esac
+
+export FS_DISK0 FS_DISK1 FS_DISK2 FS_DISK3 SINGLE_DISK
+export FS_SIDE0 FS_SIDE1 FS_SIDE2 FS_SIDE3
+export disk0 disk1 disk2 disk3 disktargets
+export rawdisk0 rawdisk1 rawdisk2 rawdisk3 rawtargets
+export vdisks sdisks vslices sslices
+
+export UFSMP=$TESTDIR/testinuseufsdump
+export FS_SIZE=1g
+export PREVDUMPDEV=""
+export PIDUFSDUMP=""
+export PIDUFSRESTORE=""
+# size of block to be written to test file - currently 1mb
+export BLOCK_SIZE=$(( 1024 * 1024 ))
+# number of blocks to write == size of file
+export BLOCK_COUNT=100
+export STF_TIMEOUT=1200			# 20 minutes max.
--- /dev/null	Fri Nov 22 15:20:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh	Fri Nov 22 15:20:48 2013
@@ -0,0 +1,90 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# ZFS will not interfere with devices that are in use by dumpadm.
+#
+# STRATEGY:
+# 1. Create crash dump device using 'dumpadm'
+# 2. Try to create a ZFS pool using the 'dumpadm' crash dump device.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	#
+	# Remove dump device.
+	#
+	if [[ -n $PREVDUMPDEV ]]; then
+		log_must $DUMPADM -u -d $PREVDUMPDEV > /dev/null
+	fi
+
+	destroy_pool $TESTPOOL
+}
+
+log_assert "Ensure ZFS cannot use a device designated as a dump device"
+
+log_onexit cleanup
+
+typeset dumpdev=""
+typeset diskslice=""
+
+PREVDUMPDEV=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+
+log_note "Zero $FS_DISK0 and place free space in to slice 0"
+log_must cleanup_devices $FS_DISK0
+
+if [[ $WRAPPER == *"smi"* ]]; then
+	diskslice="/dev/dsk/${FS_DISK0}s2"
+else
+	diskslice="/dev/dsk/${FS_DISK0}s0"
+fi
+
+log_note "Configuring $diskslice as dump device"
+log_must $DUMPADM -d $diskslice > /dev/null
+
+log_note "Confirm that dump device has been setup"
+dumpdev=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+[[ -z "$dumpdev" ]] && log_untested "No dump device has been configured"
+
+[[ "$dumpdev" != "$diskslice" ]] && \
+    log_untested "Dump device has not been been configured to $diskslice"
+
+log_note "Attempt to zpool the dump device"
+log_mustnot $ZPOOL create $TESTPOOL "$diskslice"
+log_mustnot poolexists $TESTPOOL
+
+log_pass "Unable to zpool a device in use by dumpadm"
--- /dev/null	Fri Nov 22 15:20:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_002_pos.ksh	Fri Nov 22 15:20:48 2013
@@ -0,0 +1,111 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# ZFS will not interfere with devices that are in use by SVM
+#
+# STRATEGY:
+# 1. Create SVM device d99 with a disk
+# 2. Try to create a ZFS pool with same disk
+# 3. Try a use the same disk as a spare device
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
+
+	$METASTAT d99 > /dev/null 2>&1
+	(( $? == 0 )) && $METACLEAR -f d99
+
+	typeset metadb=""
+	typeset i=""
+
+	metadb=`$METADB | $CUT -f6 | $GREP dev | $UNIQ`
+	for i in $metadb; do
+		$METADB -fd $i > /dev/null 2>&1
+	done
+
+	#
+	# Tidy up the disks we used.
+	#
+	cleanup_devices $vdisks $sdisks
+}
+
+log_assert "Ensure ZFS does not interfere with devices in use by SVM"
+
+log_onexit cleanup
+
+for num in 0 1 2; do
+	eval typeset slice=\${FS_SIDE$num}
+	disk=${slice%s*}
+	slice=${slice##*s}
+	if [[ $WRAPPER == *"smi"* && \
+		$disk == ${saved_disk} ]]; then
+		cyl=$(get_endslice $disk ${saved_slice})
+		log_must set_partition $slice "$cyl" $FS_SIZE $disk
+	else
+		log_must set_partition $slice "" $FS_SIZE $disk
+	fi
+	saved_disk=$disk
+	saved_slice=$slice
+done
+
+log_note "Configuring metadb with $FS_SIDE1"
+log_must $METADB -a -f -c 3 $FS_SIDE1
+
+log_note "Configure d99 with $FS_SIDE0"
+log_must $METAINIT d99 1 1 $FS_SIDE0
+
+log_note "Attempt to zpool the device in use by SVM"
+log_mustnot $ZPOOL create $TESTPOOL1 $FS_SIDE0
+log_mustnot poolexists $TESTPOOL1
+
+log_note "Attempt to take device in use by SVM as spare device"
+log_mustnot $ZPOOL create $TESTPOOL1 $FS_SIDE2 spare $FS_SIDE0
+log_mustnot poolexists $TESTPOOL1
+
+log_note "Attempt to zpool a metadb device in use by SVM"
+log_mustnot $ZPOOL create $TESTPOOL2 $FS_SIDE1
+log_mustnot poolexists $TESTPOOL2
+
+log_note "Attempt to take device in use by SVM as spare device"
+log_mustnot $ZPOOL create $TESTPOOL2 $FS_SIDE2 spare $FS_SIDE1
+log_mustnot poolexists $TESTPOOL2
+
+log_pass "Unable to zpool a device in use by SVM"
--- /dev/null	Fri Nov 22 15:20:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh	Fri Nov 22 15:20:49 2013
@@ -0,0 +1,185 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# ZFS will not interfere with devices that are in use by ufsdump or
+# ufsrestore.
+#
+# STRATEGY:
+# 1. newfs a disk
+# 2. mount the disk
+# 3. create files and dirs on disk
+# 4. umount the disk
+# 5. ufsdump this disk to a backup disk
+# 6. Try to create a ZFS pool with same disk (also as a spare device)
+# 7. ufsrestore the disk from backup
+# 8. try to create a zpool during the ufsrestore
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
+
+	log_note "Kill off ufsdump process if still running"
+	$KILL -0 $PIDUFSDUMP > /dev/null 2>&1 && \
+	    log_must $KILL -9 $PIDUFSDUMP  > /dev/null 2>&1
+	#
+	# Note: It would appear that ufsdump spawns a number of processes
+	# which are not killed when the $PIDUFSDUMP is whacked.  So best bet
+	# is to find the rest of the them and deal with them individually.
+	#
+	for all in `$PGREP ufsdump`
+	do
+		$KILL -9 $all > /dev/null 2>&1
+	done
+
+	log_note "Kill off ufsrestore process if still running"
+	$KILL -0 $PIDUFSRESTORE > /dev/null 2>&1 && \
+	    log_must $KILL -9 $PIDUFSRESTORE  > /dev/null 2>&1
+
+	ismounted $UFSMP ufs && log_must $UMOUNT $UFSMP
+
+	$RM -rf $UFSMP
+	$RM -rf $TESTDIR
+
+	#
+	# Tidy up the disks we used.
+	#
+	log_must cleanup_devices $vdisks $sdisks
+}
+
+log_assert "Ensure ZFS does not interfere with devices that are in use by " \
+    "ufsdump or ufsrestore"
+
+log_onexit cleanup
+
+typeset bigdir="${UFSMP}/bigdirectory"
+typeset restored_files="${UFSMP}/restored_files"
+typeset -i dirnum=0
+typeset -i filenum=0
+typeset cwd=""
+
+for num in 0 1 2; do
+	eval typeset slice=\${FS_SIDE$num}
+	disk=${slice%s*}
+	slice=${slice##*s}
+	if [[ $WRAPPER == *"smi"* && $disk == ${saved_disk} ]]; then
+		cyl=$(get_endslice $disk ${saved_slice})
+		log_must set_partition $slice "$cyl" $FS_SIZE $disk
+	else
+		log_must set_partition $slice "" $FS_SIZE $disk
+	fi
+	saved_disk=$disk
+	saved_slice=$slice
+done
+
+log_note "Make a ufs filesystem on source $rawdisk1"
+$ECHO "y" | $NEWFS -v $rawdisk1 > /dev/null 2>&1
+(($? != 0)) && log_untested "Unable to create ufs filesystem on $rawdisk1"
+
+log_must $MKDIR -p $UFSMP
+
+log_note "mount source $disk1 on $UFSMP"
+log_must $MOUNT $disk1 $UFSMP
+
+log_note "Now create some directories and files to be ufsdump'ed"
+while (($dirnum <= 2)); do
+	log_must $MKDIR $bigdir${dirnum}
+	while (( $filenum <= 2 )); do
+		$FILE_WRITE -o create -f $bigdir${dirnum}/file${filenum} \
+		    -b $BLOCK_SIZE -c $BLOCK_COUNT
+		if [[ $? -ne 0 ]]; then
+			if [[ $dirnum -lt 3 ]]; then
+				log_fail "$FILE_WRITE only wrote" \
+				    "<(( $dirnum * 3 + $filenum ))>" \
+				    "files, this is not enough"
+			fi
+		fi
+		((filenum = filenum + 1))
+	done
+	filenum=0
+	((dirnum = dirnum + 1))
+done
+
+log_must $UMOUNT $UFSMP
+
+log_note "Start ufsdump in the background"
+log_note "$UFSDUMP 0bf 512 $rawdisk0 $disk1"
+$UFSDUMP 0bf 512 $rawdisk0 $disk1 &
+PIDUFSDUMP=$!
+
+log_note "Attempt to zpool the source device in use by ufsdump"
+log_mustnot $ZPOOL create $TESTPOOL1 "$disk1"
+log_mustnot poolexists $TESTPOOL1
+
+log_note "Attempt to take the source device in use by ufsdump as spare device"
+log_mustnot $ZPOOL create $TESTPOOL1 "$FS_SIDE2" spare "$disk1"
+log_mustnot poolexists $TESTPOOL1
+
+wait $PIDUFSDUMP
+typeset -i retval=$?
+(($retval != 0)) && log_fail "$UFSDUMP failed with error code $ret_val"
+
+log_must $MOUNT $disk1 $UFSMP
+
+log_must $RM -rf $UFSMP/*
+log_must $MKDIR $restored_files
+
+cwd=$PWD
+log_must cd $restored_files
+log_note "Start ufsrestore in the background from the target device"
+log_note "$UFSRESTORE rbf 512 $rawdisk0"
+$UFSRESTORE rbf 512 $rawdisk0 &
+PIDUFSRESTORE=$!
+log_must cd $cwd
+
+log_note "Attempt to zpool the restored device in use by ufsrestore"
+log_mustnot $ZPOOL create -f $TESTPOOL2 "$disk1"
+log_mustnot poolexists $TESTPOOL2
+
+log_note "Attempt to take the restored device in use by ufsrestore as spare" \
+    "device"
+log_mustnot $ZPOOL create -f $TESTPOOL2 "$FS_SIDE2" spare "$disk1"
+log_mustnot poolexists $TESTPOOL2
+
+log_pass "Unable to zpool over a device in use by ufsdump or ufsrestore"
--- /dev/null	Fri Nov 22 15:20:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh	Fri Nov 22 15:20:49 2013
@@ -0,0 +1,94 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# format will disallow modification of a mounted zfs disk partition or a spare
+# device
+#
+# STRATEGY:
+# 1. Create a ZFS filesystem
+# 2. Add a spare device to the ZFS pool
+# 3. Attempt to format the disk and the spare device.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	#
+	# Essentailly this is the default_cleanup rountine but I cannot get it
+	# to work correctly.  So its reproduced below.  Still need to full
+	# understand why default_cleanup does not work correctly from here.
+	#
+        log_must $ZFS umount $TESTPOOL/$TESTFS
+
+        $RM -rf $TESTDIR || \
+            log_unresolved Could not remove $TESTDIR
+
+	log_must $ZFS destroy $TESTPOOL/$TESTFS
+	destroy_pool $TESTPOOL
+}
+#
+# Currently, if a ZFS disk gets formatted things go horribly wrong, hence the
+# mini_format function.  If the modify option is reached, then we know format
+# would happily continue - best to not go further.
+#
+function mini_format
+{
+        typeset disk=$1
+
+	typeset format_file=/var/tmp/format_in.$$.1
+	$ECHO "partition" > $format_file
+	$ECHO "modify" >> $format_file
+
+	$FORMAT -e -s -d $disk -f $format_file
+	typeset -i retval=$?
+	$RM -rf $format_file
+	return $retval
+}
+
+log_assert "format will disallow modification of a mounted zfs disk partition"\
+ " or a spare device"
+
+log_onexit cleanup
+log_must default_setup_noexit $FS_DISK0
+log_must $ZPOOL add $TESTPOOL spare $FS_DISK1
+
+log_note "Attempt to format a ZFS disk"
+log_mustnot mini_format $FS_DISK0
+log_note "Attempt to format a ZFS spare device"
+log_mustnot mini_format $FS_DISK1
+
+log_pass "Unable to format a disk in use by ZFS"
--- /dev/null	Fri Nov 22 15:20:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh	Fri Nov 22 15:20:49 2013
@@ -0,0 +1,122 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# newfs will not interfere with devices and spare devices that are in use
+# by active pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Try to newfs against the disk, verify it fails as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	#
+	# Tidy up the disks we used.
+	#
+	cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+	typeset targets=$1
+
+	for t in $targets; do
+		$ECHO "y" | $NEWFS -v $t > /dev/null 2>&1
+		(( $? !=0 )) || \
+			log_fail "newfs over active pool " \
+			"unexpected return code of 0"
+	done
+
+	return 0
+}
+
+log_assert "Verify newfs over active pool fails."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+while (( i < ${#vdevs[*]} )); do
+
+	for num in 0 1 2 3 ; do
+		eval typeset slice=\${FS_SIDE$num}
+		disk=${slice%s*}
+		slice=${slice##*s}
+		if [[ $WRAPPER == *"smi"* && \
+			$disk == ${saved_disk} ]]; then
+			cyl=$(get_endslice $disk ${saved_slice})
+			log_must set_partition $slice "$cyl" $FS_SIZE $disk
+		else
+			log_must set_partition $slice "" $FS_SIZE $disk
+		fi
+		saved_disk=$disk
+		saved_slice=$slice
+	done
+
+	if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+	verify_assertion "$rawtargets"
+	destroy_pool $TESTPOOL1
+
+	if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+	verify_assertion "$rawtargets"
+	destroy_pool $TESTPOOL1
+
+	(( i = i + 1 ))
+done
+
+log_pass "Newfs over active pool fails."
--- /dev/null	Fri Nov 22 15:20:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh	Fri Nov 22 15:20:50 2013
@@ -0,0 +1,125 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# dumpadm will not interfere with devices and spare devices that are in use
+# by active pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Try to dumpadm against the disk, verify it fails as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if [[ -n $PREVDUMPDEV ]]; then
+		log_must $DUMPADM -u -d $PREVDUMPDEV
+	fi
+
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	#
+	# Tidy up the disks we used.
+	#
+	cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+	typeset targets=$1
+
+	for t in $targets; do
+		log_mustnot $DUMPADM -d $t
+	done
+
+        return 0
+}
+
+log_assert "Verify dumpadm over active pool fails."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+PREVDUMPDEV=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+
+while (( i < ${#vdevs[*]} )); do
+
+	for num in 0 1 2 3 ; do
+		eval typeset slice=\${FS_SIDE$num}
+		disk=${slice%s*}
+		slice=${slice##*s}
+		if [[ $WRAPPER == *"smi"* && \
+			$disk == ${saved_disk} ]]; then
+			cyl=$(get_endslice $disk ${saved_slice})
+			log_must set_partition $slice "$cyl" $FS_SIZE $disk
+		else
+			log_must set_partition $slice "" $FS_SIZE $disk
+		fi
+		saved_disk=$disk
+		saved_slice=$slice
+	done
+
+	if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+	verify_assertion "$disktargets"
+	destroy_pool $TESTPOOL1
+
+	if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+	verify_assertion "$disktargets"
+	destroy_pool $TESTPOOL1
+
+	(( i = i + 1 ))
+done
+
+log_pass "Dumpadm over active pool fails."
--- /dev/null	Fri Nov 22 15:20:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh	Fri Nov 22 15:20:50 2013
@@ -0,0 +1,134 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# dumpadm will interfere with devices and spare devices that are in use
+# by exported pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Export the pool
+# 3. Try to dumpadm against the disk, verify it succeeds as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if [[ -n $PREVDUMPDEV ]]; then
+		log_must $DUMPADM -u -d $PREVDUMPDEV
+	fi
+
+	poolexists $TESTPOOL1 || $ZPOOL import $TESTPOOL1 >/dev/null 2>&1
+
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	#
+	# Tidy up the disks we used.
+	#
+	cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+	typeset targets=$1
+
+	for t in $targets; do
+		log_must $DUMPADM -u -d $t
+
+		log_must $DUMPADM -u -d $PREVDUMPDEV
+	done
+
+	return 0
+}
+
+log_assert "Verify dumpadm over exported pool succeed."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+PREVDUMPDEV=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'`
+
+while (( i < ${#vdevs[*]} )); do
+
+	for num in 0 1 2 3 ; do
+		eval typeset slice=\${FS_SIDE$num}
+		disk=${slice%s*}
+		slice=${slice##*s}
+		if [[ $WRAPPER == *"smi"* && \
+			$disk == ${saved_disk} ]]; then
+			cyl=$(get_endslice $disk ${saved_slice})
+			log_must set_partition $slice "$cyl" $FS_SIZE $disk
+		else
+			log_must set_partition $slice "" $FS_SIZE $disk
+		fi
+		saved_disk=$disk
+		saved_slice=$slice
+	done
+
+	if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+	log_must $ZPOOL export $TESTPOOL1
+	verify_assertion "$disktargets"
+	log_must $ZPOOL import $TESTPOOL1
+	destroy_pool $TESTPOOL1
+
+	if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+	log_must $ZPOOL export $TESTPOOL1
+	verify_assertion "$disktargets"
+	log_must $ZPOOL import $TESTPOOL1
+	destroy_pool $TESTPOOL1
+
+	(( i = i + 1 ))
+done
+
+log_pass "Dumpadm over exported pool succeed."
--- /dev/null	Fri Nov 22 15:20:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh	Fri Nov 22 15:20:50 2013
@@ -0,0 +1,111 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# Newfs will interfere with devices and spare devices that are in use
+# by exported pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Export the pool
+# 3. Try to newfs against the disk, verify it succeeds as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 || $ZPOOL import $TESTPOOL1 >/dev/null 2>&1
+
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	#
+	# Tidy up the disks we used.
+	#
+	cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #slices
+{
+	typeset targets=$1
+
+	for t in $targets; do
+		$ECHO "y" | $NEWFS -v $t > /dev/null 2>&1
+		(( $? !=0 )) && \
+			log_fail "newfs over exported pool " \
+				"failes unexpected."
+	done
+
+	return 0
+}
+
+log_assert "Verify newfs over exported pool succeed."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+for num in 0 1 2 3 ; do
+	eval typeset slice=\${FS_SIDE$num}
+	disk=${slice%s*}
+	slice=${slice##*s}
+	if [[ $WRAPPER == *"smi"* && \
+		$disk == ${saved_disk} ]]; then
+		cyl=$(get_endslice $disk ${saved_slice})
+		log_must set_partition $slice "$cyl" $FS_SIZE $disk
+	else
+		log_must set_partition $slice "" $FS_SIZE $disk
+	fi
+	saved_disk=$disk
+	saved_slice=$slice
+done
+
+while (( i < ${#vdevs[*]} )); do
+	if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+	log_must $ZPOOL export $TESTPOOL1
+	verify_assertion "$rawtargets"
+	cleanup_devices $vslices $sslices
+
+	(( i = i + 1 ))
+done
+
+log_pass "Newfs over exported pool succeed."
--- /dev/null	Fri Nov 22 15:20:51 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/inuse_009_pos.ksh	Fri Nov 22 15:20:51 2013
@@ -0,0 +1,122 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/inuse/inuse.cfg
+
+#
+# DESCRIPTION:
+# format command will interfere with devices and spare devices that are in use
+# by exported pool.
+#
+# STRATEGY:
+# 1. Create a regular|mirror|raidz|raidz2 pool with the given disk
+# 2. Export the pool
+# 3. Try to format against the disk, verify it succeeds as expect.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	poolexists $TESTPOOL1 || $ZPOOL import $TESTPOOL1 >/dev/null 2>&1
+
+	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
+
+	#
+	# Tidy up the disks we used.
+	#
+	cleanup_devices $vdisks $sdisks
+}
+
+function verify_assertion #disks
+{
+	typeset targets=$1
+
+	for t in $targets; do
+		log_must set_partition 0 "" 0mb $t
+	done
+
+	return 0
+}
+
+log_assert "Verify format over exported pool succeed."
+
+log_onexit cleanup
+
+set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
+
+typeset -i i=0
+
+while (( i < ${#vdevs[*]} )); do
+
+	for num in 0 1 2 3 ; do
+		eval typeset slice=\${FS_SIDE$num}
+		disk=${slice%s*}
+		slice=${slice##*s}
+		if [[ $WRAPPER == *"smi"* && \
+			$disk == ${saved_disk} ]]; then
+			cyl=$(get_endslice $disk ${saved_slice})
+			log_must set_partition $slice "$cyl" $FS_SIZE $disk
+		else
+			log_must set_partition $slice "" $FS_SIZE $disk
+		fi
+		saved_disk=$disk
+		saved_slice=$slice
+	done
+
+	if [[ -n $SINGLE_DISK && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vslices spare $sslices
+	log_must $ZPOOL export $TESTPOOL1
+	verify_assertion "$vdisks $sdisks"
+
+	if [[ ( $FS_DISK0 == $FS_DISK2 ) && -n ${vdevs[i]} ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	if [[ ( $FS_DISK0 == $FS_DISK3 ) && ( ${vdevs[i]} == "raidz2" ) ]]; then
+		(( i = i + 1 ))
+		continue
+	fi
+
+	create_pool $TESTPOOL1 ${vdevs[i]} $vdisks spare $sdisks
+	log_must $ZPOOL export $TESTPOOL1
+	verify_assertion "$vdisks $sdisks"
+
+	(( i = i + 1 ))
+done
+
+log_pass "Format over exported pool succeed."
--- /dev/null	Fri Nov 22 15:20:51 2013
+++ new/usr/src/test/zfs-tests/tests/functional/inuse/setup.ksh	Fri Nov 22 15:20:51 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:51 2013
+++ new/usr/src/test/zfs-tests/tests/functional/large_files/Makefile	Fri Nov 22 15:20:51 2013
@@ -0,0 +1,41 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/large_files
+
+PROGS = cleanup \
+	large_files_001_pos \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/large_files/cleanup.ksh	Fri Nov 22 15:20:52 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/large_files/large_files_001_pos.ksh	Fri Nov 22 15:20:52 2013
@@ -0,0 +1,53 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Write a file to the allowable ZFS fs size.
+#
+# STRATEGY:
+# 1. largest_file will write to a file and increase its size
+# to the maximum allowable.
+# 2. The last byte of the file should be accessbile without error.
+# 3. Writing beyond the maximum file size generates an 'errno' of
+# EFBIG.
+#
+
+verify_runnable "both"
+
+log_assert "Write a file to the allowable ZFS fs size."
+
+log_note "Invoke 'largest_file' with $TESTDIR/bigfile"
+log_must $LARGEST_FILE $TESTDIR/bigfile
+
+log_pass "Successfully created a file to the maximum allowable size."
--- /dev/null	Fri Nov 22 15:20:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/large_files/setup.ksh	Fri Nov 22 15:20:52 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+disk=${DISKS%% *}
+
+default_setup $disk
--- /dev/null	Fri Nov 22 15:20:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/largest_pool/Makefile	Fri Nov 22 15:20:53 2013
@@ -0,0 +1,41 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/largest_pool
+
+PROGS = largest_pool_001_pos
+
+FILES = largest_pool.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/largest_pool/largest_pool.cfg	Fri Nov 22 15:20:53 2013
@@ -0,0 +1,43 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTVOL=testvol$$
+export VOL_PATH=/dev/zvol/dsk/${TESTPOOL2}/$TESTVOL
+export VOLSIZES=${VOLSIZES-"2pb 5pb 10pb 2eb 5eb 8eb 9eb"}
+
+# There're 3 different prompt messages while create
+# a volume that great than 1TB on 32-bit
+#       - volume size exceeds limit for this system. (happy gate)
+#       - max volume size is 1TB on 32-bit systems (s10u2)
+#       - value is too large (old)
+
+export VOL_LIMIT_KEYWORD1="1TB on 32-bit"
+export VOL_LIMIT_KEYWORD2="value is too large"
+export VOL_LIMIT_KEYWORD3="volume size exceeds limit"
--- /dev/null	Fri Nov 22 15:20:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh	Fri Nov 22 15:20:53 2013
@@ -0,0 +1,160 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/largest_pool/largest_pool.cfg
+
+# DESCRIPTION:
+#	The largest pool can be created and a dataset in that
+#	pool can be created and mounted.
+#
+# STRATEGY:
+#	create a pool which will contain a volume device.
+#	create a volume device of desired sizes.
+#	create the largest pool allowed using the volume vdev.
+#	create and mount a dataset in the largest pool.
+#	create some files in the zfs file system.
+#	do some zpool list commands and parse the output.
+
+verify_runnable "global"
+
+#
+# Parse the results of zpool & zfs creation with specified size
+#
+# $1: volume size
+#
+# return value:
+# 0 -> success
+# 1 -> failure
+#
+function parse_expected_output
+{
+	UNITS=`$ECHO $1 | $SED -e 's/^\([0-9].*\)\([a-z].\)/\2/'`
+	case "$UNITS" in
+		'mb') CHKUNIT="M" ;;
+		'gb') CHKUNIT="G" ;;
+		'tb') CHKUNIT="T" ;;
+		'pb') CHKUNIT="P" ;;
+		'eb') CHKUNIT="E" ;;
+		*) CHKUNIT="M" ;;
+	esac
+
+	log_note "Detect zpool $TESTPOOL in this test machine."
+	log_must eval "$ZPOOL list $TESTPOOL > /tmp/j.$$"
+	log_must eval "$GREP $TESTPOOL /tmp/j.$$ | \
+		$AWK '{print $2}' | $GREP $CHKUNIT"
+
+	log_note "Detect the file system in this test machine."
+	log_must eval "$DF -F zfs -h > /tmp/j.$$"
+	log_must eval "$GREP $TESTPOOL /tmp/j.$$ | \
+		$AWK '{print $2}' | $GREP $CHKUNIT"
+
+	return 0
+}
+
+#
+# Check and destroy zfs, volume & zpool remove the temporary files
+#
+function cleanup
+{
+	log_note "Start cleanup the zfs and pool"
+
+	if datasetexists $TESTPOOL/$TESTFS ; then
+		if ismounted $TESTPOOL/$TESTFS ; then
+			log_must $ZFS unmount $TESTPOOL/$TESTFS
+		fi
+		log_must $ZFS destroy $TESTPOOL/$TESTFS
+	fi
+
+	destroy_pool $TESTPOOL
+
+	datasetexists $TESTPOOL2/$TESTVOL && \
+		log_must $ZFS destroy $TESTPOOL2/$TESTVOL
+
+	destroy_pool $TESTPOOL2
+
+	$RM -f /tmp/j.* > /dev/null
+}
+
+log_assert "The largest pool can be created and a dataset in that" \
+	"pool can be created and mounted."
+
+# Set trigger. When the test case exit, cleanup is executed.
+log_onexit cleanup
+
+# -----------------------------------------------------------------------
+# volume sizes with unit designations.
+#
+# Note: specifying the number '1' as size will not give the correct
+# units for 'df'.  It must be greater than one.
+# -----------------------------------------------------------------------
+typeset str
+typeset -i ret
+for volsize in $VOLSIZES; do
+	log_note "Create a pool which will contain a volume device"
+	create_pool $TESTPOOL2 "$DISKS"
+
+	log_note "Create a volume device of desired sizes: $volsize"
+	str=$($ZFS create -sV $volsize $TESTPOOL2/$TESTVOL 2>&1)
+	ret=$?
+	if (( ret != 0 )); then
+		if [[ $($ISAINFO -b) == 32 && \
+			$str == *${VOL_LIMIT_KEYWORD1}* || \
+			$str == *${VOL_LIMIT_KEYWORD2}* || \
+			$str == *${VOL_LIMIT_KEYWORD3}* ]]
+		then
+			log_unsupported \
+				"Max volume size is 1TB on 32-bit systems."
+		else
+			log_fail "$ZFS create -sV $volsize $TESTPOOL2/$TESTVOL"
+		fi
+	fi
+
+	log_note "Create the largest pool allowed using the volume vdev"
+	create_pool $TESTPOOL "$VOL_PATH"
+
+	log_note "Create a zfs file system in the largest pool"
+	log_must $ZFS create $TESTPOOL/$TESTFS
+
+	log_note "Parse the execution result"
+	parse_expected_output $volsize
+
+	log_note "unmount this zfs file system $TESTPOOL/$TESTFS"
+	log_must $ZFS unmount $TESTPOOL/$TESTFS
+
+	log_note "Destroy zfs, volume & zpool"
+	log_must $ZFS destroy $TESTPOOL/$TESTFS
+	destroy_pool $TESTPOOL
+	log_must $ZFS destroy $TESTPOOL2/$TESTVOL
+	destroy_pool $TESTPOOL2
+done
+
+log_pass "Dateset can be created, mounted & destroy in largest pool succeeded."
--- /dev/null	Fri Nov 22 15:20:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/link_count/Makefile	Fri Nov 22 15:20:53 2013
@@ -0,0 +1,41 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/link_count
+
+PROGS = cleanup \
+	link_count_001 \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/link_count/cleanup.ksh	Fri Nov 22 15:20:54 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/link_count/link_count_001.ksh	Fri Nov 22 15:20:54 2013
@@ -0,0 +1,89 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify file link count is zero on zfs
+#
+# STRATEGY:
+# 1. Make sure this test executes on multi-processes system
+# 2. Make zero size files and remove them in the background
+# 3. Call the binary
+# 4. Make sure the files can be removed successfully
+#
+
+verify_runnable "both"
+
+log_assert "Verify file link count is zero on zfs"
+
+export ITERS=10
+export NUMFILES=10000
+
+# Detect and make sure this test must be executed on a multi-process system
+is_mp || log_fail "This test requires a multi-processor system."
+
+log_must $MKDIR -p ${TESTDIR}/tmp
+
+typeset -i i=0
+while [ $i -lt $NUMFILES ]; do
+        (( i = i + 1 ))
+        $TOUCH ${TESTDIR}/tmp/x$i > /dev/null 2>&1
+done
+
+sleep 3
+
+$RM -f ${TESTDIR}/tmp/x* >/dev/null 2>&1
+
+$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test$$ > /dev/null 2>&1 &
+PID=$!
+log_note "$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test$$ pid: $PID"
+
+i=0
+while [ $i -lt $ITERS ]; do
+	if ! $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null ; then
+		log_note "$RM_LNKCNT_ZERO_FILE completes"
+		break
+	fi
+	log_must $SLEEP 10
+	(( i = i + 1 ))
+done
+
+if $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null; then
+	log_must $KILL -TERM $PID
+	log_fail "file link count is zero"
+fi
+
+log_must $KILL -TERM $PID
+log_must $RM -f ${TESTDIR}/tmp/test$$*
+
+log_pass "Verify file link count is zero on zfs"
--- /dev/null	Fri Nov 22 15:20:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/link_count/setup.ksh	Fri Nov 22 15:20:54 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:20:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mdb/Makefile	Fri Nov 22 15:20:55 2013
@@ -0,0 +1,42 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/mdb
+
+PROGS = cleanup \
+	mdb_001_pos \
+	setup
+
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mdb/cleanup.ksh	Fri Nov 22 15:20:55 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+default_cleanup
--- /dev/null	Fri Nov 22 15:20:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mdb/mdb_001_pos.ksh	Fri Nov 22 15:20:55 2013
@@ -0,0 +1,105 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Verify that the ZFS mdb dcmds and walkers are working as expected.
+#
+# STRATEGY:
+#	1) Given a list of dcmds and walkers
+#	2) Step through each element of the list
+#	3) Verify the output by checking for "mdb:" in the output string
+#
+
+function cleanup
+{
+	$RM -f $OUTFILE
+}
+
+verify_runnable "global"
+log_onexit cleanup
+
+OUTFILE='/var/tmp/mdb-outfile'
+set -A dcmds "::walk spa" \
+	"::walk spa | ::spa " \
+	"::walk spa | ::spa -c" \
+	"::walk spa | ::spa -v" \
+	"::walk spa | ::spa_config" \
+	"::walk spa | ::spa_space" \
+	"::walk spa | ::spa_space -b" \
+	"::walk spa | ::spa_vdevs" \
+	"::walk spa | ::walk metaslab" \
+	"::walk spa | ::print struct spa spa_root_vdev | ::vdev" \
+	"::walk spa | ::print struct spa spa_root_vdev | ::vdev -re" \
+	"::dbufs" \
+	"::dbufs -n mos -o mdn -l 0 -b 0" \
+	"::dbufs | ::dbuf" \
+	"::dbuf_stats" \
+	"::abuf_find 1 2" \
+        "::walk spa | ::print -a struct spa spa_uberblock.ub_rootbp | ::blkptr" \
+        "::walk spa | ::print -a struct spa spa_dsl_pool->dp_dirty_datasets | ::walk txg_list" \
+        "::walk spa | ::walk zms_freelist"
+#
+# The commands above were supplied by the ZFS development team. The idea is to
+# do as much checking as possible without the need to hardcode addresses.
+#
+
+log_assert "Verify that the ZFS mdb dcmds and walkers are working as expected."
+
+typeset -i RET=0
+
+i=0
+while (( $i < ${#dcmds[*]} )); do
+	log_note "Verifying: '${dcmds[i]}'"
+        $ECHO "${dcmds[i]}" | $MDB -k > $OUTFILE 2>&1
+	RET=$?
+	if (( $RET != 0 )); then
+		log_fail "mdb '${dcmds[i]}' returned error $RET"
+	fi
+
+	#
+	# mdb prefixes all errors with "mdb: " so we check the output.
+	#
+	$GREP "mdb:" $OUTFILE > /dev/null 2>&1
+	RET=$?
+	if (( $RET == 0 )); then
+		$ECHO "mdb '${dcmds[i]}' contained 'mdb:'"
+		# Using $TAIL limits the number of lines in the log
+		$TAIL -100 $OUTFILE
+		log_fail "mdb walker or dcmd failed"
+	fi
+
+        ((i = i + 1))
+done
+
+log_pass "The ZFS mdb dcmds and walkers are working as expected."
--- /dev/null	Fri Nov 22 15:20:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mdb/setup.ksh	Fri Nov 22 15:20:56 2013
@@ -0,0 +1,38 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+DISK=${DISKS%% *}
+
+default_setup "$DISK"
--- /dev/null	Fri Nov 22 15:20:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/Makefile	Fri Nov 22 15:20:56 2013
@@ -0,0 +1,55 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/migration
+
+PROGS = cleanup \
+	migration_001_pos \
+	migration_002_pos \
+	migration_003_pos \
+	migration_004_pos \
+	migration_005_pos \
+	migration_006_pos \
+	migration_007_pos \
+	migration_008_pos \
+	migration_009_pos \
+	migration_010_pos \
+	migration_011_pos \
+	migration_012_pos \
+	setup
+
+FILES = migration.cfg \
+	migration.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:20:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/cleanup.ksh	Fri Nov 22 15:20:56 2013
@@ -0,0 +1,58 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.cfg
+
+verify_runnable "global"
+
+ismounted $NONZFS_TESTDIR ufs
+(( $? == 0 )) && log_must $UMOUNT -f $NONZFS_TESTDIR
+
+ismounted $TESTPOOL/$TESTFS
+[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR
+destroy_pool $TESTPOOL
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+case $DISK_COUNT in
+0)
+	log_note "No disk devices to restore"
+	;;
+1)
+	log_must cleanup_devices $ZFS_DISK
+	;;
+*)
+	log_must cleanup_devices $ZFS_DISK $NONZFS_DISK
+	;;
+esac
+
+log_pass
--- /dev/null	Fri Nov 22 15:20:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration.cfg	Fri Nov 22 15:20:57 2013
@@ -0,0 +1,66 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+set -A disk_array $(find_disks $DISKS)
+case "${#disk_array[*]}" in
+0)
+	DISK_COUNT=0
+	;;
+1)
+	# We need to repartition the single disk to two slices.
+	DISK_COUNT=1
+	ZFS_DISK=${disk_array[0]}
+	SINGLE_DISK=$ZFS_DISK
+	NONZFS_DISK=$ZFS_DISK
+	ZFSSIDE_DISK=${SINGLE_DISK}s0
+	NONZFSSIDE_DISK=${SINGLE_DISK}s1
+	;;
+*)
+	# In this case there are at least enough disks to use.
+	DISK_COUNT=2
+	ZFS_DISK=${disk_array[0]}
+	NONZFS_DISK=${disk_array[1]}
+	ZFSSIDE_DISK=${ZFS_DISK}s0
+	NONZFSSIDE_DISK=${NONZFS_DISK}s0
+	;;
+esac
+
+export DISK_COUNT ZFS_DISK NONZFS_DISK SINGLE_DISK ZFSSIDE_DISK NONZFSSIDE_DISK
+
+export TESTFILE=/etc/passwd
+export NONZFS_TESTDIR=$TESTDIR/nonzfstestdir
+tmp=`$SUM $TESTFILE`
+export SUMA=`$ECHO $tmp | $AWK '{print $1}'`
+export SUMB=`$ECHO $tmp | $AWK '{print $2}'`
+export FS_SIZE=1g
+export BNAME=`$BASENAME $TESTFILE`
+export DNAME=`$DIRNAME $TESTFILE`
--- /dev/null	Fri Nov 22 15:20:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration.kshlib	Fri Nov 22 15:20:57 2013
@@ -0,0 +1,153 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/migration/migration.cfg
+
+#
+# This function creates the test archive for migration.
+#
+# Usage:
+# prepare srcdir cmd
+#
+# Return value: 0 on success
+#		1 on failure
+#
+# Where:
+#	srcdir: is the directory where the testfile is
+#	cmd:	is the command to be executed.
+#		E.g.
+#		$TAR cf $TESTDIR/tar$$.tar
+#
+function prepare #srcdir cmd
+{
+	typeset srcdir=$1
+	typeset cmd=$2
+	typeset -i retval=0
+
+	cwd=$PWD
+	cd $srcdir
+	(( $? != 0 )) && return 1
+
+	$cmd
+	(( $? != 0 )) && return 1
+
+	cd $cwd
+	(( $? != 0 )) && return 1
+
+	return 0
+}
+
+#
+# This function executes a passed in command and then determines the chksum
+# of the resulting file.  The chksum components are checked against the ones
+# passed in to determine if they are equal.  If they are equal, 0 is returned
+# otherwise 1 is returned.
+#
+# Usage:
+# migrate destdir oldsuma oldsumb command_to_execute
+#
+# Return value: 0 on success
+#		1 on failure
+#
+# Where:
+#	destdir: is the directory where the command is to be executed on
+#	oldsuma: is the first part of the values returned by sum
+#	oldsumb: is the second part of the values returned by sum
+#	cmd: is the command to be executed;
+#		E.g.
+#		"$TAR xf $TESTDIR/tar$$.tar"
+#
+function migrate #destdir oldsuma oldsumb cmd
+{
+	typeset destdir=$1
+	typeset oldsuma=$2
+	typeset oldsumb=$3
+	typeset cmd=$4
+	typeset -i retval=0
+
+	cwd=$PWD
+	cd $destdir
+	(( $? != 0 )) && return 1
+
+	$cmd
+	(( $? != 0 )) && return 1
+
+	sumy=`$SUM ./$BNAME`
+	suma=`$ECHO $sumy | $AWK '{print $1}'`
+	sumb=`$ECHO $sumy | $AWK '{print $2}'`
+
+	if (( $oldsuma != $suma )); then
+		log_note "$SUM values are not the same"
+		retval=1
+	fi
+
+	if (( $oldsumb != $sumb )); then
+		log_note "$SUM values are not the same"
+		retval=1
+	fi
+
+	cd $cwd
+	(( $? != 0 )) && return 1
+	return $retval
+}
+
+function migrate_cpio
+{
+	typeset destdir=$1
+	typeset archive=$2
+	typeset oldsuma=$3
+	typeset oldsumb=$4
+	typeset -i retval=0
+
+	cwd=$PWD
+	cd $destdir
+	(( $? != 0 )) && return 1
+
+	$CPIO -iv < $archive
+	(( $? != 0 )) && return 1
+
+	sumy=`$SUM ./$BNAME`
+	suma=`$ECHO $sumy | $AWK '{print $1}'`
+	sumb=`$ECHO $sumy | $AWK '{print $2}'`
+
+	if (( $oldsuma != $suma )); then
+		log_note "$SUM values are not the same"
+		retval=1
+	fi
+
+	if (( $oldsumb != $sumb )); then
+		log_note "$SUM values are not the same"
+		retval=1
+	fi
+
+	cd $cwd
+	(( $? != 0 )) && return 1
+	return $retval
+}
--- /dev/null	Fri Nov 22 15:20:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_001_pos.ksh	Fri Nov 22 15:20:57 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using tar.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Tar up test file and place on a ZFS filesystem
+# 3. Extract tar contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/tar$$.tar
+	$RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using tar"
+
+log_onexit cleanup
+
+prepare $DNAME "$TAR cf $TESTDIR/tar$$.tar $BNAME"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$TAR xf $TESTDIR/tar$$.tar"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:20:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_002_pos.ksh	Fri Nov 22 15:20:58 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using tar.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Tar up test file and place on a ZFS filesystem
+# 3. Extract tar contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/tar$$.tar
+	$RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to UFS fs using tar"
+
+log_onexit cleanup
+
+prepare $DNAME "$TAR cf $TESTDIR/tar$$.tar $BNAME"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $NONZFS_TESTDIR $SUMA $SUMB "$TAR xf $TESTDIR/tar$$.tar"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to UFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
--- /dev/null	Fri Nov 22 15:20:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_003_pos.ksh	Fri Nov 22 15:20:58 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using tar.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Tar up test file and place on a UFS filesystem
+# 3. Extract tar contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $NONZFS_TESTDIR/tar$$.tar
+	$RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using tar"
+
+log_onexit cleanup
+
+prepare $DNAME "$TAR cf $NONZFS_TESTDIR/tar$$.tar $BNAME"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$TAR xvf $NONZFS_TESTDIR/tar$$.tar"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "UFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:20:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_004_pos.ksh	Fri Nov 22 15:20:58 2013
@@ -0,0 +1,73 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using cpio
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Cpio up test file and place on a ZFS filesystem
+# 3. Extract cpio contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/cpio$$.cpio
+	$RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using cpio"
+
+log_onexit cleanup
+
+cwd=$PWD
+cd $DNAME
+(( $? != 0 )) && log_untested "Could not change directory to $DNAME"
+
+$LS $BNAME | $CPIO -oc > $TESTDIR/cpio$$.cpio
+(( $? != 0 )) && log_failED "Unable to create cpio archive"
+
+cd $cwd
+(( $? != 0 )) && log_untested "Could not change directory to $cwd"
+
+migrate_cpio $TESTDIR "$TESTDIR/cpio$$.cpio" $SUMA $SUMB
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:20:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_005_pos.ksh	Fri Nov 22 15:20:59 2013
@@ -0,0 +1,73 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using cpio
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Cpio up test file and place on a ZFS filesystem
+# 3. Extract cpio contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/cpio$$.cpio
+	$RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to uFS fs using cpio"
+
+log_onexit cleanup
+
+cwd=$PWD
+cd $DNAME
+(( $? != 0 )) && log_untested "Could not change directory to $DNAME"
+
+$LS $BNAME | $CPIO -oc > $TESTDIR/cpio$$.cpio
+(( $? != 0 )) && log_failED "Unable to create cpio archive"
+
+cd $cwd
+(( $? != 0 )) && log_untested "Could not change directory to $cwd"
+
+migrate_cpio $NONZFS_TESTDIR "$TESTDIR/cpio$$.cpio" $SUMA $SUMB
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to UFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
--- /dev/null	Fri Nov 22 15:20:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_006_pos.ksh	Fri Nov 22 15:20:59 2013
@@ -0,0 +1,73 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using cpio
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Cpio up test file and place on a UFS filesystem
+# 3. Extract cpio contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $NONZFS_TESTDIR/cpio$$.cpio
+	$RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using cpio"
+
+log_onexit cleanup
+
+cwd=$PWD
+cd $DNAME
+(( $? != 0 )) && log_untested "Could not change directory to $DNAME"
+
+$LS $BNAME | $CPIO -oc > $NONZFS_TESTDIR/cpio$$.cpio
+(( $? != 0 )) && log_failED "Unable to create cpio archive"
+
+cd $cwd
+(( $? != 0 )) && log_untested "Could not change directory to $cwd"
+
+migrate_cpio $TESTDIR "$NONZFS_TESTDIR/cpio$$.cpio" $SUMA $SUMB
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:21:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_007_pos.ksh	Fri Nov 22 15:21:00 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using dd.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Dd up test file and place on a ZFS filesystem
+# 3. Extract dd contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/dd$$.dd
+	$RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using dd"
+
+log_onexit cleanup
+
+prepare $DNAME "$DD if=$BNAME obs=128k of=$TESTDIR/dd$$.dd"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$DD if=$TESTDIR/dd$$.dd obs=128k of=$BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:21:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_008_pos.ksh	Fri Nov 22 15:21:00 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using dd.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Dd up test file and place on a ZFS filesystem
+# 3. Extract dd contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/dd$$.dd
+	$RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to UFS fs using dd"
+
+log_onexit cleanup
+
+prepare $DNAME "$DD if=$BNAME obs=128k of=$TESTDIR/dd$$.dd"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $NONZFS_TESTDIR $SUMA $SUMB "$DD if=$TESTDIR/dd$$.dd obs=128k of=$BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
--- /dev/null	Fri Nov 22 15:21:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_009_pos.ksh	Fri Nov 22 15:21:00 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using dd.
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. Dd up test file and place on a UFS filesystem
+# 3. Extract dd contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/dd$$.dd
+	$RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using dd"
+
+log_onexit cleanup
+
+prepare $DNAME "$DD if=$BNAME obs=128k of=$NONZFS_TESTDIR/dd$$.dd"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$DD if=$NONZFS_TESTDIR/dd$$.dd obs=128k of=$BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:21:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_010_pos.ksh	Fri Nov 22 15:21:01 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to ZFS fs using cp
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. CP up test file and place on a ZFS filesystem
+# 3. Extract cp contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/cp$$.cp
+	$RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to ZFS fs using cp"
+
+log_onexit cleanup
+
+prepare $DNAME "$CP $BNAME $TESTDIR/cp$$.cp"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$CP $TESTDIR/cp$$.cp $BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:21:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_011_pos.ksh	Fri Nov 22 15:21:01 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from ZFS fs to UFS fs using cp
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. CP up test file and place on a ZFS filesystem
+# 3. Extract cp contents to a UFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $NONZFS_TESTDIR/cp$$.cp
+	$RM -rf $TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from ZFS fs to UFS fs using cp"
+
+log_onexit cleanup
+
+prepare $DNAME "$CP $BNAME $TESTDIR/cp$$.cp"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $NONZFS_TESTDIR $SUMA $SUMB "$CP $TESTDIR/cp$$.cp $BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "ZFS fs to UFS fs"
+
+log_pass "Successully migrated test file from ZFS fs to UFS fs".
--- /dev/null	Fri Nov 22 15:21:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/migration_012_pos.ksh	Fri Nov 22 15:21:01 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.kshlib
+
+#
+# DESCRIPTION:
+# Migrating test file from UFS fs to ZFS fs using cp
+#
+# STRATEGY:
+# 1. Calculate chksum of testfile
+# 2. CP up test file and place on a UFS filesystem
+# 3. Extract cp contents to a ZFS file system
+# 4. Calculate chksum of extracted file
+# 5. Compare old and new chksums.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/cp$$.cp
+	$RM -rf $NONZFS_TESTDIR/$BNAME
+}
+
+log_assert "Migrating test file from UFS fs to ZFS fs using cp"
+
+log_onexit cleanup
+
+prepare $DNAME "$CP $BNAME $NONZFS_TESTDIR/cp$$.cp"
+(( $? != 0 )) && log_fail "Unable to create src archive"
+
+migrate $TESTDIR $SUMA $SUMB "$CP $NONZFS_TESTDIR/cp$$.cp $BNAME"
+(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \
+    "UFS fs to ZFS fs"
+
+log_pass "Successully migrated test file from UFS fs to ZFS fs".
--- /dev/null	Fri Nov 22 15:21:02 2013
+++ new/usr/src/test/zfs-tests/tests/functional/migration/setup.ksh	Fri Nov 22 15:21:02 2013
@@ -0,0 +1,69 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/migration/migration.cfg
+
+verify_runnable "global"
+
+case $DISK_COUNT in
+0)
+	log_untested "Need at least 1 disk device for test"
+	;;
+1)
+	log_note "Partitioning a single disk ($SINGLE_DISK)"
+	;;
+*)
+	log_note "Partitioning disks ($ZFS_DISK $NONZFS_DISK)"
+	;;
+esac
+
+set_partition ${ZFSSIDE_DISK##*s} "" $FS_SIZE $ZFS_DISK
+set_partition ${NONZFSSIDE_DISK##*s} "" $FS_SIZE $NONZFS_DISK
+
+create_pool $TESTPOOL "$ZFSSIDE_DISK"
+
+$RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
+$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+
+log_must $ZFS create $TESTPOOL/$TESTFS
+log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+$RM -rf $NONZFS_TESTDIR  || log_unresolved Could not remove $NONZFS_TESTDIR
+$MKDIR -p $NONZFS_TESTDIR || log_unresolved Could not create $NONZFS_TESTDIR
+
+$ECHO "y" | $NEWFS -v /dev/rdsk/$NONZFSSIDE_DISK
+(( $? != 0 )) &&
+	log_untested "Unable to setup a UFS file system"
+
+log_must $MOUNT /dev/dsk/$NONZFSSIDE_DISK $NONZFS_TESTDIR
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:02 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mmap/Makefile	Fri Nov 22 15:21:02 2013
@@ -0,0 +1,42 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/mmap
+
+PROGS = cleanup \
+	mmap_read_001_pos \
+	mmap_write_001_pos \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mmap/cleanup.ksh	Fri Nov 22 15:21:03 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mmap/mmap_read_001_pos.ksh	Fri Nov 22 15:21:03 2013
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# read()s from mmap()'ed file contain correct data.
+#
+# STRATEGY:
+# 1. Create a pool & dataset
+# 2. Call readmmap binary
+# 3. unmount this file system
+# 4. Verify the integrity of this pool & dateset
+#
+
+verify_runnable "global"
+
+log_assert "read()s from mmap()'ed file contain correct data."
+
+log_must $CHMOD 777 $TESTDIR
+log_must $READMMAP $TESTDIR/test-read-file
+log_must $ZFS unmount $TESTPOOL/$TESTFS
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass "read(2) calls from a mmap(2)'ed file succeeded."
--- /dev/null	Fri Nov 22 15:21:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mmap/mmap_write_001_pos.ksh	Fri Nov 22 15:21:03 2013
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Writing to a file and mmaping that file at the
+# same time does not result in a deadlock.
+#
+# STRATEGY:
+# 1. Make sure this test executes on multi-processes system.
+# 2. Call mmapwrite binary.
+# 3. wait 30s and make sure the test file existed.
+#
+
+verify_runnable "both"
+
+log_assert "write()s to a file and mmap() that file at the same time does not "\
+	"result in a deadlock."
+
+# Detect and make sure this test must be executed on a multi-process system
+is_mp || log_fail "This test requires a multi-processor system."
+
+log_must $CHMOD 777 $TESTDIR
+$MMAPWRITE $TESTDIR/test-write-file &
+PID_MMAPWRITE=$!
+log_note "$MMAPWRITE $TESTDIR/test-write-file pid: $PID_MMAPWRITE"
+log_must $SLEEP 30
+
+log_must $KILL -9 $PID_MMAPWRITE
+log_must $LS -l $TESTDIR/test-write-file
+
+log_pass "write(2) a mmap(2)'ing file succeeded."
--- /dev/null	Fri Nov 22 15:21:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mmap/setup.ksh	Fri Nov 22 15:21:04 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:21:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mount/Makefile	Fri Nov 22 15:21:04 2013
@@ -0,0 +1,42 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/mount
+
+PROGS = cleanup \
+	umount_001 \
+	umountall_001 \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mount/cleanup.ksh	Fri Nov 22 15:21:04 2013
@@ -0,0 +1,38 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+log_must destroy_pool $TESTPOOL
+
+for dir in $TESTDIRS; do
+	$RM -rf $dir
+done
--- /dev/null	Fri Nov 22 15:21:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mount/setup.ksh	Fri Nov 22 15:21:04 2013
@@ -0,0 +1,48 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+create_pool $TESTPOOL "$DISK"
+
+for i in 1 2 3; do
+	dir=$TESTDIR.$i
+	fs=$TESTPOOL/$TESTFS.$i
+
+	log_must $ZFS create $fs
+	log_must $MKDIR -p $dir
+	log_must $ZFS set mountpoint=$dir $fs
+
+	log_must mounted $fs
+done
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mount/umount_001.ksh	Fri Nov 22 15:21:05 2013
@@ -0,0 +1,54 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# zfs mount and unmount commands should mount and unmount existing
+# file systems.
+#
+# STRATEGY:
+# 1. Call zfs mount command
+# 2. Make sure the file systems were mounted
+# 3. Call zfs unmount command
+# 4. Make sure the file systems were unmounted
+#
+
+for fs in 1 2 3; do
+	log_must mounted $TESTDIR.$fs
+	log_must $ZFS umount $TESTPOOL/$TESTFS.$fs
+	log_must unmounted $TESTDIR.$fs
+	log_must $ZFS mount $TESTPOOL/$TESTFS.$fs
+	log_must mounted $TESTDIR.$fs
+done
+
+log_pass "All file systems are unmounted"
--- /dev/null	Fri Nov 22 15:21:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mount/umountall_001.ksh	Fri Nov 22 15:21:05 2013
@@ -0,0 +1,59 @@
+#!/usr/bin/ksh -p
+
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# There are myriad problems associated with trying to test umountall in a way
+# that works reliable across different systems. Some filesystems won't unmount
+# because they're busy. Some won't remount because they were legacy mounts in
+# the first place. etc...
+# Make a best approximation by calling umountall with the -n option, and verify
+# that the list of things it would try to unmout makes sense.
+#
+# STRATEGY:
+# 1. Make a list of file systems umountall is known to ignore.
+# 2. Append all ZFS file systems on this system.
+# 3. Run umountall -n and verify the file systems it reports are in the list.
+#
+
+log_must $ZFS mount -a
+for fs in 1 2 3 ; do
+	log_must mounted $TESTPOOL/$TESTFS.$fs
+done
+
+# This is the list we check the output of umountall -n against. We seed it
+# with these values because umountall will ignore them, and they're possible
+# (though most are improbable) ZFS filesystem mountpoints.
+zfs_list="/ /lib /sbin /tmp /usr /var /var/adm /var/run"
+
+# Append our ZFS filesystems to the list, not worrying about duplicates.
+for fs in $($MOUNT -p | $AWK '{if ($4 == "zfs") print $3}'); do
+	zfs_list="$zfs_list $fs"
+done
+
+fs=''
+for fs in $($UMOUNTALL -n -F zfs 2>&1 | $AWK '{print $2}'); do
+	for i in $zfs_list; do
+		[[ $fs = $i ]] && continue 2
+	done
+	log_fail "umountall -n -F zfs tried to unmount $fs"
+done
+[[ -n $fs ]] || log_fail "umountall -n -F zfs produced no output"
+
+log_pass "All ZFS file systems would have been unmounted"
--- /dev/null	Fri Nov 22 15:21:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mv_files/Makefile	Fri Nov 22 15:21:05 2013
@@ -0,0 +1,45 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/mv_files
+
+PROGS = cleanup \
+	mv_files_001_pos \
+	mv_files_002_pos \
+	setup
+
+FILES = mv_files.cfg \
+	mv_files_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mv_files/cleanup.ksh	Fri Nov 22 15:21:06 2013
@@ -0,0 +1,48 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+verify_runnable "global"
+
+[[ -f /var/tmp/exitsZero.ksh ]] && \
+	log_must $RM -f /var/tmp/exitsZero.ksh
+[[ -f /var/tmp/testbackgprocs.ksh ]] && \
+	log_must $RM -f /var/tmp/testbackgprocs.ksh
+
+ismounted $TESTPOOL/$TESTFS_TGT
+(( $? == 0 )) && log_must $ZFS umount $TESTPOOL/$TESTFS_TGT
+log_must $ZFS destroy $TESTPOOL/$TESTFS_TGT
+
+[[ -d $TESTDIR_TGT ]] && log_must $RM -rf $TESTDIR_TGT
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mv_files/mv_files.cfg	Fri Nov 22 15:21:06 2013
@@ -0,0 +1,43 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export DISK=${DISKS%% *}
+
+export TESTFILE=testfile
+
+export TESTDIR_TGT=${TEST_BASE_DIR%%/}/testdir_tgt
+export TESTFS_TGT=testzfs_tgt
+export OLDDIR=$TESTDIR/olddir
+export NEWDIR_IN_FS=$TESTDIR/newdir
+export NEWDIR_ACROSS_FS=$TESTDIR_TGT/newdir
+
+export MVNUMFILES=2000 # <number of files to start>
+export MVNUMINCR=1000  # <number of files to be increased to>
+export GANGPIDS=50 	# <number of limit for parallel background running process>
--- /dev/null	Fri Nov 22 15:21:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mv_files/mv_files_001_pos.ksh	Fri Nov 22 15:21:06 2013
@@ -0,0 +1,69 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+#
+# DESCRIPTION:
+# Doing a 'mv' of a large amount of files between two directories
+# within a zfs filesystem works without errors.
+#
+# STRATEGY:
+#
+# 1. create a pool and a zfs filesystem
+# 2. create two directories within the filesystem
+# 3. create a large number of files within a directory
+# 4. Move files from one directory to another and back again
+# 5. validate file number
+# 6. increase the number of files to $MVNUMFILES + $MVNUMINCR
+# 7. repeat steps 3,4,5,6 above
+# 8. verify the data integrity
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	PIDS=""
+	$RM -f $OLDDIR/* >/dev/null 2>&1
+	$RM -f $NEWDIR_IN_FS/* >/dev/null 2>&1
+}
+
+log_assert "Doing a 'mv' of a large amount of files within a zfs filesystem" \
+	    "works without errors."
+
+log_onexit cleanup
+
+mv_test $OLDDIR $NEWDIR_IN_FS
+(($? != 0 )) &&  log_fail "'mv' test failed to complete."
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mv_files/mv_files_002_pos.ksh	Fri Nov 22 15:21:07 2013
@@ -0,0 +1,71 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+#
+# DESCRIPTION:
+# Doing a 'mv' of a large amount of files between two directories across
+# two zfs filesystems works without errors.
+#
+# STRATEGY:
+#
+# 1. create a pool and two zfs filesystems
+# 2. create a directory in each filesystem
+# 3. create a large number of files in a directory of a filesystem
+# 4. Move files from the directory to another directory in another
+# filesystem and back again
+# 5. validate file number
+# 6. increase the number of files to $MVNUMFILES + $MVNUMINCR
+# 7. repeat steps 3,4,5,6 above
+# 8. verify the data integrity
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	PIDS=""
+	$RM -f $OLDDIR/* >/dev/null 2>&1
+	$RM -f $NEWDIR_ACROSS_FS/* >/dev/null 2>&1
+}
+
+log_assert "Doing a 'mv' of a large amount of files across two zfs filesystems" \
+	    "works without errors."
+
+log_onexit cleanup
+
+mv_test $OLDDIR $NEWDIR_ACROSS_FS
+(($? != 0 )) && \
+        log_fail "'mv' test failed to complete."
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib	Fri Nov 22 15:21:07 2013
@@ -0,0 +1,217 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/mv_files/mv_files.cfg
+
+#
+# Determine whether this version of the ksh being
+# executed has a bug where the limit of background
+# processes of 25.
+#
+function check_bg_procs_limit_num
+{
+$ECHO "#!/usr/bin/ksh" > /var/tmp/exitsZero.ksh
+$ECHO  "exit 0" >> /var/tmp/exitsZero.ksh
+$CHMOD 777 /var/tmp/exitsZero.ksh
+
+$CAT <<EOF > /var/tmp/testbackgprocs.ksh
+#!/usr/bin/ksh
+#
+# exitsZero.ksh is a one line script
+# that exit with status of "0"
+#
+
+PIDS=""
+typeset -i i=1
+while [ \$i -le 50 ]
+do
+	/var/tmp/exitsZero.ksh &
+        PIDS="\$PIDS \$!"
+        (( i = i + 1 ))
+done
+
+\$SLEEP 1
+
+for pid in \$PIDS
+do
+	\$WAIT \$pid
+        (( \$? == 127 )) && exit 1
+done
+exit 0
+EOF
+
+$KSH /var/tmp/testbackgprocs.ksh
+if [[ $? -eq 1 ]]; then
+#
+# Current ksh being executed has a limit
+# of 25 background processes.
+#
+	return 1
+else
+        return 0
+fi
+}
+
+function init_setup
+{
+
+	typeset disklist=$1
+
+        create_pool $TESTPOOL "$disklist"
+
+	if ! is_global_zone ; then
+		reexport_pool
+	fi
+
+        $RM -rf $TESTDIR  || log_unresolved Could not remove $TESTDIR
+        $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR
+
+        $RM -rf $TESTDIR_TGT  || log_unresolved Could not remove $TESTDIR_TGT
+        $MKDIR -p $TESTDIR_TGT || log_unresolved Could not create $TESTDIR_TGT
+
+        log_must $ZFS create $TESTPOOL/$TESTFS
+        log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+
+        log_must $ZFS create $TESTPOOL/$TESTFS_TGT
+        log_must $ZFS set mountpoint=$TESTDIR_TGT $TESTPOOL/$TESTFS_TGT
+
+        $MKDIR -p $OLDDIR || log_unresolved Could not create $OLDDIR
+        $MKDIR -p $NEWDIR_IN_FS || log_unresolved Could not create $NEWDIR_IN_FS
+        $MKDIR -p $NEWDIR_ACROSS_FS || log_unresolved Could not create $NEWDIR_ACROSS_FS
+
+}
+
+function wait_pid
+{
+	for pid in $1
+	do
+		$PS -e | $GREP $pid >/dev/null 2>&1
+		(( $? == 0 )) && $WAIT $pid
+        done
+}
+
+
+#
+# Generate given number files in a
+# directory of zfs file system
+# $1 - the directory holds the generated files
+# $2 - number of to-be-generated files
+#
+
+function generate_files
+{
+	typeset -i count
+        typeset -i proc_num=0
+
+	if (( $2 == $MVNUMFILES )); then
+		count=1
+	else
+		count=$MVNUMFILES+1
+	fi
+
+        while (( count <= $2 ))
+        do
+                $CP /etc/passwd $1/file_$count \
+                         > /dev/null 2>&1 &
+
+                PIDS="$PIDS $!"
+
+                proc_num=`$ECHO $PIDS | $WC -w`
+                if (( proc_num >= GANGPIDS )); then
+                        wait_pid "$PIDS"
+                        proc_num=0
+                        PIDS=""
+                fi
+
+               (( count = count + 1 ))
+        done
+
+}
+
+#
+# Move given number files from one directory to
+# another directory in parallel
+# $1 - source directory
+# $2 - target directory
+#
+function mv_files
+{
+
+        $FIND $1 -type f -print | xargs -i \
+                $MV {} $2 > /dev/null 2>&1
+}
+
+#
+# Count the files number after moving, and
+# compare it with the original number
+# $1 - directory that to be operated
+# $2 - original files number
+#
+function count_files
+{
+        typeset -i file_num
+        file_num=`$FIND $1  -type f -print | \
+                wc -l`
+        (( file_num != $2 )) && \
+                log_fail "The file number of target directory"\
+                        "$2 is not equal to that of the source "\
+                        "directory $1"
+
+}
+
+#
+# Running the 'mv' test
+# $1 - old directory
+# $2 - new directory
+#
+function mv_test
+{
+        typeset old=$1
+        typeset new=$2
+
+        typeset -i inc_num=$(( MVNUMFILES + MVNUMINCR ))
+        typeset -i num=0
+
+        for num in $MVNUMFILES $inc_num
+        do
+                generate_files $old $num
+
+                mv_files $old $new
+                count_files $new $num
+
+                mv_files $new $old
+                count_files $old $num
+        done
+
+	typeset dir=$(get_device_dir $DISKS)
+        verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+        return 0
+}
--- /dev/null	Fri Nov 22 15:21:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/mv_files/setup.ksh	Fri Nov 22 15:21:07 2013
@@ -0,0 +1,47 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/mv_files/mv_files_common.kshlib
+
+verify_runnable "global"
+
+check_bg_procs_limit_num
+if [[ $? -ne 0 ]]; then
+	log_note "ksh background process limit number is 25"
+	export GANGPIDS=25
+fi
+
+export PIDS=""
+
+init_setup $DISK
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/nestedfs/Makefile	Fri Nov 22 15:21:07 2013
@@ -0,0 +1,41 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/nestedfs
+
+PROGS = cleanup \
+	nestedfs_001_pos \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/nestedfs/cleanup.ksh	Fri Nov 22 15:21:08 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
--- /dev/null	Fri Nov 22 15:21:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/nestedfs/nestedfs_001_pos.ksh	Fri Nov 22 15:21:08 2013
@@ -0,0 +1,59 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Given a pool create a nested file system and a ZFS file system
+# in the nested file system. Populate the file system.
+#
+# As a sub-assertion, the test verifies that a nested file system with
+# a mounted file system cannot be destroyed.
+#
+# STRATEGY:
+# 1. Create a file in the new mountpoint
+# 2. Unmount the new mountpoint
+# 3. Show a nested file system with file systems cannot be destroyed
+#
+
+verify_runnable "both"
+
+log_assert "Verify a nested file system can be created/destroyed."
+
+log_must $FILE_WRITE -o create -f $TESTDIR1/file -b 8192 -c 600 -d 0
+log_must $ZFS unmount $TESTDIR1
+
+log_note "Verify that a nested file system with a mounted file system "\
+    "cannot be destroyed."
+log_mustnot $ZFS destroy $TESTPOOL/$TESTCTR
+
+log_pass "A nested file system was successfully populated."
--- /dev/null	Fri Nov 22 15:21:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/nestedfs/setup.ksh	Fri Nov 22 15:21:09 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_setup $DISK
--- /dev/null	Fri Nov 22 15:21:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/no_space/Makefile	Fri Nov 22 15:21:09 2013
@@ -0,0 +1,43 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/no_space
+
+PROGS = cleanup \
+	enospc_001_pos \
+	setup
+
+FILES = enospc.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/no_space/cleanup.ksh	Fri Nov 22 15:21:09 2013
@@ -0,0 +1,49 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/no_space/enospc.cfg
+
+verify_runnable "global"
+
+DISK=${DISKS%% *}
+
+ismounted "$TESTPOOL/$TESTFS"
+(( $? == 0 )) && \
+        log_must $ZFS umount $TESTDIR
+
+destroy_pool $TESTPOOL
+#
+# Remove 100mb partition.
+#
+create_pool dummy$$ "$DISK"
+destroy_pool dummy$$
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/no_space/enospc.cfg	Fri Nov 22 15:21:10 2013
@@ -0,0 +1,38 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE0=testfile0.$$
+export TESTFILE1=testfile1.$$
+
+export SIZE=100mb
+export ENOSPC=28
+export BLOCKSZ=8192
+export NUM_WRITES=65536
+export DATA=0
--- /dev/null	Fri Nov 22 15:21:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/no_space/enospc_001_pos.ksh	Fri Nov 22 15:21:10 2013
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/no_space/enospc.cfg
+
+#
+# DESCRIPTION:
+# ENOSPC is returned on an attempt to write a second file
+# to a file system after a first file was written that terminated
+# with ENOSPC on a cleanly initialized file system.
+#
+# STRATEGY:
+# 1. Write a file until the file system is full.
+# 2. Ensure that ENOSPC is returned.
+# 3. Write a second file while the file system remains full.
+# 4. Verify the return code is ENOSPC.
+#
+
+verify_runnable "both"
+
+log_assert "ENOSPC is returned when file system is full."
+log_must $ZFS set compression=off $TESTPOOL/$TESTFS
+
+log_note "Writing file: $TESTFILE0 until ENOSPC."
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+ret=$?
+
+(( $ret != $ENOSPC )) && \
+    log_fail "$TESTFILE0 returned: $ret rather than ENOSPC."
+
+log_note "Write another file: $TESTFILE1 but expect ENOSPC."
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+ret=$?
+
+(( $ret != $ENOSPC )) && \
+    log_fail "$TESTFILE1 returned: $ret rather than ENOSPC."
+
+log_pass "ENOSPC returned as expected."
--- /dev/null	Fri Nov 22 15:21:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/no_space/setup.ksh	Fri Nov 22 15:21:10 2013
@@ -0,0 +1,45 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/no_space/enospc.cfg
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+DISK=${DISKS%% *}
+
+log_must set_partition 0 "" $SIZE $DISK
+
+default_setup $DISK"s0"
--- /dev/null	Fri Nov 22 15:21:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/online_offline/Makefile	Fri Nov 22 15:21:11 2013
@@ -0,0 +1,45 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/online_offline
+
+PROGS = cleanup \
+	online_offline_001_pos \
+	online_offline_002_neg \
+	online_offline_003_neg \
+	setup
+
+FILES = online_offline.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/online_offline/cleanup.ksh	Fri Nov 22 15:21:11 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/online_offline/online_offline.cfg	Fri Nov 22 15:21:11 2013
@@ -0,0 +1,38 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile.$$
+export TESTFILE1=testfile1.$$
+export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb
+export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"}
+export HOLES_SEED=${HOLES_SEED-""}
+export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""}
+export HOLES_COUNT=${HOLES_COUNT-"16384"}	   # FILESIZE/BLKSIZE/8
+export STF_TIMEOUT=3600
--- /dev/null	Fri Nov 22 15:21:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/online_offline/online_offline_001_pos.ksh	Fri Nov 22 15:21:12 2013
@@ -0,0 +1,144 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/online_offline/online_offline.cfg
+
+#
+# DESCRIPTION:
+# 	Turning a disk offline and back online during I/O completes.
+#
+# STRATEGY:
+#	1. Create a mirror and start some random I/O
+#	2. For each disk in the mirror, set it offline and online
+#	3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+function cleanup
+{
+	#
+	# Ensure we don't leave disks in the offline state
+	#
+	for disk in $DISKLIST; do
+		log_must $ZPOOL online $TESTPOOL $disk
+		check_state $TESTPOOL $disk "online"
+		if [[ $? != 0 ]]; then
+			log_fail "Unable to online $disk"
+		fi
+
+	done
+
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Turning a disk offline and back online during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+typeset child_pid=""
+
+typeset -i iters=2
+typeset -i index=0
+
+i=0
+while [[ $i -lt $iters ]]; do
+	log_note "Invoking $FILE_TRUNC with: $options_display"
+	$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+	typeset pid=$!
+
+	$SLEEP 1
+	if ! $PS -p $pid > /dev/null 2>&1; then
+		log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+	fi
+
+	child_pids="$child_pids $pid"
+	((i = i + 1))
+done
+
+for disk in $DISKLIST; do
+	#
+	# Allow some common data to reach each side of the mirror.
+	#
+	$SLEEP 30
+
+        i=0
+        while [[ $i -lt $iters ]]; do
+		log_must $ZPOOL offline $TESTPOOL $disk
+		check_state $TESTPOOL $disk "offline"
+                if [[ $? != 0 ]]; then
+                        log_fail "$disk of $TESTPOOL is not offline."
+                fi
+
+                (( i = i + 1 ))
+        done
+
+	#
+	# Sleep to allow the two sides to get out of sync
+	#
+	$SLEEP 60
+
+        log_must $ZPOOL online $TESTPOOL $disk
+        check_state $TESTPOOL $disk "online"
+        if [[ $? != 0 ]]; then
+                log_fail "$disk of $TESTPOOL did not match online state"
+        fi
+done
+
+for wait_pid in $child_pids
+do
+	$KILL $wait_pid
+done
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/online_offline/online_offline_002_neg.ksh	Fri Nov 22 15:21:12 2013
@@ -0,0 +1,141 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/online_offline/online_offline.cfg
+
+#
+# DESCRIPTION:
+# 	Turning both disks offline should fail.
+#
+# STRATEGY:
+#	1. Create a mirror and start some random I/O
+#	2. For each disk in the mirror, set them offline sequentially.
+#	3. Only one disk can be offline at any one time.
+#	4. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+function cleanup
+{
+	if [[ -n "$child_pids" ]]; then
+		for wait_pid in $child_pids
+		do
+		        $KILL $wait_pid
+		done
+	fi
+
+	#
+	# Ensure we don't leave disks in the offline state
+	#
+	for disk in $DISKLIST; do
+		log_must $ZPOOL online $TESTPOOL $disk
+		check_state $TESTPOOL $disk "online"
+		if [[ $? != 0 ]]; then
+			log_fail "Unable to online $disk"
+		fi
+
+	done
+
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Turning both disks offline should fail."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pid=""
+
+typeset -i iters=2
+typeset -i index=0
+
+i=0
+while [[ $i -lt $iters ]]; do
+	log_note "Invoking $FILE_TRUNC with: $options_display"
+	$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+	typeset pid=$!
+
+	$SLEEP 1
+	if ! $PS -p $pid > /dev/null 2>&1; then
+		log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+	fi
+
+	child_pids="$child_pids $pid"
+	((i = i + 1))
+done
+
+set -A disk "" $DISKLIST
+
+log_must $ZPOOL offline $TESTPOOL ${disk[1]}
+
+$SLEEP 60
+
+for wait_pid in $child_pids
+do
+	$KILL $wait_pid
+done
+child_pids=""
+
+i=1
+while [[ $i != ${#disk[*]} ]]; do
+	log_must $ZPOOL online $TESTPOOL ${disk[$i]}
+	check_state $TESTPOOL ${disk[$i]} "online"
+	if [[ $? != 0 ]]; then
+		log_fail "${disk[$i]} of $TESTPOOL did not match online state"
+	fi
+
+	((i = i + 1))
+done
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/online_offline/online_offline_003_neg.ksh	Fri Nov 22 15:21:12 2013
@@ -0,0 +1,133 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/online_offline/online_offline.cfg
+
+#
+# DESCRIPTION:
+# 	Turning both disks offline should fail.
+#
+# STRATEGY:
+#	1. Create a multidisk stripe and start some random I/O
+#	2. For two disks in the stripe, set them offline sequentially.
+#	3. Zpool offline should fail in both cases.
+#	4. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+DISKLIST=$(get_disklist $TESTPOOL)
+
+function cleanup
+{
+	if [[ -n "$child_pids" ]]; then
+		for wait_pid in $child_pids
+		do
+		        $KILL $wait_pid
+		done
+	fi
+
+	if poolexists $TESTPOOL1; then
+		destroy_pool $TESTPOOL1
+	fi
+
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Turning a disk offline and back online during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pid=""
+
+typeset -i iters=2
+typeset -i index=0
+
+specials_list=""
+i=0
+while [[ $i != 3 ]]; do
+	$MKFILE 100m $TESTDIR/$TESTFILE1.$i
+	specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+
+	((i = i + 1))
+done
+
+create_pool $TESTPOOL1 $specials_list
+log_must $ZFS create $TESTPOOL1/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+i=0
+while [[ $i -lt $iters ]]; do
+	log_note "Invoking $FILE_TRUNC with: $options_display"
+	$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+	typeset pid=$!
+
+	$SLEEP 1
+	if ! $PS -p $pid > /dev/null 2>&1; then
+		log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+	fi
+
+	child_pids="$child_pids $pid"
+	((i = i + 1))
+done
+
+set -A disk "" $specials_list
+
+log_mustnot $ZPOOL offline $TESTPOOL1 ${disk[1]}
+log_mustnot $ZPOOL offline $TESTPOOL1 ${disk[2]}
+
+$SLEEP 60
+
+for wait_pid in $child_pids
+do
+	$KILL $wait_pid
+done
+child_pids=""
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/online_offline/setup.ksh	Fri Nov 22 15:21:13 2013
@@ -0,0 +1,47 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+index=`expr $RANDOM % 2`
+case $index in
+0)	log_note "Pool Type: Mirror"
+	default_mirror_setup $DISKS
+	;;
+1)	log_note "Pool Type: RAID-Z"
+	default_raidz_setup $DISKS
+	;;
+esac
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/pool_names/Makefile	Fri Nov 22 15:21:13 2013
@@ -0,0 +1,40 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/pool_names
+
+PROGS = pool_names_001_pos \
+	pool_names_002_neg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/pool_names/pool_names_001_pos.ksh	Fri Nov 22 15:21:14 2013
@@ -0,0 +1,115 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Test that a set of valid names can be used to create pools. Further
+# verify that the created pools can be destroyed.
+#
+# STRATEGY:
+# 1) For each valid character in the character set, try to create
+# and destroy the pool.
+# 2) Given a list of valid pool names, try to create and destroy
+# pools with the given names.
+#
+
+verify_runnable "global"
+
+log_assert "Ensure that pool names can use the ASCII subset of UTF-8"
+
+function cleanup
+{
+	if [[ -n $name ]] && poolexists $name ; then
+		log_must $ZPOOL destroy $name
+	fi
+
+	if [[ -d $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR
+	fi
+
+}
+
+log_onexit cleanup
+
+DISK=${DISKS%% *}
+if [[ ! -e $TESTDIR ]]; then
+	log_must $MKDIR $TESTDIR
+fi
+
+log_note "Ensure letters of the alphabet are allowable"
+
+typeset name=""
+
+for name in A B C D E F G H I J K L M \
+    N O P Q R S T U V W X Y Z \
+    a b c d e f g h i j k l m \
+    n o p q r s t u v w x y z
+do
+	log_must $ZPOOL create -m $TESTDIR $name $DISK
+	if ! poolexists $name; then
+		log_fail "Could not create a pool called '$name'"
+	fi
+
+	log_must $ZPOOL destroy $name
+done
+
+log_note "Ensure a variety of unusual names passes"
+
+name=""
+
+for name in "a.............................." "a_" "a-" "a:" \
+    "a." "a123456" "bc0t0d0" "m1rr0r_p00l" "ra1dz_p00l" \
+    "araidz2" "C0t2d0" "cc0t0" "raid2:-_." "mirr_:-." \
+    "m1rr0r-p00l" "ra1dz-p00l" "spar3_p00l" \
+    "spar3-p00l" "hiddenmirrorpool" "hiddenraidzpool" \
+    "hiddensparepool"
+do
+	log_must $ZPOOL create -m $TESTDIR $name $DISK
+	if ! poolexists $name; then
+		log_fail "Could not create a pool called '$name'"
+	fi
+
+	#
+	# Since the naming convention applies to datasets too,
+	# create datasets with the same names as above.
+	#
+	log_must $ZFS create $name/$name
+	log_must $ZFS snapshot $name/$name@$name
+	log_must $ZFS clone $name/$name@$name $name/clone_$name
+	log_must $ZFS create -V 150m $name/$name/$name
+
+	log_must $ZPOOL destroy $name
+done
+
+log_pass "Valid pool names were accepted correctly."
--- /dev/null	Fri Nov 22 15:21:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/pool_names/pool_names_002_neg.ksh	Fri Nov 22 15:21:14 2013
@@ -0,0 +1,131 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Ensure that a set of invalid names cannot be used to create pools.
+#
+# STRATEGY:
+# 1) For each invalid character in the character set, try to create
+# and destroy the pool. Verify it fails.
+# 2) Given a list of invalid pool names, ensure the pools are not
+# created.
+#
+
+verify_runnable "global"
+
+log_assert "Ensure that a set of invalid names cannot be used to create pools."
+
+# Global variable use to cleanup failures.
+POOLNAME=""
+
+function cleanup
+{
+	if poolexists $POOLNAME; then
+		log_must $ZPOOL destroy $POOLNAME
+	fi
+
+	if [[ -d $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR
+	fi
+}
+
+log_onexit cleanup
+
+typeset exclude=`eval $ECHO \"'(${KEEP})'\"`
+for pool in $($ZPOOL list -H -o name | \
+	$EGREP -v "$exclude" | \
+	$GREP -v "$TESTPOOL" | \
+	$EGREP -v "$NO_POOLS"); do
+	log_must $ZPOOL destroy $pool
+done
+
+DISK=${DISKS%% *}
+if [[ ! -e $TESTDIR ]]; then
+        log_must $MKDIR $TESTDIR
+fi
+
+log_note "Ensure invalid characters fail"
+for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \
+    "\*" "+" "," "-" "\." "/" "\\" \
+    0 1 2 3 4 5 6 7 8 9 \
+    ":" ";" "<" "=" ">" "\?" "@" \
+    "[" "]" "^" "_" "\`" "{" "|" "}" "~"
+do
+	log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK
+        if poolexists $POOLNAME; then
+                log_fail "Unexpectedly created pool: '$POOLNAME'"
+        fi
+
+	log_mustnot $ZPOOL destroy $POOLNAME
+done
+
+log_note "Check that invalid octal values fail"
+for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \
+    "\010" "\011" "\012" "\013" "\014" "\015" "\017" \
+    "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \
+    "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \
+    "\040" "\177"
+do
+	POOLNAME=`eval "echo x | tr 'x' '$oct'"`
+	log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK
+        if poolexists $POOLNAME; then
+                log_fail "Unexpectedly created pool: '$POOLNAME'"
+        fi
+
+	log_mustnot $ZPOOL destroy $POOLNAME
+done
+
+log_note "Verify invalid pool names fail"
+set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \
+    "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \
+    "2222222222222222222" "mirror_pool" "raidz_pool" \
+    "mirror-pool" "raidz-pool" "spare" "spare_pool" \
+    "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd"
+if verify_slog_support ; then
+	POOLNAME[${#POOLNAME[@]}]='log'
+fi
+typeset -i i=0
+while ((i < ${#POOLNAME[@]})); do
+	log_mustnot $ZPOOL create -m $TESTDIR ${POOLNAME[$i]} $DISK
+        if poolexists ${POOLNAME[$i]}; then
+                log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'"
+        fi
+
+	log_mustnot $ZPOOL destroy ${POOLNAME[$i]}
+
+	((i += 1))
+done
+
+log_pass "Invalid names and characters were caught correctly"
--- /dev/null	Fri Nov 22 15:21:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/poolversion/Makefile	Fri Nov 22 15:21:14 2013
@@ -0,0 +1,42 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/poolversion
+
+PROGS = cleanup \
+	poolversion_001_pos \
+	poolversion_002_pos \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/poolversion/cleanup.ksh	Fri Nov 22 15:21:15 2013
@@ -0,0 +1,42 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+log_must $ZPOOL destroy $TESTPOOL
+log_must $ZPOOL destroy $TESTPOOL2
+
+log_must $RM /tmp/zpool_version_1.dat
+log_must $RM /tmp/zpool2_version_1.dat
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/poolversion/poolversion_001_pos.ksh	Fri Nov 22 15:21:15 2013
@@ -0,0 +1,58 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool set version can upgrade a pool
+#
+# STRATEGY:
+# 1. Taking a version 1 pool
+# 2. For all known versions, set the version of the pool using zpool set
+# 3. Verify that pools version
+#
+
+verify_runnable "global"
+log_assert "zpool set version can upgrade a pool"
+for version in 1 2 3 4 5 6 7 8
+do
+	log_must $ZPOOL set version=$version $TESTPOOL
+	ACTUAL=$($ZPOOL get version $TESTPOOL | $GREP version \
+		| $AWK '{print $3}')
+	if [ "$ACTUAL" != "$version" ]
+	then
+		log_fail "v. $ACTUAL set for $TESTPOOL, expected v. $version!"
+	fi
+done
+
+log_pass "zpool set version can upgrade a pool"
--- /dev/null	Fri Nov 22 15:21:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/poolversion/poolversion_002_pos.ksh	Fri Nov 22 15:21:15 2013
@@ -0,0 +1,71 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# zpool set version can only increment pool version
+#
+# STRATEGY:
+# 1. Set a version 1 pool to be a version 6 pool
+# 2. Verify it's set to version 6
+# 3. Attempt to set prior versions
+# 4. Verify it's still set to version 6
+#
+
+verify_runnable "global"
+log_assert "zpool set version can only increment pool version"
+
+log_must $ZPOOL set version=6 $TESTPOOL2
+# verify it's actually that version - by checking the version property
+# and also by trying to set bootfs (which should fail if it is not version 6)
+
+VERSION=$($ZPOOL get version $TESTPOOL2| $GREP version | $AWK '{print $3}')
+if [ "$VERSION" != "6" ]
+then
+	log_fail "Version $VERSION set for $TESTPOOL2 expected version 6!"
+fi
+log_must $ZPOOL set bootfs=$TESTPOOL2 $TESTPOOL2
+
+# now verify we can't downgrade the version
+log_mustnot $ZPOOL set version=5 $TESTPOOL2
+log_mustnot $ZPOOL set version=-1 $TESTPOOL2
+
+# verify the version is still 6
+VERSION=$($ZPOOL get version $TESTPOOL2 | $GREP version | $AWK '{print $3}')
+if [ "$VERSION" != "6" ]
+then
+	log_fail "Version $VERSION set for $TESTPOOL2, expected version 6!"
+fi
+
+log_pass "zpool set version can only increment pool version"
--- /dev/null	Fri Nov 22 15:21:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/poolversion/setup.ksh	Fri Nov 22 15:21:16 2013
@@ -0,0 +1,45 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+# create a version 1 pool
+log_must $MKFILE 64m /tmp/zpool_version_1.dat
+log_must $ZPOOL create -o version=1 $TESTPOOL /tmp/zpool_version_1.dat
+
+
+# create another version 1 pool
+log_must $MKFILE 64m /tmp/zpool2_version_1.dat
+log_must $ZPOOL create -o version=1 $TESTPOOL2 /tmp/zpool2_version_1.dat
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/privilege/Makefile	Fri Nov 22 15:21:16 2013
@@ -0,0 +1,42 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/privilege
+
+PROGS = cleanup \
+	privilege_001_pos \
+	privilege_002_pos \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/privilege/cleanup.ksh	Fri Nov 22 15:21:16 2013
@@ -0,0 +1,49 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+ZFS_USER=$($CAT /tmp/zfs-privs-test-user.txt)
+USES_NIS=$($CAT /tmp/zfs-privs-test-nis.txt)
+
+if [ "${USES_NIS}" == "true" ]
+then
+    $SVCADM enable svc:/network/nis/client:default
+fi
+
+$USERDEL $ZFS_USER
+[[ -d /export/home/$ZFS_USER ]] && $RM -rf /export/home/$ZFS_USER
+$RM /tmp/zfs-privs-test-nis.txt
+$RM /tmp/zfs-privs-test-user.txt
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:17 2013
+++ new/usr/src/test/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh	Fri Nov 22 15:21:17 2013
@@ -0,0 +1,91 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# The RBAC profile "ZFS Storage Management" works
+#
+# STRATEGY:
+#	(create)
+#	1. As a normal user, try to create a pool - which should fail.
+#       2. Assign "ZFS Storage Management" profile, try to create pool again,
+#	   which should succeed.
+#
+#	(works well with other ZFS profile tests)
+#	3. Attempt to create a ZFS filesystem, which should fail.
+#	4. Add the "ZFS File System Management" profile, attempt to create a FS
+# 	   which should succeed.
+#
+#	(destroy)
+#       5. Remove the FS profile, then attempt to destroy the pool, which
+# 	   should succeed.
+#	6. Remove the Storage profile, then attempt to recreate the pool, which
+#	   should fail.
+#
+
+# We can only run this in the global zone
+verify_runnable "global"
+
+log_assert "The RBAC profile \"ZFS Storage Management\" works"
+
+ZFS_USER=$($CAT /tmp/zfs-privs-test-user.txt)
+
+# the user shouldn't be able to do anything initially
+log_mustnot $SU $ZFS_USER -c "$ZPOOL create $TESTPOOL $DISKS"
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZPOOL create $TESTPOOL $DISKS"
+
+# the first time we assign the profile, we insist it should work
+log_must $USERMOD -P "ZFS Storage Management" $ZFS_USER
+log_must $SU $ZFS_USER -c "$PFEXEC $ZPOOL create -f $TESTPOOL $DISKS"
+
+# ensure the user can't create a filesystem with this profile
+log_mustnot $SU $ZFS_USER -c "$ZFS create $TESTPOOL/fs"
+
+# add ZFS File System Management profile, and try to create a fs
+log_must $USERMOD -P "ZFS File System Management" $ZFS_USER
+log_must $SU $ZFS_USER -c "$PFEXEC $ZFS create $TESTPOOL/fs"
+
+# revoke File System Management profile
+$USERMOD -P, $ZFS_USER
+$USERMOD -P "ZFS Storage Management" $ZFS_USER
+
+# ensure the user can destroy pools
+log_mustnot $SU $ZFS_USER -c "$ZPOOL destroy $TESTPOOL"
+log_must $SU $ZFS_USER -c "$PFEXEC $ZPOOL destroy $TESTPOOL"
+
+# revoke Storage Management profile
+$USERMOD -P, $ZFS_USER
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZPOOL create -f $TESTPOOL $DISKS"
+
+log_pass "The RBAC profile \"ZFS Storage Management\" works"
--- /dev/null	Fri Nov 22 15:21:17 2013
+++ new/usr/src/test/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh	Fri Nov 22 15:21:17 2013
@@ -0,0 +1,101 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# The RBAC profile "ZFS File System Management" works
+#
+# STRATEGY:
+#
+#	The following actions are taken, both using profile execution (pfexec)
+#	and without profile execution - we make sure that the latter should
+#	always fail.
+#
+#	(create)
+#	1. As a normal user, try to create a filesystem - which should fail.
+#       2. Assign "ZFS File System Management" profile, try to create fs again,
+#	   which should succeed.
+#
+#	(pools)
+#	3. Ensure a user with this profile can't perform pool administration
+#	   by attempting to destroy a pool.
+#
+#	(destroy)
+#       5. Remove the FS profile, then attempt to destroy the fs, which
+# 	   should fail.
+#	6. Assign the FS profile, then attempt to destroy the fs, which
+#	   should succeed.
+#
+
+verify_runnable "both"
+
+log_assert "The RBAC profile \"ZFS File System Management\" works"
+
+ZFS_USER=$($CAT /tmp/zfs-privs-test-user.txt)
+
+# Set a $DATASET where we can create child files systems
+if is_global_zone; then
+	log_must $ZPOOL create -f $TESTPOOL $DISKS
+	DATASET=$TESTPOOL
+else
+	DATASET=zonepool/zonectr0
+fi
+
+# A user shouldn't be able to create filesystems
+log_mustnot $SU $ZFS_USER -c "$ZFS create $DATASET/zfsprivfs"
+
+# Insist this invocation of usermod works
+log_must $USERMOD -P "ZFS File System Management" $ZFS_USER
+
+# Now try to create file systems as the user
+log_mustnot $SU $ZFS_USER -c "$ZFS create $DATASET/zfsprivfs"
+log_must $SU $ZFS_USER -c "$PFEXEC $ZFS create $DATASET/zfsprivfs"
+
+# Ensure the user can't do anything to pools in this state:
+log_mustnot $SU $ZFS_USER -c "$ZPOOL destroy $DATASET"
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZPOOL destroy $DATASET"
+
+# revoke File System Management profile
+$USERMOD -P, $ZFS_USER
+
+# Ensure the user can't create more filesystems
+log_mustnot $SU $ZFS_USER -c "$ZFS create $DATASET/zfsprivfs2"
+log_mustnot $SU $ZFS_USER -c "$PFEXEC $ZFS create $DATASET/zfsprivfs2"
+
+# assign the profile again and destroy the fs.
+$USERMOD -P "ZFS File System Management" $ZFS_USER
+log_must $SU $ZFS_USER -c "$PFEXEC $ZFS destroy $DATASET/zfsprivfs"
+$USERMOD -P, $ZFS_USER
+
+log_pass "The RBAC profile \"ZFS File System Management\" works"
--- /dev/null	Fri Nov 22 15:21:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/privilege/setup.ksh	Fri Nov 22 15:21:18 2013
@@ -0,0 +1,67 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+ZFS_USER=zfsrbac
+USES_NIS=false
+
+# if we're running NIS, turn it off until we clean up
+# (it can cause useradd to take a long time, hitting our TIMEOUT)
+$SVCS svc:/network/nis/client:default | $GREP online > /dev/null
+if [ $? -eq 0 ]
+then
+  $SVCADM disable svc:/network/nis/client:default
+  USES_NIS=true
+fi
+
+
+# create a unique user that we can use to run the tests,
+# making sure not to clobber any existing users.
+FOUND=""
+while [ -z "${FOUND}" ]
+do
+  USER_EXISTS=$( grep $ZFS_USER /etc/passwd )
+  if [ ! -z "${USER_EXISTS}" ]
+  then
+      ZFS_USER="${ZFS_USER}x"
+  else
+      FOUND="true"
+  fi
+done
+
+log_must $MKDIR -p /export/home/$ZFS_USER
+log_must $USERADD -c "ZFS Privileges Test User" -d /export/home/$ZFS_USER $ZFS_USER
+
+echo $ZFS_USER > /tmp/zfs-privs-test-user.txt
+echo $USES_NIS > /tmp/zfs-privs-test-nis.txt
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/Makefile	Fri Nov 22 15:21:18 2013
@@ -0,0 +1,49 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/quota
+
+PROGS = cleanup \
+	quota_001_pos \
+	quota_002_pos \
+	quota_003_pos \
+	quota_004_pos \
+	quota_005_pos \
+	quota_006_neg \
+	setup
+
+FILES = quota.cfg \
+	quota.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/cleanup.ksh	Fri Nov 22 15:21:18 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
--- /dev/null	Fri Nov 22 15:21:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota.cfg	Fri Nov 22 15:21:18 2013
@@ -0,0 +1,35 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BLOCK_SIZE=8192
+export QUOTA_VALUE=10000000
+export TESTFILE1=file1
+export TESTFILE2=file2
+export TOLERANCE=131071
--- /dev/null	Fri Nov 22 15:21:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota.kshlib	Fri Nov 22 15:21:19 2013
@@ -0,0 +1,91 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/quota/quota.cfg
+
+# BLOCK_SIZE, QUOTA_VALUE and TOLERANCE set in quota.cfg
+readonly EDQUOT=49
+
+#
+# Function to fill the quota of a zfs filesystem
+#
+# $1 - The File system or container to fill.
+# $2 - The mountpoint to use.
+#
+function fill_quota
+{
+	typeset FILESYSTEM="$1"
+	typeset MNTPT="$2"
+
+	log_must $ZFS set quota=$QUOTA_VALUE $FILESYSTEM
+
+	typeset -i write_size=0
+	(( write_size = 2 * QUOTA_VALUE ))
+
+	typeset -i zret=0
+	$FILE_WRITE -o create -f $MNTPT/$TESTFILE1 -b $BLOCK_SIZE \
+		 -c $write_size -d 0
+	zret=$?
+        [[ $zret -ne EDQUOT ]] && \
+            log_fail "Returned error code: $zret. Expected: $EDQUOT."
+
+	typeset -i file_size=`$LS -ls $MNTPT/$TESTFILE1 | $AWK '{ print $1 }'`
+	typeset -i limit=0
+	(( file_size = file_size * 512 ))
+	(( limit = QUOTA_VALUE + TOLERANCE ))
+	(( file_size > limit )) && \
+	    log_fail "File was created larger than the quota value, aborting!!!"
+	return 0
+}
+
+#
+# Function attempts to write another file in a ZFS filesystem
+# that has already filled its quota
+#
+function exceed_quota
+{
+	typeset FILESYSTEM="$1"
+	typeset MNTPT="$2"
+
+	log_must fill_quota $FILESYSTEM $MNTPT
+	typeset -i write_size=0
+        (( write_size = 2 * QUOTA_VALUE ))
+	typeset -i zret=0
+	#
+	# Writing a file without API to access return code
+	#
+	log_note "Creating a file in a FS that has already exceeded its quota"
+	$FILE_WRITE -o create -f $MNTPT/$TESTFILE2 \
+		-b $BLOCK_SIZE -c $write_size -d 0
+	zret=$?
+	[[ $zret -ne EDQUOT ]] && \
+	    log_fail "Returned error code: $zret. Expected: EDQUOT."
+	return 0
+}
--- /dev/null	Fri Nov 22 15:21:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota_001_pos.ksh	Fri Nov 22 15:21:19 2013
@@ -0,0 +1,76 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+#
+# A ZFS file system quota limits the amount of pool space
+# available to a file system. Apply a quota and verify
+# that no more file creates are permitted.
+#
+# STRATEGY:
+# 1) Apply quota to ZFS file system
+# 2) Create a file which is larger than the set quota
+# 3) Verify that the resulting file size is less than the quota limit
+#
+
+verify_runnable "both"
+
+log_assert "Verify that file size is limited by the file system quota"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+	[[ -e $TESTDIR/$TESTFILE1 ]] && \
+	    log_must $RM $TESTDIR/$TESTFILE1
+	#
+	# Need to allow time for space to be released back to
+	# pool, otherwise next test will fail trying to set a
+	# quota which is less than the space used.
+	#
+	sleep 5
+}
+
+log_onexit cleanup
+
+#
+# Sets the quota value and attempts to fill it with a file
+# twice the size of the quota
+#
+log_must fill_quota $TESTPOOL/$TESTFS $TESTDIR
+
+log_pass "File size limited by quota"
--- /dev/null	Fri Nov 22 15:21:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota_002_pos.ksh	Fri Nov 22 15:21:20 2013
@@ -0,0 +1,73 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+# A zfs file system quota limits the amount of pool space
+# available to a given ZFS file system. Once exceeded, it is impossible
+# to write any more files to the file system.
+#
+# STRATEGY:
+# 1) Apply quota to the ZFS file system
+# 2) Exceed the quota
+# 3) Attempt to write another file
+# 4) Verify the attempt fails with error code 49 (EDQUOTA)
+#
+#
+
+verify_runnable "both"
+
+log_assert "Verify that a file write cannot exceed the file system quota"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+        [[ -e $TESTDIR/$TESTFILE1 ]] && \
+            log_must $RM $TESTDIR/$TESTFILE1
+
+	[[ -e $TESTDIR/$TESTFILE2 ]] && \
+            log_must $RM $TESTDIR/$TESTFILE2
+}
+
+log_onexit cleanup
+
+#
+# Fills the quota & attempts to write another file
+#
+log_must exceed_quota $TESTPOOL/$TESTFS $TESTDIR
+
+log_pass "Could not write file. Quota limit enforced as expected"
--- /dev/null	Fri Nov 22 15:21:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota_003_pos.ksh	Fri Nov 22 15:21:20 2013
@@ -0,0 +1,79 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+# A ZFS file system quota limits the amount of pool space
+# available to a file system dataset. Apply a quota and verify
+# that no more file creates are permitted.
+#
+# NOTE: THis test applies to a dataset rather than a file system.
+#
+# STRATEGY:
+# 1) Apply quota to ZFS file system dataset
+# 2) Create a file which is larger than the set quota
+# 3) Verify that the resulting file size is less than the quota limit
+#
+
+verify_runnable "both"
+
+log_assert "Verify that file size is limited by the file system quota" \
+    "(dataset version)"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+	[[ -e $TESTDIR1/$TESTFILE1 ]] && \
+	    log_must $RM $TESTDIR1/$TESTFILE1
+
+	#
+        # Need to allow time for space to be released back to
+        # pool, otherwise next test will fail trying to set a
+        # quota which is less than the space used.
+        #
+        sleep 5
+}
+
+log_onexit cleanup
+
+#
+# Sets the quota value and attempts to fill it with a file
+# twice the size of the quota
+#
+log_must fill_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1
+
+log_pass "File size limited by quota"
--- /dev/null	Fri Nov 22 15:21:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota_004_pos.ksh	Fri Nov 22 15:21:20 2013
@@ -0,0 +1,74 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+# A zfs file system quota limits the amount of pool space
+# available to a given ZFS file system dataset. Once exceeded, it
+# is impossible to write any more files to the file system.
+#
+# STRATEGY:
+# 1) Apply quota to the ZFS file system dataset
+# 2) Exceed the quota
+# 3) Attempt to write another file
+# 4) Verify the attempt fails with error code 49 (EDQUOTA)
+#
+#
+
+verify_runnable "both"
+
+log_assert "Verify that a file write cannot exceed the file system quota" \
+    "(dataset version)"
+
+#
+# cleanup to be used internally as otherwise quota assertions cannot be
+# run independently or out of order
+#
+function cleanup
+{
+        [[ -e $TESTDIR1/$TESTFILE1 ]] && \
+            log_must $RM $TESTDIR1/$TESTFILE1
+
+	[[ -e $TESTDIR1/$TESTFILE2 ]] && \
+            log_must $RM $TESTDIR1/$TESTFILE2
+}
+
+log_onexit cleanup
+
+#
+# Fills the quota & attempts to write another file
+#
+log_must exceed_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1
+
+log_pass "Could not write file. Quota limit enforced as expected"
--- /dev/null	Fri Nov 22 15:21:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota_005_pos.ksh	Fri Nov 22 15:21:20 2013
@@ -0,0 +1,76 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+#
+# Verify that quota doesn't inherit its value from parent.
+#
+# STRATEGY:
+# 1) Set quota for parents
+# 2) Create a filesystem tree
+# 3) Verify that the 'quota' for descendent doesnot inherit the value.
+#
+###############################################################################
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $fs_child && \
+		log_must $ZFS destroy $fs_child
+
+	log_must $ZFS set quota=$quota_val $fs
+}
+
+log_onexit cleanup
+
+log_assert "Verify that quota doesnot inherit its value from parent."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+fs_child=$TESTPOOL/$TESTFS/$TESTFS
+
+space_avail=$(get_prop available $fs)
+quota_val=$(get_prop quota $fs)
+typeset -i quotasize=$space_avail
+((quotasize = quotasize * 2 ))
+log_must $ZFS set quota=$quotasize $fs
+
+log_must $ZFS create $fs_child
+quota_space=$(get_prop quota $fs_child)
+[[ $quota_space == $quotasize ]] && \
+	log_fail "The quota of child dataset inherits its value from parent."
+
+log_pass "quota doesnot inherit its value from parent as expected."
--- /dev/null	Fri Nov 22 15:21:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/quota_006_neg.ksh	Fri Nov 22 15:21:21 2013
@@ -0,0 +1,71 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/quota/quota.kshlib
+
+#
+# DESCRIPTION:
+#
+# Can't set a quota to less than currently being used by the dataset.
+#
+# STRATEGY:
+# 1) Create a filesystem
+# 2) Set a quota on the filesystem that is lower than the space
+#	currently in use.
+# 3) Verify that the attempt fails.
+#
+
+verify_runnable "both"
+
+log_assert "Verify cannot set quota lower than the space currently in use"
+
+function cleanup
+{
+	log_must $ZFS set quota=none $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+typeset -i quota_integer_size=0
+typeset invalid_size="123! @456 7#89 0\$ abc123% 123%s 12%s3 %c123 123%d %x123 12%p3 \
+	^def456 789&ghi"
+typeset -i space_used=`get_prop used $TESTPOOL/$TESTFS`
+(( quota_integer_size = space_used  - 1 ))
+quota_fp_size=${quota_integer_size}.123
+
+for size in 0 -1 $quota_integer_size -$quota_integer_size $quota_fp_size -$quota_fp_size \
+	$invalid_size ; do
+	log_mustnot $ZFS set quota=$size $TESTPOOL/$TESTFS
+done
+log_must $ZFS set quota=$space_used $TESTPOOL/$TESTFS
+
+log_pass "As expected cannot set quota lower than space currently in use"
--- /dev/null	Fri Nov 22 15:21:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/quota/setup.ksh	Fri Nov 22 15:21:21 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_setup $DISK
--- /dev/null	Fri Nov 22 15:21:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/Makefile	Fri Nov 22 15:21:21 2013
@@ -0,0 +1,47 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/redundancy
+
+PROGS = cleanup \
+	redundancy_001_pos \
+	redundancy_002_pos \
+	redundancy_003_pos \
+	redundancy_004_neg \
+	setup
+
+FILES = redundancy.cfg \
+	redundancy.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/cleanup.ksh	Fri Nov 22 15:21:22 2013
@@ -0,0 +1,38 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+verify_runnable "global"
+
+cleanup
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy.cfg	Fri Nov 22 15:21:22 2013
@@ -0,0 +1,40 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BASEDIR=/var/tmp/basedir.$$
+export TESTFILE=testfile.$$
+
+export PRE_RECORD_FILE=$BASEDIR/pre-record-file.$$
+export PST_RECORD_FILE=$BASEDIR/pst-record-file.$$
+
+export DEV_SIZE=64M
+
+export BLOCKSZ=$(( 1024 * 1024 ))
+export NUM_WRITES=40
--- /dev/null	Fri Nov 22 15:21:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy.kshlib	Fri Nov 22 15:21:22 2013
@@ -0,0 +1,365 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/redundancy/redundancy.cfg
+
+function cleanup
+{
+	if poolexists $TESTPOOL; then
+		destroy_pool $TESTPOOL
+	fi
+	typeset dir
+	for dir in $TESTDIR $BASEDIR; do
+		if [[ -d $dir ]]; then
+			log_must $RM -rf $dir
+		fi
+	done
+}
+
+#
+# Get random number between min and max number.
+#
+# $1 Minimal value
+# $2 Maximal value
+#
+function random
+{
+	typeset -i min=$1
+	typeset -i max=$2
+	typeset -i value
+
+	while true; do
+		((value = RANDOM % (max + 1)))
+		if ((value >= min)); then
+			break
+		fi
+	done
+
+	$ECHO $value
+}
+
+#
+# Record the directories construction and checksum all the files which reside
+# within the specified pool
+#
+# $1 The specified pool
+# $2 The file which save the record.
+#
+function record_data
+{
+	typeset pool=$1
+	typeset recordfile=$2
+
+	[[ -z $pool ]] && log_fail "No specified pool."
+	[[ -f $recordfile ]] && log_must $RM -f $recordfile
+
+	typeset mntpnt
+	mntpnt=$(get_prop mountpoint $pool)
+	log_must eval "$DU -a $mntpnt > $recordfile 2>&1"
+	#
+	# When the data was damaged, checksum is failing and return 1
+	# So, will not use log_must
+	#
+	$FIND $mntpnt -type f -exec $CKSUM {} + >> $recordfile 2>&1
+}
+
+#
+# Create test pool and fill with files and directories.
+#
+# $1 pool name
+# $2 pool type
+# $3 virtual devices number
+#
+function setup_test_env
+{
+	typeset pool=$1
+	typeset keyword=$2
+	typeset -i vdev_cnt=$3
+	typeset vdevs
+
+	typeset -i i=0
+	while (( i < vdev_cnt )); do
+		vdevs="$vdevs $BASEDIR/vdev$i"
+		((i += 1))
+	done
+
+	if [[ ! -d $BASEDIR ]]; then
+		log_must $MKDIR $BASEDIR
+	fi
+
+	if poolexists $pool ; then
+		destroy_pool $pool
+	fi
+
+	log_must $MKFILE $DEV_SIZE $vdevs
+
+	log_must $ZPOOL create -m $TESTDIR $pool $keyword $vdevs
+
+	log_note "Filling up the filesystem ..."
+	typeset -i ret=0
+	typeset -i i=0
+	typeset file=$TESTDIR/file
+	while $TRUE ; do
+		$FILE_WRITE -o create -f $file.$i \
+			-b $BLOCKSZ -c $NUM_WRITES
+		ret=$?
+		(( $ret != 0 )) && break
+		(( i = i + 1 ))
+	done
+	(($ret != 28 )) && log_note "$FILE_WRITE return value($ret) is unexpected."
+
+	record_data $TESTPOOL $PRE_RECORD_FILE
+}
+
+#
+# Check pool status is healthy
+#
+# $1 pool
+#
+function is_healthy
+{
+	typeset pool=$1
+
+	typeset healthy_output="pool '$pool' is healthy"
+	typeset real_output=$($ZPOOL status -x $pool)
+
+	if [[ "$real_output" == "$healthy_output" ]]; then
+		return 0
+	else
+		typeset -i ret
+		$ZPOOL status -x $pool | $GREP "state:" | \
+			$GREP "FAULTED" >/dev/null 2>&1
+		ret=$?
+		(( $ret == 0 )) && return 1
+		typeset l_scan
+		typeset errnum
+		l_scan=$($ZPOOL status -x $pool | $GREP "scan:")
+		l_scan=${l_scan##*"with"}
+		errnum=$($ECHO $l_scan | $AWK '{print $1}')
+
+		return $errnum
+	fi
+}
+
+#
+# Check pool data is valid
+#
+# $1 pool
+#
+function is_data_valid
+{
+	typeset pool=$1
+
+	record_data $pool $PST_RECORD_FILE
+	if ! $DIFF $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then
+		return 1
+	fi
+
+	return 0
+}
+
+#
+# Get the specified count devices name
+#
+# $1 pool name
+# $2 devices count
+#
+function get_vdevs #pool cnt
+{
+	typeset pool=$1
+	typeset -i cnt=$2
+
+	typeset all_devs=$($ZPOOL iostat -v $pool | $AWK '{print $1}'| \
+		$EGREP -v "^pool$|^capacity$|^mirror$|^raidz1$|^raidz2$|---" | \
+		$EGREP -v "/old$|^$pool$")
+	typeset -i i=0
+	typeset vdevs
+	while ((i < cnt)); do
+		typeset dev=$($ECHO $all_devs | $AWK '{print $1}')
+		eval all_devs=\${all_devs##*$dev}
+
+		vdevs="$dev $vdevs"
+		((i += 1))
+	done
+
+	$ECHO "$vdevs"
+}
+
+#
+# Synchronize all the data in pool
+#
+# $1 pool name
+#
+function sync_pool #pool
+{
+	typeset pool=$1
+
+	log_must $SYNC
+	log_must $SLEEP 2
+	# Flush all the pool data.
+	typeset -i ret
+	$ZPOOL scrub $pool >/dev/null 2>&1
+	ret=$?
+	(( $ret != 0 )) && \
+		log_fail "$ZPOOL scrub $pool failed."
+
+	while ! is_pool_scrubbed $pool; do
+		if is_pool_resilvered $pool ; then
+			log_fail "$pool should not be resilver completed."
+		fi
+		log_must $SLEEP 2
+	done
+}
+
+#
+# Create and replace the same name virtual device files
+#
+# $1 pool name
+# $2-n virtual device files
+#
+function replace_missing_devs
+{
+	typeset pool=$1
+	shift
+
+	typeset vdev
+	for vdev in $@; do
+		log_must $MKFILE $DEV_SIZE $vdev
+		log_must $ZPOOL replace -f $pool $vdev $vdev
+		while true; do
+			if ! is_pool_resilvered $pool ; then
+				log_must $SLEEP 2
+			else
+				break
+			fi
+		done
+	done
+}
+
+#
+# Damage the pool's virtual device files.
+#
+# $1 pool name
+# $2 Failing devices count
+# $3 damage vdevs method, if not null, we keep
+#    the label for the vdevs
+#
+function damage_devs
+{
+	typeset pool=$1
+	typeset -i cnt=$2
+	typeset label="$3"
+	typeset vdevs
+	typeset -i bs_count
+
+	vdevs=$(get_vdevs $pool $cnt)
+	if [[ -n $label ]]; then
+		typeset dev
+		for dev in $vdevs; do
+			bs_count=$($LS -l $dev | $AWK '{print $5}')
+			(( bs_count = bs_count/1024 - 512 ))
+			$DD if=/dev/zero of=$dev seek=512 bs=1024 \
+				count=$bs_count conv=notrunc >/dev/null 2>&1
+		done
+	else
+		log_must $MKFILE $DEV_SIZE $vdevs
+	fi
+
+	sync_pool $pool
+}
+
+#
+# Clear errors in the pool caused by data corruptions
+#
+# $1 pool name
+#
+function clear_errors
+{
+	typeset pool=$1
+
+	log_must $ZPOOL clear $pool
+
+	if ! is_healthy $pool ; then
+		log_note "$pool should be healthy."
+		return 1
+	fi
+	if ! is_data_valid $pool ; then
+		log_note "Data should be valid in $pool."
+		return 1
+	fi
+
+	return 0
+}
+
+#
+# Remove the specified pool's virtual device files
+#
+# $1 Pool name
+# $2 Missing devices count
+#
+function remove_devs
+{
+	typeset pool=$1
+	typeset -i cnt=$2
+	typeset vdevs
+
+	vdevs=$(get_vdevs $pool $cnt)
+	log_must $RM -f $vdevs
+
+	sync_pool $pool
+}
+
+#
+# Recover the bad or missing device files in the pool
+#
+# $1 Pool name
+# $2 Missing devices count
+#
+function recover_bad_missing_devs
+{
+	typeset pool=$1
+	typeset -i cnt=$2
+	typeset vdevs
+
+	vdevs=$(get_vdevs $pool $cnt)
+	replace_missing_devs $pool $vdevs
+
+	if ! is_healthy $pool ; then
+		log_note "$pool should be healthy."
+		return 1
+	fi
+	if ! is_data_valid $pool ; then
+		log_note "Data should be valid in $pool."
+		return 1
+	fi
+
+	return 0
+}
--- /dev/null	Fri Nov 22 15:21:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh	Fri Nov 22 15:21:23 2013
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#	A raidz pool can withstand at most 1 device failing or missing.
+#
+# STRATEGY:
+#	1. Create N(>2,<5) virtual disk files.
+#	2. Create raidz pool based on the virtual disk files.
+#	3. Fill the filesystem with directories and files.
+#	4. Record all the files and directories checksum information.
+#	5. Damaged one of the virtual disk file.
+#	6. Verify the data is correct to prove raidz can withstand 1 devicd is
+#	   failing.
+#
+
+verify_runnable "global"
+
+log_assert "Verify raidz pool can withstand one device is failing."
+log_onexit cleanup
+
+typeset -i cnt=$(random 2 5)
+setup_test_env $TESTPOOL raidz $cnt
+
+#
+# Inject data corruption error for raidz pool
+#
+damage_devs $TESTPOOL 1 "label"
+log_must is_data_valid $TESTPOOL
+log_must clear_errors $TESTPOOL
+
+#
+# Inject bad device error for raidz pool
+#
+damage_devs $TESTPOOL 1
+log_must is_data_valid $TESTPOOL
+log_must recover_bad_missing_devs $TESTPOOL 1
+
+#
+# Inject missing device error for raidz pool
+#
+remove_devs $TESTPOOL 1
+log_must is_data_valid $TESTPOOL
+
+log_pass "Raidz pool can withstand one devices is failing passed."
--- /dev/null	Fri Nov 22 15:21:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh	Fri Nov 22 15:21:23 2013
@@ -0,0 +1,83 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#	A raidz2 pool can withstand 2 devices are failing or missing.
+#
+# STRATEGY:
+#	1. Create N(>3,<5) virtual disk files.
+#	2. Create raidz2 pool based on the virtual disk files.
+#	3. Fill the filesystem with directories and files.
+#	4. Record all the files and directories checksum information.
+#	5. Damaged at most two of the virtual disk files.
+#	6. Verify the data is correct to prove raidz2 can withstand 2 devices
+#	   are failing.
+#
+
+verify_runnable "global"
+
+log_assert "Verify raidz2 pool can withstand two devices are failing."
+log_onexit cleanup
+
+typeset -i cnt=$(random 3 5)
+setup_test_env $TESTPOOL raidz2 $cnt
+
+#
+# Inject data corruption errors for raidz2 pool
+#
+for i in 1 2; do
+	damage_devs $TESTPOOL $i "label"
+	log_must is_data_valid $TESTPOOL
+	log_must clear_errors $TESTPOOL
+done
+
+#
+# Inject bad devices errors for raidz2 pool
+#
+for i in 1 2; do
+	damage_devs $TESTPOOL $i
+	log_must is_data_valid $TESTPOOL
+	log_must recover_bad_missing_devs $TESTPOOL $i
+done
+
+#
+# Inject missing device errors for raidz2 pool
+#
+for i in 1 2; do
+	remove_devs $TESTPOOL $i
+	log_must is_data_valid $TESTPOOL
+	log_must recover_bad_missing_devs $TESTPOOL $i
+done
+
+log_pass "Raidz2 pool can withstand two devices are failing passed."
--- /dev/null	Fri Nov 22 15:21:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh	Fri Nov 22 15:21:23 2013
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#	A mirrored pool can withstand N-1 device are failing or missing.
+#
+# STRATEGY:
+#	1. Create N(>2,<5) virtual disk files.
+#	2. Create mirror pool based on the virtual disk files.
+#	3. Fill the filesystem with directories and files.
+#	4. Record all the files and directories checksum information.
+#	5. Damaged at most N-1 of the virtual disk files.
+#	6. Verify the data are correct to prove mirror can withstand N-1 devices
+#	   are failing.
+#
+
+verify_runnable "global"
+
+log_assert "Verify mirrored pool can withstand N-1 devices are failing or missing."
+log_onexit cleanup
+
+typeset -i cnt=$(random 2 5)
+setup_test_env $TESTPOOL mirror $cnt
+
+typeset -i i=1
+
+#
+# Inject data corruption errors for mirrored pool
+#
+while (( i < cnt )); do
+	damage_devs $TESTPOOL $i "label"
+	log_must is_data_valid $TESTPOOL
+	log_must clear_errors $TESTPOOL
+
+	(( i +=1 ))
+done
+
+#
+# Inject  bad devices errors for mirrored pool
+#
+i=1
+while (( i < cnt )); do
+        damage_devs $TESTPOOL $i
+        log_must is_data_valid $TESTPOOL
+	log_must recover_bad_missing_devs $TESTPOOL $i
+
+	(( i +=1 ))
+done
+
+#
+# Inject missing device errors for mirrored pool
+#
+i=1
+while (( i < cnt )); do
+        remove_devs $TESTPOOL $i
+        log_must is_data_valid $TESTPOOL
+	log_must recover_bad_missing_devs $TESTPOOL $i
+
+	(( i +=1 ))
+done
+
+log_pass "Mirrored pool can withstand N-1 devices failing as expected."
--- /dev/null	Fri Nov 22 15:21:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh	Fri Nov 22 15:21:24 2013
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
+
+#
+# DESCRIPTION:
+#	Striped pool have no data redundancy. Any device errors will
+#	cause data corruption.
+#
+# STRATEGY:
+#	1. Create N virtual disk file.
+#	2. Create stripe pool based on the virtual disk files.
+#	3. Fill the filesystem with directories and files.
+#	4. Record all the files and directories checksum information.
+#	5. Damage one of the virtual disk file.
+#	6. Verify the data is error.
+#
+
+verify_runnable "global"
+
+log_assert "Verify striped pool have no data redundancy."
+log_onexit cleanup
+
+typeset -i cnt=$(random 2 5)
+setup_test_env $TESTPOOL "" $cnt
+
+damage_devs $TESTPOOL 1 "keep_label"
+log_must $ZPOOL clear $TESTPOOL
+
+# Wait for the scrub intiated by the clear to wrap, or is_healthy will be wrong.
+while ! is_pool_scrubbed $TESTPOOL; do
+	sync
+done
+
+log_mustnot is_healthy $TESTPOOL
+
+log_pass "Striped pool has no data redundancy as expected."
--- /dev/null	Fri Nov 22 15:21:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/setup.ksh	Fri Nov 22 15:21:24 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/Makefile	Fri Nov 22 15:21:25 2013
@@ -0,0 +1,46 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/refquota
+
+PROGS = cleanup \
+	refquota_001_pos \
+	refquota_002_pos \
+	refquota_003_pos \
+	refquota_004_pos \
+	refquota_005_pos \
+	refquota_006_neg \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/cleanup.ksh	Fri Nov 22 15:21:25 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/refquota_001_pos.ksh	Fri Nov 22 15:21:25 2013
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	refquota limits the amount of space a dataset can consume, but does
+#	not include space used by descendents.
+#
+# STRATEGY:
+#	1. Setting refquota in given filesystem
+#	2. Create descendent filesystem
+#	3. Verify refquota limits the amount of space a dataset can consume
+#	4. Verify the limit does not impact descendents
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "refquota limits the amount of space a dataset can consume, " \
+	"but does not include space used by descendents."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+sub=$fs/sub
+log_must $ZFS create $sub
+
+log_must $ZFS set refquota=10M $fs
+mntpnt=$(get_prop mountpoint $fs)
+
+log_mustnot $MKFILE 11M $mntpnt/file
+log_must $MKFILE 9M $mntpnt/file
+log_must $ZFS snapshot $fs@snap
+log_mustnot $MKFILE 2M $mntpnt/file2
+
+mntpnt=$(get_prop mountpoint $sub)
+log_must $MKFILE 10M $mntpnt/file
+log_must $ZFS snapshot $sub@snap
+log_must $MKFILE 10 $mntpnt/file2
+
+log_pass "refquota limits the amount of space a dataset can consume, " \
+	"but does not include space used by descendents."
--- /dev/null	Fri Nov 22 15:21:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/refquota_002_pos.ksh	Fri Nov 22 15:21:26 2013
@@ -0,0 +1,90 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Quotas are enforced using the minimum of the two properties:
+#	quota & refquota
+#
+# STRATEGY:
+#	1. Set value for quota and refquota. Quota less than refquota.
+#	2. Creating file which should be limited by quota.
+#	3. Switch the value of quota and refquota.
+#	4. Verify file should be limited by refquota.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Quotas are enforced using the minimum of the two properties"
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=15M $fs
+log_must $ZFS set refquota=25M $fs
+
+mntpnt=$(get_prop mountpoint $fs)
+log_mustnot $MKFILE 20M $mntpnt/$TESTFILE
+typeset -i used quota
+used=$(get_prop used $fs)
+quota=$(get_prop quota $fs)
+((used = used / (1024 * 1024)))
+((quota = quota / (1024 * 1024)))
+if [[ $used -ne $quota ]]; then
+	log_fail "ERROR: $used -ne $quota Quotas are not limited by quota"
+fi
+
+#
+# Switch the value of them and try again
+#
+log_must $RM $mntpnt/$TESTFILE
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=15M $fs
+
+log_mustnot $MKFILE 20M $mntpnt/$TESTFILE
+used=$(get_prop used $fs)
+refquota=$(get_prop refquota $fs)
+((used = used / (1024 * 1024)))
+((refquota = refquota / (1024 * 1024)))
+if [[ $used -ne $refquota ]]; then
+	log_fail "ERROR: $used -ne $refquota Quotas are not limited by refquota"
+fi
+
+log_pass "Quotas are enforced using the minimum of the two properties"
--- /dev/null	Fri Nov 22 15:21:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/refquota_003_pos.ksh	Fri Nov 22 15:21:26 2013
@@ -0,0 +1,83 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Sub-filesystem quotas are not enforced by property 'refquota'
+#
+# STRATEGY:
+#	1. Setting quota and refquota for parent. refquota < quota
+#	2. Verify sub-filesystem will not be limited by refquota
+#	3. Verify sub-filesystem will only be limited by quota
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Sub-filesystem quotas are not enforced by property 'refquota'"
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=10M $fs
+log_must $ZFS create $fs/subfs
+
+mntpnt=$(get_prop mountpoint $fs/subfs)
+log_must $MKFILE 20M $mntpnt/$TESTFILE
+
+typeset -i used quota refquota
+used=$(get_prop used $fs)
+refquota=$(get_prop refquota $fs)
+((used = used / (1024 * 1024)))
+((refquota = refquota / (1024 * 1024)))
+if [[ $used -lt $refquota ]]; then
+	log_fail "ERROR: $used < $refquota subfs quotas are limited by refquota"
+fi
+
+log_mustnot $MKFILE 20M $mntpnt/$TESTFILE.2
+used=$(get_prop used $fs)
+quota=$(get_prop quota $fs)
+((used = used / (1024 * 1024)))
+((quota = quota / (1024 * 1024)))
+if [[ $used -gt $quota ]]; then
+	log_fail "ERROR: $used > $quota subfs quotas aren't limited by quota"
+fi
+
+log_pass "Sub-filesystem quotas are not enforced by property 'refquota'"
--- /dev/null	Fri Nov 22 15:21:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/refquota_004_pos.ksh	Fri Nov 22 15:21:26 2013
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	refquotas are not limited by snapshots.
+#
+# STRATEGY:
+#	1. Setting refquota < quota
+#	2. Create file in filesytem, take snapshot and remove the file
+#	3. Verify snapshot will not consume refquota
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "refquotas are not limited by snapshots."
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=15M $fs
+
+mntpnt=$(get_prop mountpoint $fs)
+typeset -i i=0
+while ((i < 3)); do
+	log_must $MKFILE 7M $mntpnt/$TESTFILE.$i
+	log_must $ZFS snapshot $fs@snap.$i
+	log_must $RM $mntpnt/$TESTFILE.$i
+
+	((i += 1))
+done
+
+#
+# Verify out of the limitation of 'quota'
+#
+log_mustnot $MKFILE 7M $mntpnt/$TESTFILE
+
+log_pass "refquotas are not limited by snapshots."
--- /dev/null	Fri Nov 22 15:21:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/refquota_005_pos.ksh	Fri Nov 22 15:21:27 2013
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	refquotas are not limited by sub-filesystem snapshots.
+#
+# STRATEGY:
+#	1. Setting refquota < quota for parent
+#	2. Create file in sub-filesytem, take snapshot and remove the file
+#	3. Verify sub-filesystem snapshot will not consume refquota
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "refquotas are not limited by sub-filesystem snapshots."
+log_onexit cleanup
+
+TESTFILE='testfile'
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refquota=15M $fs
+log_must $ZFS create $fs/subfs
+
+mntpnt=$(get_prop mountpoint $fs/subfs)
+typeset -i i=0
+while ((i < 3)); do
+	log_must $MKFILE 7M $mntpnt/$TESTFILE.$i
+	log_must $ZFS snapshot $fs/subfs@snap.$i
+	log_must $RM $mntpnt/$TESTFILE.$i
+
+	((i += 1))
+done
+
+#
+# Verify out of the limitation of 'quota'
+#
+log_mustnot $MKFILE 7M $mntpnt/$TESTFILE
+
+log_pass "refquotas are not limited by sub-filesystem snapshots"
--- /dev/null	Fri Nov 22 15:21:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/refquota_006_neg.ksh	Fri Nov 22 15:21:27 2013
@@ -0,0 +1,70 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	'zfs set refquota/refreserv' can handle incorrect arguments correctly.
+#
+# STRATEGY:
+#	1. Setup incorrect arguments arrays.
+#	2. Set the bad argument to refquota.
+#	3. Verify zfs can handle it correctly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS set refquota=none $TESTPOOL/$TESTFS
+	log_must $ZFS set refreserv=none $TESTPOOL/$TESTFS
+}
+
+log_assert "'zfs set refquota' can handle incorrect arguments correctly."
+log_onexit cleanup
+
+set -A badopt	\
+	"None"		"-1"		"1TT"		"%5"		\
+	"123!"		"@456"		"7#89" 		"0\$"		\
+	"abc123%"	"123%s"		"12%s3"		"%c123"		\
+	"123%d"		"%x123"		"12%p3" 	"^def456" 	\
+	"\0"		"x0"
+
+typeset -i i=0
+while ((i < ${#badopt[@]})); do
+	log_mustnot $ZFS set refquota=${badopt[$i]} $TESTPOOL/$TESTFS
+	log_mustnot $ZFS set refreserv=${badopt[$i]} $TESTPOOL/$TESTFS
+
+	((i += 1))
+done
+
+log_pass "'zfs set refquota' can handle incorrect arguments correctly."
--- /dev/null	Fri Nov 22 15:21:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refquota/setup.ksh	Fri Nov 22 15:21:27 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:21:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/Makefile	Fri Nov 22 15:21:28 2013
@@ -0,0 +1,47 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/refreserv
+
+PROGS = cleanup \
+	refreserv_001_pos \
+	refreserv_002_pos \
+	refreserv_003_pos \
+	refreserv_004_pos \
+	refreserv_005_pos \
+	setup
+
+FILES = refreserv.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/cleanup.ksh	Fri Nov 22 15:21:28 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/refreserv.cfg	Fri Nov 22 15:21:28 2013
@@ -0,0 +1,31 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile
--- /dev/null	Fri Nov 22 15:21:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/refreserv_001_pos.ksh	Fri Nov 22 15:21:29 2013
@@ -0,0 +1,75 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#	Reservations are enforced using the maximum of 'reserv' and 'refreserv'
+#
+# STRATEGY:
+#	1. Setting quota for parent filesystem.
+#	2. Setting reservation and refreservation for sub-filesystem.
+#	3. Verify the sub-fs reservation are enforced by the maximum of 'reserv'
+#	   and 'refreserv'.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Reservations are enforced using the maximum of " \
+	"'reserv' and 'refreserv'"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS ; subfs=$fs/subfs
+log_must $ZFS create $subfs
+log_must $ZFS set quota=25M $fs
+
+log_must $ZFS set reserv=10M $subfs
+log_must $ZFS set refreserv=20M $subfs
+mntpnt=$(get_prop mountpoint $fs)
+log_mustnot $MKFILE 15M $mntpnt/$TESTFILE
+
+log_must $RM -f $mntpnt/$TESTFILE
+
+log_must $ZFS set reserv=20M $subfs
+log_must $ZFS set refreserv=10M $subfs
+log_mustnot $MKFILE 15M $mntpnt/$TESTFILE
+
+log_pass "Reservations are enforced using the maximum of " \
+	"'reserv' and 'refreserv'"
--- /dev/null	Fri Nov 22 15:21:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh	Fri Nov 22 15:21:29 2013
@@ -0,0 +1,114 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#	Setting full size as refreservation, verify no snapshot can be created.
+#
+# STRATEGY:
+#	1. Setting full size as refreservation on pool
+#	2. Verify no snapshot can be created on this pool
+#	3. Setting full size as refreservation on filesystem
+#	4. Verify no snapshot can be created on it and its subfs
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if is_global_zone ; then
+		log_must $ZFS set refreservation=none $TESTPOOL
+
+		if datasetexists $TESTPOOL@snap ; then
+			log_must $ZFS destroy -f $TESTPOOL@snap
+		fi
+	fi
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+# This function iteratively increases refreserv to its highest possible
+# value. Simply setting refreserv == quota can allow enough writes to
+# complete that the test fails.
+function max_refreserv
+{
+	typeset ds=$1
+	typeset -i incsize=131072
+	typeset -i rr=$(get_prop available $ds)
+
+	log_must $ZFS set refreserv=$rr $ds
+	while :; do
+		$ZFS set refreserv=$((rr + incsize)) $ds >/dev/null 2>&1
+		if [[ $? == 0 ]]; then
+			((rr += incsize))
+			continue
+		else
+			((incsize /= 2))
+			((incsize == 0)) && break
+		fi
+	done
+}
+
+
+log_assert "Setting full size as refreservation, verify no snapshot " \
+	"can be created."
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS/subfs
+
+typeset datasets
+if is_global_zone; then
+	datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
+else
+	datasets="$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs"
+fi
+
+for ds in $datasets; do
+	#
+	# Verify refreservation on dataset
+	#
+	log_must $ZFS set quota=25M $ds
+	max_refreserv $ds
+	log_mustnot $ZFS snapshot $ds@snap
+	if datasetexists $ds@snap ; then
+		log_fail "ERROR: $ds@snap should not exists."
+	fi
+
+	log_must $ZFS set quota=none $ds
+	log_must $ZFS set refreservation=none $ds
+done
+
+log_pass "Setting full size as refreservation, verify no snapshot " \
+	"can be created."
--- /dev/null	Fri Nov 22 15:21:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/refreserv_003_pos.ksh	Fri Nov 22 15:21:29 2013
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#	Verify a snapshot will only be allowed if there is enough free pool
+#	space outside of this refreservation.
+#
+# STRATEGY:
+#	1. Setting quota and refservation
+#	2. Verify snapshot can be created, when used =< quota - refreserv
+#	3. Verify failed to create snapshot, when used > quota - refreserv
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify a snapshot will only be allowed if there is enough " \
+	"free space outside of this refreservation."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refreservation=10M $fs
+
+mntpnt=$(get_prop mountpoint $fs)
+log_must $MKFILE 7M $mntpnt/$TESTFILE
+log_must $ZFS snapshot $fs@snap
+
+log_must $MKFILE 7M $mntpnt/$TESTFILE.2
+log_must $ZFS snapshot $fs@snap2
+
+log_must $MKFILE 7M $mntpnt/$TESTFILE.3
+log_mustnot $ZFS snapshot $fs@snap3
+if datasetexists $fs@snap3 ; then
+	log_fail "ERROR: $fs@snap3 should not exists."
+fi
+
+log_pass "Verify a snapshot will only be allowed if there is enough " \
+	"free space outside of this refreservation."
--- /dev/null	Fri Nov 22 15:21:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/refreserv_004_pos.ksh	Fri Nov 22 15:21:30 2013
@@ -0,0 +1,90 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/refreserv/refreserv.cfg
+
+#
+# DESCRIPTION:
+#	Verify refreservation is limited by available space.
+#
+# STRATEGY:
+#	1. Setting quota and refreservation on parent filesystem.
+#	2. Get available space on sub-filesystem.
+#	3. Verify refreservation is limited by available on it.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if is_global_zone ; then
+		log_must $ZFS set refreservation=none $TESTPOOL
+	fi
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify refreservation is limited by available space."
+log_onexit cleanup
+
+pool=$TESTPOOL ; fs=$pool/$TESTFS ; subfs=$fs/subfs
+log_must $ZFS create $subfs
+
+typeset datasets
+if is_global_zone; then
+        datasets="$pool $fs"
+else
+        datasets="$fs"
+fi
+
+for ds in $datasets; do
+	log_must $ZFS set quota=25M $ds
+	log_must $ZFS set refreservation=15M $ds
+
+	typeset -i avail
+	avail=$(get_prop avail $subfs)
+	log_must $ZFS set refreservation=$avail $subfs
+	typeset mntpnt
+	mntpnt=$(get_prop mountpoint $subfs)
+	log_must $MKFILE $avail $mntpnt/$TESTFILE
+
+	typeset -i exceed
+	((exceed = avail + 1))
+	log_mustnot $ZFS set refreservation=$exceed $subfs
+	log_mustnot $MKFILE $avail $mntpnt/$TESTFILE
+
+	log_must $ZFS set quota=none $ds
+	log_must $ZFS set reservation=15M $ds
+done
+
+log_pass "Verify refreservation is limited by available space."
--- /dev/null	Fri Nov 22 15:21:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/refreserv_005_pos.ksh	Fri Nov 22 15:21:30 2013
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	Volume refreservation is limited by volsize
+#
+# STRATEGY:
+#	1. Create volume on filesystem
+#	2. Setting quota for parenet filesytem
+#	3. Verify volume refreservation is only limited by volsize
+#	4. Verify volume refreservation can be changed when volsize changed
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	log_must $ZFS destroy -rf $TESTPOOL/$TESTFS
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Volume refreservation is limited by volsize"
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS; vol=$fs/vol
+log_must $ZFS create -V 10M $vol
+
+# Verify the parent filesystem does not affect volume
+log_must $ZFS set quota=25M $fs
+log_must $ZFS set refreservation=10M $vol
+avail=$(get_prop mountpoint $vol)
+log_mustnot $ZFS set refreservation=$avail $vol
+
+# Verify it is affected by volsize
+log_must $ZFS set volsize=15M $vol
+log_must $ZFS set refreservation=15M $vol
+log_mustnot $ZFS set refreservation=16M $vol
+
+log_pass "Volume refreservation is limited by volsize"
--- /dev/null	Fri Nov 22 15:21:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/refreserv/setup.ksh	Fri Nov 22 15:21:30 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "both"
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:21:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rename_dirs/Makefile	Fri Nov 22 15:21:31 2013
@@ -0,0 +1,41 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/rename_dirs
+
+PROGS = cleanup \
+	rename_dirs_001_pos \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rename_dirs/cleanup.ksh	Fri Nov 22 15:21:31 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rename_dirs/rename_dirs_001_pos.ksh	Fri Nov 22 15:21:31 2013
@@ -0,0 +1,71 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Create two directory trees in ZFS filesystem, and concurently rename
+# directory across the two trees. ZFS should be able to handle the race
+# situation.
+#
+# STRATEGY:
+# 1. Create a ZFS filesystem
+# 2. Make two directory tree in the zfs file system
+# 3. Continually rename directory from one tree to another tree in two process
+# 4. After the specified time duration, the system should not be panic.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "ZFS can handle race directory rename operation."
+
+log_onexit cleanup
+
+$CD $TESTDIR
+$MKDIR -p 1/2/3/4/5 a/b/c/d/e
+
+$RENAME_DIRS &
+
+$SLEEP 500
+typeset -i retval=1
+$PGREP $RENAME_DIRS >/dev/null 2>&1
+retval=$?
+if (( $retval == 0 )); then
+	$PKILL -9 $RENAME_DIRS >/dev/null 2>&1
+fi
+
+log_pass "ZFS handle race directory rename operation as expected."
--- /dev/null	Fri Nov 22 15:21:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rename_dirs/setup.ksh	Fri Nov 22 15:21:32 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:21:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/replacement/Makefile	Fri Nov 22 15:21:32 2013
@@ -0,0 +1,45 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/replacement
+
+PROGS = cleanup \
+	replacement_001_pos \
+	replacement_002_pos \
+	replacement_003_pos \
+	setup
+
+FILES = replacement.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/replacement/cleanup.ksh	Fri Nov 22 15:21:33 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/replacement/replacement.cfg	Fri Nov 22 15:21:33 2013
@@ -0,0 +1,38 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile
+export TESTFILE1=testfile1
+export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb
+export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"}
+export HOLES_SEED=${HOLES_SEED-""}
+export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""}
+export HOLES_COUNT=${HOLES_COUNT-"16384"}	   # FILESIZE/BLKSIZE/8
+export REPLACEFILE="sparedisk"
--- /dev/null	Fri Nov 22 15:21:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/replacement/replacement_001_pos.ksh	Fri Nov 22 15:21:33 2013
@@ -0,0 +1,160 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/replacement/replacement.cfg
+
+#
+# DESCRIPTION:
+# 	Replacing disks during I/O should pass for supported pools.
+#
+# STRATEGY:
+#	1. Create multidisk pools (stripe/mirror/raidz) and
+#	   start some random I/O
+#	2. Replace a disk in the pool with anbother disk.
+#	3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if [[ -n "$child_pids" ]]; then
+		for wait_pid in $child_pids
+		do
+		        $KILL $wait_pid
+		done
+	fi
+
+	if poolexists $TESTPOOL1; then
+		destroy_pool $TESTPOOL1
+	fi
+
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Replacing a disk during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pids=""
+
+function replace_test
+{
+	typeset -i iters=2
+	typeset -i index=0
+	typeset opt=$1
+	typeset disk1=$2
+	typeset disk2=$3
+
+	typeset i=0
+	while [[ $i -lt $iters ]]; do
+		log_note "Invoking $FILE_TRUNC with: $options_display"
+		$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+		typeset pid=$!
+
+		$SLEEP 1
+		if ! $PS -p $pid > /dev/null 2>&1; then
+			log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+		fi
+
+		child_pids="$child_pids $pid"
+		((i = i + 1))
+	done
+
+	log_must $ZPOOL replace $opt $TESTPOOL1 $disk1 $disk2
+
+	$SLEEP 10
+
+	for wait_pid in $child_pids
+	do
+		$KILL $wait_pid
+	done
+	child_pids=""
+
+        log_must $ZPOOL export $TESTPOOL1
+        log_must $ZPOOL import -d $TESTDIR $TESTPOOL1
+        log_must $ZFS umount $TESTPOOL1/$TESTFS1
+        log_must $ZDB -cdui $TESTPOOL1/$TESTFS1
+        log_must $ZFS mount $TESTPOOL1/$TESTFS1
+
+}
+
+specials_list=""
+i=0
+while [[ $i != 2 ]]; do
+        $MKFILE 100m $TESTDIR/$TESTFILE1.$i
+        specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+
+        ((i = i + 1))
+done
+
+#
+# Create a replacement disk special file.
+#
+$MKFILE 100m $TESTDIR/$REPLACEFILE
+
+for type in "" "raidz" "raidz1" "mirror"; do
+	for op in "" "-f"; do
+		create_pool $TESTPOOL1 $type $specials_list
+		log_must $ZFS create $TESTPOOL1/$TESTFS1
+		log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+		replace_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE
+
+		$ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE"
+		if [[ $? -ne 0 ]]; then
+			log_fail "$REPLACEFILE is not present."
+		fi
+
+		destroy_pool $TESTPOOL1
+		log_must $RM -rf /$TESTPOOL1
+	done
+done
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/replacement/replacement_002_pos.ksh	Fri Nov 22 15:21:34 2013
@@ -0,0 +1,177 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/replacement/replacement.cfg
+
+#
+# DESCRIPTION:
+# 	Attaching disks during I/O should pass for supported pools.
+#
+# STRATEGY:
+#	1. Create multidisk pools (stripe/mirror/raidz) and
+#	   start some random I/O
+#	2. Attach a disk to the pool.
+#	3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if [[ -n "$child_pids" ]]; then
+		for wait_pid in $child_pids
+		do
+		        $KILL $wait_pid
+		done
+	fi
+
+	if poolexists $TESTPOOL1; then
+		destroy_pool $TESTPOOL1
+	fi
+
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Replacing a disk during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pids=""
+
+function attach_test
+{
+	typeset -i iters=2
+	typeset -i index=0
+	typeset opt=$1
+	typeset disk1=$2
+	typeset disk2=$3
+
+	typeset i=0
+	while [[ $i -lt $iters ]]; do
+		log_note "Invoking $FILE_TRUNC with: $options_display"
+		$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+		typeset pid=$!
+
+		$SLEEP 1
+		if ! $PS -p $pid > /dev/null 2>&1; then
+			log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+		fi
+
+		child_pids="$child_pids $pid"
+		((i = i + 1))
+	done
+
+	log_must $ZPOOL attach $opt $TESTPOOL1 $disk1 $disk2
+
+	$SLEEP 10
+
+	for wait_pid in $child_pids
+	do
+		$KILL $wait_pid
+	done
+	child_pids=""
+
+        log_must $ZPOOL export $TESTPOOL1
+        log_must $ZPOOL import -d $TESTDIR $TESTPOOL1
+        log_must $ZFS umount $TESTPOOL1/$TESTFS1
+        log_must $ZDB -cdui $TESTPOOL1/$TESTFS1
+        log_must $ZFS mount $TESTPOOL1/$TESTFS1
+
+}
+
+specials_list=""
+i=0
+while [[ $i != 2 ]]; do
+	$MKFILE 100m $TESTDIR/$TESTFILE1.$i
+	specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+
+	((i = i + 1))
+done
+
+#
+# Create a replacement disk special file.
+#
+$MKFILE 100m $TESTDIR/$REPLACEFILE
+
+for op in "" "-f"; do
+	create_pool $TESTPOOL1 mirror $specials_list
+	log_must $ZFS create $TESTPOOL1/$TESTFS1
+	log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+	attach_test "$opt" $TESTDIR/$TESTFILE1.1 $TESTDIR/$REPLACEFILE
+
+	$ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE"
+	if [[ $? -ne 0 ]]; then
+		log_fail "$REPLACEFILE is not present."
+	fi
+
+	destroy_pool $TESTPOOL1
+done
+
+log_note "Verify 'zpool attach' fails with non-mirrors."
+
+for type in "" "raidz" "raidz1"; do
+	for op in "" "-f"; do
+		create_pool $TESTPOOL1 $type $specials_list
+		log_must $ZFS create $TESTPOOL1/$TESTFS1
+		log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+		log_mustnot $ZPOOL attach "$opt" $TESTDIR/$TESTFILE1.1 \
+		    $TESTDIR/$REPLACEFILE
+
+		$ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$REPLACEFILE"
+		if [[ $? -eq 0 ]]; then
+		        log_fail "$REPLACEFILE should not be present."
+		fi
+
+		destroy_pool $TESTPOOL1
+	done
+done
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/replacement/replacement_003_pos.ksh	Fri Nov 22 15:21:34 2013
@@ -0,0 +1,164 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/replacement/replacement.cfg
+
+#
+# DESCRIPTION:
+# 	Detaching disks during I/O should pass for supported pools.
+#
+# STRATEGY:
+#	1. Create multidisk pools (stripe/mirror/raidz) and
+#	   start some random I/O
+#	2. Detach a disk from the pool.
+#	3. Verify the integrity of the file system and the resilvering.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if [[ -n "$child_pids" ]]; then
+		for wait_pid in $child_pids
+		do
+		        $KILL $wait_pid
+		done
+	fi
+
+	if poolexists $TESTPOOL1; then
+		destroy_pool $TESTPOOL1
+	fi
+
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Replacing a disk during I/O completes."
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+ptions="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+child_pids=""
+
+function detach_test
+{
+	typeset -i iters=2
+	typeset -i index=0
+	typeset disk1=$1
+
+	typeset i=0
+	while [[ $i -lt $iters ]]; do
+		log_note "Invoking $FILE_TRUNC with: $options_display"
+		$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
+		typeset pid=$!
+
+		$SLEEP 1
+		if ! $PS -p $pid > /dev/null 2>&1; then
+			log_fail "$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i"
+		fi
+
+		child_pids="$child_pids $pid"
+		((i = i + 1))
+	done
+
+	log_must $ZPOOL detach $TESTPOOL1 $disk1
+
+	$SLEEP 10
+
+	for wait_pid in $child_pids
+	do
+		$KILL $wait_pid
+	done
+	child_pids=""
+
+        log_must $ZPOOL export $TESTPOOL1
+        log_must $ZPOOL import -d $TESTDIR $TESTPOOL1
+        log_must $ZFS umount $TESTPOOL1/$TESTFS1
+        log_must $ZDB -cdui $TESTPOOL1/$TESTFS1
+        log_must $ZFS mount $TESTPOOL1/$TESTFS1
+}
+
+specials_list=""
+i=0
+while [[ $i != 2 ]]; do
+	$MKFILE 100m $TESTDIR/$TESTFILE1.$i
+	specials_list="$specials_list $TESTDIR/$TESTFILE1.$i"
+
+	((i = i + 1))
+done
+
+create_pool $TESTPOOL1 mirror $specials_list
+log_must $ZFS create $TESTPOOL1/$TESTFS1
+log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+detach_test $TESTDIR/$TESTFILE1.1
+
+$ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
+if [[ $? -eq 0 ]]; then
+	log_fail "$TESTFILE1.1 should no longer be present."
+fi
+
+destroy_pool $TESTPOOL1
+
+log_note "Verify 'zpool detach' fails with non-mirrors."
+
+for type in "" "raidz" "raidz1" ; do
+	create_pool $TESTPOOL1 $type $specials_list
+	log_must $ZFS create $TESTPOOL1/$TESTFS1
+	log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL1/$TESTFS1
+
+	log_mustnot $ZPOOL detach $TESTDIR/$TESTFILE1.1
+
+	$ZPOOL iostat -v $TESTPOOL1 | grep "$TESTDIR/$TESTFILE1.1"
+	if [[ $? -ne 0 ]]; then
+	        log_fail "$TESTFILE1.1 is not present."
+	fi
+
+	destroy_pool $TESTPOOL1
+done
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/replacement/setup.ksh	Fri Nov 22 15:21:34 2013
@@ -0,0 +1,47 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+verify_disk_count "$DISKS" 2
+
+index=`expr $RANDOM % 2`
+case $index in
+0)	log_note "Pool Type: Mirror"
+	default_mirror_setup $DISKS
+	;;
+1)	log_note "Pool Type: RAID-Z"
+	default_raidz_setup $DISKS
+	;;
+esac
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/Makefile	Fri Nov 22 15:21:35 2013
@@ -0,0 +1,64 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/reservation
+
+PROGS = cleanup \
+	reservation_001_pos \
+	reservation_002_pos \
+	reservation_003_pos \
+	reservation_004_pos \
+	reservation_005_pos \
+	reservation_006_pos \
+	reservation_007_pos \
+	reservation_008_pos \
+	reservation_009_pos \
+	reservation_010_pos \
+	reservation_011_pos \
+	reservation_012_pos \
+	reservation_013_pos \
+	reservation_014_pos \
+	reservation_015_pos \
+	reservation_016_pos \
+	reservation_017_pos \
+	reservation_018_pos \
+	setup
+
+FILES = reservation.cfg \
+	reservation.shlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.sh
+	$(INS.rename)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/cleanup.ksh	Fri Nov 22 15:21:35 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation.cfg	Fri Nov 22 15:21:35 2013
@@ -0,0 +1,44 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export RESV_DELTA=5242880
+export RESV_TOLERANCE=5242880	# Acceptable limit (5MB) for diff in space stats
+export RESV_SIZE=52428800	# Default reservation size (50MB)
+export RESV_FREE_SPACE=52428800	# Amount of space (50MB) to leave free in a pool
+export RESV_NUM_FS=10		# Number of filesystems to create
+export RESV_ITER=10		# Number of iterations
+
+export BLOCK_SIZE=1048576
+export ENOSPC=28
+
+export TESTVOL=testvol$$
+export TESTVOL2=testvol2-$$
+export TESTFILE1=file1.$$
+export TESTFILE2=file2.$$
--- /dev/null	Fri Nov 22 15:21:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation.shlib	Fri Nov 22 15:21:36 2013
@@ -0,0 +1,201 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/reservation/reservation.cfg
+
+#
+# Function to set the reservation property of a dataset to
+# 'none' and verify that it is correctly set using both the
+# "normal" 'zfs get reservation' and the '-p' option which
+# gives a numerical value.
+#
+function zero_reservation
+{
+	typeset resv_val
+	dataset=$1
+
+	log_must $ZFS set reservation=none $dataset
+
+	resv_val=`$ZFS get -H reservation $dataset | awk '{print $3}'`
+	if [[ $? -ne 0 ]]; then
+		log_fail "Unable to get reservation prop on $dataset"
+	elif [[ $resv_val != "none" ]]; then
+		log_fail "Reservation not 'none' ($resv_val) as expected"
+	fi
+
+
+	resv_val=`$ZFS get -pH reservation $dataset | awk '{print $3}'`
+	if [[ $? -ne 0 ]]; then
+		log_fail "Unable to get reservation prop on $dataset"
+	elif [[ $resv_val -ne 0 ]]; then
+		log_fail "Reservation not 0 ($resv_val) as expected"
+	fi
+
+	return 0
+}
+
+#
+# Utility function to see if two values are within a certain specified
+# limit of each other. Used primarily to check that a dataset's parent
+# is correctly accounting for space used/available. Need this function as
+# currently there is some slop in the way space is accounted (i.e. can't
+# do a direct comparison).
+#
+function within_limits
+{
+	typeset -l valA=$1
+	typeset -l valB=$2
+	typeset -l delta=$3
+
+	if ((valA <= valB)); then
+		if (((valB - valA) <= delta)); then
+			return 0
+		fi
+	elif ((valB <= valA)); then
+		if (((valA - valB) <= delta)); then
+			return 0
+		fi
+	fi
+
+	return 1
+}
+
+#
+# Function to create and mount multiple filesystems. The filesystem
+# will be named according to the name specified with a suffix value
+# taken from the loop counter.
+#
+function create_multiple_fs # num_fs base_fs_name base_mnt_name
+{
+	typeset -i iter=0
+	typeset -i count=$1
+	typeset FS_NAME=$2
+	typeset MNT_NAME=$3
+
+	while  (($iter < $count)); do
+		log_must $ZFS create ${FS_NAME}$iter
+		log_must $ZFS set mountpoint=${MNT_NAME}$iter ${FS_NAME}$iter
+		((iter = iter + 1))
+	done
+}
+
+#
+# This function compute the largest volume size which is multiple of volume
+# block size (default 8K) and not greater than the largest expected volsize.
+#
+# $1 The largest expected volume size.
+# $2 The volume block size
+#
+function floor_volsize #<largest_volsize> [volblksize]
+{
+	typeset -l largest_volsize=$1
+	typeset -l volblksize=${2:-8192}
+
+	if ((largest_volsize < volblksize)); then
+		log_fail "The largest_volsize must be greater than volblksize."
+	fi
+	typeset -l real_volsize
+	typeset -l n
+
+	((n = largest_volsize / volblksize))
+	((largest_volsize = volblksize * n))
+
+	print $largest_volsize
+}
+
+#
+# This function is a copy of a function by the same name in libzfs_dataset.c
+# Its purpose is to reserve additional space for volume metadata so volumes
+# don't unexpectedly run out of room.
+#
+# Note: This function can be used to do an estimate for a volume that has not
+# yet been created. In this case, $vol is not a volume, but rather a pool in
+# which a volume is going to be created. In this case, use default properties.
+#
+function volsize_to_reservation
+{
+	typeset vol=$1
+	typeset -i volsize=$2
+
+	typeset -i DN_MAX_INDBLKSHIFT=14
+	typeset -i SPA_BLKPTRSHIFT=7
+	typeset -i SPA_DVAS_PER_BP=3
+
+	typeset -i DNODES_PER_LEVEL_SHIFT=$((DN_MAX_INDBLKSHIFT - \
+	    SPA_BLKPTRSHIFT))
+	typeset -i DNODES_PER_LEVEL=$((1 << $DNODES_PER_LEVEL_SHIFT))
+
+	if ds_is_volume $vol; then
+		typeset -i ncopies=$(get_prop copies $vol)
+		typeset -i volblocksize=$(get_prop volblocksize $vol)
+	else
+		typeset -i ncopies=1
+		typeset -i volblocksize=8192
+	fi
+	typeset -i nblocks=$((volsize / volblocksize))
+
+	typeset -i numdb=7
+	while ((nblocks > 1)); do
+		((nblocks += DNODES_PER_LEVEL - 1))
+		((nblocks /= DNODES_PER_LEVEL))
+		((numdb += nblocks))
+	done
+
+	((numdb *= SPA_DVAS_PER_BP < ncopies + 1 ? SPA_DVAS_PER_BP : \
+	    ncopies + 1))
+	((volsize *= ncopies))
+	((numdb *= 1 << DN_MAX_INDBLKSHIFT))
+	((volsize += numdb))
+	echo $volsize
+}
+
+#
+# This function takes a pool name as an argument, and returns the largest (give
+# or take some slop) -V value that can be used to create a volume in that pool.
+# This is necessary because during volume creation, a reservation is created
+# that will be larger than the value specified with -V, and potentially larger
+# than the available space in the pool. See volsize_to_reservation().
+#
+function largest_volsize_from_pool
+{
+	typeset pool=$1
+	typeset -i poolsize=$(get_prop available $pool)
+	typeset -i volsize=$poolsize
+	typeset -i nvolsize
+
+	while :; do
+		# knock 50M off the volsize each time through
+		((volsize -= 50 * 1024 * 1024))
+		nvolsize=$(volsize_to_reservation $pool $volsize)
+		nvolsize=$(floor_volsize $nvolsize)
+		((nvolsize < poolsize)) && break
+	done
+	echo $volsize
+}
--- /dev/null	Fri Nov 22 15:21:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_001_pos.sh	Fri Nov 22 15:21:36 2013
@@ -0,0 +1,124 @@
+#!/usr/bin/bash -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# ZFS allows reservations to be set on filesystems and volumes, provided
+# the reservation is less than the space available in the pool.
+#
+# STRATEGY:
+# 1) Create a regular and sparse volume
+#   (filesystem already created by default_setup)
+# 2) Get the space available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+#    the correct value.
+# 5) Reset the reservation to 'none'
+# 6) Repeat steps 2-5 for both volume types
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for obj in $OBJ_LIST; do
+		datasetexists $obj && log_must $ZFS destroy -f $obj
+	done
+}
+
+log_onexit cleanup
+
+log_assert "Verify that to set a reservation on a filesystem or volume must " \
+    "use value smaller than space available property of pool"
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+	OBJ_LIST=""
+else
+	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+	((vol_set_size = space_avail / 4))
+	vol_set_size=$(floor_volsize $vol_set_size)
+	((sparse_vol_set_size = space_avail * 4))
+	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+	#
+	# Note that when creating a regular volume we are implicitly
+	# setting a reservation upon it (i.e. the size of the volume)
+	# which we reset back to zero initially.
+	#
+	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+	log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
+	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do
+
+	space_avail=`get_prop available $TESTPOOL`
+	resv_size_set=`expr $space_avail - $RESV_DELTA`
+
+	#
+	# For a regular (non-sparse) volume the upper limit
+	# for reservations is not determined by the space
+	# available in the pool but rather by the size of
+	# the volume itself.
+	#
+	[[ $obj == $TESTPOOL/$TESTVOL ]] && \
+	    ((resv_size_set = vol_set_size - RESV_DELTA))
+
+	log_must $ZFS set reservation=$resv_size_set $obj
+
+	resv_size_get=`get_prop reservation $obj`
+	if [[ $resv_size_set != $resv_size_get ]]; then
+		log_fail "Reservation not the expected value " \
+		    "($resv_size_set != $resv_size_get)"
+	fi
+
+	log_must zero_reservation $obj
+
+	new_space_avail=`get_prop available $obj`
+
+	#
+	# Due to the way space is consumed and released by metadata we
+	# can't do an exact check here, but we do do a basic sanity
+	# check.
+	#
+	log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
+done
+
+log_pass "Successfully set reservation on filesystem and volume"
--- /dev/null	Fri Nov 22 15:21:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_002_pos.sh	Fri Nov 22 15:21:37 2013
@@ -0,0 +1,108 @@
+#!/usr/bin/bash -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Reservation values cannot exceed the amount of space available
+# in the pool. Verify that attempting to set a reservation greater
+# than this value fails.
+#
+# STRATEGY:
+# 1) Create a filesystem, regular and sparse volume
+# 2) Get the space available in the pool
+# 3) Attempt to set a reservation greater than the available space
+# on the filesystem and verify it fails.
+# 4) Verify that the reservation is still set to 'none' (or 0) on
+# the filesystem.
+# 5) Repeat 3-4 for regular and sparse volume
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for obj in $OBJ_LIST; do
+		datasetexists $obj && log_must $ZFS destroy -f $obj
+	done
+
+	log_must zero_reservation $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+log_assert "Reservation values cannot exceed the amount of space" \
+	" available in the pool"
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+	OBJ_LIST=""
+else
+	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+	((vol_set_size = space_avail / 4))
+	vol_set_size=$(floor_volsize $vol_set_size)
+	((sparse_vol_set_size = space_avail * 4))
+	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+
+	space_avail=`get_prop available $TESTPOOL`
+	resv_size_set=`expr $space_avail + $RESV_DELTA`
+
+	#
+	# For regular (non-sparse) volumes the upper limit is determined
+	# not by the space available in the pool but rather by the size
+	# of the volume itself.
+	#
+	[[ $obj == $TESTPOOL/$TESTVOL ]] && \
+	    ((resv_size_set = vol_set_size + RESV_DELTA))
+
+	log_must zero_reservation $obj
+	log_mustnot $ZFS set reservation=$resv_size_set $obj
+
+	resv_size_get=`get_prop reservation $obj`
+
+	if (($resv_size_get != 0)); then
+		log_fail "Reservation value non-zero ($resv_size_get)"
+	fi
+done
+
+log_pass "Attempting to set too large reservation failed as expected"
--- /dev/null	Fri Nov 22 15:21:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_003_pos.sh	Fri Nov 22 15:21:37 2013
@@ -0,0 +1,134 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Verify that it's possible to set a reservation on a filesystem,
+# or volume multiple times, without resetting the reservation
+# to none.
+#
+# STRATEGY:
+# 1) Create a regular volume and a sparse volume
+# 2) Get the space available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+# the correct value.
+# 5) Repeat 2-4 for different reservation values
+# 6) Repeat 3-5 for regular and sparse volume
+#
+
+verify_runnable "both"
+
+log_assert "Verify it is possible to set reservations multiple times " \
+	"on a filesystem regular and sparse volume"
+
+function cleanup
+{
+	log_must zero_reservation $TESTPOOL/$TESTFS
+
+	for obj in $OBJ_LIST; do
+	datasetexists $obj && log_must $ZFS destroy -f $obj
+	done
+}
+
+log_onexit cleanup
+
+
+#
+# Set a reservation $RESV_ITER times on a dataset and verify that
+# the reservation is correctly set each time.
+#
+function multiple_resv { #dataset
+	typeset -i i=0
+
+	dataset=$1
+
+	log_must zero_reservation $dataset
+	space_avail=`get_prop available $TESTPOOL`
+
+	((resv_size = (space_avail - RESV_DELTA) / RESV_ITER))
+
+	#
+	# For regular (non-sparse) volumes the upper limit is determined
+	# not by the space available in the pool but rather by the size
+	# of the volume itself.
+	#
+	[[ $obj == $TESTPOOL/$TESTVOL ]] && \
+	    ((resv_size = (vol_set_size - RESV_DELTA) / RESV_ITER))
+
+	resv_size_set=$resv_size
+
+	while (($i < $RESV_ITER)); do
+
+		((i = i + 1))
+
+		((resv_size_set = resv_size * i))
+
+		log_must $ZFS set reservation=$resv_size_set $dataset
+
+		resv_size_get=`get_prop reservation $dataset`
+		if [[ $resv_size_set != $resv_size_get ]]; then
+			log_fail "Reservation not the expected value " \
+			    "($resv_size_set != $resv_size_get)"
+		fi
+	done
+
+	log_must zero_reservation $dataset
+}
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+	OBJ_LIST=""
+else
+	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+	((vol_set_size = space_avail / 4))
+	vol_set_size=$(floor_volsize $vol_set_size)
+	((sparse_vol_set_size = space_avail * 4))
+	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+
+	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+	multiple_resv $obj
+done
+
+log_pass "Multiple reservations successfully set on filesystem" \
+    " and both volume types"
--- /dev/null	Fri Nov 22 15:21:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_004_pos.sh	Fri Nov 22 15:21:37 2013
@@ -0,0 +1,124 @@
+#!/bin/bash -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# When a dataset which has a reservation set on it is destroyed,
+# the space consumed or reserved by that dataset should be released
+# back into the pool.
+#
+# STRATEGY:
+# 1) Create a filesystem, regular and sparse volume
+# 2) Get the space used and available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+# the correct value.
+# 5) Destroy the filesystem without resetting the reservation value.
+# 6) Verify that the space used and available totals for the pool have
+# changed by the expected amounts (within tolerances).
+# 7) Repeat steps 3-6 for a regular volume and sparse volume
+#
+
+verify_runnable "both"
+
+function cleanup {
+
+	for obj in $OBJ_LIST; do
+		datasetexists $obj && log_must $ZFS destroy -f $obj
+	done
+}
+
+log_assert "Verify space released when a dataset with reservation is destroyed"
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS2
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+	OBJ_LIST="$TESTPOOL/$TESTFS2"
+else
+	OBJ_LIST="$TESTPOOL/$TESTFS2 \
+		$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+	((vol_set_size = space_avail / 4))
+	vol_set_size=$(floor_volsize $vol_set_size)
+	((sparse_vol_set_size = space_avail * 4))
+	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+	log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
+	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+# re-calculate space available.
+space_avail=`get_prop available $TESTPOOL`
+
+# Calculate a large but valid reservation value.
+resv_size_set=`expr $space_avail - $RESV_DELTA`
+
+for obj in $OBJ_LIST ; do
+
+	space_avail=`get_prop available $TESTPOOL`
+	space_used=`get_prop used $TESTPOOL`
+
+	#
+	# For regular (non-sparse) volumes the upper limit is determined
+	# not by the space available in the pool but rather by the size
+	# of the volume itself.
+	#
+	[[ $obj == $TESTPOOL/$TESTVOL ]] && \
+	    ((resv_size_set = vol_set_size - RESV_DELTA))
+
+	log_must $ZFS set reservation=$resv_size_set $obj
+
+	resv_size_get=`get_prop reservation $obj`
+	if [[ $resv_size_set != $resv_size_get ]]; then
+		log_fail "Reservation not the expected value " \
+		"($resv_size_set != $resv_size_get)"
+	fi
+
+	log_must $ZFS destroy -f $obj
+
+	new_space_avail=`get_prop available $TESTPOOL`
+	new_space_used=`get_prop used $TESTPOOL`
+
+	log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
+	log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
+done
+
+log_pass "Space correctly released when dataset is destroyed"
--- /dev/null	Fri Nov 22 15:21:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_005_pos.sh	Fri Nov 22 15:21:38 2013
@@ -0,0 +1,118 @@
+#!/usr/bin/bash -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# When a reservation property of a filesystem, regular volume
+# or sparse volume is set to 'none' the space previously consumed by the
+# reservation should be released back to the pool
+#
+# STRATEGY:
+# 1) Create a filesystem, regular volume and sparse volume
+# 2) Get the space used and available in the pool
+# 3) Set a reservation on the filesystem less than the space available.
+# 4) Verify that the 'reservation' property for the filesystem has
+# the correct value.
+# 5) Reset the reservation value back to zero (or 'none')
+# 6) Verify that the space used and available totals for the pool have
+# changed by the expected amounts (within tolerances).
+# 7) Repeat steps 3-6 for a regular volume, sparse volume
+#
+
+verify_runnable "both"
+
+log_assert "Verify space released when reservation on a dataset is set "\
+	"to 'none'"
+
+function cleanup
+{
+	for obj in $OBJ_LIST; do
+		datasetexists $obj && log_must $ZFS destroy -f $obj
+	done
+}
+
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+	OBJ_LIST=""
+else
+	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+	((vol_set_size = space_avail / 4))
+	vol_set_size=$(floor_volsize $vol_set_size)
+	((sparse_vol_set_size = space_avail * 4))
+	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+
+	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+	log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL
+	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+space_avail=`get_prop available $TESTPOOL`
+space_used=`get_prop used $TESTPOOL`
+
+# Calculate a large but valid reservation value.
+resv_size_set=`expr $space_avail - $RESV_DELTA`
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+
+	#
+	# For regular (non-sparse) volumes the upper limit is determined
+	# not by the space available in the pool but rather by the size
+	# of the volume itself.
+	#
+	[[ $obj == $TESTPOOL/$TESTVOL ]] && \
+	    ((resv_size_set = vol_set_size - RESV_DELTA))
+
+	log_must $ZFS set reservation=$resv_size_set $obj
+
+	resv_size_get=`get_prop reservation $obj`
+	if [[ $resv_size_set != $resv_size_get ]]; then
+		log_fail "Reservation not the expected value "\
+			"($resv_size_set != $resv_size_get)"
+	fi
+
+	log_must $ZFS set reservation=none $obj
+
+	new_space_avail=`get_prop available $TESTPOOL`
+	new_space_used=`get_prop used $TESTPOOL`
+
+	log_must within_limits $space_used $new_space_used $RESV_TOLERANCE
+	log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE
+done
+
+log_pass "Space correctly released when dataset reservation set to 'none'"
--- /dev/null	Fri Nov 22 15:21:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_006_pos.sh	Fri Nov 22 15:21:38 2013
@@ -0,0 +1,81 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Reservations (if successfully set) guarantee a minimum amount of space
+# for a dataset. Unlike quotas however there should be no restrictions
+# on accessing space outside of the limits of the reservation (if the
+# space is available in the pool). Verify that in a filesystem with a
+# reservation set that its possible to create files both within the
+# reserved space and also outside.
+#
+# STRATEGY:
+# 1) Create a filesystem
+# 2) Get the space used and available in the pool
+# 3) Set a reservation on the filesystem
+# 4) Verify can write a file that is bigger than the reserved space
+#
+# i.e. we start writing within the reserved region and then continue
+# for 20MB outside it.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	[[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+	log_must $ZFS set reservation=none $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+log_assert "Verify can create files both inside and outside reserved areas"
+
+space_used=`get_prop used $TESTPOOL`
+
+log_must $ZFS set reservation=$RESV_SIZE $TESTPOOL/$TESTFS
+
+#
+# Calculate how many writes of BLOCK_SIZE it would take to fill
+# up RESV_SIZE + 20971520 (20 MB).
+#
+fill_size=`expr $RESV_SIZE + 20971520`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \
+    -c $write_count -d 0
+
+log_pass "Able to create files inside and outside reserved area"
--- /dev/null	Fri Nov 22 15:21:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_007_pos.sh	Fri Nov 22 15:21:38 2013
@@ -0,0 +1,128 @@
+#!/usr/bin/bash -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Setting a reservation on dataset should have no effect on any other
+# dataset at the same level in the hierarchy beyond using up available
+# space in the pool.
+#
+# STRATEGY:
+# 1) Create a filesystem
+# 2) Set a reservation on the filesystem
+# 3) Create another filesystem at the same level
+# 4) Set a reservation on the second filesystem
+# 5) Destroy both the filesystems
+# 6) Verify space accounted for correctly
+#
+
+verify_runnable "both"
+
+log_assert "Verify reservations on data sets doesn't affect other data sets " \
+    "at same level except for consuming space from common pool"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTFS2 && \
+	    log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
+
+	datasetexists $TESTPOOL/$TESTFS1 && \
+	    log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+}
+
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+space_used=`get_prop used $TESTPOOL`
+
+resv_size_set=`expr $space_avail / 3`
+
+#
+# Function which creates two datasets, sets reservations on them,
+# then destroys them and ensures that space is correctly accounted
+# for.
+#
+# Any special arguments for create are passed in via the args
+# paramater.
+#
+function create_resv_destroy { # args1 dataset1 args2 dataset2
+
+	args1=$1
+	dataset1=$2
+	args2=$3
+	dataset2=$4
+
+	log_must $ZFS create $args1 $dataset1
+
+	log_must $ZFS set reservation=$RESV_SIZE $dataset1
+
+	avail_aft_dset1=`get_prop available $TESTPOOL`
+	used_aft_dset1=`get_prop used $TESTPOOL`
+
+	log_must $ZFS create $args2 $dataset2
+
+	log_must $ZFS set reservation=$RESV_SIZE $dataset2
+
+	#
+	# After destroying the second dataset the space used and
+	# available totals should revert back to the values they
+	# had after creating the first dataset.
+	#
+	log_must $ZFS destroy -f $dataset2
+
+	avail_dest_dset2=`get_prop available $TESTPOOL`
+	used_dest_dset2=`get_prop used $TESTPOOL`
+
+	log_must within_limits $avail_aft_dset1 $avail_dest_dset2 $RESV_TOLERANCE
+	log_must within_limits $used_aft_dset1 $used_dest_dset2 $RESV_TOLERANCE
+
+
+	# After destroying the first dataset the space used and
+	# space available totals should revert back to the values
+	# they had when the pool was first created.
+	log_must $ZFS destroy -f $dataset1
+
+	avail_dest_dset1=`get_prop available $TESTPOOL`
+	used_dest_dset1=`get_prop used $TESTPOOL`
+
+	log_must within_limits $avail_dest_dset1 $space_avail $RESV_TOLERANCE
+	log_must within_limits $used_dest_dset1 $space_used $RESV_TOLERANCE
+}
+
+create_resv_destroy "" $TESTPOOL/$TESTFS1 ""  $TESTPOOL/$TESTFS2
+create_resv_destroy "" $TESTPOOL/$TESTFS2 "" $TESTPOOL/$TESTFS1
+
+log_pass "Verify reservations on data sets doesn't affect other data sets at" \
+	" same level except for consuming space from common pool"
--- /dev/null	Fri Nov 22 15:21:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_008_pos.sh	Fri Nov 22 15:21:39 2013
@@ -0,0 +1,124 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Setting a reservation reserves a defined minimum amount of space for
+# a dataset, and prevents other datasets using that space. Verify that
+# reducing the reservation on a filesystem allows other datasets in
+# the pool to use that space.
+#
+# STRATEGY:
+# 1) Create multiple filesystems
+# 2) Set reservations on all bar one of the filesystems
+# 3) Fill up the one non-reserved filesystem
+# 4) Reduce one of the reservations and verify can write more
+# data into the non-reserved filesystem
+#
+
+verify_runnable "both"
+
+log_assert "Verify reducing reservation allows other datasets to use space"
+
+function cleanup
+{
+	typeset -i loop=0
+	while (($loop < $RESV_NUM_FS)); do
+		datasetexists $TESTPOOL/${TESTFS}$loop && \
+		    log_must $ZFS destroy -f $TESTPOOL/${TESTFS}$loop
+
+		[[ -d ${TESTDIR}$loop ]] && log_must $RM -r ${TESTDIR}$loop
+
+		((loop = loop + 1))
+	done
+}
+
+log_onexit cleanup
+
+log_must create_multiple_fs $RESV_NUM_FS $TESTPOOL/$TESTFS $TESTDIR
+
+space_avail=`get_prop available $TESTPOOL`
+space_used=`get_prop used $TESTPOOL`
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a reservation setting which when
+# applied to all bar one of the filesystems (RESV_NUM_FS-1) will
+# ensure we have RESV_FREE_SPACE left free in the pool, which we will
+# be able to quickly fill.
+#
+resv_space_avail=`expr $space_avail - $RESV_FREE_SPACE`
+num_resv_fs=`expr $RESV_NUM_FS - 1` # Number of FS to which resv will be applied
+resv_size_set=`expr $resv_space_avail / $num_resv_fs`
+
+#
+# We set the reservations now, rather than when we created the filesystems
+# to allow us to take into account space used by the filsystem metadata
+#
+# Note we don't set a reservation on the first filesystem we created,
+# hence num=1 rather than zero below.
+#
+typeset -i num=1
+while (($num < $RESV_NUM_FS)); do
+	log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS$num
+	((num = num + 1))
+done
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+# Now fill up the first filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+num=0
+log_note "Writing to $TESTDIR$num/$TESTFILE1"
+
+$FILE_WRITE -o create -f $TESTDIR$num/$TESTFILE1 -b $BLOCK_SIZE \
+    -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+	log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+# Remove the reservation on one of the other filesystems and verify
+# can write more data to the original non-reservation filesystem.
+num=1
+log_must $ZFS set reservation=none $TESTPOOL/${TESTFS}$num
+num=0
+log_must $FILE_WRITE -o create -f ${TESTDIR}$num/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "reducing reservation allows other datasets to use space"
--- /dev/null	Fri Nov 22 15:21:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_009_pos.sh	Fri Nov 22 15:21:39 2013
@@ -0,0 +1,100 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and another filesystem with a reservation
+# setting the reservation on the second filesystem to 'none' should allow more
+# data to be written to the first filesystem.
+#
+#
+# STRATEGY:
+# 1) Create a filesystem as a dataset
+# 2) Create a filesystem at the same level
+# 3) Set a reservation on the dataset filesystem
+# 4) Fill up the filesystem
+# 5) Set the reservation on the dataset filesystem to 'none'
+# 6) Verify we can write more data to the first filesystem
+#
+
+verify_runnable "both"
+
+log_assert "Setting top level dataset reservation to 'none' allows more data "
+    "to be written to top level filesystem"
+
+function cleanup
+{
+	log_must $RM -rf $TESTDIR/$TESTFILE1
+	log_must $RM -rf $TESTDIR/$TESTFILE2
+	log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+}
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+
+space_avail=`get_prop available $TESTPOOL`
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a reservation setting which when
+# applied to the dataset will ensure we have RESV_FREE_SPACE
+# left free in the pool which we can quickly fill.
+#
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS1
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \
+        -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+	log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS set reservation=none $TESTPOOL/$TESTFS1
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Setting top level dataset reservation to 'none' allows more " \
+    "data to be written to the top level filesystem"
--- /dev/null	Fri Nov 22 15:21:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_010_pos.sh	Fri Nov 22 15:21:39 2013
@@ -0,0 +1,101 @@
+#!/usr/bin/bash -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and a filesystem with a reservation
+# destroying another filesystem should allow more data to be written to
+# the full filesystem
+#
+#
+# STRATEGY:
+# 1) Create a filesystem as dataset
+# 2) Create a filesystem at the same level
+# 3) Set a reservation on the dataset filesystem
+# 4) Fill up the second filesystem
+# 5) Destroy the dataset filesystem
+# 6) Verify can write more data to the full filesystem
+#
+
+verify_runnable "both"
+
+log_assert "Destroying top level filesystem with reservation allows more " \
+    "data to be written to another top level filesystem"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTFS1 && \
+	    log_must $ZFS destroy $TESTPOOL/$TESTFS1
+
+	[[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+	[[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+}
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+
+space_avail=`get_prop available $TESTPOOL`
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a reservation setting which when
+# applied to the dataset filesystem  will ensure we have
+# RESV_FREE_SPACE left free in the pool.
+#
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS1
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=`expr $space_avail_still + $RESV_TOLERANCE`
+write_count=`expr $fill_size / $BLOCK_SIZE`
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+	log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Destroying top level filesystem with reservation allows more data " \
+    "to be written to another top level filesystem"
--- /dev/null	Fri Nov 22 15:21:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_011_pos.sh	Fri Nov 22 15:21:40 2013
@@ -0,0 +1,75 @@
+#!/usr/bin/bash -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# ZFS has two mechanisms dealing with space for datasets, namely
+# reservations and quotas. Setting one should not affect the other,
+# provided the values are legal (i.e. enough space in pool etc).
+#
+# STRATEGY:
+# 1) Create one filesystem
+# 2) Get the current quota setting
+# 3) Set a reservation
+# 4) Verify that the quota value remains unchanged
+#
+
+verify_runnable "both"
+
+log_assert "Verify reservation settings do not affect quota settings"
+
+function cleanup
+{
+	log_must zero_reservation $TESTPOOL/$TESTFS
+}
+
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+
+((resv_size_set = (space_avail - RESV_DELTA) / 2))
+
+fs_quota=`$ZFS get quota $TESTPOOL/$TESTFS`
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS
+
+new_fs_quota=`$ZFS get quota $TESTPOOL/$TESTFS`
+
+if [[ $fs_quota != $new_fs_quota ]]; then
+	log_fail "Quota value on $TESTFS has changed " \
+	    "($fs_quota != $new_fs_quota)"
+fi
+
+log_pass "Quota settings unaffected by reservation settings"
--- /dev/null	Fri Nov 22 15:21:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_012_pos.sh	Fri Nov 22 15:21:40 2013
@@ -0,0 +1,88 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# A reservation guarantees a certain amount of space for a dataset.
+# Nothing else which happens in the same pool should affect that
+# space, i.e. even if the rest of the pool fills up the reserved
+# space should still be accessible.
+#
+# STRATEGY:
+# 1) Create 2 filesystems
+# 2) Set a reservation on one filesystem
+# 3) Fill up the other filesystem (which does not have a reservation
+# set) until all space is consumed
+# 4) Verify can still write to the filesystem which has a reservation
+#
+
+verify_runnable "both"
+
+log_assert "Verify reservations protect space"
+
+function cleanup
+{
+	log_must $ZFS destroy -f $TESTPOOL/$TESTFS2
+	log_must zero_reservation $TESTPOOL/$TESTFS
+
+	[[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+	[[ -d $TESTDIR2 ]] && log_must $RM -rf $TESTDIR2
+}
+
+log_onexit cleanup
+
+log_must $ZFS create $TESTPOOL/$TESTFS2
+log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS2
+
+space_avail=`get_prop available $TESTPOOL`
+
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+
+log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS
+
+((write_count = (RESV_FREE_SPACE + RESV_TOLERANCE) / BLOCK_SIZE))
+
+$FILE_WRITE -o create -f $TESTDIR2/$TESTFILE1 -b $BLOCK_SIZE -c $write_count \
+    -d 0
+ret=$?
+if [[ $ret != $ENOSPC ]]; then
+	log_fail "Did not get ENOSPC (got $ret) for non-reserved filesystem"
+fi
+
+((write_count = (RESV_FREE_SPACE - RESV_TOLERANCE) / BLOCK_SIZE))
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE -c \
+    $write_count -d 0
+
+log_pass "Reserved space preserved correctly"
--- /dev/null	Fri Nov 22 15:21:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_013_pos.sh	Fri Nov 22 15:21:40 2013
@@ -0,0 +1,112 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Reservation properties on data objects should be preserved when the
+# pool within which they are contained is exported and then re-imported.
+#
+#
+# STRATEGY:
+# 1) Create a filesystem as dataset
+# 2) Create another filesystem at the same level
+# 3) Create a regular volume at the same level
+# 4) Create a sparse volume at the same level
+# 5) Create a filesystem within the dataset filesystem
+# 6) Set reservations on all filesystems
+# 7) Export the pool
+# 8) Re-import the pool
+# 9) Verify that the reservation settings are correct
+#
+
+verify_runnable "global"
+
+log_assert "Reservation properties preserved across exports and imports"
+
+function cleanup
+{
+	for obj in $OBJ_LIST; do
+                datasetexists $obj && log_must $ZFS destroy -f $obj
+        done
+
+	log_must zero_reservation $TESTPOOL/$TESTFS
+}
+log_onexit cleanup
+
+OBJ_LIST="$TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \
+    $TESTPOOL/$TESTVOL2"
+
+log_must $ZFS create $TESTPOOL/$TESTFS1
+log_must $ZFS create $TESTPOOL/$TESTFS1/$TESTFS2
+
+space_avail=$(get_prop available $TESTPOOL)
+[[ $? -ne 0 ]] && \
+    log_fail "Unable to get space available property for $TESTPOOL"
+
+((resv_set = space_avail / 5))
+resv_set=$(floor_volsize $resv_set)
+((sparse_vol_set_size = space_avail * 5))
+sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+# When initially created, a regular volume's reservation property is set
+# equal to its size (unlike a sparse volume), so we don't need to set it
+# explictly later on
+log_must $ZFS create -V $resv_set $TESTPOOL/$TESTVOL
+log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTFS
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTFS1
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTFS1/$TESTFS2
+log_must $ZFS set reservation=$resv_set $TESTPOOL/$TESTVOL2
+
+log_must $ZPOOL export $TESTPOOL
+log_must $ZPOOL import $TESTPOOL
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do
+
+	if [[ $obj == $TESTPOOL/$TESTVOL ]]; then
+		expected=$(volsize_to_reservation $obj $resv_set)
+		found=$(get_prop refreservation $obj)
+	else
+		expected=$resv_set
+		found=$(get_prop reservation $obj)
+	fi
+
+	[[ $found != $expected ]] && \
+	    log_fail "Reservation property for $obj incorrect. Expected " \
+	    "$expected but got $found."
+done
+
+log_pass "Reservation properties preserved across exports and imports"
--- /dev/null	Fri Nov 22 15:21:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_014_pos.sh	Fri Nov 22 15:21:41 2013
@@ -0,0 +1,123 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# A reservation cannot exceed the quota on a dataset
+#
+# STRATEGY:
+# 1) Create a filesystem and volume
+# 2) Set a quota on the filesystem
+# 3) Attempt to set a reservation larger than the quota. Verify
+# that the attempt fails.
+# 4) Repeat 2-3 for volume
+#
+
+verify_runnable "both"
+
+log_assert "Verify cannot set reservation larger than quota"
+
+function cleanup
+{
+	#
+	# Note we don't destroy $TESTFS as it's used by other tests
+	for obj in $OBJ_LIST ; do
+		datasetexists $obj && log_must $ZFS destroy -f $obj
+	done
+
+	log_must zero_reservation $TESTPOOL/$TESTFS
+}
+log_onexit cleanup
+
+space_avail=`get_prop available $TESTPOOL`
+
+if ! is_global_zone ; then
+	OBJ_LIST=""
+else
+	OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2"
+
+        ((vol_set_size = space_avail / 4))
+	vol_set_size=$(floor_volsize $vol_set_size)
+	((sparse_vol_set_size = space_avail * 4))
+	sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size)
+
+	log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+	log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2
+fi
+
+for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do
+
+	space_avail=`get_prop available $TESTPOOL`
+	((quota_set_size = space_avail / 3))
+
+	#
+	# A regular (non-sparse) volume's size is effectively
+	# its quota so only need to explicitly set quotas for
+	# filesystems and datasets.
+	#
+	# A volumes size is effectively its quota. The maximum
+	# reservation value that can be set on a volume is
+	# determined by the size of the volume or the amount of
+	# space in the pool, whichever is smaller.
+	#
+	if [[ $obj == $TESTPOOL/$TESTFS ]]; then
+		log_must $ZFS set quota=$quota_set_size $obj
+		((resv_set_size = quota_set_size + RESV_SIZE))
+
+	elif [[ $obj == $TESTPOOL/$TESTVOL2 ]] ; then
+
+		((resv_set_size = sparse_vol_set_size + RESV_SIZE))
+
+	elif [[ $obj == $TESTPOOL/$TESTVOL ]] ; then
+
+		((resv_set_size = vol_set_size + RESV_SIZE))
+	fi
+
+	orig_quota=`get_prop quota $obj`
+
+	log_mustnot $ZFS set reservation=$resv_set_size $obj
+	new_quota=`get_prop quota $obj`
+
+	if [[ $orig_quota != $new_quota ]]; then
+		log_fail "Quota value changed from $orig_quota " \
+				"to $new_quota"
+	fi
+
+	if [[ $obj == $TESTPOOL/$TESTFS ]]; then
+		log_must $ZFS set quota=none $obj
+	fi
+done
+
+log_pass "As expected cannot set reservation larger than quota"
--- /dev/null	Fri Nov 22 15:21:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_015_pos.sh	Fri Nov 22 15:21:41 2013
@@ -0,0 +1,99 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and a regular volume with an implicit
+# reservation, setting the reservation on the volume to 'none' should allow
+# more data to be written to the filesystem.
+#
+#
+# STRATEGY:
+# 1) Create a regular non-sparse volume (which implicitly sets the reservation
+#    property to a value equal to the volume size)
+# 2) Create a filesystem at the same level
+# 3) Fill up the filesystem
+# 4) Set the reservation on the volume to 'none'
+# 5) Verify can write more data to the filesystem
+#
+
+verify_runnable "global"
+
+log_assert "Setting volume reservation to 'none' allows more data to be " \
+    "written to top level filesystem"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTVOL && \
+	log_must $ZFS destroy $TESTPOOL/$TESTVOL
+
+	[[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+	[[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+}
+log_onexit cleanup
+
+space_avail=$(largest_volsize_from_pool $TESTPOOL)
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a volume size which when applied
+# to the volume will ensure we have RESV_FREE_SPACE
+# left free in the pool which we can quickly fill.
+#
+((resv_size_set = space_avail - RESV_FREE_SPACE))
+resv_size_set=$(floor_volsize $resv_size_set)
+
+log_must $ZFS create -V $resv_size_set $TESTPOOL/$TESTVOL
+
+space_avail_still=`get_prop available $TESTPOOL`
+
+fill_size=$((space_avail_still + $RESV_TOLERANCE))
+write_count=$((fill_size / BLOCK_SIZE))
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+	log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Setting top level volume reservation to 'none' allows more " \
+    "data to be written to the top level filesystem"
--- /dev/null	Fri Nov 22 15:21:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_016_pos.sh	Fri Nov 22 15:21:41 2013
@@ -0,0 +1,98 @@
+#!/usr/bin/bash -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# In pool with a full filesystem and a regular volume (with implicit
+# reservation) destroying the volume should allow more data to be written
+# to the filesystem
+#
+#
+# STRATEGY:
+# 1) Create a regular (non-sparse) volume
+# 2) Create a filesystem at the same level
+# 3) Fill up the filesystem
+# 4) Destroy the volume
+# 5) Verify can write more data to the filesystem
+#
+
+verify_runnable "global"
+
+log_assert "Destroying a regular volume with reservation allows more data to" \
+    " be written to top level filesystem"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$TESTVOL && \
+	    log_must $ZFS destroy $TESTPOOL/$TESTVOL
+
+	[[ -e $TESTDIR/$TESTFILE1 ]] && log_must $RM -rf $TESTDIR/$TESTFILE1
+	[[ -e $TESTDIR/$TESTFILE2 ]] && log_must $RM -rf $TESTDIR/$TESTFILE2
+}
+log_onexit cleanup
+
+space_avail=$(largest_volsize_from_pool $TESTPOOL)
+
+#
+# To make sure this test doesn't take too long to execute on
+# large pools, we calculate a volume size which will ensure we
+# have RESV_FREE_SPACE left free in the pool.
+#
+((vol_set_size = space_avail - RESV_FREE_SPACE))
+vol_set_size=$(floor_volsize $vol_set_size)
+
+# Creating a regular volume implicitly sets its reservation
+# property to the same value.
+log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL
+
+space_avail_still=$(get_prop available $TESTPOOL)
+fill_size=$((space_avail_still + $RESV_TOLERANCE))
+write_count=$((fill_size / BLOCK_SIZE))
+
+# Now fill up the filesystem (which doesn't have a reservation set
+# and thus will use up whatever free space is left in the pool).
+$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0
+ret=$?
+if (($ret != $ENOSPC)); then
+	log_fail "Did not get ENOSPC as expected (got $ret)."
+fi
+
+log_must $ZFS destroy -f $TESTPOOL/$TESTVOL
+
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $PAGESIZE \
+    -c 1000 -d 0
+
+log_pass "Destroying volume with reservation allows more data to be written " \
+    "to top level filesystem"
--- /dev/null	Fri Nov 22 15:21:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_017_pos.sh	Fri Nov 22 15:21:42 2013
@@ -0,0 +1,101 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# For a sparse volume changes to the volsize are not reflected in the
+# reservation.
+#
+# STRATEGY:
+# 1) Create a regular and sparse volume
+# 2) Get the space available in the pool
+# 3) Set reservation with various sizes on the regular and sparse volumes
+# 4) Verify that the 'reservation' property for the regular volume has
+#    the correct value.
+# 5) Verify that the 'reservation' property for the sparse volume is set to
+#    'none'
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset vol
+
+	for vol in $regvol $sparsevol; do
+		datasetexists $vol &&  log_must $ZFS destroy $vol
+	done
+}
+log_onexit cleanup
+
+log_assert "Verify that the volsize changes of sparse volumes are not " \
+    "reflected in the reservation."
+log_onexit cleanup
+
+# Create a regular and sparse volume for testing.
+regvol=$TESTPOOL/$TESTVOL
+sparsevol=$TESTPOOL/$TESTVOL2
+log_must $ZFS create -V 64M $regvol
+log_must $ZFS create -s -V 64M $sparsevol
+
+typeset -i vsize=$(get_prop available $TESTPOOL)
+typeset -i iterate=10
+typeset -i regreserv
+typeset -i sparsereserv
+typeset -i volblocksize=$(get_prop volblocksize $regvol)
+typeset -i blknum=0
+typeset -i randomblknum
+((blknum = vsize / volblocksize))
+
+while ((iterate > 1)); do
+	((randomblknum = 1 + RANDOM % blknum))
+	# Make sure volsize is a multiple of volume block size
+	((vsize = randomblknum * volblocksize))
+	log_must $ZFS set volsize=$vsize $regvol
+	log_must $ZFS set volsize=$vsize $sparsevol
+	vsize=$(volsize_to_reservation $regvol $vsize)
+	regreserv=$(get_prop refreservation $regvol)
+	sparsereserv=$(get_prop reservation $sparsevol)
+	((sparsereserv == vsize)) && \
+		log_fail "volsize changes of sparse volume is reflected in " \
+		    "reservation (expected $vsize, got $sparsereserv)."
+	((regreserv != vsize)) && \
+		log_fail "volsize changes of regular volume is not reflected " \
+		    "in reservation (expected $vsize, got $regreserv)."
+	((iterate = iterate - 1))
+done
+
+log_pass "The volsize changes of sparse volumes are not reflected in the " \
+    "reservation"
--- /dev/null	Fri Nov 22 15:21:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/reservation_018_pos.sh	Fri Nov 22 15:21:42 2013
@@ -0,0 +1,72 @@
+#!/usr/bin/bash -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/reservation/reservation.shlib
+
+#
+# DESCRIPTION:
+#
+# Verify that reservation doesn't inherit its value from parent.
+#
+# STRATEGY:
+# 1) Create a filesystem tree
+# 2) Set reservation for parents
+# 3) Verify that the 'reservation' for descendent doesnot inherit the value.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $fs_child && log_must $ZFS destroy $fs_child
+	log_must $ZFS set reservation=$reserv_val $fs
+}
+
+log_onexit cleanup
+
+log_assert "Verify that reservation doesnot inherit its value from parent."
+
+fs=$TESTPOOL/$TESTFS
+fs_child=$TESTPOOL/$TESTFS/$TESTFS
+
+space_avail=$(get_prop available $fs)
+reserv_val=$(get_prop reservation $fs)
+typeset -l reservsize=$space_avail
+((reservsize = reservsize / 2))
+log_must $ZFS set reservation=$reservsize $fs
+
+log_must $ZFS create $fs_child
+rsv_space=$(get_prop reservation $fs_child)
+[[ $rsv_space == $reservsize ]] && \
+    log_fail "The reservation of child dataset inherits its value from parent."
+
+log_pass "reservation doesnot inherit its value from parent as expected."
--- /dev/null	Fri Nov 22 15:21:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/reservation/setup.ksh	Fri Nov 22 15:21:43 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_setup_noexit ${DISKS%% *}
+log_pass
--- /dev/null	Fri Nov 22 15:21:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rootpool/Makefile	Fri Nov 22 15:21:43 2013
@@ -0,0 +1,43 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/rootpool
+
+PROGS = cleanup \
+	rootpool_002_neg \
+	rootpool_003_neg \
+	rootpool_007_neg \
+	setup
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rootpool/cleanup.ksh	Fri Nov 22 15:21:43 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:21:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rootpool/rootpool_002_neg.ksh	Fri Nov 22 15:21:44 2013
@@ -0,0 +1,68 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# the zfs rootpool can not be destroyed
+#
+# STRATEGY:
+# 1) check if the current system is installed as zfs root
+# 2) get the rootpool
+# 3) try to destroy the rootpool, which should fail.
+# 4) try to destroy the rootpool filesystem, which should fail.
+#
+
+verify_runnable "global"
+log_assert "zpool/zfs destory <rootpool> should return error"
+
+typeset rootpool=$(get_rootpool)
+typeset tmpfile="/tmp/mounted-datasets.$$"
+
+# Collect the currently mounted ZFS filesystems, so that we can repair any
+# damage done by the attempted pool destroy. The destroy itself should fail, but
+# some filesystems can become unmounted in the process, and aren't automatically
+# remounted.
+$MOUNT -p | $AWK '{if ($4 == "zfs") print $1" "$3}' > $tmpfile
+
+log_mustnot $ZPOOL destroy $rootpool
+
+# Remount any filesystems that the destroy attempt unmounted.
+while read ds mntpt; do
+	mounted $ds || log_must $MOUNT -Fzfs $ds $mntpt
+done < $tmpfile
+$RM -f $tmpfile
+
+log_mustnot $ZFS destroy $rootpool
+
+log_pass "rootpool can not be destroyed"
--- /dev/null	Fri Nov 22 15:21:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rootpool/rootpool_003_neg.ksh	Fri Nov 22 15:21:44 2013
@@ -0,0 +1,61 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+#  system related filesystems can not be renamed or destroyed
+#
+# STRATEGY:
+#
+# 1) check if the current system is installed as zfs rootfs
+# 2) get the rootfs
+# 3) try to rename the rootfs to some newfs, which should fail.
+# 4) try to destroy the rootfs, which should fail.
+# 5) try to destroy the rootfs with -f which should fail
+# 6) try to destroy the rootfs with -fR which should fail
+#
+
+verify_runnable "global"
+log_assert "system related filesytems can not be renamed or destroyed"
+
+typeset rootpool=$(get_rootpool)
+typeset rootfs=$(get_rootfs)
+
+log_mustnot $ZFS rename $rootfs $rootpool/newfs
+log_mustnot $ZFS rename -f $rootfs $rootpool/newfs
+
+log_mustnot $ZFS destroy $rootfs
+log_mustnot $ZFS destroy -f $rootfs
+
+log_pass "system related filesystems can not be renamed or destroyed"
--- /dev/null	Fri Nov 22 15:21:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rootpool/rootpool_007_neg.ksh	Fri Nov 22 15:21:44 2013
@@ -0,0 +1,70 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# the zfs rootfilesystem's compression property can not set to gzip[1-9]
+#
+# STRATEGY:
+# 1) check if the current system is installed as zfs root
+# 2) get the rootfs
+# 3) set the rootfs's compression to gzip 1-9 which should fail.
+#
+
+verify_runnable "global"
+
+function cleanup {
+	log_must $ZFS set compression=$orig_compress $rootfs
+}
+
+log_onexit cleanup
+log_assert $assert_msg
+
+typeset rootpool=$(get_rootpool)
+typeset rootfs=$(get_pool_prop bootfs $rootpool)
+typeset orig_compress=$(get_prop compression $rootfs)
+
+typeset assert_msg="the zfs rootfs's compression property can not set to \
+		   gzip and gzip[1-9]"
+
+set -A gtype "gzip" "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" \
+	     "gzip-6" "gzip-7" "gzip-8" "gzip-9"
+
+typeset -i i=0
+while (( i < ${#gtype[@]} )); do
+	log_mustnot $ZFS set compression=${gtype[i]} $rootfs
+	(( i += 1 ))
+done
+
+log_pass $assert_msg
--- /dev/null	Fri Nov 22 15:21:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rootpool/setup.ksh	Fri Nov 22 15:21:45 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
--- /dev/null	Fri Nov 22 15:21:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/Makefile	Fri Nov 22 15:21:45 2013
@@ -0,0 +1,56 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/rsend
+
+PROGS = cleanup \
+	rsend_001_pos \
+	rsend_002_pos \
+	rsend_003_pos \
+	rsend_004_pos \
+	rsend_005_pos \
+	rsend_006_pos \
+	rsend_007_pos \
+	rsend_008_pos \
+	rsend_009_pos \
+	rsend_010_pos \
+	rsend_011_pos \
+	rsend_012_pos \
+	rsend_013_pos \
+	setup
+
+FILES = rsend.cfg \
+	rsend.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/cleanup.ksh	Fri Nov 22 15:21:45 2013
@@ -0,0 +1,53 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+verify_runnable "both"
+
+#
+# Check if the system support 'send -R'
+#
+$ZFS send 2>&1 | $GREP "\[-[a-zA-Z]*R[a-zA-Z]*\]" >/dev/null 2>&1
+if (($? != 0)); then
+	log_unsupported
+fi
+
+if is_global_zone ; then
+	destroy_pool $POOL
+	destroy_pool $POOL2
+else
+	cleanup_pool $POOL
+	cleanup_pool $POOL2
+fi
+log_must $RM -rf $BACKDIR $TESTDIR
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend.cfg	Fri Nov 22 15:21:46 2013
@@ -0,0 +1,37 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export BACKDIR=${TEST_BASE_DIR%%/}/backdir-rsend
+
+export DISK1=$($ECHO $DISKS | $AWK '{print $1}')
+export DISK2=$($ECHO $DISKS | $AWK '{print $2}')
+
+export POOL=$TESTPOOL
+export POOL2=$TESTPOOL1
+export FS=$TESTFS
--- /dev/null	Fri Nov 22 15:21:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend.kshlib	Fri Nov 22 15:21:46 2013
@@ -0,0 +1,376 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/rsend/rsend.cfg
+
+#
+# Set up test model which includes various datasets
+#
+#               @final
+#               @snapB
+#               @init
+#               |
+#   ______ pclone
+#  |      /
+#  |@psnap
+#  ||                         @final
+#  ||@final       @final      @snapC
+#  ||@snapC       @snapC      @snapB
+#  ||@snapA       @snapB      @snapA
+#  ||@init        @init       @init
+#  |||            |           |
+# $pool -------- $FS ------- fs1 ------- fs2
+#    \             \\_____     \          |
+#     vol           vol   \____ \         @fsnap
+#      |              |        \ \              \
+#      @init          @vsnap   |  ------------ fclone
+#      @snapA         @init \  |                    |
+#      @final         @snapB \ |                    @init
+#                     @snapC  vclone                @snapA
+#                     @final       |                @final
+#                                 @init
+#                                 @snapC
+#                                 @final
+#
+# $1 pool name
+#
+function setup_test_model
+{
+	typeset pool=$1
+
+	log_must $ZFS create -p $pool/$FS/fs1/fs2
+
+	log_must $ZFS snapshot $pool@psnap
+	log_must $ZFS clone $pool@psnap $pool/pclone
+
+	if is_global_zone ; then
+		log_must $ZFS create -V 16M $pool/vol
+		log_must $ZFS create -V 16M $pool/$FS/vol
+
+		log_must $ZFS snapshot $pool/$FS/vol@vsnap
+		log_must $ZFS clone $pool/$FS/vol@vsnap $pool/$FS/vclone
+	fi
+
+	log_must snapshot_tree $pool/$FS/fs1/fs2@fsnap
+	log_must $ZFS clone $pool/$FS/fs1/fs2@fsnap $pool/$FS/fs1/fclone
+	log_must $ZFS snapshot -r $pool@init
+
+	log_must snapshot_tree $pool@snapA
+	log_must snapshot_tree $pool@snapC
+	log_must snapshot_tree $pool/pclone@snapB
+	log_must snapshot_tree $pool/$FS@snapB
+	log_must snapshot_tree $pool/$FS@snapC
+	log_must snapshot_tree $pool/$FS/fs1@snapA
+	log_must snapshot_tree $pool/$FS/fs1@snapB
+	log_must snapshot_tree $pool/$FS/fs1@snapC
+	log_must snapshot_tree $pool/$FS/fs1/fclone@snapA
+
+	if is_global_zone ; then
+		log_must $ZFS snapshot $pool/vol@snapA
+		log_must $ZFS snapshot $pool/$FS/vol@snapB
+		log_must $ZFS snapshot $pool/$FS/vol@snapC
+		log_must $ZFS snapshot $pool/$FS/vclone@snapC
+	fi
+
+	log_must $ZFS snapshot -r $pool@final
+
+	return 0
+}
+
+#
+# Cleanup the BACKDIR and given pool content and all the sub datasets
+#
+# $1 pool name
+#
+function cleanup_pool
+{
+	typeset pool=$1
+	log_must $RM -rf $BACKDIR/*
+
+	if is_global_zone ; then
+		log_must $ZFS destroy -Rf $pool
+	else
+		typeset list=$($ZFS list -H -r -t filesystem,snapshot,volume -o name $pool)
+		for ds in $list ; do
+			if [[ $ds != $pool ]] ; then
+				if datasetexists $ds ; then
+					log_must $ZFS destroy -Rf $ds
+				fi
+			fi
+		done
+	fi
+
+	typeset mntpnt=$(get_prop mountpoint $pool)
+	if ! ismounted $pool ; then
+		# Make sure mountpoint directory is empty
+		if [[ -d $mntpnt ]]; then
+			log_must $RM -rf $mntpnt/*
+		fi
+
+		log_must $ZFS mount $pool
+	fi
+	if [[ -d $mntpnt ]]; then
+		log_must $RM -rf $mntpnt/*
+	fi
+
+	return 0
+}
+
+#
+# Detect if the given two filesystems have same sub-datasets
+#
+# $1 source filesystem
+# $2 destination filesystem
+#
+function cmp_ds_subs
+{
+	typeset src_fs=$1
+	typeset dst_fs=$2
+
+	$ZFS list -r -H -t filesystem,snapshot,volume -o name $src_fs > $BACKDIR/src1
+	$ZFS list -r -H -t filesystem,snapshot,volume -o name $dst_fs > $BACKDIR/dst1
+
+	eval $SED -e 's:^$src_fs:PREFIX:g' < $BACKDIR/src1 > $BACKDIR/src
+	eval $SED -e 's:^$dst_fs:PREFIX:g' < $BACKDIR/dst1 > $BACKDIR/dst
+
+	$DIFF $BACKDIR/src $BACKDIR/dst
+	typeset -i ret=$?
+
+	$RM -f $BACKDIR/src $BACKDIR/dst $BACKDIR/src1 $BACKDIR/dst1
+
+	return $ret
+}
+
+#
+# Compare all the directores and files in two filesystems
+#
+# $1 source filesystem
+# $2 destination filesystem
+#
+function cmp_ds_cont
+{
+	typeset src_fs=$1
+	typeset dst_fs=$2
+
+	typeset srcdir dstdir
+	srcdir=$(get_prop mountpoint $src_fs)
+	dstdir=$(get_prop mountpoint $dst_fs)
+
+	$DIFF -r $srcdir $dstdir > /dev/null 2>&1
+	echo $?
+}
+
+#
+# Compare the given two dataset properties
+#
+# $1 dataset 1
+# $2 dataset 2
+#
+function cmp_ds_prop
+{
+	typeset dtst1=$1
+	typeset dtst2=$2
+
+	for item in "type" "origin" "volblocksize" "aclinherit" "aclmode" \
+		"atime" "canmount" "checksum" "compression" "copies" "devices" \
+		"exec" "quota" "readonly" "recordsize" "reservation" "setuid" \
+		"sharenfs" "snapdir" "version" "volsize" "xattr" "zoned" \
+		"mountpoint";
+	do
+		$ZFS get -H -o property,value,source $item $dtst1 >> \
+			$BACKDIR/dtst1
+		$ZFS get -H -o property,value,source $item $dtst2 >> \
+			$BACKDIR/dtst2
+	done
+
+	eval $SED -e 's:$dtst1:PREFIX:g' < $BACKDIR/dtst1 > $BACKDIR/dtst1
+	eval $SED -e 's:$dtst2:PREFIX:g' < $BACKDIR/dtst2 > $BACKDIR/dtst2
+
+	$DIFF $BACKDIR/dtst1 $BACKDIR/dtst2
+	typeset -i ret=$?
+
+	$RM -f $BACKDIR/dtst1 $BACKDIR/dtst2
+
+	return $ret
+
+}
+
+#
+# Random create directories and files
+#
+# $1 directory
+#
+function random_tree
+{
+	typeset dir=$1
+
+	if [[ -d $dir ]]; then
+		$RM -rf $dir
+	fi
+	$MKDIR -p $dir
+	typeset -i ret=$?
+
+	typeset -i nl nd nf
+	((nl = RANDOM % 6 + 1))
+	((nd = RANDOM % 3 ))
+	((nf = RANDOM % 5 ))
+	$MKTREE -b $dir -l $nl -d $nd -f $nf
+	((ret |= $?))
+
+	return $ret
+}
+
+#
+# Put data in filesystem and take snapshot
+#
+# $1 snapshot name
+#
+function snapshot_tree
+{
+	typeset snap=$1
+	typeset ds=${snap%%@*}
+	typeset type=$(get_prop "type" $ds)
+
+	typeset -i ret=0
+	if [[ $type == "filesystem" ]]; then
+		typeset mntpnt=$(get_prop mountpoint $ds)
+		((ret |= $?))
+
+		if ((ret == 0)) ; then
+			eval random_tree $mntpnt/${snap##$ds}
+			((ret |= $?))
+		fi
+	fi
+
+	if ((ret == 0)) ; then
+		$ZFS snapshot $snap
+		((ret |= $?))
+	fi
+
+	return $ret
+}
+
+#
+# Destroy the given snapshot and stuff
+#
+# $1 snapshot
+#
+function destroy_tree
+{
+	typeset -i ret=0
+	typeset snap
+	for snap in "$@" ; do
+		$ZFS destroy $snap
+		ret=$?
+
+		typeset ds=${snap%%@*}
+		typeset type=$(get_prop "type" $ds)
+		if [[ $type == "filesystem" ]]; then
+			typeset mntpnt=$(get_prop mountpoint $ds)
+			((ret |= $?))
+
+			if ((ret != 0)); then
+				$RM -r $mntpnt/$snap
+				((ret |= $?))
+			fi
+		fi
+
+		if ((ret != 0)); then
+			return $ret
+		fi
+	done
+
+	return 0
+}
+
+#
+# Get all the sub-datasets of give dataset with specific suffix
+#
+# $1 Given dataset
+# $2 Suffix
+#
+function getds_with_suffix
+{
+	typeset ds=$1
+	typeset suffix=$2
+
+	typeset list=$($ZFS list -r -H -t filesystem,snapshot,volume -o name $ds \
+		| $GREP "$suffix$")
+
+	$ECHO $list
+}
+
+#
+# Output inherited properties whitch is edited for file system
+#
+function fs_inherit_prop
+{
+	typeset fs_prop
+	if is_global_zone ; then
+		fs_prop=$($ZFS inherit 2>&1 | \
+			$AWK '$2=="YES" && $3=="YES" {print $1}')
+		if ! is_te_enabled ; then
+		        fs_prop=$(echo $fs_prop | $GREP -v "mlslabel")
+		fi
+	else
+		fs_prop=$($ZFS inherit 2>&1 | \
+			$AWK '$2=="YES" && $3=="YES" {print $1}'|
+			$EGREP -v "devices|mlslabel|sharenfs|sharesmb|zoned")
+	fi
+
+	$ECHO $fs_prop
+}
+
+#
+# Output inherited properties for volume
+#
+function vol_inherit_prop
+{
+	$ECHO "checksum readonly"
+}
+
+#
+# Get the destination dataset to compare
+#
+function get_dst_ds
+{
+	typeset srcfs=$1
+	typeset dstfs=$2
+
+	#
+	# If the srcfs is not pool
+	#
+	if ! $ZPOOL list $srcfs > /dev/null 2>&1 ; then
+		eval dstfs="$dstfs/${srcfs#*/}"
+	fi
+
+	$ECHO $dstfs
+}
--- /dev/null	Fri Nov 22 15:21:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_001_pos.ksh	Fri Nov 22 15:21:46 2013
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs send -R send replication stream up to the named snap.
+#
+# STRATEGY:
+#	1. Back up all the data from POOL/FS
+#	2. Verify all the datasets and data can be recovered in POOL2
+#	3. Back up all the data from root filesystem POOL2
+#	4. Verify all the data can be recovered, too
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -R send replication stream up to the named snap."
+log_onexit cleanup_pool $POOL2
+
+#
+# Verify the entire pool and sub-ds can be backup and restored.
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+# Cleanup POOL2
+log_must cleanup_pool $POOL2
+
+#
+# Verify all the filesystem and sub-fs can be backup and restored.
+#
+log_must eval "$ZFS send -R $POOL/$FS@final > $BACKDIR/fs-final-R"
+log_must eval "$ZFS receive -d $POOL2 < $BACKDIR/fs-final-R"
+
+dstds=$(get_dst_ds $POOL/$FS $POOL2)
+log_must cmp_ds_subs $POOL/$FS $dstds
+log_must cmp_ds_cont $POOL/$FS $dstds
+
+log_pass "zfs send -R send replication stream up to the named snap."
--- /dev/null	Fri Nov 22 15:21:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_002_pos.ksh	Fri Nov 22 15:21:47 2013
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs send -I sends all incrementals from fs@init to fs@final.
+#
+# STRATEGY:
+#	1. Create several snapshots in pool2
+#	2. Send -I @snapA @final
+#	3. Destroy all the snapshot except @snapA
+#	4. Make sure all the snapshots and content are recovered
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -I sends all incrementals from fs@init to fs@final."
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R"
+
+if is_global_zone ; then
+	#
+	# Verify send -I will backup all the incrementals in pool
+	#
+	log_must eval "$ZFS send -I $POOL2@init $POOL2@final > " \
+		"$BACKDIR/pool-init-final-I"
+	log_must destroy_tree $POOL2@final $POOL2@snapC $POOL2@snapA
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-I"
+	log_must cmp_ds_subs $POOL $POOL2
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+
+#
+# Verify send -I will backup all the incrementals in filesystem
+#
+log_must eval "$ZFS send -I @init $dstds/$FS@final > $BACKDIR/fs-init-final-I"
+log_must destroy_tree $dstds/$FS@final $dstds/$FS@snapC $dstds/$FS@snapB
+log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-I"
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+if is_global_zone ; then
+	#
+	# Verify send -I will backup all the incrementals in volume
+	#
+	dataset=$POOL2/$FS/vol
+	log_must eval "$ZFS send -I @vsnap $dataset@final > " \
+		"$BACKDIR/vol-vsnap-final-I"
+	log_must destroy_tree $dataset@final $dataset@snapC  \
+		$dataset@snapB $dataset@init
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-vsnap-final-I"
+	log_must cmp_ds_subs $POOL $POOL2
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -I sends all incrementals from fs@init to fs@final."
--- /dev/null	Fri Nov 22 15:21:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_003_pos.ksh	Fri Nov 22 15:21:47 2013
@@ -0,0 +1,95 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs send -I dataset@init to clone@snap can create a clone
+#
+# STRATEGY:
+#	1. Setup test model
+#	2. send -I pool@init to clone@snap
+#	3. Verify the clone and snapshot can be recovered via receive
+#	4. Verify the similar operating in filesystem and volume
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -I send all incrementals from dataset@init to clone@snap"
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R"
+
+if is_global_zone ; then
+	#
+	# Verify send -I backup all incrementals from pool
+	#
+	log_must eval "$ZFS send -I $POOL2@psnap $POOL2/pclone@final > " \
+		"$BACKDIR/pool-clone-I"
+	log_must $ZFS destroy -rf $POOL2/pclone
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-clone-I"
+	log_must cmp_ds_subs $POOL $POOL2
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+
+#
+# Verify send -I backup all incrementals from filesystem
+#
+ds=$dstds/$FS/fs1
+log_must eval "$ZFS send -I $ds/fs2@fsnap $ds/fclone@final > " \
+	"$BACKDIR/fs-clone-I"
+log_must $ZFS destroy -rf $ds/fclone
+log_must eval "$ZFS receive -F $ds/fclone < $BACKDIR/fs-clone-I"
+
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+if is_global_zone ; then
+	#
+	# Verify send -I backup all incrementals from volume
+	#
+	ds=$POOL2/$FS
+	log_must eval "$ZFS send -I $ds/vol@vsnap $ds/vclone@final > " \
+		"$BACKDIR/vol-clone-I"
+	log_must $ZFS destroy -rf $ds/vclone
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-clone-I"
+	log_must cmp_ds_subs $POOL $POOL2
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -I send all incrementals from dataset@init to clone@snap"
--- /dev/null	Fri Nov 22 15:21:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_004_pos.ksh	Fri Nov 22 15:21:47 2013
@@ -0,0 +1,120 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs send -R -i send incremental from fs@init to fs@final.
+#
+# STRATEGY:
+#	1. Create a set of snapshots and fill with data.
+#	2. Create sub filesystems.
+#	3. Create final snapshot
+#	4. Verify zfs send -R -i will backup all the datasets which has
+#	   snapshot suffix @final
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -R -i send incremental from fs@init to fs@final."
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+if is_global_zone ; then
+	#
+	# Testing send -R -i backup from pool
+	#
+	srclist=$(getds_with_suffix $POOL2 @final)
+	interlist="$srclist $(getds_with_suffix $POOL2 @snapC)"
+	interlist="$interlist $(getds_with_suffix $POOL2 @snapB)"
+	interlist="$interlist $(getds_with_suffix $POOL2 @snapA)"
+
+	log_must eval "$ZFS send -R -i @init $POOL2@final > " \
+		"$BACKDIR/pool-init-final-iR"
+	log_must destroy_tree $interlist
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-iR"
+
+	# Get current datasets with suffix @final
+	dstlist=$(getds_with_suffix $POOL2 @final)
+	if [[ $srclist != $dstlist ]]; then
+		log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)"
+	fi
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Testing send -R -i backup from filesystem
+#
+log_must eval "$ZFS send -R -i @init $dstds/$FS@final > " \
+	"$BACKDIR/fs-init-final-iR"
+
+srclist=$(getds_with_suffix $dstds/$FS @final)
+interlist="$srclist $(getds_with_suffix $dstds/$FS @snapC)"
+interlist="$interlist $(getds_with_suffix $dstds/$FS @snapB)"
+interlist="$interlist $(getds_with_suffix $dstds/$FS @snapA)"
+log_must destroy_tree $interlist
+if is_global_zone ; then
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/fs-init-final-iR"
+else
+	$ZFS receive -F -d $dstds/$FS < $BACKDIR/fs-init-final-iR
+fi
+
+dstlist=$(getds_with_suffix $dstds/$FS @final)
+if [[ $srclist != $dstlist ]]; then
+	log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)"
+fi
+log_must cmp_ds_cont $POOL $POOL2
+
+if is_global_zone ; then
+	#
+	# Testing send -R -i backup from volume
+	#
+	srclist=$(getds_with_suffix $POOL2/$FS/vol @final)
+	log_must eval "$ZFS send -R -i @init $POOL2/$FS/vol@final > " \
+		"$BACKDIR/vol-init-final-iR"
+	log_must destroy_tree $srclist
+	log_must eval "$ZFS receive -d $POOL2 < $BACKDIR/vol-init-final-iR"
+
+	dstlist=$(getds_with_suffix $POOL2/$FS/vol @final)
+	if [[ $srclist != $dstlist ]]; then
+		log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)"
+	fi
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -R -i send incremental from fs@init to fs@final."
--- /dev/null	Fri Nov 22 15:21:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_005_pos.ksh	Fri Nov 22 15:21:48 2013
@@ -0,0 +1,104 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs send -R -I send all the incremental between fs@init with fs@final
+#
+# STRATEGY:
+#	1. Setup test model
+#	2. Send -R -I @init @final on pool
+#	3. Destroy all the snapshots which is later than @init
+#	4. Verify receive can restore all the snapshots and data
+#	5. Do the same test on filesystem and volume
+#
+
+verify_runnable "both"
+
+log_assert "zfs send -R -I send all the incremental between @init with @final"
+log_onexit cleanup_pool $POOL2
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+if is_global_zone ; then
+	#
+	# Testing send -R -I from pool
+	#
+	log_must eval "$ZFS send -R -I @init $POOL2@final > " \
+		"$BACKDIR/pool-init-final-IR"
+	list=$(getds_with_suffix $POOL2 @snapA)
+	list="$list $(getds_with_suffix $POOL2 @snapB)"
+	list="$list $(getds_with_suffix $POOL2 @snapC)"
+	list="$list $(getds_with_suffix $POOL2 @final)"
+	log_must destroy_tree $list
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-IR"
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Testing send -R -I from filesystem
+#
+log_must eval "$ZFS send -R -I @init $dstds/$FS@final > " \
+	"$BACKDIR/fs-init-final-IR"
+list=$(getds_with_suffix $dstds/$FS @snapA)
+list="$list $(getds_with_suffix $dstds/$FS @snapB)"
+list="$list $(getds_with_suffix $dstds/$FS @snapC)"
+list="$list $(getds_with_suffix $dstds/$FS @final)"
+log_must destroy_tree $list
+if is_global_zone ; then
+	log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-IR"
+else
+	$ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-IR
+fi
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+if is_global_zone ; then
+	#
+	# Testing send -I -R for volume
+	#
+	vol=$POOL2/$FS/vol
+	log_must eval "$ZFS send -R -I @init $vol@final > " \
+		"$BACKDIR/vol-init-final-IR"
+	log_must destroy_tree $vol@snapB $vol@snapC $vol@final
+	log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-init-final-IR"
+	log_must cmp_ds_subs $POOL $POOL2
+	log_must cmp_ds_cont $POOL $POOL2
+fi
+
+log_pass "zfs send -R -I send all the incremental between @init with @final"
--- /dev/null	Fri Nov 22 15:21:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_006_pos.ksh	Fri Nov 22 15:21:48 2013
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	Rename snapshot name will not change the dependent order.
+#
+# STRATEGY:
+#	1. Set up a set of datasets.
+#	2. Rename part of snapshots.
+#	3. Send -R all the POOL
+#	4. Verify snapshot name will not change the dependent order.
+#
+
+verify_runnable "both"
+
+#		Source			Target
+#
+set -A	snaps	"$POOL@init"		"$POOL@snap0"	\
+		"$POOL@snapA"		"$POOL@snap1"	\
+		"$POOL@snapC"		"$POOL@snap2"	\
+		"$POOL@final"		"$POOL@init"
+
+function cleanup
+{
+	log_must cleanup_pool $POOL
+	log_must cleanup_pool $POOL2
+
+	log_must setup_test_model $POOL
+}
+
+log_assert "Rename snapshot name will not change the dependent order."
+log_onexit cleanup
+
+typeset -i i=0
+while ((i < ${#snaps[@]})); do
+	log_must $ZFS rename -r ${snaps[$i]} ${snaps[((i+1))]}
+
+	((i += 2))
+done
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@init > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+log_pass "Rename snapshot name will not change the dependent order."
--- /dev/null	Fri Nov 22 15:21:48 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_007_pos.ksh	Fri Nov 22 15:21:48 2013
@@ -0,0 +1,99 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	Rename parent filesystem name will not change the dependent order.
+#
+# STRATEGY:
+#	1. Separately rename pool clone, filesystem and volume name.
+#	2. Send -R all the POOL
+#	3. Verify renamed dataset will not change the snapshot dependent order.
+#
+
+verify_runnable "both"
+
+set -A 	dtst \
+	"$POOL/pclone"		"$POOL/$FS/pclone"	\
+	"$POOL/$FS/fs1/fs2"	"$POOL/fs2"
+if is_global_zone ; then
+	typeset -i n=${#dtst[@]}
+	dtst[((n))]="$POOL/vol"; 	dtst[((n+1))]="$POOL/$FS/fs1/vol"
+fi
+
+function cleanup
+{
+	log_must cleanup_pool $POOL
+	log_must cleanup_pool $POOL2
+
+	log_must setup_test_model $POOL
+}
+
+log_assert "Rename parent filesystem name will not change the dependent order."
+log_onexit cleanup
+
+typeset -i i=0
+while ((i < ${#dtst[@]})); do
+	log_must $ZFS rename ${dtst[$i]} ${dtst[((i+1))]}
+
+	((i += 2))
+done
+
+#
+# Verify zfs send -R should succeed
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+#
+# Verify zfs send -R -I should succeed
+#
+log_must eval "$ZFS send -R -I @init $dstds@final > " \
+        "$BACKDIR/pool-init-final-IR"
+list=$(getds_with_suffix $dstds @snapA)
+list="$list $(getds_with_suffix $dstds @snapB)"
+list="$list $(getds_with_suffix $dstds @snapC)"
+list="$list $(getds_with_suffix $dstds @final)"
+log_must destroy_tree $list
+if is_global_zone ; then
+	log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/pool-init-final-IR"
+else
+	$ZFS receive -d -F $dstds < $BACKDIR/pool-init-final-IR
+fi
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+log_pass "Rename parent filesystem name will not change the dependent order."
--- /dev/null	Fri Nov 22 15:21:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_008_pos.ksh	Fri Nov 22 15:21:49 2013
@@ -0,0 +1,128 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	Changes made by 'zfs promote' can be properly received.
+#
+# STRATEGY:
+#	1. Seperatly promote pool clone, filesystem clone and volume clone.
+#	2. Recursively backup all the POOL and restore in POOL2
+#	3. Verify all the datesets and property be properly received.
+#
+
+verify_runnable "both"
+
+#		Origin			Clone
+#
+set -A	dtst	"$POOL"			"$POOL/pclone"		\
+		"$POOL/$FS/fs1/fs2"	"$POOL/$FS/fs1/fclone"
+if is_global_zone ; then
+	typeset -i n=${#dtst[@]}
+	dtst[((n))]="$POOL/$FS/vol"; 	dtst[((n+1))]="$POOL/$FS/vclone"
+fi
+
+function cleanup
+{
+	typeset origin
+	typeset -i i=0
+	while ((i < ${#dtst[@]})); do
+		origin=$(get_prop origin ${dtst[$i]})
+
+		if [[ $origin != "-" ]]; then
+			log_must $ZFS promote ${dtst[$i]}
+		fi
+
+		((i += 2))
+	done
+
+	origin=$(get_prop origin $POOL2)
+	if [[ $origin != "-" ]]; then
+		log_must $ZFS promote $POOL2
+	fi
+	log_must cleanup_pool $POOL2
+}
+
+log_assert "Changes made by 'zfs promote' can be properly received."
+log_onexit cleanup
+
+typeset -i i=0
+while ((i < ${#dtst[@]})); do
+	log_must $ZFS promote ${dtst[((i+1))]}
+
+	((i += 2))
+done
+
+#
+# Verify zfs send -R should succeed
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Define all the POOL/POOL2 datasets pair
+#
+set -A pair 	"$POOL" 		"$dstds" 		\
+		"$POOL/$FS" 		"$dstds/$FS" 		\
+		"$POOL/$FS/fs1"		"$dstds/$FS/fs1"	\
+		"$POOL/$FS/fs1/fs2"	"$dstds/$FS/fs1/fs2"	\
+		"$POOL/pclone"		"$dstds/pclone"		\
+		"$POOL/$FS/fs1/fclone"	"$dstds/$FS/fs1/fclone"
+
+if is_global_zone ; then
+	typeset -i n=${#pair[@]}
+	pair[((n))]="$POOL/vol"; 	pair[((n+1))]="$dstds/vol"
+	pair[((n+2))]="$POOL/$FS/vol"	pair[((n+3))]="$dstds/$FS/vol"
+fi
+
+#
+# Verify all the sub-datasets can be properly received.
+#
+log_must cmp_ds_subs $POOL $dstds
+typeset -i i=0
+while ((i < ${#pair[@]})); do
+	log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]}
+	log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
+
+	((i += 2))
+done
+
+# Verify the original filesystem can be promoted
+log_must $ZFS promote $dstds
+if is_global_zone ; then
+	log_must $ZFS promote $dstds/$FS/vol
+fi
+log_must $ZFS promote $dstds/$FS/fs1/fs2
+
+log_pass "Changes made by 'zfs promote' can be properly received."
--- /dev/null	Fri Nov 22 15:21:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_009_pos.ksh	Fri Nov 22 15:21:49 2013
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs receive can handle out of space correctly.
+#
+# STRATEGY:
+#	1. Create two pools, one is big and another is small.
+#	2. Fill the big pool with data.
+#	3. Take snapshot and backup the whole pool.
+#	4. Receive this stream in small pool.
+#	5. Verify zfs receive can handle the out of space error correctly.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if datasetexists bpool ; then
+		log_must $ZPOOL destroy -f bpool
+	fi
+	if datasetexists spool ; then
+		log_must $ZPOOL destroy -f spool
+	fi
+}
+
+log_assert "Verify zfs receive can handle out of space correctly."
+log_onexit cleanup
+
+log_must $MKFILE 100M $TESTDIR/bfile
+log_must $MKFILE 64M  $TESTDIR/sfile
+log_must $ZPOOL create bpool $TESTDIR/bfile
+log_must $ZPOOL create spool $TESTDIR/sfile
+
+#
+# Test out of space on sub-filesystem
+#
+log_must $ZFS create bpool/fs
+mntpnt=$(get_prop mountpoint bpool/fs)
+log_must $MKFILE 30M $mntpnt/file
+
+log_must $ZFS snapshot bpool/fs@snap
+log_must eval "$ZFS send -R bpool/fs@snap > $BACKDIR/fs-R"
+log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/fs-R"
+
+log_must datasetnonexists spool/fs
+log_must ismounted spool
+
+#
+# Test out of space on top filesystem
+#
+mntpnt2=$(get_prop mountpoint bpool)
+log_must $MV $mntpnt/file $mntpnt2
+log_must $ZFS destroy -rf bpool/fs
+
+log_must $ZFS snapshot bpool@snap
+log_must eval "$ZFS send -R bpool@snap > $BACKDIR/bpool-R"
+log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/bpool-R"
+
+log_must datasetnonexists spool/fs
+log_must ismounted spool
+
+log_pass "zfs receive can handle out of space correctly."
--- /dev/null	Fri Nov 22 15:21:49 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_010_pos.ksh	Fri Nov 22 15:21:49 2013
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	ZFS can handle stream with multiple identical (same GUID) snapshots
+#
+# STRATEGY:
+#	1. Recursively backup snapshot
+#	2. Restore it to the given filesystem
+#	3. Resend the snapshot again
+#	4. Verify this stream can be restore to this filesystem again
+#
+
+verify_runnable "both"
+
+log_assert "ZFS can handle stream with multiple identical (same GUID) snapshots"
+log_onexit cleanup_pool $POOL2
+
+log_must $ZFS create $POOL2/$FS
+log_must $ZFS snapshot $POOL2/$FS@snap
+
+#
+# First round restore the stream
+#
+log_must eval "$ZFS send -R $POOL2/$FS@snap > $BACKDIR/fs-R"
+log_must eval "$ZFS receive -d -F $POOL2/$FS < $BACKDIR/fs-R"
+
+#
+# In order to avoid 'zfs send -R' failed, create snapshot for
+# all the sub-systems
+#
+list=$($ZFS list -r -H -o name -t filesystem $POOL2/$FS)
+for item in $list ; do
+	if datasetnonexists $item@snap ; then
+		log_must $ZFS snapshot $item@snap
+	fi
+done
+
+#
+# Second round restore the stream
+#
+log_must eval "$ZFS send -R $POOL2/$FS@snap > $BACKDIR/fs-R"
+dstds=$(get_dst_ds $POOL2/$FS $POOL2/$FS)
+log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-R"
+
+log_pass "ZFS can handle stream with multiple identical (same GUID) snapshots"
--- /dev/null	Fri Nov 22 15:21:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_011_pos.ksh	Fri Nov 22 15:21:50 2013
@@ -0,0 +1,125 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	Changes made by 'zfs inherit' can be properly received.
+#
+# STRATEGY:
+#	1. Inherit property for filesystem and volume
+#	2. Send and restore them in the target pool
+#	3. Verify all the datasets can be properly backup and receive
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	export __ZFS_POOL_RESTRICT="$POOL $POOL2"
+	log_must $ZFS unmount -a
+	unset __ZFS_POOL_RESTRICT
+	log_must cleanup_pool $POOL
+	log_must cleanup_pool $POOL2
+
+	log_must setup_test_model $POOL
+}
+
+log_assert "Verify changes made by 'zfs inherit' can be properly received."
+log_onexit cleanup
+
+#
+# Setting all the $FS properties as local value,
+#
+for prop in $(fs_inherit_prop); do
+	value=$(get_prop $prop $POOL/$FS)
+	log_must $ZFS set $prop=$value $POOL/$FS
+done
+
+#
+# Inherit propertes in sub-datasets
+#
+for ds in "$POOL/$FS/fs1" "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do
+	for prop in $(fs_inherit_prop) ; do
+		$ZFS inherit $prop $ds
+		if (($? !=0 )); then
+			log_fail "$ZFS inherit $prop $ds"
+		fi
+	done
+done
+if is_global_zone ; then
+	for prop in $(vol_inherit_prop) ; do
+		$ZFS inherit $prop $POOL/$FS/vol
+		if (($? !=0 )); then
+			log_fail "$ZFS inherit $prop $POOL/$FS/vol"
+		fi
+	done
+fi
+
+#
+# Verify datasets can be backup and restore correctly
+# Unmount $POOL/$FS to avoid two fs mount in the same mountpoint
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R"
+log_must $ZFS unmount -f $POOL/$FS
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+#
+# Define all the POOL/POOL2 datasets pair
+#
+set -A pair 	"$POOL" 		"$dstds" 		\
+		"$POOL/$FS" 		"$dstds/$FS" 		\
+		"$POOL/$FS/fs1"		"$dstds/$FS/fs1"	\
+		"$POOL/$FS/fs1/fs2"	"$dstds/$FS/fs1/fs2"	\
+		"$POOL/pclone"		"$dstds/pclone"		\
+		"$POOL/$FS/fs1/fclone"	"$dstds/$FS/fs1/fclone"
+
+if is_global_zone ; then
+	typeset -i n=${#pair[@]}
+	pair[((n))]="$POOL/vol"; 	pair[((n+1))]="$dstds/vol"
+	pair[((n+2))]="$POOL/$FS/vol"	pair[((n+3))]="$dstds/$FS/vol"
+fi
+
+#
+# Verify all the sub-datasets can be properly received.
+#
+log_must cmp_ds_subs $POOL $dstds
+typeset -i i=0
+while ((i < ${#pair[@]})); do
+	log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]}
+	log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
+
+	((i += 2))
+done
+
+log_pass "Changes made by 'zfs inherit' can be properly received."
--- /dev/null	Fri Nov 22 15:21:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh	Fri Nov 22 15:21:50 2013
@@ -0,0 +1,201 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs send -R will backup all the filesystem properties correctly.
+#
+# STRATEGY:
+#	1. Setting properties for all the filesystem and volumes randomly
+#	2. Backup all the data from POOL by send -R
+#	3. Restore all the data in POOL2
+#	4. Verify all the perperties in two pools are same
+#
+
+verify_runnable "global"
+
+function rand_set_prop
+{
+	typeset dtst=$1
+	typeset prop=$2
+	shift 2
+	typeset value=$(random_get $@)
+
+	log_must eval "$ZFS set $prop='$value' $dtst"
+}
+
+function edited_prop
+{
+	typeset behaviour=$1
+	typeset ds=$2
+	typeset backfile=$TESTDIR/edited_prop_$ds
+
+	case $behaviour in
+		"get")
+			typeset props=$($ZFS inherit 2>&1 | \
+				$AWK '$2=="YES" {print $1}' | \
+				$EGREP -v "^vol|\.\.\.$")
+			for item in $props ; do
+				if [[ $item == "mlslabel" ]] && \
+					! is_te_enabled ; then
+					continue
+				fi
+				$ZFS get -H -o property,value $item $ds >> \
+					$backfile
+				if (($? != 0)); then
+					log_fail "zfs get -H -o property,value"\
+						"$item $ds > $backfile"
+				fi
+			done
+			;;
+		"set")
+			if [[ ! -f $backfile ]] ; then
+				log_fail "$ds need backup properties firstly."
+			fi
+
+			typeset prop value
+			while read prop value ; do
+				eval $ZFS set $prop='$value' $ds
+				if (($? != 0)); then
+					log_fail "$ZFS set $prop=$value $ds"
+				fi
+			done < $backfile
+			;;
+		*)
+			log_fail "Unrecognized behaviour: $behaviour"
+	esac
+}
+
+function cleanup
+{
+	log_must cleanup_pool $POOL
+	log_must cleanup_pool $POOL2
+
+	log_must edited_prop "set" $POOL
+	log_must edited_prop "set" $POOL2
+
+	typeset prop
+	for prop in $(fs_inherit_prop) ; do
+		log_must $ZFS inherit $prop $POOL
+		log_must $ZFS inherit $prop $POOL2
+	done
+
+	#if is_shared $POOL; then
+	#	log_must $ZFS set sharenfs=off $POOL
+	#fi
+	log_must setup_test_model $POOL
+
+	if [[ -d $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR/*
+	fi
+}
+
+log_assert "Verify zfs send -R will backup all the filesystem properties " \
+	"correctly."
+log_onexit cleanup
+
+log_must edited_prop "get" $POOL
+log_must edited_prop "get" $POOL2
+
+for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \
+	"$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do
+	rand_set_prop $fs aclinherit "discard" "noallow" "secure" "passthrough"
+	rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
+	rand_set_prop $fs aclmode "discard" "groupmask" "passthrough"
+	rand_set_prop $fs atime "on" "off"
+	rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
+	rand_set_prop $fs compression "on" "off" "lzjb" "gzip" \
+		"gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6"   \
+		"gzip-7" "gzip-8" "gzip-9"
+	rand_set_prop $fs copies "1" "2" "3"
+	rand_set_prop $fs devices "on" "off"
+	rand_set_prop $fs exec "on" "off"
+	rand_set_prop $fs quota "512M" "1024M"
+	rand_set_prop $fs recordsize "512" "2K" "8K" "32K" "128K"
+	rand_set_prop $fs setuid "on" "off"
+	rand_set_prop $fs snapdir "hidden" "visible"
+	rand_set_prop $fs xattr "on" "off"
+	rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?"
+done
+
+for vol in "$POOL/vol" "$POOL/$FS/vol" ; do
+	rand_set_prop $vol checksum "on" "off" "fletcher2" "fletcher4" "sha256"
+	rand_set_prop $vol compression "on" "off" "lzjb" "gzip" \
+		"gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6"   \
+		"gzip-7" "gzip-8" "gzip-9"
+	rand_set_prop $vol readonly "on" "off"
+	rand_set_prop $vol copies "1" "2" "3"
+	rand_set_prop $vol user:prop "aaa" "bbb" "23421" "()-+?"
+done
+
+
+# Verify inherited property can be received
+rand_set_prop $POOL sharenfs "on" "off" "rw"
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R"
+
+#
+# Define all the POOL/POOL2 datasets pair
+#
+set -A pair 	"$POOL" 		"$POOL2" 		\
+		"$POOL/$FS" 		"$POOL2/$FS" 		\
+		"$POOL/$FS/fs1"		"$POOL2/$FS/fs1"	\
+		"$POOL/$FS/fs1/fs2"	"$POOL2/$FS/fs1/fs2"	\
+		"$POOL/pclone"		"$POOL2/pclone"		\
+		"$POOL/$FS/fs1/fclone"	"$POOL2/$FS/fs1/fclone" \
+		"$POOL/vol"		"$POOL2/vol" 		\
+		"$POOL/$FS/vol"		"$POOL2/$FS/vol"
+
+typeset -i i=0
+while ((i < ${#pair[@]})); do
+	log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
+
+	((i += 2))
+done
+
+
+$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1
+if (( $? == 0 )) ; then
+	i=0
+	while ((i < ${#pair[@]})); do
+		log_must cmp_ds_prop ${pair[$i]}@final ${pair[((i+1))]}@final
+		((i += 2))
+	done
+fi
+
+log_pass "Verify zfs send -R will backup all the filesystem properties " \
+	"correctly."
--- /dev/null	Fri Nov 22 15:21:50 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/rsend_013_pos.ksh	Fri Nov 22 15:21:50 2013
@@ -0,0 +1,86 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+#
+# DESCRIPTION:
+#	zfs receive -dF with incremental stream will destroy all the
+#	dataset that not exist on the sender side.
+#
+# STRATEGY:
+#	1. Setup test model
+#	2. Send -R @final on pool
+#	3. Destroy some dataset within the @final, and create @destroy
+#	4. Send -R -I @final @destroy on pool
+#	5. Verify receive -dF will destroy all the dataset that not exist
+#	   on the sender side.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	cleanup_pool $POOL2
+	cleanup_pool $POOL
+	log_must setup_test_model $POOL
+}
+
+log_assert "zfs receive -dF will destroy all the dataset that not exist" \
+	"on the sender side"
+log_onexit cleanup
+
+cleanup
+
+#
+# Duplicate POOL2 for testing
+#
+log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R"
+log_must eval "$ZFS receive -dF $POOL2 < $BACKDIR/pool-final-R"
+
+log_must $ZFS destroy -Rf $POOL/$FS
+log_must $ZFS destroy -Rf $POOL/pclone
+
+if is_global_zone ; then
+	log_must $ZFS destroy -Rf $POOL/vol
+fi
+log_must $ZFS snapshot -r $POOL@destroy
+
+log_must eval "$ZFS send -R -I @final $POOL@destroy > " \
+	"$BACKDIR/pool-final-destroy-IR"
+log_must eval "$ZFS receive -dF $POOL2 < $BACKDIR/pool-final-destroy-IR"
+
+dstds=$(get_dst_ds $POOL $POOL2)
+log_must cmp_ds_subs $POOL $dstds
+log_must cmp_ds_cont $POOL $dstds
+
+log_pass "zfs receive -dF will destroy all the dataset that not exist" \
+	"on the sender side"
--- /dev/null	Fri Nov 22 15:21:51 2013
+++ new/usr/src/test/zfs-tests/tests/functional/rsend/setup.ksh	Fri Nov 22 15:21:51 2013
@@ -0,0 +1,53 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/rsend/rsend.kshlib
+
+verify_runnable "both"
+verify_disk_count "$DISKS" 2
+
+#
+# Check if the system support 'send -R'
+#
+$ZFS send 2>&1 | $GREP "\[-[a-zA-Z]*R[a-zA-Z]*\]" >/dev/null 2>&1
+if (($? != 0)); then
+	log_unsupported
+fi
+
+if is_global_zone ; then
+	log_must $ZPOOL create $POOL $DISK1
+	log_must $ZPOOL create $POOL2 $DISK2
+fi
+log_must $MKDIR $BACKDIR $TESTDIR
+
+log_must setup_test_model $POOL
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:51 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/Makefile	Fri Nov 22 15:21:51 2013
@@ -0,0 +1,47 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/scrub_mirror
+
+PROGS = cleanup \
+	scrub_mirror_001_pos \
+	scrub_mirror_002_pos \
+	scrub_mirror_003_pos \
+	scrub_mirror_004_pos \
+	setup
+
+FILES = default.cfg \
+	scrub_mirror_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/cleanup.ksh	Fri Nov 22 15:21:52 2013
@@ -0,0 +1,50 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/default.cfg
+
+
+verify_runnable "global"
+
+$DF -F zfs -h | $GREP "$TESTFS " >/dev/null
+[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR
+destroy_pool $TESTPOOL
+
+# recreate and destroy a zpool over the disks to restore the partitions to
+# normal
+if [[ -n $SINGLE_DISK ]]; then
+	log_must cleanup_devices $MIRROR_PRIMARY
+else
+	log_must cleanup_devices $MIRROR_PRIMARY $MIRROR_SECONDARY
+fi
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/default.cfg	Fri Nov 22 15:21:52 2013
@@ -0,0 +1,55 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+typeset -i NUMBER_OF_DISKS=0
+for i in $DISKS; do
+	[[ -n $MIRROR_PRIMARY ]] && MIRROR_SECONDARY=$i
+	[[ -z $MIRROR_PRIMARY ]] && MIRROR_PRIMARY=$i
+done
+
+if [[ -z $MIRROR_SECONDARY ]]; then
+	# We need to repartition the single disk to two slices
+	SINGLE_DISK=$MIRROR_PRIMARY
+	MIRROR_SECONDARY=$MIRROR_PRIMARY
+	SIDE_PRIMARY=${SINGLE_DISK}s0
+	SIDE_SECONDARY=${SINGLE_DISK}s1
+else
+	SIDE_PRIMARY=${MIRROR_PRIMARY}s0
+	SIDE_SECONDARY=${MIRROR_SECONDARY}s0
+fi
+
+export MIRROR_PRIMARY MIRROR_SECONDARY SINGLE_DISK SIDE_PRIMARY SIDE_SECONDARY
+
+export FILE_COUNT=30
+export FILE_SIZE=$(( 1024 * 1024 ))
+export MIRROR_MEGS=70
+export MIRROR_SIZE=${MIRROR_MEGS}m # default mirror size
+export DD_BLOCK=$(( 64 * 1024 ))
+export DD_COUNT=$(( MIRROR_MEGS * 1024 * 1024 / DD_BLOCK ))
--- /dev/null	Fri Nov 22 15:21:52 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_001_pos.ksh	Fri Nov 22 15:21:52 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/zero over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_PRIMARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
--- /dev/null	Fri Nov 22 15:21:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_002_pos.ksh	Fri Nov 22 15:21:53 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be zeroed without causing damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/zero over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely wiped" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_SECONDARY /dev/zero
+
+log_pass "The overwrite had no effect on the data"
--- /dev/null	Fri Nov 22 15:21:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_003_pos.ksh	Fri Nov 22 15:21:53 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The primary side of a zpool mirror can be mangled causing without damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem mirror
+# 2) dd from /dev/urandom over the primary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_PRIMARY /dev/urandom
+
+log_pass "The overwrite did not have any effect on the data"
--- /dev/null	Fri Nov 22 15:21:53 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_004_pos.ksh	Fri Nov 22 15:21:53 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/scrub_mirror_common.kshlib
+
+#
+# DESCRIPTION:
+# The secondary side of a zpool mirror can be mangled causing without damage
+# to the data in the pool
+#
+# STRATEGY:
+# 1) Write several files to the ZFS filesystem in the mirrored pool
+# 2) dd from /dev/urandom over the secondary side of the mirror
+# 3) verify that all the file contents are unchanged on the file system
+#
+
+verify_runnable "global"
+
+log_assert "The primary side of a zpool mirror may be completely mangled" \
+	"without affecting the content of the pool"
+
+overwrite_verify_mirror $TESTPOOL $SIDE_SECONDARY /dev/urandom
+
+log_pass "The overwrite had no effect on the data"
--- /dev/null	Fri Nov 22 15:21:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/scrub_mirror_common.kshlib	Fri Nov 22 15:21:54 2013
@@ -0,0 +1,78 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+. $STF_SUITE/tests/functional/scrub_mirror/default.cfg
+
+function overwrite_verify_mirror
+{
+	typeset POOL=$1
+	typeset AFFECTED_DEVICE=$2
+	typeset OVERWRITING_DEVICE=$3
+
+	typeset atfile=0
+	set -A files
+	set -A cksums
+	set -A newcksums
+
+	while (( atfile < FILE_COUNT )); do
+		files[$atfile]=$TESTDIR/file.$atfile
+		log_must $FILE_WRITE -o create -f $TESTDIR/file.$atfile \
+			-b $FILE_SIZE -c 1
+		cksums[$atfile]=$($CKSUM ${files[$atfile]})
+		(( atfile = atfile + 1 ))
+	done
+
+	# dd the affected side of the mirror
+	log_must $DD if=$OVERWRITING_DEVICE of=/dev/dsk/$AFFECTED_DEVICE \
+		seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 8 )) conv=notrunc
+
+	log_must $ZPOOL scrub $POOL
+
+	while is_pool_scrubbing $POOL; do
+		$SLEEP 2
+	done
+
+	atfile=0
+
+	typeset -i failedcount=0
+	while (( atfile < FILE_COUNT )); do
+		files[$atfile]=$TESTDIR/file.$atfile
+		newcksum=$($CKSUM ${files[$atfile]})
+		if [[ $newcksum != ${cksums[$atfile]} ]]; then
+			(( failedcount = failedcount + 1 ))
+		fi
+		$RM -f ${files[$atfile]}
+		(( atfile = atfile + 1 ))
+	done
+
+	if (( $failedcount > 0 )); then
+		log_fail "of the $FILE_COUNT files $failedcount did not " \
+		    "have the same checksum before and after."
+	fi
+}
--- /dev/null	Fri Nov 22 15:21:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/scrub_mirror/setup.ksh	Fri Nov 22 15:21:54 2013
@@ -0,0 +1,51 @@
+#! /usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/scrub_mirror/default.cfg
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+if [[ -n $SINGLE_DISK ]]; then
+	log_note "Partitioning a single disk ($SINGLE_DISK)"
+else
+	log_note "Partitioning disks ($MIRROR_PRIMARY $MIRROR_SECONDARY)"
+fi
+log_must set_partition ${SIDE_PRIMARY##*s} "" $MIRROR_SIZE $MIRROR_PRIMARY
+log_must set_partition ${SIDE_SECONDARY##*s} "" $MIRROR_SIZE $MIRROR_SECONDARY
+
+default_mirror_setup $SIDE_PRIMARY $SIDE_SECONDARY
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:54 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/Makefile	Fri Nov 22 15:21:54 2013
@@ -0,0 +1,57 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/slog
+
+PROGS = cleanup \
+	setup \
+	slog_001_pos \
+	slog_002_pos \
+	slog_003_pos \
+	slog_004_pos \
+	slog_005_pos \
+	slog_006_pos \
+	slog_007_pos \
+	slog_008_neg \
+	slog_009_neg \
+	slog_010_neg \
+	slog_011_neg \
+	slog_012_neg \
+	slog_013_pos \
+	slog_014_pos
+
+FILES = slog.cfg \
+	slog.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:21:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/cleanup.ksh	Fri Nov 22 15:21:55 2013
@@ -0,0 +1,54 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/slog/slog.cfg
+
+verify_runnable "global"
+
+if ! verify_slog_support ; then
+	log_unsupported "This system doesn't support separate intent logs"
+fi
+
+if datasetexists $TESTPOOL ; then
+	log_must $ZPOOL destroy -f $TESTPOOL
+fi
+if datasetexists $TESTPOOL2 ; then
+	log_must $ZPOOL destroy -f $TESTPOOL2
+fi
+if [[ -d $VDIR ]]; then
+	log_must $RM -rf $VDIR
+fi
+if [[ -d $VDIR2 ]]; then
+	log_must $RM -rf $VDIR2
+fi
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:55 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/setup.ksh	Fri Nov 22 15:21:55 2013
@@ -0,0 +1,50 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/slog/slog.cfg
+
+verify_runnable "global"
+
+if ! verify_slog_support ; then
+	log_unsupported "This system doesn't support separate intent logs"
+fi
+
+if [[ -d $VDEV ]]; then
+	log_must $RM -rf $VDIR
+fi
+if [[ -d $VDEV2 ]]; then
+	log_must $RM -rf $VDIR2
+fi
+log_must $MKDIR -p $VDIR $VDIR2
+log_must $MKFILE $SIZE $VDEV $SDEV $LDEV $VDEV2 $SDEV2 $LDEV2
+
+log_pass
--- /dev/null	Fri Nov 22 15:21:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog.cfg	Fri Nov 22 15:21:56 2013
@@ -0,0 +1,41 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export SIZE=64M
+
+export VDIR=/disk-slog
+export VDIR2=/disk2-slog
+
+export VDEV="$VDIR/a $VDIR/b $VDIR/c"
+export SDEV="$VDIR/d"
+export LDEV="$VDIR/e $VDIR/f"
+export VDEV2="$VDIR2/a $VDIR2/b $VDIR2/c"
+export SDEV2="$VDIR2/d"
+export LDEV2="$VDIR2/e $VDIR2/f"
--- /dev/null	Fri Nov 22 15:21:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog.kshlib	Fri Nov 22 15:21:56 2013
@@ -0,0 +1,157 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/slog/slog.cfg
+
+function cleanup
+{
+	if datasetexists $TESTPOOL ; then
+		log_must $ZPOOL destroy -f $TESTPOOL
+	fi
+	if datasetexists $TESTPOOL2 ; then
+		log_must $ZPOOL destroy -f $TESTPOOL2
+	fi
+}
+
+#
+# Try zpool status/iostat for given pool
+#
+# $1 pool
+#
+function display_status
+{
+	typeset pool=$1
+
+	typeset -i ret=0
+	$ZPOOL status -xv $pool > /dev/null 2>&1
+	ret=$?
+
+	$ZPOOL iostat > /dev/null 2>&1
+	((ret |= $?))
+
+	typeset mntpnt=$(get_prop mountpoint $pool)
+	$DD if=/dev/random of=$mntpnt/testfile.$$ &
+	typeset pid=$!
+
+	$ZPOOL iostat -v 1 3 > /dev/null
+	((ret |= $?))
+
+	kill -9 $pid
+
+	return $ret
+}
+
+#
+# Verify the give slog device have correct type and status
+#
+# $1 pool name
+# $2 device name
+# $3 device status
+# $4 device type
+#
+function verify_slog_device
+{
+	typeset pool=$1
+	typeset device=$2
+	typeset status=$3
+	typeset type=$4
+
+	if [[ -z $pool || -z $device || -z $status ]]; then
+		log_fail "Usage: verify_slog_device <pool> <device> " \
+			"<status> [type]"
+	fi
+
+	if [[ $WRAPPER == *"smi"* ]]; then
+		$ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
+		if (( $? == 0 )); then
+			device=${device}s2
+		fi
+	fi
+
+	#
+	# Get all the slog devices and status table like below
+	#
+	# mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE
+	#
+	set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK 'BEGIN {start=0} \
+				/\tlogs/ {start=1}
+				/\tmirror/ || /\tspares/ || /^$/ {start=0}
+				(start==1) && /\t  (\/|[a-zA-Z])/ \
+					{print "stripe:" $1 " " $2}
+				(start==1) && /\t    (\/|[a-zA-Z])/ \
+					{print "mirror:" $1 " " $2}
+				# When hotspare is replacing
+				(start==1) && /\t      (\/|[a-zA-Z])/ \
+					{print "mirror:" $1 " " $2}'
+			     )
+
+	typeset -i i=0
+	typeset find=0
+	while (( i < ${#dev_stat_tab[@]} )); do
+		typeset dev=${dev_stat_tab[$i]}
+		typeset stat=${dev_stat_tab[((i+1))]}
+
+		case $dev in
+			stripe:$device)
+				if [[ "$type" == 'mirror' ]]; then
+					log_note "Unexpected type: mirror"
+					return 1
+				else
+					if [[ $stat != $status ]]; then
+						log_note "Status($stat) " \
+							"!= Expected stat($status)"
+						return 1
+					fi
+					return 0
+				fi
+				;;
+			mirror:$device)
+				if [[ -z "$type" || $type == 'stripe' ]]; then
+					log_note "Unexpected type: stripe"
+					return 1
+				else
+					if [[ $stat != $status ]]; then
+						log_note "Status($stat) " \
+							"!= Expected stat($status)"
+						return 1
+					fi
+					return 0
+				fi
+				;;
+		esac
+
+		((i += 2))
+	done
+
+	log_note "Can not find device: $device"
+
+	return 1
+}
--- /dev/null	Fri Nov 22 15:21:56 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_001_pos.ksh	Fri Nov 22 15:21:56 2013
@@ -0,0 +1,68 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Creating a pool with a log device succeeds.
+#
+# STRATEGY:
+#	1. Create pool with separated log devices.
+#	2. Display pool status
+#	3. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Creating a pool with a log device succeeds."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "" "mirror"
+		do
+			log_must $ZPOOL create $TESTPOOL $type $VDEV \
+				$spare $SDEV log $logtype $LDEV
+			log_must display_status $TESTPOOL
+
+			ldev=$(random_get $LDEV)
+			log_must verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' $logtype
+
+			log_must $ZPOOL destroy -f $TESTPOOL
+		done
+	done
+done
+
+log_pass "Creating a pool with a log device succeeds."
--- /dev/null	Fri Nov 22 15:21:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_002_pos.ksh	Fri Nov 22 15:21:57 2013
@@ -0,0 +1,67 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Adding a log device to normal pool works.
+#
+# STRATEGY:
+#	1. Create pool
+#	2. Add log devices with different configuration
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Adding a log device to normal pool works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "" "mirror"
+		do
+			log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV
+			log_must $ZPOOL add $TESTPOOL log $logtype $LDEV
+			log_must display_status $TESTPOOL
+			typeset ldev=$(random_get $LDEV)
+			log_must verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' $logtype
+			log_must $ZPOOL destroy -f $TESTPOOL
+		done
+	done
+done
+
+log_pass "Adding a log device to normal pool works."
--- /dev/null	Fri Nov 22 15:21:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_003_pos.ksh	Fri Nov 22 15:21:57 2013
@@ -0,0 +1,74 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Adding an extra log device works
+#
+# STRATEGY:
+#	1. Create pool with separated log devices.
+#	2. Add an extra log devices
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Adding an extra log device works."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "" "mirror"
+		do
+			for newtype in "" "mirror"
+			do
+				log_must $ZPOOL create $TESTPOOL $type $VDEV \
+					$spare $SDEV log $logtype $LDEV
+				log_must $ZPOOL add $TESTPOOL \
+					log $newtype $LDEV2
+
+				log_must display_status $TESTPOOL
+				ldev=$(random_get $LDEV2)
+				log_must verify_slog_device \
+					$TESTPOOL $ldev 'ONLINE' $newtype
+
+				log_must $ZPOOL destroy -f $TESTPOOL
+			done
+		done
+	done
+done
+
+log_pass "Adding an extra log device works."
--- /dev/null	Fri Nov 22 15:21:57 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_004_pos.ksh	Fri Nov 22 15:21:57 2013
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Attaching a log device passes.
+#
+# STRATEGY:
+#	1. Create pool with separated log devices.
+#	2. Attaching a log device for existing log device
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Attaching a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "" "mirror"
+		do
+			log_must $ZPOOL create $TESTPOOL $type $VDEV \
+				$spare $SDEV log $logtype $LDEV
+
+			ldev=$(random_get $LDEV)
+			typeset ldev2=$(random_get $LDEV2)
+			log_must $ZPOOL attach $TESTPOOL $ldev $ldev2
+			log_must display_status $TESTPOOL
+			log_must verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' 'mirror'
+			log_must verify_slog_device \
+				$TESTPOOL $ldev2 'ONLINE' 'mirror'
+
+			log_must $ZPOOL destroy -f $TESTPOOL
+		done
+	done
+done
+
+log_pass "Attaching a log device passes."
--- /dev/null	Fri Nov 22 15:21:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_005_pos.ksh	Fri Nov 22 15:21:58 2013
@@ -0,0 +1,65 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Detaching a log device passes.
+#
+# STRATEGY:
+#	1. Create pool with mirror log devices.
+#	2. Detaching a log device
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Detaching a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+			log mirror $LDEV mirror $LDEV2
+		ldev=$(random_get $LDEV $LDEV2)
+		log_must $ZPOOL detach $TESTPOOL $ldev
+		log_must display_status $TESTPOOL
+		log_mustnot verify_slog_device $TESTPOOL $ldev 'ONLINE' 'mirror'
+
+		log_must $ZPOOL destroy -f $TESTPOOL
+	done
+done
+
+log_pass "Detaching a log device passes."
--- /dev/null	Fri Nov 22 15:21:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_006_pos.ksh	Fri Nov 22 15:21:58 2013
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Replacing a log device passes.
+#
+# STRATEGY:
+#	1. Create pool with log devices.
+#	2. Replacing one log device
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Replacing a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "" "mirror"
+		do
+			log_must $ZPOOL create $TESTPOOL $type $VDEV \
+				$spare $SDEV log $logtype $LDEV
+			sdev=$(random_get $LDEV)
+			tdev=$(random_get $LDEV2)
+			log_must $ZPOOL replace $TESTPOOL $sdev $tdev
+			log_must display_status $TESTPOOL
+			# sleep 15 to make sure replacement completely.
+			log_must $SLEEP 15
+			log_must verify_slog_device \
+				$TESTPOOL $tdev 'ONLINE' $logtype
+
+			log_must $ZPOOL destroy -f $TESTPOOL
+		done
+	done
+done
+
+log_pass "Replacing a log device passes."
--- /dev/null	Fri Nov 22 15:21:58 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_007_pos.ksh	Fri Nov 22 15:21:58 2013
@@ -0,0 +1,93 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Exporting and importing pool with log devices passes.
+#
+# STRATEGY:
+#	1. Create pool with log devices.
+#	2. Export and import the pool
+#	3. Display pool status
+#	4. Destroy and import the pool again
+#	5. Display pool status
+#	6. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Exporting and importing pool with log devices passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "" "mirror"
+		do
+			#
+			# Create pool which devices resider in different
+			# directory
+			#
+			log_must $ZPOOL create $TESTPOOL $type $VDEV \
+				$spare $SDEV log $logtype $LDEV $LDEV2
+			ldev=$(random_get $LDEV $LDEV2)
+			log_must verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' $logtype
+
+			#
+			# Nomal export/import operating
+			#
+			log_must $ZPOOL export $TESTPOOL
+			log_must $ZPOOL import -d $VDIR -d $VDIR2 $TESTPOOL
+			log_must display_status $TESTPOOL
+			ldev=$(random_get $LDEV $LDEV2)
+			log_must verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' $logtype
+
+			#
+			# Destroy the pool and import again
+			#
+			log_must $ZPOOL destroy $TESTPOOL
+			log_must $ZPOOL import -Df -d $VDIR -d $VDIR2 $TESTPOOL
+			log_must display_status $TESTPOOL
+			ldev=$(random_get $LDEV $LDEV2)
+			log_must verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' $logtype
+
+			log_must $ZPOOL destroy -f $TESTPOOL
+		done
+	done
+done
+
+log_pass "Exporting and importing pool with log devices passes."
--- /dev/null	Fri Nov 22 15:21:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_008_neg.ksh	Fri Nov 22 15:21:59 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	A raidz/raidz2 log is not supported.
+#
+# STRATEGY:
+#	1. Try to create pool with unsupported type
+#	2. Verify failed to create pool.
+#
+
+verify_runnable "global"
+
+log_assert "A raidz/raidz2 log is not supported."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "raidz" "raidz1" "raidz2"
+		do
+			log_mustnot $ZPOOL create $TESTPOOL $type $VDEV \
+				$spare $SDEV log $logtype $LDEV $LDEV2
+			ldev=$(random_get $LDEV $LDEV2)
+			log_mustnot verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' $logtype
+			log_must datasetnonexists $TESTPOOL
+		done
+	done
+done
+
+log_pass "A raidz/raidz2 log is not supported."
--- /dev/null	Fri Nov 22 15:21:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_009_neg.ksh	Fri Nov 22 15:21:59 2013
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	A raidz/raidz2 log can not be added to existed pool.
+#
+# STRATEGY:
+#	1. Create pool with or without log.
+#	2. Add a raidz/raidz2 log to this pool.
+#	3. Verify failed to add.
+#
+
+verify_runnable "global"
+
+log_assert "A raidz/raidz2 log can not be added to existed pool."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		for logtype in "raidz" "raidz1" "raidz2"
+		do
+			log=$(random_get_with_non "log")
+			log_must $ZPOOL create $TESTPOOL $type $VDEV \
+				$spare $SDEV $log $LDEV
+
+			log_mustnot $ZPOOL add $TESTPOOL log $logtype $LDEV2
+			ldev=$(random_get $LDEV2)
+			log_mustnot verify_slog_device \
+				$TESTPOOL $ldev 'ONLINE' $logtype
+
+			log_must $ZPOOL destroy $TESTPOOL
+		done
+	done
+done
+
+log_pass "A raidz/raidz2 log can not be added to existed pool."
--- /dev/null	Fri Nov 22 15:21:59 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_010_neg.ksh	Fri Nov 22 15:21:59 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Slog device can not be replaced with spare device
+#
+# STRATEGY:
+#	1. Create a pool with hotspare and log devices.
+#	2. Verify slog device can not be replaced with hotspare device.
+#	3. Create pool2 with hotspare
+#	4. Verify slog device can not be replaced with hotspare device in pool2.
+#
+
+verify_runnable "global"
+
+log_assert "Slog device can not be replaced with spare device."
+log_onexit cleanup
+
+log_must $ZPOOL create $TESTPOOL $VDEV spare $SDEV log $LDEV
+sdev=$(random_get $SDEV)
+ldev=$(random_get $LDEV)
+log_mustnot $ZPOOL replace $TESTPOOL $ldev $sdev
+log_mustnot verify_slog_device $TESTPOOL $sdev 'ONLINE'
+log_must verify_slog_device $TESTPOOL $ldev 'ONLINE'
+
+log_must $ZPOOL create $TESTPOOL2 $VDEV2 spare $SDEV2
+sdev2=$(random_get $SDEV2)
+log_mustnot $ZPOOL replace $TESTPOOL $ldev $sdev2
+log_mustnot $ZPOOL replace -f $TESTPOOL $ldev $sdev2
+log_mustnot verify_slog_device $TESTPOOL $sdev2 'ONLINE'
+log_must verify_slog_device $TESTPOOL $ldev 'ONLINE'
+
+log_pass "Slog device can not be replaced with spare device."
--- /dev/null	Fri Nov 22 15:22:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_011_neg.ksh	Fri Nov 22 15:22:00 2013
@@ -0,0 +1,70 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Offline and online a log device passes.
+#
+# STRATEGY:
+#	1. Create pool with mirror log devices.
+#	2. Offine and online a log device
+#	3. Display pool status
+#	4. Destroy and loop to create pool with different configuration.
+#
+
+verify_runnable "global"
+
+log_assert "Offline and online a log device passes."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+			log mirror $LDEV mirror $LDEV2
+
+		ldev=$(random_get $LDEV $LDEV2)
+		log_must $ZPOOL offline $TESTPOOL $ldev
+		log_must display_status $TESTPOOL
+		log_must verify_slog_device $TESTPOOL $ldev 'OFFLINE' 'mirror'
+
+		log_must $ZPOOL online $TESTPOOL $ldev
+		log_must display_status $TESTPOOL
+		log_must verify_slog_device $TESTPOOL $ldev 'ONLINE' 'mirror'
+
+		log_must $ZPOOL destroy -f $TESTPOOL
+	done
+done
+
+log_pass "Offline and online a log device passes."
--- /dev/null	Fri Nov 22 15:22:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_012_neg.ksh	Fri Nov 22 15:22:00 2013
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Pool can survive when one of mirror log device get corrupted
+#
+# STRATEGY:
+#	1. Create pool with mirror slog devices
+#	2. Make corrupted on one disk
+#	3. Verify the pool is fine
+#
+
+verify_runnable "global"
+
+log_assert "Pool can survive when one of mirror log device get corrupted."
+log_onexit cleanup
+
+for type in "" "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+			log mirror $LDEV
+
+		mntpnt=$(get_prop mountpoint $TESTPOOL)
+		#
+		# Create file in pool to trigger writting in slog devices
+		#
+		log_must $DD if=/dev/random of=$mntpnt/testfile.$$ count=100
+
+		ldev=$(random_get $LDEV)
+		log_must $MKFILE $SIZE $ldev
+		log_must $ZPOOL scrub $TESTPOOL
+
+		log_must display_status $TESTPOOL
+		log_must verify_slog_device $TESTPOOL $ldev 'UNAVAIL' 'mirror'
+
+		log_must $ZPOOL destroy -f $TESTPOOL
+	done
+done
+
+log_pass "Pool can survive when one of mirror log device get corrupted."
--- /dev/null	Fri Nov 22 15:22:00 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_013_pos.ksh	Fri Nov 22 15:22:00 2013
@@ -0,0 +1,94 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	Verify slog device can be disk, file, lofi device or any device that
+#	presents a block interface.
+#
+# STRATEGY:
+#	1. Create a pool
+#	2. Loop to add different object as slog
+#	3. Verify it passes
+#
+
+verify_runnable "global"
+
+function cleanup_testenv
+{
+	cleanup
+	if datasetexists $TESTPOOL2 ; then
+		log_must $ZPOOL destroy -f $TESTPOOL2
+	fi
+	if [[ -n $lofidev ]]; then
+		$LOFIADM -d $lofidev
+	fi
+}
+
+log_assert "Verify slog device can be disk, file, lofi device or any device " \
+	"that presents a block interface."
+verify_disk_count "$DISKS" 2
+log_onexit cleanup_testenv
+
+dsk1=${DISKS%% *}
+log_must $ZPOOL create $TESTPOOL ${DISKS#$dsk1}
+
+# Add nomal disk
+log_must $ZPOOL add $TESTPOOL log $dsk1
+log_must verify_slog_device $TESTPOOL $dsk1 'ONLINE'
+# Add nomal file
+log_must $ZPOOL add $TESTPOOL log $LDEV
+ldev=$(random_get $LDEV)
+log_must verify_slog_device $TESTPOOL $ldev 'ONLINE'
+
+# Add lofi device
+lofidev=${LDEV2%% *}
+log_must $LOFIADM -a $lofidev
+lofidev=$($LOFIADM $lofidev)
+log_must $ZPOOL add $TESTPOOL log $lofidev
+log_must verify_slog_device $TESTPOOL $lofidev 'ONLINE'
+
+log_pass "Verify slog device can be disk, file, lofi device or any device " \
+	"that presents a block interface."
+
+# Temp disable fore bug 6569095
+# Add file which reside in the itself
+mntpnt=$(get_prop mountpoint $TESTPOOL)
+log_must $MKFILE 100M $mntpnt/vdev
+log_must $ZPOOL add $TESTPOOL $mntpnt/vdev
+
+# Temp disable fore bug 6569072
+# Add ZFS volume
+vol=$TESTPOOL/vol
+log_must $ZPOOL create -V 64M $vol
+log_must $ZPOOL add $TESTPOOL /dev/zvol/dsk/$vol
--- /dev/null	Fri Nov 22 15:22:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/slog/slog_014_pos.ksh	Fri Nov 22 15:22:01 2013
@@ -0,0 +1,80 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/slog/slog.kshlib
+
+#
+# DESCRIPTION:
+#	log device can survive when one of pool device get corrupted
+#
+# STRATEGY:
+#	1. Create pool with slog devices
+#	2. Corrupt the data on one disk.
+#	3. Verify the log is fine
+#
+
+verify_runnable "global"
+
+log_assert "log device can survive when one of the pool device get corrupted."
+
+for type in "mirror" "raidz" "raidz2"
+do
+	for spare in "" "spare"
+	do
+		log_must $ZPOOL create $TESTPOOL $type $VDEV $spare $SDEV \
+			log $LDEV
+
+		# Corrupt a pool device to make the pool DEGRADED
+		$DD if=/dev/urandom of=/$TESTPOOL/filler bs=1024k count=50
+		# The oseek value below is to skip past the vdev label.
+		log_must $DD if=/dev/urandom of=$VDIR/a bs=1024k oseek=4 \
+		    conv=notrunc count=50
+		log_must $ZPOOL scrub $TESTPOOL
+		log_must display_status $TESTPOOL
+		log_must $ZPOOL status $TESTPOOL 2>&1 >/dev/null
+
+		$ZPOOL status -v $TESTPOOL | \
+			$GREP "state: DEGRADED" 2>&1 >/dev/null
+		if (( $? != 0 )); then
+			log_fail "pool $TESTPOOL status should be DEGRADED"
+		fi
+
+		$ZPOOL status -v $TESTPOOL | $GREP logs | \
+			$GREP "DEGRADED" 2>&1 >/dev/null
+		if (( $? == 0 )); then
+			log_fail "log device should display correct status"
+		fi
+
+		log_must $ZPOOL destroy -f $TESTPOOL
+	done
+done
+
+log_pass "log device can survive when one of the pool device get corrupted."
--- /dev/null	Fri Nov 22 15:22:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/Makefile	Fri Nov 22 15:22:01 2013
@@ -0,0 +1,63 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/snapshot
+
+PROGS = cleanup \
+	clone_001_pos \
+	rollback_001_pos \
+	rollback_002_pos \
+	rollback_003_pos \
+	setup \
+	snapshot_001_pos \
+	snapshot_002_pos \
+	snapshot_003_pos \
+	snapshot_004_pos \
+	snapshot_005_pos \
+	snapshot_006_pos \
+	snapshot_007_pos \
+	snapshot_008_pos \
+	snapshot_009_pos \
+	snapshot_010_pos \
+	snapshot_011_pos \
+	snapshot_012_pos \
+	snapshot_013_pos \
+	snapshot_014_pos \
+	snapshot_015_pos \
+	snapshot_016_pos \
+	snapshot_017_pos
+
+FILES = snapshot.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:22:01 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/cleanup.ksh	Fri Nov 22 15:22:01 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_container_cleanup
--- /dev/null	Fri Nov 22 15:22:02 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh	Fri Nov 22 15:22:02 2013
@@ -0,0 +1,161 @@
+#! /bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	Create a snapshot from regular filesystem, volume,
+#	or filesystem upon volume, Build a clone file system
+#	from the snapshot and verify new files can be written.
+#
+# STRATEGY:
+# 	1. Create snapshot use 3 combination:
+#		- Regular filesystem
+#		- Regular volume
+#		- Filesystem upon volume
+# 	2. Clone a new file system from the snapshot
+# 	3. Verify the cloned file system is writable
+#
+
+verify_runnable "both"
+
+# Setup array, 4 elements as a group, refer to:
+# i+0: name of a snapshot
+# i+1: mountpoint of the snapshot
+# i+2: clone created from the snapshot
+# i+3: mountpoint of the clone
+
+set -A args "$SNAPFS" "$SNAPDIR" "$TESTPOOL/$TESTCLONE" "$TESTDIR.0" \
+	"$SNAPFS1" "$SNAPDIR3" "$TESTPOOL/$TESTCLONE1" "" \
+	"$SNAPFS2" "$SNAPDIR2" "$TESTPOOL1/$TESTCLONE2" "$TESTDIR.2"
+
+function setup_all
+{
+	create_pool $TESTPOOL1 /dev/zvol/dsk/$TESTPOOL/$TESTVOL
+	log_must $ZFS create $TESTPOOL1/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL1/$TESTFS
+
+	return 0
+}
+
+function cleanup_all
+{
+	typeset -i i=0
+
+	i=0
+	while (( i < ${#args[*]} )); do
+		snapexists ${args[i]} && \
+			log_must $ZFS destroy -Rf ${args[i]}
+
+		[[ -d ${args[i+3]} ]] && \
+			log_must $RM -rf ${args[i+3]}
+
+		[[ -d ${args[i+1]} ]] && \
+			log_must $RM -rf ${args[i+1]}
+
+		(( i = i + 4 ))
+	done
+
+	datasetexists $TESTPOOL1/$TESTFS  && \
+		log_must $ZFS destroy -f $TESTPOOL1/$TESTFS
+
+	destroy_pool $TESTPOOL1
+
+	[[ -d $TESTDIR2 ]] && \
+		log_must $RM -rf $TESTDIR2
+
+	return 0
+}
+
+log_assert "Verify a cloned file system is writable."
+
+log_onexit cleanup_all
+
+setup_all
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+typeset -i i=0
+
+for mtpt in $TESTDIR $TESTDIR2 ; do
+	log_note "Populate the $mtpt directory (prior to snapshot)"
+	typeset -i j=1
+	while [[ $j -le $COUNT ]]; do
+		log_must $FILE_WRITE -o create -f $mtpt/before_file$j \
+			-b $BLOCKSZ -c $NUM_WRITES -d $j
+
+		(( j = j + 1 ))
+	done
+done
+
+while (( i < ${#args[*]} )); do
+	#
+	# Take a snapshot of the test file system.
+	#
+	log_must $ZFS snapshot ${args[i]}
+
+	#
+	# Clone a new file system from the snapshot
+	#
+	log_must $ZFS clone ${args[i]} ${args[i+2]}
+	if [[ -n ${args[i+3]} ]] ; then
+		log_must $ZFS set mountpoint=${args[i+3]} ${args[i+2]}
+
+		FILE_COUNT=`$LS -Al ${args[i+3]} | $GREP -v "total" \
+		    | $GREP -v "\.zfs" | wc -l`
+		if [[ $FILE_COUNT -ne $COUNT ]]; then
+			$LS -Al ${args[i+3]}
+			log_fail "AFTER: ${args[i+3]} contains $FILE_COUNT files(s)."
+		fi
+
+		log_note "Verify the ${args[i+3]} directory is writable"
+		j=1
+		while [[ $j -le $COUNT ]]; do
+			log_must $FILE_WRITE -o create -f ${args[i+3]}/after_file$j \
+			-b $BLOCKSZ -c $NUM_WRITES -d $j
+			(( j = j + 1 ))
+		done
+
+		FILE_COUNT=`$LS -Al ${args[i+3]}/after* | $GREP -v "total" | wc -l`
+		if [[ $FILE_COUNT -ne $COUNT ]]; then
+			$LS -Al ${args[i+3]}
+			log_fail "${args[i+3]} contains $FILE_COUNT after* files(s)."
+		fi
+	fi
+
+	(( i = i + 4 ))
+done
+
+log_pass "The clone file system is writable."
--- /dev/null	Fri Nov 22 15:22:02 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/rollback_001_pos.ksh	Fri Nov 22 15:22:02 2013
@@ -0,0 +1,115 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Populate a file system and take a snapshot. Add some more files to the
+# file system and rollback to the last snapshot. Verify no post snapshot
+# file exist.
+#
+# STRATEGY:
+# 1. Empty a file system
+# 2. Populate the file system
+# 3. Take a snapshot of the file system
+# 4. Add new files to the file system
+# 5. Perform a rollback
+# 6. Verify the snapshot and file system agree
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $SNAPFS
+	[[ $? -eq 0 ]] && \
+		log_must $ZFS destroy $SNAPFS
+
+	[[ -e $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that a rollback to a previous snapshot succeeds."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+	log_must $FILE_WRITE -o create -f $TESTDIR/before_file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+	(( i = i + 1 ))
+done
+
+log_must $ZFS snapshot $SNAPFS
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne $COUNT ]]; then
+        $LS -Al $SNAPDIR
+        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
+fi
+
+log_note "Populate the $TESTDIR directory (post snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+        log_must $FILE_WRITE -o create -f $TESTDIR/after_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+#
+# Now rollback to latest snapshot
+#
+log_must $ZFS rollback $SNAPFS
+
+FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
+fi
+
+FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \
+    | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne $COUNT ]]; then
+	$LS -Al $TESTDIR
+	log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
+fi
+
+log_pass "The rollback operation succeeded."
--- /dev/null	Fri Nov 22 15:22:02 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/rollback_002_pos.ksh	Fri Nov 22 15:22:02 2013
@@ -0,0 +1,133 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that rollbacks are with respect to the latest snapshot.
+#
+# STRATEGY:
+# 1. Empty a file system
+# 2. Populate the file system
+# 3. Take a snapshot of the file system
+# 4. Add new files to the file system
+# 5. Take a snapshot
+# 6. Remove the original files
+# 7. Perform a rollback
+# 8. Verify the latest snapshot and file system agree
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $SNAPFS.1
+	[[ $? -eq 0 ]] && \
+		log_must $ZFS destroy $SNAPFS.1
+
+	snapexists $SNAPFS
+	[[ $? -eq 0 ]] && \
+		log_must $ZFS destroy $SNAPFS
+
+	[[ -e $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify rollback is with respect to latest snapshot."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to first snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+	log_must $FILE_WRITE -o create -f $TESTDIR/original_file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+	(( i = i + 1 ))
+done
+
+log_must $ZFS snapshot $SNAPFS
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne $COUNT ]]; then
+        $LS -Al $SNAPDIR
+        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
+fi
+
+log_note "Populate the $TESTDIR directory (prior to second snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+        log_must $FILE_WRITE -o create -f $TESTDIR/afterfirst_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+log_must $ZFS snapshot $SNAPFS.1
+
+log_note "Populate the $TESTDIR directory (Post second snapshot)"
+typeset -i i=1
+while [[ $i -le $COUNT ]]; do
+        log_must $FILE_WRITE -o create -f $TESTDIR/aftersecond_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/original_file* > /dev/null 2>&1
+
+#
+# Now rollback to latest snapshot
+#
+log_must $ZFS rollback $SNAPFS.1
+
+FILE_COUNT=`$LS -Al $TESTDIR/aftersecond* 2> /dev/null \
+    | $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)."
+fi
+
+FILE_COUNT=`$LS -Al $TESTDIR/original* $TESTDIR/afterfirst*| $GREP -v "total" | wc -l`
+if [[ $FILE_COUNT -ne 20 ]]; then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT original* files(s)."
+fi
+
+log_pass "The rollback to the latest snapshot succeeded."
--- /dev/null	Fri Nov 22 15:22:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/rollback_003_pos.ksh	Fri Nov 22 15:22:03 2013
@@ -0,0 +1,106 @@
+#! /bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+
+#
+# DESCRIPTION:
+# Verify that rollbacks succeed when there are nested file systems.
+#
+# STRATEGY:
+# 1) Snapshot an empty file system and rollback
+# 2) Create a file in the file system
+# 3) Rollback the file system to empty
+# 4) Create a nested file system with the same name as the file created in (2)
+# 5) Verify a rollback succeeds
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset snap=""
+	typeset fs=""
+
+	export __ZFS_POOL_RESTRICT="$TESTPOOL"
+	log_must $ZFS mount -a
+	unset __ZFS_POOL_RESTRICT
+
+	for snap in "$SNAPPOOL.1" "$SNAPPOOL"
+	do
+		snapexists $snap
+		[[ $? -eq 0 ]] && \
+			log_must $ZFS destroy $snap
+	done
+
+	for fs in "$TESTPOOL/$TESTFILE/$TESTFILE.1" "$TESTPOOL/$TESTFILE"
+	do
+		datasetexists $fs
+		[[ $? -eq 0 ]] && \
+			log_must $ZFS destroy -r $fs
+	done
+
+	[[ -e /$TESTPOOL ]] && \
+		log_must $RM -rf $TESTPOOL/*
+}
+
+log_assert "Verify rollback succeeds when there are nested file systems."
+
+log_onexit cleanup
+
+log_must $ZFS snapshot $SNAPPOOL
+log_must $ZFS rollback $SNAPPOOL
+log_mustnot $ZFS snapshot $SNAPPOOL
+
+log_must $TOUCH /$TESTPOOL/$TESTFILE
+
+log_must $ZFS rollback $SNAPPOOL
+log_must $ZFS create $TESTPOOL/$TESTFILE
+
+log_must $ZFS rollback $SNAPPOOL
+
+log_note "Verify rollback of multiple nested file systems succeeds."
+log_must $ZFS snapshot $TESTPOOL/$TESTFILE@$TESTSNAP
+log_must $ZFS snapshot $SNAPPOOL.1
+
+export __ZFS_POOL_RESTRICT="$TESTPOOL"
+log_must $ZFS unmount -a
+log_must $ZFS mount -a
+unset __ZFS_POOL_RESTRICT
+
+log_must $TOUCH /$TESTPOOL/$TESTFILE/$TESTFILE.1
+
+log_must $ZFS rollback $SNAPPOOL.1
+
+log_pass "Rollbacks succeed when nested file systems are present."
--- /dev/null	Fri Nov 22 15:22:03 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/setup.ksh	Fri Nov 22 15:22:03 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_container_volume_setup ${DISK}
--- /dev/null	Fri Nov 22 15:22:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot.cfg	Fri Nov 22 15:22:04 2013
@@ -0,0 +1,53 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export TESTFILE=testfile-snapshot
+export SNAPROOT=".zfs/snapshot"
+
+export SNAPPOOL="$TESTPOOL@$TESTSNAP"
+export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP"
+export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP"
+export SNAPFS2="$TESTPOOL1/$TESTFS@$TESTSNAP"
+export SNAPCTR="$TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP"
+export SNAPDIR="$TESTDIR/$SNAPROOT/$TESTSNAP"
+export SNAPDIR1="$TESTDIR1/$SNAPROOT/$TESTSNAP"
+export SNAPDIR2="$TESTDIR2/$SNAPROOT/$TESTSNAP"
+export SNAPDIR3="/$SNAPFS1"
+
+export VOLSIZE=1gb
+export BLOCKSZ=8192
+export NUM_WRITES=20
+export DATA=0
+export LIMIT=524288 # tolerance measured in bytes, 512K
+export FSQUOTA=500m
+export FILESIZE=400m
+export FILESIZE1=200m
--- /dev/null	Fri Nov 22 15:22:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_001_pos.ksh	Fri Nov 22 15:22:04 2013
@@ -0,0 +1,91 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# A zfs file system snapshot is identical to
+# the originally snapshot'd file system, after the file
+# system has been changed. Uses 'sum -r'.
+#
+# STRATEGY:
+# 1. Create a file in the zfs file system
+# 2. Checksum the file for later comparison
+# 3. Create a snapshot of the dataset
+# 4. Append to the original file
+# 5. Verify the snapshot and file agree
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $SNAPFS
+	if [[ $? -eq 0 ]]; then
+		log_must $ZFS destroy $SNAPFS
+	fi
+
+	if [[ -e $SNAPDIR ]]; then
+		log_must $RM -rf $SNAPDIR > /dev/null 2>&1
+	fi
+
+	if [[ -e $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+	fi
+}
+
+log_assert "Verify a file system snapshot is identical to original."
+
+log_onexit cleanup
+
+log_note "Create a file in the zfs filesystem..."
+log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Sum the file, save for later comparison..."
+FILE_SUM=`$SUM -r $TESTDIR/$TESTFILE | $AWK  '{ print $1 }'`
+log_note "FILE_SUM = $FILE_SUM"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPFS
+
+log_note "Append to the original file..."
+log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+SNAP_FILE_SUM=`$SUM -r $SNAPDIR/$TESTFILE | $AWK '{ print $1 }'`
+if [[ $SNAP_FILE_SUM -ne $FILE_SUM ]]; then
+	log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)"
+fi
+
+log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)"
--- /dev/null	Fri Nov 22 15:22:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_002_pos.ksh	Fri Nov 22 15:22:04 2013
@@ -0,0 +1,134 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# An archive of a zfs file system and an archive of its snapshot
+# is identical even though the original file system has
+# changed sinced the snapshot was taken.
+#
+# STRATEGY:
+# 1) Create files in all of the zfs file systems
+# 2) Create a tarball of the file system
+# 3) Create a snapshot of the dataset
+# 4) Remove all the files in the original file system
+# 5) Create a tarball of the snapshot
+# 6) Extract each tarball and compare directory structures
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ -d $CWD ]]; then
+		cd $CWD || log_fail "Could not cd $CWD"
+	fi
+
+        snapexists $SNAPFS
+        if [[ $? -eq 0 ]]; then
+                log_must $ZFS destroy $SNAPFS
+        fi
+
+        if [[ -e $SNAPDIR ]]; then
+                log_must $RM -rf $SNAPDIR > /dev/null 2>&1
+        fi
+
+        if [[ -e $TESTDIR ]]; then
+                log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+        fi
+
+	if [[ -e /tmp/zfs_snapshot2.$$ ]]; then
+		log_must $RM -rf /tmp/zfs_snapshot2.$$ > /dev/null 2>&1
+	fi
+
+}
+
+log_assert "Verify an archive of a file system is identical to " \
+    "an archive of its snapshot."
+
+log_onexit cleanup
+
+typeset -i COUNT=21
+typeset OP=create
+
+[[ -n $TESTDIR ]] && \
+    $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+log_note "Create files in the zfs filesystem..."
+
+typeset i=1
+while [ $i -lt $COUNT ]; do
+	log_must $FILE_WRITE -o $OP -f $TESTDIR/file$i \
+	    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+	(( i = i + 1 ))
+done
+
+log_note "Create a tarball from $TESTDIR contents..."
+CWD=$PWD
+cd $TESTDIR || log_fail "Could not cd $TESTDIR"
+log_must $TAR cf $TESTDIR/tarball.original.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPFS
+
+log_note "Remove all of the original files..."
+log_must $RM -f $TESTDIR/file* > /dev/null 2>&1
+
+log_note "Create tarball of snapshot..."
+CWD=$PWD
+cd $SNAPDIR || log_fail "Could not cd $SNAPDIR"
+log_must $TAR cf $TESTDIR/tarball.snapshot.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_must $MKDIR $TESTDIR/original
+log_must $MKDIR $TESTDIR/snapshot
+
+CWD=$PWD
+cd $TESTDIR/original || log_fail "Could not cd $TESTDIR/original"
+log_must $TAR xf $TESTDIR/tarball.original.tar
+
+cd $TESTDIR/snapshot || log_fail "Could not cd $TESTDIR/snapshot"
+log_must $TAR xf $TESTDIR/tarball.snapshot.tar
+
+cd $CWD || log_fail "Could not cd $CWD"
+
+$DIRCMP $TESTDIR/original $TESTDIR/snapshot > /tmp/zfs_snapshot2.$$
+$GREP different /tmp/zfs_snapshot2.$$ >/dev/null 2>&1
+if [[ $? -ne 1 ]]; then
+	log_fail "Directory structures differ."
+fi
+
+log_pass "Directory structures match."
--- /dev/null	Fri Nov 22 15:22:04 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_003_pos.ksh	Fri Nov 22 15:22:04 2013
@@ -0,0 +1,103 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that many snapshots can be made on a zfs file system.
+#
+# STRATEGY:
+# 1) Create a files in the zfs file system
+# 2) Create a snapshot of the dataset
+# 3) Remove all the files from the original file system
+# 4) Verify consistency of each snapshot directory
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i=1
+	while [ $i -lt $COUNT ]; do
+		snapexists $SNAPFS.$i
+		if [[ $? -eq 0 ]]; then
+			log_must $ZFS destroy $SNAPFS.$i
+		fi
+
+		if [[ -e $SNAPDIR.$i ]]; then
+			log_must $RM -rf $SNAPDIR.$i > /dev/null 2>&1
+		fi
+
+		(( i = i + 1 ))
+	done
+
+	if [[ -e $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+	fi
+}
+
+log_assert "Verify many snapshots of a file system can be taken."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Create some files in the $TESTDIR directory..."
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+	log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+	log_must $ZFS snapshot $SNAPFS.$i
+
+	(( i = i + 1 ))
+done
+
+log_note "Remove all of the original files"
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/file* > /dev/null 2>&1
+
+i=1
+while [[ $i -lt $COUNT ]]; do
+	FILECOUNT=`$LS $SNAPDIR.$i/file* | wc -l`
+	typeset j=1
+	while [ $j -lt $FILECOUNT ]; do
+		log_must $FILE_CHECK $SNAPDIR.$i/file$j $j
+		(( j = j + 1 ))
+	done
+	(( i = i + 1 ))
+done
+
+log_pass "All files are consistent"
--- /dev/null	Fri Nov 22 15:22:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_004_pos.ksh	Fri Nov 22 15:22:05 2013
@@ -0,0 +1,90 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Create a null snapshot i.e. a snapshot created before file system
+# activity is empty.
+#
+# STRATEGY:
+# 1. Empty a file system
+# 2. Take a snapshot of the empty file system.
+# 3. Populate the file system
+# 4. Verify the snapshot is still empty
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $SNAPFS
+	[[ $? -eq 0 ]] && \
+		log_must $ZFS destroy $SNAPFS
+
+	[[ -e $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that a snapshot of an empty file system remains empty."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+log_must $ZFS snapshot $SNAPFS
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total 0" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+	$LS $SNAPDIR
+	log_fail "BEFORE: $SNAPDIR contains $FILE_COUNT files(s)."
+fi
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory"
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+	log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+	(( i = i + 1 ))
+done
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total 0" | wc -l`
+if [[ $FILE_COUNT -ne 0 ]]; then
+        $LS $SNAPDIR
+        log_fail "AFTER: $SNAPDIR contains $FILE_COUNT files(s)."
+fi
+
+log_pass "The NULL snapshot remains empty."
--- /dev/null	Fri Nov 22 15:22:05 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_005_pos.ksh	Fri Nov 22 15:22:05 2013
@@ -0,0 +1,90 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# to the originally snapshot'd file system, after the file
+# system has been changed. Uses 'sum -r'.
+#
+# STRATEGY:
+# 1) Create a file in the zfs dataset
+# 2) Sum the file for later comparison
+# 3) Create a snapshot of the dataset
+# 4) Append to the original file
+# 5) Verify both checksums match
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $SNAPCTR
+	if [[ $? -eq 0 ]]; then
+		log_must $ZFS destroy $SNAPCTR
+	fi
+
+	if [[ -e $SNAPDIR1 ]]; then
+		log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1
+	fi
+
+	if [[ -e $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+	fi
+}
+
+log_assert "Verify that a snapshot of a dataset is identical to " \
+    "the original dataset."
+log_onexit cleanup
+
+log_note "Create a file in the zfs filesystem..."
+log_must $FILE_WRITE -o create -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+log_note "Sum the file, save for later comparison..."
+FILE_SUM=`$SUM -r $TESTDIR1/$TESTFILE | $AWK  '{ print $1 }'`
+log_note "FILE_SUM = $FILE_SUM"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPCTR
+
+log_note "Append to the original file..."
+log_must $FILE_WRITE -o append -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
+    -c $NUM_WRITES -d $DATA
+
+SNAP_FILE_SUM=`$SUM -r $SNAPDIR1/$TESTFILE | $AWK '{ print $1 }'`
+if [[ $SNAP_FILE_SUM -ne $FILE_SUM ]]; then
+	log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)"
+fi
+
+log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)"
--- /dev/null	Fri Nov 22 15:22:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_006_pos.ksh	Fri Nov 22 15:22:06 2013
@@ -0,0 +1,132 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# An archive of a zfs dataset and an archive of its snapshot
+# changed sinced the snapshot was taken.
+#
+# STRATEGY:
+# 1) Create some files in a ZFS dataset
+# 2) Create a tarball of the dataset
+# 3) Create a snapshot of the dataset
+# 4) Remove all the files in the original dataset
+# 5) Create a tarball of the snapshot
+# 6) Extract each tarball and compare directory structures
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if [[ -d $CWD ]]; then
+		cd $CWD || log_fail "Could not cd $CWD"
+	fi
+
+        snapexists $SNAPCTR
+        if [[ $? -eq 0 ]]; then
+                log_must $ZFS destroy $SNAPCTR
+        fi
+
+        if [[ -e $SNAPDIR1 ]]; then
+                log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1
+        fi
+
+        if [[ -e $TESTDIR1 ]]; then
+                log_must $RM -rf $TESTDIR1/* > /dev/null 2>&1
+        fi
+
+	if [[ -e /tmp/zfs_snapshot2.$$ ]]; then
+		log_must $RM -rf /tmp/zfs_snapshot2.$$ > /dev/null 2>&1
+	fi
+
+}
+
+log_assert "Verify that an archive of a dataset is identical to " \
+   "an archive of the dataset's snapshot."
+
+log_onexit cleanup
+
+typeset -i COUNT=21
+typeset OP=create
+
+[[ -n $TESTDIR1 ]] && $RM -rf $TESTDIR1/* > /dev/null 2>&1
+
+log_note "Create files in the zfs dataset ..."
+
+typeset i=1
+while [ $i -lt $COUNT ]; do
+	log_must $FILE_WRITE -o $OP -f $TESTDIR1/file$i \
+	    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+	(( i = i + 1 ))
+done
+
+log_note "Create a tarball from $TESTDIR1 contents..."
+CWD=$PWD
+cd $TESTDIR1 || log_fail "Could not cd $TESTDIR1"
+log_must $TAR cf $TESTDIR1/tarball.original.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_note "Create a snapshot and mount it..."
+log_must $ZFS snapshot $SNAPCTR
+
+log_note "Remove all of the original files..."
+log_must $RM -f $TESTDIR1/file* > /dev/null 2>&1
+
+log_note "Create tarball of snapshot..."
+CWD=$PWD
+cd $SNAPDIR1 || log_fail "Could not cd $SNAPDIR1"
+log_must $TAR cf $TESTDIR1/tarball.snapshot.tar file*
+cd $CWD || log_fail "Could not cd $CWD"
+
+log_must $MKDIR $TESTDIR1/original
+log_must $MKDIR $TESTDIR1/snapshot
+
+CWD=$PWD
+cd $TESTDIR1/original || log_fail "Could not cd $TESTDIR1/original"
+log_must $TAR xf $TESTDIR1/tarball.original.tar
+
+cd $TESTDIR1/snapshot || log_fail "Could not cd $TESTDIR1/snapshot"
+log_must $TAR xf $TESTDIR1/tarball.snapshot.tar
+
+cd $CWD || log_fail "Could not cd $CWD"
+
+$DIRCMP $TESTDIR1/original $TESTDIR1/snapshot > /tmp/zfs_snapshot2.$$
+$GREP different /tmp/zfs_snapshot2.$$ >/dev/null 2>&1
+if [[ $? -ne 1 ]]; then
+	log_fail "Directory structures differ."
+fi
+
+log_pass "Directory structures match."
--- /dev/null	Fri Nov 22 15:22:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_007_pos.ksh	Fri Nov 22 15:22:06 2013
@@ -0,0 +1,107 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that many snapshots can be made on a zfs dataset.
+#
+# STRATEGY:
+# 1) Create a file in the zfs dataset
+# 2) Create a snapshot of the dataset
+# 3) Remove all the files from the original dataset
+# 4) For each snapshot directory verify consistency
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i=1
+	while [ $i -lt $COUNT ]; do
+		snapexists $SNAPCTR.$i
+		if [[ $? -eq 0 ]]; then
+			log_must $ZFS destroy $SNAPCTR.$i
+		fi
+
+		if [[ -e $SNAPDIR.$i ]]; then
+			log_must $RM -rf $SNAPDIR1.$i > /dev/null 2>&1
+		fi
+
+		(( i = i + 1 ))
+	done
+
+	if [[ -e $SNAPDIR1 ]]; then
+		log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1
+	fi
+
+	if [[ -e $TESTDIR ]]; then
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+	fi
+}
+
+log_assert "Verify that many snapshots can be made on a zfs dataset."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Create some files in the $TESTDIR directory..."
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+	log_must $FILE_WRITE -o create -f $TESTDIR1/file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+	log_must $ZFS snapshot $SNAPCTR.$i
+
+	(( i = i + 1 ))
+done
+
+log_note "Remove all of the original files"
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR1/file* > /dev/null 2>&1
+
+i=1
+while [[ $i -lt $COUNT ]]; do
+	FILECOUNT=`$LS $SNAPDIR1.$i/file* | wc -l`
+	typeset j=1
+	while [ $j -lt $FILECOUNT ]; do
+		log_must $FILE_CHECK $SNAPDIR1.$i/file$j $j
+		(( j = j + 1 ))
+	done
+	(( i = i + 1 ))
+done
+
+log_pass "All files are consistent"
--- /dev/null	Fri Nov 22 15:22:06 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_008_pos.ksh	Fri Nov 22 15:22:06 2013
@@ -0,0 +1,100 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+# Verify that destroying snapshots returns space to the pool.
+#
+# STRATEGY:
+# 1. Create a file system and populate it while snapshotting.
+# 2. Destroy the snapshots and remove the files.
+# 3. Verify the space returns to the pool.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i=1
+	while [[ $i -lt $COUNT ]]; do
+		snapexists $SNAPFS.$i
+		[[ $? -eq 0 ]] && \
+			log_must $ZFS destroy $SNAPFS.$i
+
+		(( i = i + 1 ))
+	done
+
+	[[ -e $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that destroying snapshots returns space to the pool."
+
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+orig_size=`get_prop available $TESTPOOL`
+
+log_note "Populate the $TESTDIR directory"
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+	log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+	log_must $ZFS snapshot $SNAPFS.$i
+	(( i = i + 1 ))
+done
+
+typeset -i i=1
+while [[ $i -lt $COUNT ]]; do
+	log_must rm -rf $TESTDIR/file$i > /dev/null 2>&1
+	log_must $ZFS destroy $SNAPFS.$i
+
+	(( i = i + 1 ))
+done
+
+new_size=`get_prop available $TESTPOOL`
+
+typeset -i tolerance=0
+
+(( tolerance = new_size - orig_size))
+if (( tolerance > LIMIT )); then
+        log_fail "Space not freed. ($orig_size != $new_size)"
+fi
+
+log_pass "After destroying snapshots, the space is returned to the pool."
--- /dev/null	Fri Nov 22 15:22:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_009_pos.ksh	Fri Nov 22 15:22:07 2013
@@ -0,0 +1,119 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	Verify 'snapshot -r' and 'destroy -r' can correctly create and destroy
+#	snapshot tree respectively.
+#
+# STRATEGY:
+# 1. Use the snapshot -r to create snapshot for top level pool
+# 2. Verify the children snapshots are created correctly.
+# 3. Use destroy -r to destroy the top level snapshot
+# 4. Verify that all children snapshots are destroyed too.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset ds
+	typeset snap
+
+	for ds in $ctr/$TESTVOL1 $ctr/$TESTCLONE; do
+		datasetexists $ds && \
+			log_must $ZFS destroy -f $ds
+	done
+
+	for snap in $ctr/$TESTFS1@$TESTSNAP1 \
+		$snappool $snapvol $snapctr $snapctrvol \
+		$snapctrclone $snapctrfs
+	do
+		snapexists $snap && \
+			log_must $ZFS destroy -rf $snap
+	done
+
+}
+
+log_assert "Verify snapshot -r can correctly create a snapshot tree."
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS1
+ctrclone=$ctr/$TESTCLONE
+ctrvol=$ctr/$TESTVOL1
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapvol=$SNAPFS1
+snapctrvol=$ctrvol@$TESTSNAP
+snapctrclone=$ctrclone@$TESTSNAP
+snapctrfs=$SNAPCTR
+
+#preparation for testing
+log_must $ZFS snapshot $ctrfs@$TESTSNAP1
+log_must $ZFS clone $ctrfs@$TESTSNAP1 $ctrclone
+if is_global_zone; then
+	log_must $ZFS create -V $VOLSIZE $ctrvol
+else
+	log_must $ZFS create $ctrvol
+fi
+
+log_must $ZFS snapshot -r $snappool
+
+#verify the snapshot -r results
+for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
+		$snapctrclone $snapctrfs
+do
+	! snapexists $snap && \
+		log_fail "The snapshot $snap is not created via -r option."
+done
+
+log_note "Verify that destroy -r can destroy the snapshot tree."
+
+log_must $ZFS destroy -r $snappool
+for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
+		$snapctrclone $snapctrfs
+do
+	snapexists $snap && \
+		log_fail "The snapshot $snap is not destroyed correctly."
+done
+
+log_note "Verify that the snapshot with different name should \
+		be not destroyed."
+! snapexists $ctrfs@$TESTSNAP1 && \
+	log_fail "destroy -r incorrectly destroys the snapshot \
+		$ctrfs@$TESTSNAP1."
+
+log_pass  "snapshot|destroy -r with snapshot tree works as expected."
--- /dev/null	Fri Nov 22 15:22:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_010_pos.ksh	Fri Nov 22 15:22:07 2013
@@ -0,0 +1,101 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	Verify 'destroy -r' can correctly destroy a snapshot tree at any point.
+#
+# STRATEGY:
+# 1. Use the snapshot -r to create snapshot for top level pool
+# 2. Select a middle point of the snapshot tree, use destroy -r to destroy all
+#	snapshots beneath the point.
+# 3. Verify the destroy results.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset snap
+
+	datasetexists $ctrvol && \
+		log_must $ZFS destroy -f $ctrvol
+
+	for snap in $ctrfs@$TESTSNAP1 \
+		$snappool $snapvol $snapctr $snapctrvol \
+		$snapctrclone $snapctrfs
+	do
+		snapexists $snap && \
+			log_must $ZFS destroy -rf $snap
+	done
+
+}
+
+log_assert "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point."
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS1
+ctrvol=$ctr/$TESTVOL1
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapvol=$SNAPFS1
+snapctrvol=$ctr/$TESTVOL1@$TESTSNAP
+snapctrclone=$ctr/$TESTCLONE@$TESTSNAP
+snapctrfs=$SNAPCTR
+
+#preparation for testing
+log_must $ZFS snapshot $ctrfs@$TESTSNAP1
+if is_global_zone; then
+	log_must $ZFS create -V $VOLSIZE $ctrvol
+else
+	log_must $ZFS create $ctrvol
+fi
+
+log_must $ZFS snapshot -r $snappool
+
+#select the $TESTCTR as destroy point, $TESTCTR is a child of $TESTPOOL
+log_must $ZFS destroy -r $snapctr
+for snap in $snapctr $snapctrvol $snapctrclone $snapctrfs; do
+	snapexists $snap && \
+		log_fail "The snapshot $snap is not destroyed correctly."
+done
+
+for snap in $snappool $snapfs $snapvol $ctrfs@$TESTSNAP1;do
+	! snapexists $snap && \
+		log_fail "The snapshot $snap should be not destroyed."
+done
+
+log_pass  "'destroy -r' destroys snapshot subtree as expected."
--- /dev/null	Fri Nov 22 15:22:07 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh	Fri Nov 22 15:22:07 2013
@@ -0,0 +1,113 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	use 'snapshot -r' to create a snapshot tree, add some files to one child
+#	filesystem, rollback the child filesystem snapshot, verify that the child
+# 	filesystem gets back to the status while taking the snapshot.
+#
+# STRATEGY:
+#	1. Add some files to a target child filesystem
+#	2. snapshot -r the parent filesystem
+#	3. Add some other files to the target child filesystem
+#	4. rollback the child filesystem snapshot
+#	5. verify that the child filesystem get back to the status while being
+#	   snapshot'd
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	snapexists $SNAPPOOL && \
+		log_must $ZFS destroy -r $SNAPPOOL
+
+	[[ -e $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify that rollback to a snapshot created by snapshot -r succeeds."
+log_onexit cleanup
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to snapshot)"
+typeset -i i=0
+while (( i < COUNT )); do
+	log_must $FILE_WRITE -o create -f $TESTDIR/before_file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+	(( i = i + 1 ))
+done
+
+log_must $ZFS snapshot -r $SNAPPOOL
+
+FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
+if (( FILE_COUNT != COUNT )); then
+        $LS -Al $SNAPDIR
+        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
+fi
+
+log_note "Populate the $TESTDIR directory (post snapshot)"
+typeset -i i=0
+while (( i < COUNT )); do
+        log_must $FILE_WRITE -o create -f $TESTDIR/after_file$i \
+           -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+        (( i = i + 1 ))
+done
+
+#
+# Now rollback to latest snapshot
+#
+log_must $ZFS rollback $SNAPFS
+
+FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l`
+if (( FILE_COUNT != 0 )); then
+        $LS -Al $TESTDIR
+        log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
+fi
+
+FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \
+    | $GREP -v "total" | wc -l`
+if (( FILE_COUNT != $COUNT )); then
+	$LS -Al $TESTDIR
+	log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
+fi
+
+log_pass "Rollback with child snapshot works as expected."
--- /dev/null	Fri Nov 22 15:22:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh	Fri Nov 22 15:22:08 2013
@@ -0,0 +1,104 @@
+#! /bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	Verify 'snapshot -r' can create snapshot for promoted clone, and vice
+#	versa, a clone filesystem from the snapshot created by 'snapshot -r'
+#	can be correctly promoted.
+#
+# STRATEGY:
+#	1. Create a dataset tree
+#	2. snapshot a filesystem and clone the snapshot
+#	3. promote the clone
+#	4. snapshot -r the dataset tree
+#	5. verify that the snapshot of cloned filesystem is created correctly
+#	6. clone a snapshot from the snapshot tree
+#	7. promote the clone
+#	8. verify that the clone is promoted correctly.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	if datasetexists $clone1; then
+		log_must $ZFS promote $ctrfs
+		log_must $ZFS destroy $clone1
+	fi
+
+	snapexists $snapctr && \
+		log_must $ZFS destroy -r $snapctr
+
+	if snapexists $clone@$TESTSNAP1; then
+		log_must $ZFS promote $ctrfs
+		log_must $ZFS destroy -rR $ctrfs@$TESTSNAP1
+	fi
+}
+
+log_assert "Verify that 'snapshot -r' can work with 'zfs promote'."
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS1
+clone=$ctr/$TESTCLONE
+clone1=$ctr/$TESTCLONE1
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapctrclone=$clone@$TESTSNAP
+snapctrclone1=$clone1@$TESTSNAP
+snapctrfs=$SNAPCTR
+
+#preparation for testing
+log_must $ZFS snapshot $ctrfs@$TESTSNAP1
+log_must $ZFS clone $ctrfs@$TESTSNAP1 $clone
+log_must $ZFS promote $clone
+
+log_must $ZFS snapshot -r $snapctr
+
+! snapexists $snapctrclone && \
+	log_fail "'snapshot -r' fails to create $snapctrclone for $ctr/$TESTCLONE."
+
+log_must $ZFS clone $snapctrfs $clone1
+log_must $ZFS promote $clone1
+
+#verify the origin value is correct.
+orig_value=$(get_prop origin $ctrfs)
+if ! snapexists $snapctrclone1 || [[ "$orig_value" != "$snapctrclone1" ]]; then
+	log_fail "'zfs promote' fails to promote $clone which is cloned from \
+		$snapctrfs."
+fi
+
+log_pass "'snapshot -r' can work with 'zfs promote' as expected."
--- /dev/null	Fri Nov 22 15:22:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh	Fri Nov 22 15:22:08 2013
@@ -0,0 +1,99 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	verify that the snapshots created by 'snapshot -r' can be used for
+#	zfs send/recv
+#
+# STRATEGY:
+#	1. create a dataset tree and populate a filesystem
+#	2. snapshot -r the dataset tree
+#	3. select one snapshot used  for zfs send/recv
+#	4. verify the data integrity after zfs send/recv
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $ctrfs && \
+		$ZFS destroy -r $ctrfs
+
+	snapexists $snappool && \
+		log_must $ZFS destroy -r $snappool
+
+	[[ -e $TESTDIR ]] && \
+		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+}
+
+log_assert "Verify snapshots from 'snapshot -r' can be used for zfs send/recv"
+log_onexit cleanup
+
+ctr=$TESTPOOL/$TESTCTR
+ctrfs=$ctr/$TESTFS
+snappool=$SNAPPOOL
+snapfs=$SNAPFS
+snapctr=$ctr@$TESTSNAP
+snapctrfs=$ctrfs@$TESTSNAP
+fsdir=/$ctrfs
+snapdir=$fsdir/.zfs/snapshot/$TESTSNAP
+
+[[ -n $TESTDIR ]] && \
+    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
+
+typeset -i COUNT=10
+
+log_note "Populate the $TESTDIR directory (prior to snapshot)"
+typeset -i i=0
+while (( i < COUNT )); do
+	log_must $FILE_WRITE -o create -f $TESTDIR/file$i \
+	   -b $BLOCKSZ -c $NUM_WRITES -d $i
+
+	(( i = i + 1 ))
+done
+
+log_must $ZFS snapshot -r $snappool
+
+$ZFS send $snapfs | $ZFS receive $ctrfs >/dev/null 2>&1
+if ! datasetexists $ctrfs || ! snapexists $snapctrfs; then
+	log_fail "zfs send/receive fails with snapshot $snapfs."
+fi
+
+for dir in $fsdir $snapdir; do
+	FILE_COUNT=`$LS -Al $dir | $GREP -v "total" | wc -l`
+	(( FILE_COUNT != COUNT )) && log_fail "Got $FILE_COUNT expected $COUNT"
+done
+
+log_pass "'zfs send/receive' works as expected with snapshots from 'snapshot -r'"
--- /dev/null	Fri Nov 22 15:22:08 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh	Fri Nov 22 15:22:08 2013
@@ -0,0 +1,78 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	verify that creating/destroying snapshots do things clean
+#
+# STRATEGY:
+#	1. create a dataset and set a quota with 500m
+#	2. create file of size 400m on the dataset
+#	3. take a snapshot and destroy it
+#	4. then create file to use all spaces in the dataset
+#	5. verify removing the first file should succeed
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	[[ -e $TESTDIR1 ]] && \
+		log_must $RM -rf $TESTDIR1/* > /dev/null 2>&1
+
+	snapexists $SNAPCTR && \
+		log_must $ZFS destroy $SNAPCTR
+
+	datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \
+		log_must $ZFS set quota=none $TESTPOOL/$TESTCTR/$TESTFS1
+
+}
+
+log_assert "Verify creating/destroying snapshots do things clean"
+log_onexit cleanup
+
+log_must $ZFS set quota=$FSQUOTA $TESTPOOL/$TESTCTR/$TESTFS1
+log_must $MKFILE $FILESIZE $TESTDIR1/$TESTFILE
+
+log_must $ZFS snapshot $SNAPCTR
+log_must $ZFS destroy $SNAPCTR
+
+log_note "Make the quota of filesystem is reached"
+log_mustnot $MKFILE $FILESIZE1 $TESTDIR1/$TESTFILE1
+
+log_note "Verify removing the first file should succeed after the snapshot is \
+	removed"
+log_must $RM $TESTDIR1/$TESTFILE
+
+log_pass "Verify creating/destroying snapshots do things clean"
--- /dev/null	Fri Nov 22 15:22:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh	Fri Nov 22 15:22:09 2013
@@ -0,0 +1,121 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
+
+#
+# DESCRIPTION:
+#	Verify snapshot can be created or destroy via mkdir or rm
+#	in .zfs/snapshot.
+#
+# STRATEGY:
+#	1. Verify make directories only successfully in .zfs/snapshot.
+#	2. Verify snapshot can be created and destroy via mkdir and remove
+#	directories in .zfs/snapshot.
+#	3. Verify rollback to previous snapshot can succeed.
+#	4. Verify remove directory in snapdir can destroy snapshot.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	typeset -i i=0
+	while ((i < snap_cnt)); do
+		typeset snap=$fs@snap.$i
+		datasetexists $snap && log_must $ZFS destroy -f $snap
+
+		((i += 1))
+	done
+}
+
+$ZFS 2>&1 | $GREP "allow" > /dev/null
+(($? != 0)) && log_unsupported
+
+log_assert "Verify snapshot can be created via mkdir in .zfs/snapshot."
+log_onexit cleanup
+
+fs=$TESTPOOL/$TESTFS
+# Verify all the other directories are readonly.
+mntpnt=$(get_prop mountpoint $fs)
+snapdir=$mntpnt/.zfs
+set -A ro_dirs "$snapdir" "$snapdir/snap" "$snapdir/snapshot"
+for dir in ${ro_dirs[@]}; do
+	if [[ -d $dir ]]; then
+		log_mustnot $RM -rf $dir
+		log_mustnot $TOUCH $dir/testfile
+	else
+		log_mustnot $MKDIR $dir
+	fi
+done
+
+# Verify snapshot can be created via mkdir in .zfs/snapshot
+typeset -i snap_cnt=5
+typeset -i cnt=0
+while ((cnt < snap_cnt)); do
+	testfile=$mntpnt/testfile.$cnt
+	log_must $MKFILE 1M $testfile
+	log_must $MKDIR $snapdir/snapshot/snap.$cnt
+	if ! datasetexists $fs@snap.$cnt ; then
+		log_fail "ERROR: $fs@snap.$cnt should exists."
+	fi
+
+	((cnt += 1))
+done
+
+# Verify rollback to previous snapshot succeed.
+((cnt = RANDOM % snap_cnt))
+log_must $ZFS rollback -r $fs@snap.$cnt
+
+typeset -i i=0
+while ((i < snap_cnt)); do
+	testfile=$mntpnt/testfile.$i
+	if ((i <= cnt)); then
+		if [[ ! -f $testfile ]]; then
+			log_fail "ERROR: $testfile should exists."
+		fi
+	else
+		if [[ -f $testfile ]]; then
+			log_fail "ERROR: $testfile should not exists."
+		fi
+	fi
+
+	((i += 1))
+done
+
+# Verify remove directory in snapdir can destroy snapshot.
+log_must $RMDIR $snapdir/snapshot/snap.$cnt
+log_mustnot datasetexists $fs@snap.$cnt
+
+log_pass "Verify snapshot can be created via mkdir in .zfs/snapshot passed."
--- /dev/null	Fri Nov 22 15:22:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh	Fri Nov 22 15:22:09 2013
@@ -0,0 +1,101 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#	Verify renamed snapshots via mv can be destroyed
+#
+# STRATEGY:
+#	1. Create snapshot
+#	2. Rename the snapshot via mv command
+#	2. Verify destroying the renamed snapshot via 'zfs destroy' succeeds
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	datasetexists $SNAPFS && \
+		log_must $ZFS destroy -Rf $SNAPFS
+	datasetexists $TESTPOOL/$TESTFS@snap_a && \
+		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS@snap_a
+	datasetexists $TESTPOOL/$TESTCLONE@snap_a && \
+		log_must $ZFS destroy -Rf $TESTPOOL/$TESTCLONE@snap_a
+
+	datasetexists $TESTPOOL/$TESTCLONE && \
+		log_must $ZFS destroy $TESTPOOL/$TESTCLONE
+	datasetexists $TESTPOOL/$TESTFS && \
+		log_must $ZFS destroy $TESTPOOL/$TESTFS
+
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+log_assert "Verify renamed snapshots via mv can be destroyed."
+log_onexit cleanup
+
+# scenario 1
+
+log_must $ZFS snapshot $SNAPFS
+log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a
+
+datasetexists $TESTPOOL/$TESTFS@snap_a || \
+	log_fail "rename snapshot via mv in .zfs/snapshot fails."
+log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a
+
+# scenario 2
+
+log_must $ZFS snapshot $SNAPFS
+log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE
+log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a
+
+datasetexists $TESTPOOL/$TESTFS@snap_a || \
+        log_fail "rename snapshot via mv in .zfs/snapshot fails."
+log_must $ZFS promote $TESTPOOL/$TESTCLONE
+# promote back to $TESTPOOL/$TESTFS for scenario 3
+log_must $ZFS promote $TESTPOOL/$TESTFS
+log_must $ZFS destroy $TESTPOOL/$TESTCLONE
+log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a
+
+# scenario 3
+
+log_must $ZFS snapshot $SNAPFS
+log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE
+log_must $ZFS rename $SNAPFS $TESTPOOL/$TESTFS@snap_a
+log_must $ZFS promote $TESTPOOL/$TESTCLONE
+log_must $ZFS destroy $TESTPOOL/$TESTFS
+log_must $ZFS destroy $TESTPOOL/$TESTCLONE@snap_a
+
+log_pass "Verify renamed snapshots via mv can be destroyed."
--- /dev/null	Fri Nov 22 15:22:09 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh	Fri Nov 22 15:22:09 2013
@@ -0,0 +1,202 @@
+#!/usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
+
+#
+# DESCRIPTION:
+#
+# Directory structure of snapshots reflects filesystem structure.
+#
+# STRATEGY:
+#
+# This test makes sure that the directory structure of snapshots is
+# a proper reflection of the filesystem the snapshot was taken of.
+#
+# 1. Create a simple directory structure of files and directories
+# 2. Take a snapshot of the filesystem
+# 3. Modify original filesystem
+# 4. Walk down the snapshot directory structure verifying it
+#    checking with both absolute and relative paths
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	cd $SAVED_DIR
+
+	if datasetexists $TESTPOOL/$TESTFS ; then
+		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
+	fi
+
+	log_must $ZFS create $TESTPOOL/$TESTFS
+	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
+}
+
+function verify_structure {
+
+	# check absolute paths
+	DIR=$PWD
+	verify_file $DIR/file1
+	verify_file $DIR/file2
+	verify_file $DIR/dir1/file3
+	verify_file $DIR/dir1/file4
+	verify_file $DIR/dir1/dir2/file5
+	verify_file $DIR/dir1/dir2/file6
+
+	verify_no_file $DIR/file99
+
+	# check relative paths
+	verify_file ./file1
+	verify_file ./file2
+	verify_file ./dir1/file3
+	verify_file ./dir1/file4
+	verify_file ./dir1/dir2/file5
+	verify_file ./dir1/dir2/file6
+
+	cd dir1
+	verify_file ../file1
+	verify_file ../file2
+	verify_file ./file3
+	verify_file ./file4
+
+	verify_no_file ../file99
+
+	cd dir2
+	verify_file ./file5
+	verify_file ./file6
+	verify_file ../file3
+	verify_file ../file4
+	verify_no_file ../file99
+
+	verify_file ../../file1
+	verify_file ../../file2
+	verify_no_file ../../file99
+}
+
+function verify_file {
+	if [ ! -e $1 ]
+	then
+		log_note "Working dir is $PWD"
+		log_fail "File $1 does not exist!"
+	fi
+}
+
+function verify_no_file {
+	if [ -e $1 ]
+	then
+		log_note "Working dir is $PWD"
+		log_fail "File $1 exists when it should not!"
+	fi
+}
+
+function verify_dir {
+	if [ ! -d $1 ]
+	then
+		log_note "Working dir is $PWD"
+		log_fail "Directory $1 does not exist!"
+	fi
+}
+
+log_assert "Directory structure of snapshots reflects filesystem structure."
+log_onexit cleanup
+
+SAVED_DIR=$PWD
+
+#
+# Create a directory structure with the following files
+#
+# ./file1
+# ./file2
+# ./dir1/file3
+# ./dir1/file4
+# ./dir1/dir2/file5
+# ./dir1/dir2/file6
+
+cd $TESTDIR
+$MKFILE 10m file1
+$MKFILE 20m file2
+$MKDIR dir1
+cd dir1
+$MKFILE 10m file3
+$MKFILE 20m file4
+$MKDIR dir2
+cd dir2
+$MKFILE 10m file5
+$MKFILE 20m file6
+
+# Now walk the directory structure verifying it
+cd $TESTDIR
+verify_structure
+
+# Take snapshots
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_a
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_b
+
+# Change the filesystem structure by renaming files in the original structure
+# The snapshot file structure should not change
+cd $TESTDIR
+log_must $MV file2 file99
+cd dir1
+log_must $MV file4 file99
+cd dir2
+log_must $MV file6 file99
+
+# verify the top level snapshot directories
+verify_dir $TESTDIR/.zfs
+verify_dir $TESTDIR/.zfs/snapshot
+verify_dir $TESTDIR/.zfs/snapshot/snap_a
+verify_dir $TESTDIR/.zfs/snapshot/snap_b
+
+cd $TESTDIR/.zfs/snapshot/snap_a
+verify_structure
+
+cd $TESTDIR/.zfs/snapshot/snap_b
+verify_structure
+
+cd $TESTDIR/.zfs
+verify_dir snapshot
+cd $TESTDIR/.zfs/snapshot
+verify_dir snap_a
+verify_dir snap_b
+
+cd snap_a
+verify_dir ../snap_a
+verify_dir ../snap_b
+
+cd ..
+verify_dir snap_a
+verify_dir snap_b
+
+log_pass "Directory structure of snapshots reflects filesystem structure."
--- /dev/null	Fri Nov 22 15:22:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/Makefile	Fri Nov 22 15:22:10 2013
@@ -0,0 +1,47 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/snapused
+
+PROGS = cleanup \
+	setup \
+	snapused_001_pos \
+	snapused_002_pos \
+	snapused_003_pos \
+	snapused_004_pos \
+	snapused_005_pos
+
+FILES = snapused.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:22:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/cleanup.ksh	Fri Nov 22 15:22:10 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:22:10 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/setup.ksh	Fri Nov 22 15:22:10 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:22:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/snapused.kshlib	Fri Nov 22 15:22:11 2013
@@ -0,0 +1,185 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+export USEDTEST=$TESTPOOL/$TESTFS/usedtest-snapused
+
+function _check_used # dataset
+{
+        typeset dataset=$1
+
+	if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
+		return
+	fi
+
+	used=$(get_prop used $dataset)
+	usedbychildren=$(get_prop usedbychildren $dataset)
+	usedbydataset=$(get_prop usedbydataset $dataset)
+	usedbyrefreservation=$(get_prop usedbyrefreservation $dataset)
+	usedbysnapshots=$(get_prop usedbysnapshots $dataset)
+	((used_sum = usedbychildren + usedbydataset + \
+		usedbyrefreservation + usedbysnapshots))
+	if ((used != used_sum)); then
+		log_fail "$dataset: used($used) is not the sum($used_sum) of usedby*"
+	fi
+}
+
+function check_used # dataset
+{
+	typeset dataset=$1
+	for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+	do
+		_check_used $child
+	done
+}
+
+function check_usedbychildren # dataset
+{
+	typeset dataset=$1
+	typeset -i usedbychildren_sum=0
+	typeset -i parent_usedbychildren=0
+	for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+	do
+		if [[ "$(get_prop type $child)" == "snapshot" ]]; then
+			continue
+		fi
+
+		# parent
+		if [[ "$child" == "$dataset" ]]; then
+			parent_usedbychildren=$(get_prop usedbychildren $child)
+		else #child
+			reservation=$(get_prop reservation $child)
+			used=$(get_prop used $child)
+			if ((reservation > used)); then
+				((usedbychildren_sum += reservation))
+			else
+				((usedbychildren_sum += used))
+			fi
+		fi
+	done
+
+        if ((parent_usedbychildren != usedbychildren_sum)); then
+                log_fail "$dataset: usedbychildren($parent_usedbychildren) is not the sum($usedbychildren_sum) of used by children"
+        fi
+}
+
+function _check_usedbydataset # dataset
+{
+        typeset dataset=$1
+	if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
+		return
+	fi
+
+	usedbydataset=$(get_prop usedbydataset $dataset)
+	referenced=$(get_prop referenced $dataset)
+
+	is_cloned=$(get_prop is:cloned $dataset)
+
+	if [[ "$is_cloned" == "yes" ]]; then
+		if ((usedbydataset > referenced)); then
+			log_fail "$dataset(cloned): usedbydataset($usedbydataset) is more than referenced($referenced)"
+		fi
+	else
+		#
+		# if non-clones, should usedbydataset == referenced
+		#
+		if ((usedbydataset != referenced)); then
+			log_fail "$dataset: usedbydataset($usedbydataset) is not equal to referenced($referenced)"
+		fi
+	fi
+}
+
+function check_usedbydataset # dataset
+{
+	typeset dataset=$1
+	for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+	do
+		_check_usedbydataset $child
+	done
+}
+
+function _check_usedbyrefreservation # dataset
+{
+        typeset dataset=$1
+	if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then
+		return
+	fi
+
+	usedbyrefreservation=$(get_prop usedbyrefreservation $dataset)
+	referenced=$(get_prop referenced $dataset)
+	refreservation=$(get_prop refreservation $dataset)
+	((diff_ref = refreservation - referenced))
+	if ((usedbyrefreservation > refreservation || \
+		usedbyrefreservation < diff_ref)); then
+		log_fail "$dataset: usedbyrefreservation($usedbyrefreservation) checking is not ok"
+	fi
+}
+
+function check_usedbyrefreservation # dataset
+{
+	typeset dataset=$1
+	for child in $($ZFS list -rH -t filesystem,volume -o name $dataset)
+	do
+		_check_usedbyrefreservation $child
+	done
+}
+
+function check_usedbysnapshots # dataset
+{
+	typeset dataset=$1
+	typeset -i usedbysnapshots_sum=0
+	typeset -i parent_usedbysnapshots=0
+	for child in $($ZFS list -rH -t filesystem,volume,snapshot -o name $dataset)
+	do
+		# parent
+		if [[ "$child" == "$dataset" ]]; then
+			parent_usedbysnapshots=$(get_prop usedbysnapshots $child)
+			continue
+		fi
+
+		if [[ "$(get_prop type $child)" != "snapshot" ]]; then
+			continue
+		fi
+
+		if [[ "$child" != "$dataset@"* ]]; then
+			continue
+		fi
+
+		# snapshot
+		used=$(get_prop used $child)
+		((usedbysnapshots_sum += used))
+	done
+
+        if ((parent_usedbysnapshots < usedbysnapshots_sum)); then
+                log_fail "$dataset: usedbysnapshots($parent_usedbysnapshots) is not more than or equal to" \
+				"the sum($usedbysnapshots_sum) of used of snapshots"
+        fi
+}
--- /dev/null	Fri Nov 22 15:22:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh	Fri Nov 22 15:22:11 2013
@@ -0,0 +1,91 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#	Verify used is correct.
+#
+# STRATEGY:
+#	1. Create a filesystem.
+#	2. Set refreservation of the filesystem.
+#	3. Make file in the filesystem.
+#	4. Create sub filesystem and make file in it.
+#	5. Create volume under it.
+#	6. Snapshot it.
+#	7. Check used=usedbychildren+usedbydataset+
+#		usedbyrefreservation+usedbysnapshots.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify used is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_used $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+	((r_size=(i+1)*16))
+
+	#usedbyrefreservation
+	log_must $ZFS set refreservation="$r_size"M $USEDTEST
+
+	#usedbydataset
+	log_must $MKFILE 16M $mntpnt/file$i
+
+	#usedbychildren
+	log_must $ZFS create $USEDTEST/fs$i
+	log_must $MKFILE 16M $mntpnt/fs$i/file$i
+
+	if is_global_zone; then
+		log_must $ZFS create -V 16M $USEDTEST/vol$i
+	fi
+
+	#usedbysnapshots
+	log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+	check_used $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify used is correct."
--- /dev/null	Fri Nov 22 15:22:11 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh	Fri Nov 22 15:22:11 2013
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#	Verify usedbychildren is correct.
+#
+# STRATEGY:
+#	1. Create a filesystem.
+#	2. Create sub filesystem and make file in it.
+#	3. Set reservation of the sub filesystem.
+#	4. Create volume under it.
+#	5. Snapshot it.
+#	6. Check usedbychildren is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbychildren is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbychildren $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+	((r_size=(i+1)*16))
+
+	log_must $ZFS create $USEDTEST/fs$i
+	log_must $ZFS set reservation="$r_size"M $USEDTEST/fs$i
+	log_must $MKFILE 48M $mntpnt/fs$i/file$i
+
+	if is_global_zone; then
+		log_must $ZFS create -V 32M $USEDTEST/vol$i
+	fi
+
+	log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+	check_usedbychildren $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbychildren is correct."
--- /dev/null	Fri Nov 22 15:22:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh	Fri Nov 22 15:22:12 2013
@@ -0,0 +1,82 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#	Verify usedbydataset is correct.
+#
+# STRATEGY:
+#	1. Create a filesystem.
+#	2. Make file in the filesystem.
+#	3. Snapshot it.
+#	4. Clone it and make file in the cloned filesystem.
+#	5. Check usedbydataset is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbydataset is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbydataset $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+	((r_size=(i+1)*16))
+
+	log_must $MKFILE 16M $mntpnt/file$i
+	log_must $MKFILE "$r_size"M $mntpnt/file_var$i
+	log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+	log_must $ZFS clone $USEDTEST@snap$i $USEDTEST/cln$i
+	log_must $ZFS set is:cloned=yes $USEDTEST/cln$i
+
+	mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i)
+	log_must $MKFILE 16M $mntpnt_cln/file_cln$i
+	log_must $MKFILE "$r_size"M $mntpnt_cln/file_cln_var$i
+
+	check_usedbydataset $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbydataset is correct."
--- /dev/null	Fri Nov 22 15:22:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh	Fri Nov 22 15:22:12 2013
@@ -0,0 +1,95 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#	Verify usedbyrefreservation is correct.
+#
+# STRATEGY:
+#	1. Create a filesystem.
+#	2. Set refreservation of the filesystem.
+#	3. Make file in the filesystem.
+#	4. Create sub filesystem and make file in it.
+#	5. Set refreservation of the sub filesystem.
+#	6. Create volume under it.
+#	7. Snapshot it.
+#	8. Clone it and set refreservation of the cloned filesystem.
+#	9. Makefile the cloned filesystem.
+#	10. Check usedbyrefreservation is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbyrefreservation is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbyrefreservation $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+	((r_size=(i+1)*16))
+	log_must $ZFS set refreservation="$r_size"M $USEDTEST
+
+	log_must $MKFILE 16M $mntpnt/file$i
+
+	log_must $ZFS create $USEDTEST/fs$i
+	log_must $ZFS set refreservation="$r_size"M $USEDTEST/fs$i
+	log_must $MKFILE 16M $mntpnt/fs$i/file$i
+
+	if is_global_zone; then
+		log_must $ZFS create -V 16M $USEDTEST/vol$i
+	fi
+
+	log_must $ZFS snapshot -r $USEDTEST@snap$i
+
+	log_must $ZFS clone $USEDTEST@snap$i $USEDTEST/cln$i
+
+	mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i)
+	log_must $ZFS set refreservation="$r_size"M $USEDTEST/cln$i
+	log_must $MKFILE 16M $mntpnt_cln/file_cln$i
+
+	check_usedbyrefreservation $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbyrefreservation is correct."
--- /dev/null	Fri Nov 22 15:22:12 2013
+++ new/usr/src/test/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh	Fri Nov 22 15:22:12 2013
@@ -0,0 +1,73 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/snapused/snapused.kshlib
+
+#
+# DESCRIPTION:
+#	Verify usedbysnapshots is correct.
+#
+# STRATEGY:
+#	1. Create a filesystem.
+#	2. Make file in the filesystem.
+#	3. Snapshot it.
+#	4. Check check_usedbysnapshots is correct.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	log_must $ZFS destroy -rR $USEDTEST
+}
+
+log_assert "Verify usedbysnapshots is correct."
+log_onexit cleanup
+
+log_must $ZFS create $USEDTEST
+check_usedbysnapshots $USEDTEST
+
+typeset -i i=0
+typeset -i r_size=0
+mntpnt=$(get_prop mountpoint $USEDTEST)
+while ((i < 5)); do
+	((r_size=(i+1)*16))
+
+	log_must $MKFILE "$r_size"M $mntpnt/file$i
+
+	log_must $ZFS snapshot $USEDTEST@snap$i
+	check_usedbysnapshots $USEDTEST
+
+        ((i = i + 1))
+done
+
+log_pass "Verify usedbysnapshots is correct."
--- /dev/null	Fri Nov 22 15:22:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/sparse/Makefile	Fri Nov 22 15:22:13 2013
@@ -0,0 +1,43 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/sparse
+
+PROGS = cleanup \
+	setup \
+	sparse_001_pos
+
+FILES = sparse.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:22:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/sparse/cleanup.ksh	Fri Nov 22 15:22:13 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:22:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/sparse/setup.ksh	Fri Nov 22 15:22:13 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+disk=${DISKS%% *}
+
+default_setup $disk
--- /dev/null	Fri Nov 22 15:22:13 2013
+++ new/usr/src/test/zfs-tests/tests/functional/sparse/sparse.cfg	Fri Nov 22 15:22:13 2013
@@ -0,0 +1,37 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile.sparse
+export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb
+export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"}
+export HOLES_SEED=${HOLES_SEED-""}
+export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""}
+export HOLES_COUNT=${HOLES_COUNT-"16384"}	   # FILESIZE/BLKSIZE/8
+export STF_TIMEOUT=3600
--- /dev/null	Fri Nov 22 15:22:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/sparse/sparse_001_pos.ksh	Fri Nov 22 15:22:14 2013
@@ -0,0 +1,80 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/sparse/sparse.cfg
+
+#
+# DESCRIPTION:
+# Holes in ZFS files work correctly.
+#
+# STRATEGY:
+# 1. Open file
+# 2. Write random blocks in random places
+# 3. Read each block back to check for correctness.
+# 4. Repeat steps 2 and 3 lots of times
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
+}
+
+log_assert "Ensure random blocks are read back correctly"
+
+options=""
+options_display="default options"
+
+log_onexit cleanup
+
+[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
+
+[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
+
+[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
+
+[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
+
+[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
+
+options="$options -r "
+
+[[ -n "$options" ]] && options_display=$options
+
+log_note "Invoking $FILE_TRUNC with: $options_display"
+log_must $FILE_TRUNC $options $TESTDIR/$TESTFILE
+
+typeset dir=$(get_device_dir $DISKS)
+verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir"
+
+log_pass "Random blocks have been read back correctly."
--- /dev/null	Fri Nov 22 15:22:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/threadsappend/Makefile	Fri Nov 22 15:22:14 2013
@@ -0,0 +1,68 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/threadsappend
+
+PROG = threadsappend
+
+SCRIPTS = cleanup \
+	setup \
+	threadsappend_001_pos
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+
+OBJS = $(PROG:%=%.o)
+SRCS = $(OBJS:%.o=%.c)
+
+CMDS = $(PROG:%=$(TESTDIR)/%) $(SCRIPTS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+	$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+	$(POST_PROCESS)
+
+%.o: ../%.c
+	$(COMPILE.c) $<
+
+install: all $(CMDS)
+
+lint: lint_SRCS
+
+clobber: clean
+	-$(RM) $(PROG)
+
+clean:
+	-$(RM) $(OBJS)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:22:14 2013
+++ new/usr/src/test/zfs-tests/tests/functional/threadsappend/cleanup.ksh	Fri Nov 22 15:22:14 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:22:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/threadsappend/setup.ksh	Fri Nov 22 15:22:15 2013
@@ -0,0 +1,36 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_setup ${DISK}
--- /dev/null	Fri Nov 22 15:22:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/threadsappend/threadsappend.c	Fri Nov 22 15:22:15 2013
@@ -0,0 +1,132 @@
+/*
+ * 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 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2013 by Delphix. All rights reserved.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <thread.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/*
+ * The size of the output file, "go.out", should be 80*8192*2 = 1310720
+ *
+ * $ cd /tmp; go; ls -l go.out
+ * done.
+ * -rwxr-xr-x	1 jdm	staff	1310720 Apr 13 19:45 go.out
+ * $ cd /zfs; go; ls -l go.out
+ * done.
+ * -rwxr-xr-x	1 jdm	staff	663552 Apr 13 19:45 go.out
+ *
+ * The file on zfs is short as it does not appear that zfs is making the
+ * implicit seek to EOF and the actual write atomic. From the SUSv3
+ * interface spec, behavior is undefined if concurrent writes are performed
+ * from multi-processes to a single file. So I don't know if this is a
+ * standards violation, but I cannot find any such disclaimers in our
+ * man pages. This issue came up at a customer site in another context, and
+ * the suggestion was to open the file with O_APPEND, but that wouldn't
+ * help with zfs(see 4977529). Also see bug# 5031301.
+ */
+
+static int outfd = 0;
+
+static void *
+go(void *data)
+{
+	int i = 0, n = *(int *)data;
+	char buf[8192] = {0};
+	(void) memset(buf, n, sizeof (buf));
+
+	for (i = 0; i < 80; i++) {
+		(void) write(outfd, buf, sizeof (buf));
+	}
+	return (NULL);
+}
+
+static void
+usage()
+{
+	(void) fprintf(stderr,
+	    "usage: zfs_threadsappend <file name>\n");
+	exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+	int	ret = 0;
+	long	ncpus = 0;
+	int	i;
+
+	if (argc != 2) {
+		usage();
+	}
+
+	ncpus = sysconf(_SC_NPROCESSORS_ONLN);
+	if (ncpus < 0) {
+		(void) fprintf(stderr,
+		    "Invalid return from sysconf(_SC_NPROCESSORS_ONLN)"
+		    " : errno (decimal)=%d\n", errno);
+		exit(1);
+	}
+	if (ncpus < 2) {
+		(void) fprintf(stderr,
+		    "Must execute this binary on a multi-processor system\n");
+		exit(1);
+	}
+
+	outfd = open(argv[optind++], O_RDWR|O_CREAT|O_APPEND|O_TRUNC, 0777);
+	if (outfd == -1) {
+		(void) fprintf(stderr,
+		    "zfs_threadsappend: "
+		    "open(%s, O_RDWR|O_CREAT|O_APPEND|O_TRUNC, 0777)"
+		    " failed\n", argv[optind]);
+		perror("open");
+		exit(1);
+	}
+
+	for (i = 0; i < 2; i++) {
+		ret = thr_create(NULL, 0, go, (void *)&i, 0, NULL);
+		if (ret != 0) {
+			(void) fprintf(stderr,
+			    "zfs_threadsappend: thr_create(#%d) "
+			    "failed error=%d\n", i+1, ret);
+			exit(1);
+		}
+	}
+
+	while (thr_join(0, NULL, NULL) == 0)
+		continue;
+
+	return (0);
+}
--- /dev/null	Fri Nov 22 15:22:15 2013
+++ new/usr/src/test/zfs-tests/tests/functional/threadsappend/threadsappend_001_pos.ksh	Fri Nov 22 15:22:15 2013
@@ -0,0 +1,82 @@
+#! /bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Ensure multiple threads performing write appends to the same ZFS
+# file succeed.
+#
+# STRATEGY:
+#	1) Verify this is a multi-processor system
+#	2) Create multiple threads with each appending to a file
+#       3) Verify that the resulting file is the expected size
+#
+
+verify_runnable "both"
+
+log_assert "Ensure multiple threads performing write appends to the same" \
+	"ZFS file succeed"
+
+#
+# $FILE_SIZE is hardcoded into threadsappend.c and is the expected
+# size of the file after all the threads have appended to it
+#
+typeset -i FILE_SIZE=1310720
+THREADSAPPEND="$STF_SUITE/tests/functional/threadsappend/threadsappend"
+TESTFILE='testfile-threadsappend'
+
+#
+# This test should be run on a multi-processor system because otherwise the FS
+# will not be concurrently used by the threads
+#
+NCPUS=`$PSRINFO | $WC -l`
+if [[ -z $NCPUS || $NCPUS -le 1 ]]; then
+	 log_fail "This test should be executed on a multi-processor system."
+fi
+
+#
+# zfs_threadsappend tries to append to $TESTFILE using threads
+# so that the resulting file is $FILE_SIZE bytes in size
+#
+log_must $THREADSAPPEND ${TESTDIR}/${TESTFILE}
+
+#
+# Check the size of the resulting file
+#
+SIZE=`$LS -l ${TESTDIR}/${TESTFILE} | $AWK '{print $5}'`
+if [[ $SIZE -ne $FILE_SIZE ]]; then
+	log_fail "'The length of ${TESTDIR}/${TESTFILE}' doesnt equal 1310720."
+fi
+
+log_pass "Multiple thread appends succeeded. File size as expected"
--- /dev/null	Fri Nov 22 15:22:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/Makefile	Fri Nov 22 15:22:16 2013
@@ -0,0 +1,59 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/userquota
+
+PROGS = cleanup \
+	groupspace_001_pos \
+	groupspace_002_pos \
+	setup \
+	userquota_001_pos \
+	userquota_002_pos \
+	userquota_003_pos \
+	userquota_004_pos \
+	userquota_005_neg \
+	userquota_006_pos \
+	userquota_007_pos \
+	userquota_008_pos \
+	userquota_009_pos \
+	userquota_010_pos \
+	userquota_011_pos \
+	userquota_012_neg \
+	userspace_001_pos \
+	userspace_002_pos
+
+FILES = userquota.cfg \
+	userquota_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:22:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/cleanup.ksh	Fri Nov 22 15:22:16 2013
@@ -0,0 +1,41 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+log_must cleanup_quota
+log_must clean_user_group
+
+typeset mntp=$(get_prop mountpoint $QFS)
+log_must $CHMOD 0755 $mntp
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:22:16 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh	Fri Nov 22 15:22:16 2013
@@ -0,0 +1,79 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the zfs groupspace with all parameters
+#
+#
+# STRATEGY:
+#       1. set zfs groupquota to a fs
+#       2. write some data to the fs with specified user and group
+#	3. use zfs groupspace with all possible parameters to check the result
+#
+
+function cleanup
+{
+	if datasetexists $snap_fs; then
+		log_must $ZFS destroy $snap_fs
+	fi
+
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs groupspace with all possible parameters"
+
+set -A params -- "-n" "-H" "-p" "-o type,name,used,quota" \
+    "-o name,used,quota" "-o used,quota" "-o used" "-o quota" "-s type" \
+    "-s name" "-s used" "-s quota" "-S type" "-S name" "-S used" "-S quota" \
+    "-t posixuser" "-t posixgroup" "-t all" "-i" "-t smbuser" "-t smbgroup"
+
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS set groupquota@$QGROUP=500m $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 50m $QFILE
+
+$SYNC
+
+log_must $ZFS snapshot $snap_fs
+
+for param in "${params[@]}"; do
+	log_must eval "$ZFS groupspace $param $QFS >/dev/null 2>&1"
+	log_must eval "$ZFS groupspace $param $snap_fs >/dev/null 2>&1"
+done
+
+log_pass "Check the zfs groupspace with all possible parameters"
--- /dev/null	Fri Nov 22 15:22:17 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh	Fri Nov 22 15:22:17 2013
@@ -0,0 +1,79 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the user used and groupspace size in zfs groupspace
+#
+#
+# STRATEGY:
+#       1. set zfs groupquota to a fs
+#       2. write some data to the fs with specified user and size
+#	3. use zfs groupspace to check the used size and quota size
+#
+
+function cleanup
+{
+	if datasetexists $snapfs; then
+		log_must $ZFS destroy $snapfs
+	fi
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs groupspace used and quota"
+
+log_must $ZFS set groupquota@$QGROUP=500m $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 100m $QFILE
+
+$SYNC
+
+typeset snapfs=$QFS@snap
+
+log_must $ZFS snapshot $snapfs
+
+log_must eval "$ZFS groupspace $QFS >/dev/null 2>&1"
+log_must eval "$ZFS groupspace $snapfs >/dev/null 2>&1"
+
+for fs in "$QFS" "$snapfs"; do
+	log_note "check the quota size in zfs groupspace $fs"
+	log_must eval "$ZFS groupspace $fs | $GREP $QGROUP | $GREP 500M"
+
+	log_note "check the user used size in zfs groupspace $fs"
+	log_must eval "$ZFS groupspace $fs | $GREP $QGROUP | $GREP 100M"
+done
+
+log_pass "Check the zfs groupspace used and quota pass as expect"
--- /dev/null	Fri Nov 22 15:22:17 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/setup.ksh	Fri Nov 22 15:22:17 2013
@@ -0,0 +1,44 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+verify_runnable "both"
+
+log_must clean_user_group
+
+log_must add_group $QGROUP
+log_must add_user $QGROUP $QUSER1
+log_must add_user $QGROUP $QUSER2
+
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:22:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota.cfg	Fri Nov 22 15:22:18 2013
@@ -0,0 +1,46 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+export QUSER1=quser1
+export QUSER2=quser2
+
+export QGROUP=qgroup
+export QGROUP1=qgroup1
+export QGROUP1=qgroup2
+
+export UQUOTA_SIZE=1000000
+export GQUOTA_SIZE=4000000
+
+export QFS=$TESTPOOL/$TESTFS
+export QFILE=$TESTDIR/qf
+export OFILE=$TESTDIR/of
+
+export SNAP_QUOTA=100m
+export TEST_QUOTA=88888
--- /dev/null	Fri Nov 22 15:22:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_001_pos.ksh	Fri Nov 22 15:22:18 2013
@@ -0,0 +1,74 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+#
+# DESCRIPTION:
+#       Check the basic function of the userquota and groupquota
+#
+#
+# STRATEGY:
+#       1. Set userquota and overwrite the quota size
+#       2. The write operation should fail with Disc quota exceeded
+#       3. Set groupquota and overwrite the quota size
+#       4. The write operation should fail with Disc quota exceeded
+#
+#
+
+function cleanup
+{
+	cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "If write operation overwrite {user|group}quota size, it will fail"
+
+mkmount_writable $QFS
+log_note "Check the userquota@$QUSER1"
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must user_run $QUSER1 $MKFILE $UQUOTA_SIZE $QFILE
+$SYNC
+log_mustnot user_run $QUSER1 $MKFILE 1 $OFILE
+cleanup_quota
+
+log_note "Check the groupquota@$QGROUP"
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE $GQUOTA_SIZE $QFILE
+$SYNC
+log_mustnot user_run $QUSER1 $MKFILE 1 $OFILE
+
+cleanup_quota
+
+log_pass "Write operation overwrite {user|group}quota size, it as expect"
--- /dev/null	Fri Nov 22 15:22:18 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_002_pos.ksh	Fri Nov 22 15:22:18 2013
@@ -0,0 +1,89 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       the userquota and groupquota can be set during zpool or zfs creation"
+#
+#
+# STRATEGY:
+#       1. Set userquota and groupquota via "zpool -O or zfs create -o"
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	if poolexists $TESTPOOL1; then
+		log_must $ZPOOL destroy $TESTPOOL1
+	fi
+
+	if [[ -f $pool_vdev ]]; then
+		$RM -f $pool_vdev
+	fi
+}
+
+log_onexit cleanup
+
+log_assert \
+	"the userquota and groupquota can be set during zpool,zfs creation"
+
+typeset pool_vdev=/var/tmp/pool_dev.$$
+
+log_must $MKFILE 500m $pool_vdev
+
+if poolexists $TESTPOOL1; then
+	$ZPOOL destroy $TESTPOOL1
+fi
+
+log_must $ZPOOL create -O userquota@$QUSER1=$UQUOTA_SIZE \
+	-O groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1 $pool_vdev
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL1 > /dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL1 "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL1 "$GQUOTA_SIZE"
+
+log_must $ZFS create -o userquota@$QUSER1=$UQUOTA_SIZE \
+	-o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1/fs
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL1 > /dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL1/fs "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL1/fs "$GQUOTA_SIZE"
+
+log_pass \
+	"the userquota and groupquota can be set during zpool,zfs creation"
--- /dev/null	Fri Nov 22 15:22:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_003_pos.ksh	Fri Nov 22 15:22:19 2013
@@ -0,0 +1,61 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the basic function of set/get userquota and groupquota on fs
+#
+#
+# STRATEGY:
+#       1. Set userquota on fs and check the zfs get
+#       2. Set groupquota on fs and check the zfs get
+#
+
+function cleanup
+{
+	cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the basic function of set/get userquota and groupquota on fs"
+
+log_note "Check the set|get userquota@$QUSER1 and groupquota@QGROUP"
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must check_quota "userquota@$QUSER1" $QFS "$UQUOTA_SIZE"
+
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+log_must check_quota "groupquota@$QGROUP" $QFS "$GQUOTA_SIZE"
+
+log_pass "Check the basic function of set/get userquota on fs passed as expect"
--- /dev/null	Fri Nov 22 15:22:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_004_pos.ksh	Fri Nov 22 15:22:19 2013
@@ -0,0 +1,81 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the basic function user|group used
+#
+#
+# STRATEGY:
+#       1. Write some data to fs by normal user and check the user|group used
+#
+
+function cleanup
+{
+	cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the basic function of {user|group} used"
+
+typeset user_used=$(get_value "userused@$QUSER1" $QFS)
+typeset group_used=$(get_value "groupused@$QGROUP" $QFS)
+
+if [[ $user_used != 0 ]]; then
+	log_fail "FAIL: userused is $user_used, should be 0"
+fi
+if [[ $group_used != 0 ]]; then
+	log_fail "FAIL: groupused is $group_used, should be 0"
+fi
+
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 100m $QFILE
+$SYNC
+
+user_used=$(get_value "userused@$QUSER1" $QFS)
+group_used=$(get_value "groupused@$QGROUP" $QFS)
+
+if [[ $user_used != "100M" ]]; then
+	log_note "user $QUSER1 used is $user_used"
+	log_fail "userused for user $QUSER1 expected to be 50.0M, not $user_used"
+fi
+
+if [[ $user_used != $group_used ]]; then
+	log_note "user $QUSER1 used is $user_used"
+	log_note "group $QGROUP used is $group_used"
+	log_fail "FAIL: userused should equal to groupused"
+fi
+
+log_pass "Check the basic function of {user|group}used pass as expect"
--- /dev/null	Fri Nov 22 15:22:19 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh	Fri Nov 22 15:22:19 2013
@@ -0,0 +1,94 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the invalid parameter of zfs set user|group quota
+#
+#
+# STRATEGY:
+#       1. check the invalid zfs set user|group quota to fs
+#       1. check the valid zfs set user|group quota to snapshots
+#
+
+function cleanup
+{
+	if datasetexists $snap_fs; then
+		log_must $ZFS destroy $snap_fs
+	fi
+
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the invalid parameter of zfs set user|group quota"
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS snapshot $snap_fs
+
+set -A no_users "mms1234" "ss@#" "root-122"
+for user in "${no_users[@]}"; do
+	log_mustnot $ID $user
+	log_mustnot $ZFS set userquota@$user=100m $QFS
+done
+
+log_note "can set all numberic id even that id is not existed"
+log_must $ZFS set userquota@12345678=100m $QFS
+log_mustnot $ZFS set userquota@12345678=100m $snap_fs
+
+set -A sizes "100mfsd" "m0.12m" "GGM" "-1234-m" "123m-m"
+
+for size in "${sizes[@]}"; do
+	log_note "can not set user quota with invalid size parameter"
+	log_mustnot $ZFS set userquota@root=$size $QFS
+done
+
+log_note "can not set user quota to snapshot $snap_fs"
+log_mustnot $ZFS set userquota@root=100m $snap_fs
+
+
+set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "@@@@"
+for group in "${no_groups[@]}"; do
+	log_mustnot eval "$GREP $group /etc/group"
+	log_mustnot $ZFS set groupquota@$group=100m $QFS
+done
+
+log_note "can not set group quota with invalid size parameter"
+log_mustnot $ZFS set groupquota@root=100msfsd $QFS
+
+log_note "can not set group quota to snapshot $snap_fs"
+log_mustnot $ZFS set groupquota@root=100m $snap_fs
+
+log_pass "Check the invalid parameter of zfs set user|group quota pas as expect"
--- /dev/null	Fri Nov 22 15:22:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh	Fri Nov 22 15:22:20 2013
@@ -0,0 +1,75 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the invalid parameter of zfs get user|group quota
+#
+#
+# STRATEGY:
+#       1. check the invalid zfs get user|group quota to fs
+#       2. check the valid zfs get user|group quota to snapshots
+#
+
+function cleanup
+{
+	if datasetexists $snap_fs; then
+		log_must $ZFS destroy $snap_fs
+	fi
+
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the invalid parameter of zfs get user|group quota"
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS snapshot $snap_fs
+
+set -A no_users "mms1234" "ss@#" "root-122" "1234"
+for user in "${no_users[@]}"; do
+	log_mustnot eval "$ID $user >/dev/null 2>&1"
+	log_must eval "$ZFS get userquota@$user $QFS >/dev/null 2>&1"
+	log_must eval "$ZFS get userquota@$user $snap_fs >/dev/null 2>&1"
+done
+
+set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "1234"
+for group in "${no_groups[@]}"; do
+	log_mustnot eval "$GROUPDEL $group > /dev/null 2>&1"
+	log_must eval "$ZFS get groupquota@$group $QFS >/dev/null 2>&1"
+	log_must eval "$ZFS get groupquota@$group $snap_fs >/dev/null 2>&1"
+done
+
+log_pass "Check the invalid parameter of zfs get user|group quota pass as expect"
--- /dev/null	Fri Nov 22 15:22:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_007_pos.ksh	Fri Nov 22 15:22:20 2013
@@ -0,0 +1,75 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#
+#      userquota/groupquota can be set beyond the fs quota
+#      userquota/groupquota can be set at a smaller size than its current usage.
+#
+# STRATEGY:
+#       1. set quota to a fs and set a larger size of userquota and groupquota
+#       2. write some data to the fs and set a smaller userquota and groupquota
+#
+
+function cleanup
+{
+	log_must cleanup_quota
+	log_must $ZFS set quota=none $QFS
+}
+
+log_onexit cleanup
+
+log_assert "Check set user|group quota to larger than the quota size of a fs"
+
+log_must $ZFS set quota=200m $QFS
+log_must $ZFS set userquota@$QUSER1=500m $QFS
+log_must $ZFS set groupquota@$QGROUP=600m $QFS
+
+log_must $ZFS get userquota@$QUSER1 $QFS
+log_must $ZFS get groupquota@$QGROUP $QFS
+
+log_note "write some data to the $QFS"
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 100m $QFILE
+$SYNC
+
+log_note "set user|group quota at a smaller size than it current usage"
+log_must $ZFS set userquota@$QUSER1=90m $QFS
+log_must $ZFS set groupquota@$QGROUP=90m $QFS
+
+log_must $ZFS get userquota@$QUSER1 $QFS
+log_must $ZFS get groupquota@$QGROUP $QFS
+
+log_pass "set user|group quota to larger than quota size of a fs pass as expect"
--- /dev/null	Fri Nov 22 15:22:20 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_008_pos.ksh	Fri Nov 22 15:22:20 2013
@@ -0,0 +1,60 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#
+#      zfs get all <fs> does not print out userquota/groupquota
+#
+# STRATEGY:
+#       1. set userquota and groupquota to a fs
+#       2. check zfs get all fs
+#
+
+function cleanup
+{
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check zfs get all will not print out user|group quota"
+
+log_must $ZFS set userquota@$QUSER1=50m $QFS
+log_must $ZFS set groupquota@$QGROUP=100m $QFS
+
+log_mustnot $ZFS get all $QFS | $GREP userquota
+log_mustnot $ZFS get all $QFS | $GREP groupquota
+
+log_pass "zfs get all will not print out user|group quota"
--- /dev/null	Fri Nov 22 15:22:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh	Fri Nov 22 15:22:21 2013
@@ -0,0 +1,92 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check user|group quota to snapshot that:
+#	1) can not set user|group quota to snapshot directly
+#	2) snapshot can inherit the parent fs's user|groupquota
+#	3) the user|group quota will not change even the parent fs's quota changed.
+#
+#
+# STRATEGY:
+#       1. create a snapshot of a fs
+#       2. set the user|group quota to snapshot and expect fail
+#	3. set user|group quota to fs and check the snapshot
+#	4. re-set user|group quota to fs and check the snapshot's value
+#
+
+function cleanup
+{
+	if datasetexists $snap_fs; then
+		log_must $ZFS destroy $snap_fs
+	fi
+
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the snapshot's user|group quota"
+typeset snap_fs=$QFS@snap
+
+
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must check_quota "userquota@$QUSER1" $QFS "$UQUOTA_SIZE"
+
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+log_must check_quota "groupquota@$QGROUP" $QFS "$GQUOTA_SIZE"
+
+log_must $ZFS snapshot $snap_fs
+
+log_note "check the snapshot $snap_fs user|group quota"
+log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE"
+
+log_note  "set userquota and groupquota to $snap_fs which will fail"
+log_mustnot $ZFS set userquota@$QUSER1=$SNAP_QUOTA $snap_fs
+log_mustnot $ZFS set groupquota@$QGROUP=$SNAP_QUOTA $snap_fs
+
+log_note "change the parent's userquota and groupquota"
+log_must $ZFS set userquota@$QUSER1=$TEST_QUOTA $QFS
+log_must $ZFS set groupquota@$QGROUP=$TEST_QUOTA $QFS
+
+log_must check_quota "userquota@$QUSER1" $QFS $TEST_QUOTA
+log_must check_quota "groupquota@$QGROUP" $QFS $TEST_QUOTA
+
+log_note "check the snapshot $snap_fs userquota and groupquota"
+log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE"
+
+log_pass "Check the snapshot's user|group quota pass as expect"
--- /dev/null	Fri Nov 22 15:22:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_010_pos.ksh	Fri Nov 22 15:22:21 2013
@@ -0,0 +1,75 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check userquota and groupquota be overwrited at same time
+#
+#
+# STRATEGY:
+#       1. Set userquota and groupquota to a fs
+#       2. write to exceed the userquota size to check the result
+#       3. write to exceed the groupquota size to check the result
+#
+
+function cleanup
+{
+	cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "overwrite any of the {user|group}quota size, it will fail"
+
+log_note "overwrite to $QFS to make it exceed userquota"
+log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS
+log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS
+
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE $UQUOTA_SIZE $QFILE
+$SYNC
+
+log_must eval "$ZFS get -p userused@$QUSER1 $QFS >/dev/null 2>&1"
+log_must eval "$ZFS get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1"
+
+log_mustnot user_run $QUSER1 $MKFILE 1 $OFILE
+
+log_must $RM -f $QFILE
+
+log_note "overwrite to $QFS to make it exceed userquota"
+log_mustnot user_run $QUSER1 $MKFILE $GQUOTA_SIZE $QFILE
+
+log_must eval "$ZFS get -p userused@$QUSER1 $QFS >/dev/null 2>&1"
+log_must eval "$ZFS get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1"
+
+log_pass "overwrite any of the {user|group}quota size, it fail as expect"
--- /dev/null	Fri Nov 22 15:22:21 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh	Fri Nov 22 15:22:21 2013
@@ -0,0 +1,127 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       the userquota and groupquota will not change during zfs actions, such as
+#	snapshot,clone,rename,upgrade,send,receive.
+#
+#
+# STRATEGY:
+#       1. Create a pool, and create fs with preset user,group quota
+#       2. Check set user|group quota via zfs snapshot|clone|list -o
+#       3. Check the user|group quota can not change during zfs rename|upgrade|promote
+#       4. Check the user|group quota can not change during zfs clone
+#       5. Check the user|group quota can not change during zfs send/receive
+#
+
+function cleanup
+{
+	for ds in $TESTPOOL/fs $TESTPOOL/fs-rename $TESTPOOL/fs-clone; do
+		if datasetexists $ds; then
+			log_must $ZFS destroy -rRf $ds
+		fi
+	done
+}
+
+log_onexit cleanup
+
+log_assert \
+	"the userquota and groupquota can't change during zfs actions"
+
+cleanup
+
+log_must $ZFS create -o userquota@$QUSER1=$UQUOTA_SIZE \
+	-o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL/fs
+
+log_must $ZFS snapshot $TESTPOOL/fs@snap
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs@snap "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs@snap "$GQUOTA_SIZE"
+
+
+log_note "clone fs gets its parent's userquota/groupquota initially"
+log_must $ZFS clone  -o userquota@$QUSER1=$UQUOTA_SIZE \
+		-o groupquota@$QGROUP=$GQUOTA_SIZE \
+		$TESTPOOL/fs@snap $TESTPOOL/fs-clone
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE"
+
+log_must eval "$ZFS list -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL/fs-clone >/dev/null 2>&1"
+
+log_note "zfs promote can not change the previously set user|group quota"
+log_must $ZFS promote $TESTPOOL/fs-clone
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE"
+
+log_note "zfs send receive can not change the previously set user|group quota"
+log_must $ZFS send $TESTPOOL/fs-clone@snap | $ZFS receive $TESTPOOL/fs-rev
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rev "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rev "$GQUOTA_SIZE"
+
+log_note "zfs rename can not change the previously set user|group quota"
+log_must $ZFS rename $TESTPOOL/fs-rev $TESTPOOL/fs-rename
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL  >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE"
+
+log_note "zfs upgrade can not change the previously set user|group quota"
+log_must $ZFS upgrade $TESTPOOL/fs-rename
+
+log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \
+	$TESTPOOL >/dev/null 2>&1"
+
+log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE"
+log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE"
+
+log_pass \
+	"the userquota and groupquota can't change during zfs actions"
--- /dev/null	Fri Nov 22 15:22:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh	Fri Nov 22 15:22:22 2013
@@ -0,0 +1,66 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       userquota and groupquota can not be set against snapshot
+#
+#
+# STRATEGY:
+#       1. Set userquota on snap and check the zfs get
+#       2. Set groupquota on snap and check the zfs get
+#
+
+function cleanup
+{
+	cleanup_quota
+
+	if datasetexists $snap_fs; then
+		log_must $ZFS destroy $snap_fs
+	fi
+}
+
+log_onexit cleanup
+
+typeset snap_fs=$QFS@snap
+log_assert "Check  set userquota and groupquota on snapshot"
+
+log_note "Check can not set user|group quuota on snapshot"
+log_must $ZFS snapshot $snap_fs
+
+log_mustnot $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $snap_fs
+
+log_mustnot $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $snap_fs
+
+log_pass "Check  set userquota and groupquota on snapshot"
--- /dev/null	Fri Nov 22 15:22:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userquota_common.kshlib	Fri Nov 22 15:22:22 2013
@@ -0,0 +1,120 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota.cfg
+
+#
+# reset the userquota and groupquota and delete temporary files
+#
+function cleanup_quota
+{
+	if datasetexists $QFS; then
+		log_must $ZFS set userquota@$QUSER1=none $QFS
+		log_must $ZFS set userquota@$QUSER2=none $QFS
+		log_must $ZFS set groupquota@$QGROUP=none $QFS
+		recovery_writable $QFS
+	fi
+
+	[[ -f $QFILE ]] && log_must $RM -f $QFILE
+	[[ -f $OFILE ]] && log_must $RM -f $OFILE
+	$SYNC
+
+	 return 0
+}
+
+#
+# delete user and group that created during the test
+#
+function clean_user_group
+{
+	for usr in $QUSER1 $QUSER2; do
+		log_must del_user $usr
+	done
+
+	log_must del_group $QGROUP
+
+	return 0
+}
+
+#
+#  make the $QFS's mountpoint writable for all users
+#
+function mkmount_writable
+{
+	typeset fs=$1
+	typeset mntp=$(get_prop mountpoint $fs)
+	log_must $CHMOD 0777 $mntp
+}
+
+#
+# recovery the directory permission for $QFS
+#
+function recovery_writable
+{
+	typeset fs=$1
+	typeset mntp=$(get_prop mountpoint $fs)
+	log_must $CHMOD 0755 $mntp
+}
+
+#
+# check the quota value of a specific FS
+#
+function check_quota
+{
+	typeset fs=$2
+	typeset prop=$1
+	typeset expected=$3
+	typeset value=$(get_prop $prop $fs)
+
+	if (($value != $expected)); then
+		return 1
+	fi
+}
+
+#
+# zfs get prop, which return raw value not -p value.
+#
+function get_value # property dataset
+{
+        typeset prop_val
+        typeset prop=$1
+        typeset dataset=$2
+
+        prop_val=$($ZFS get -H -o value $prop $dataset 2>/dev/null)
+        if [[ $? -ne 0 ]]; then
+                log_note "Unable to get $prop property for dataset " \
+                "$dataset"
+                return 1
+        fi
+
+        $ECHO $prop_val
+        return 0
+}
--- /dev/null	Fri Nov 22 15:22:22 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh	Fri Nov 22 15:22:22 2013
@@ -0,0 +1,78 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the zfs userspace with all parameters
+#
+#
+# STRATEGY:
+#       1. set zfs userspace to a fs
+#       2. write some data to the fs with specified user
+#	3. use zfs userspace with all possible parameters to check the result
+#
+
+function cleanup
+{
+	if datasetexists $snap_fs; then
+		log_must $ZFS destroy $snap_fs
+	fi
+
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs userspace with all possible parameters"
+
+set -A params -- "-n" "-H" "-p" "-o type,name,used,quota" \
+    "-o name,used,quota" "-o used,quota" "-o used" "-o quota" "-s type" \
+    "-s name" "-s used" "-s quota" "-S type" "-S name" "-S used" "-S quota" \
+    "-t posixuser" "-t posixgroup" "-t all" "-i" "-tsmbuser" "-t smbgroup"
+
+typeset snap_fs=$QFS@snap
+
+log_must $ZFS set userquota@$QUSER1=100m $QFS
+mkmount_writable $QFS
+log_must user_run $QUSER1 $MKFILE 50m $QFILE
+$SYNC
+
+log_must $ZFS snapshot $snap_fs
+
+for param in "${params[@]}"; do
+	log_must eval "$ZFS userspace $param $QFS >/dev/null 2>&1"
+	log_must eval "$ZFS userspace $param $snap_fs >/dev/null 2>&1"
+done
+
+log_pass "zfs userspace with all possible parameters pass as expect"
--- /dev/null	Fri Nov 22 15:22:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh	Fri Nov 22 15:22:23 2013
@@ -0,0 +1,81 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
+
+#
+# DESCRIPTION:
+#       Check the user used size and quota in zfs userspace
+#
+#
+# STRATEGY:
+#       1. set zfs userquota to a fs
+#       2. write some data to the fs with specified user and size
+#	3. use zfs userspace to check the used size and quota size
+#
+
+function cleanup
+{
+	if datasetexists $snapfs; then
+		log_must $ZFS destroy $snapfs
+	fi
+
+	log_must cleanup_quota
+}
+
+log_onexit cleanup
+
+log_assert "Check the zfs userspace used and quota"
+
+log_must $ZFS set userquota@$QUSER1=100m $QFS
+
+mkmount_writable $QFS
+
+log_must user_run $QUSER1 $MKFILE 50m $QFILE
+$SYNC
+
+typeset snapfs=$QFS@snap
+
+log_must $ZFS snapshot $snapfs
+
+log_must eval "$ZFS userspace $QFS >/dev/null 2>&1"
+log_must eval "$ZFS userspace $snapfs >/dev/null 2>&1"
+
+for fs in "$QFS" "$snapfs"; do
+	log_note "check the quota size in zfs userspace $fs"
+	log_must eval "$ZFS userspace $fs | $GREP $QUSER1 | $GREP 100M"
+
+	log_note "check the user used size in zfs userspace $fs"
+	log_must eval "$ZFS userspace $fs | $GREP $QUSER1 | $GREP 50.0M"
+done
+
+log_pass "Check the zfs userspace used and quota"
--- /dev/null	Fri Nov 22 15:22:23 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/Makefile	Fri Nov 22 15:22:23 2013
@@ -0,0 +1,52 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/utils_test
+
+PROGS = cleanup \
+	setup \
+	utils_test_001_pos \
+	utils_test_002_pos \
+	utils_test_003_pos \
+	utils_test_004_pos \
+	utils_test_005_pos \
+	utils_test_006_pos \
+	utils_test_007_pos \
+	utils_test_008_pos \
+	utils_test_009_pos
+
+FILES = utils_test.cfg \
+	utils_test.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:22:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/cleanup.ksh	Fri Nov 22 15:22:24 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:22:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/setup.ksh	Fri Nov 22 15:22:24 2013
@@ -0,0 +1,35 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.cfg
+
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:22:24 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test.cfg	Fri Nov 22 15:22:24 2013
@@ -0,0 +1,38 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export TESTFILE=testfile-utils
+
+export WRITE_COUNT=20
+export BLOCKSZ=8192
+export DATA=0
+export NUM_FILES=10
+
+export DISK=${DISKS%% *}
--- /dev/null	Fri Nov 22 15:22:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test.kshlib	Fri Nov 22 15:22:25 2013
@@ -0,0 +1,50 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+. $STF_SUITE/tests/functional/utils_test/utils_test.cfg
+
+#
+# Given a number of files, this function will iterate through
+# the loop creating the specified number of files. The default
+# values from the .cfg file are used for block size, number of
+# writes per file and the contents of the file.
+#
+# Returns the errno if any of the writes fail.
+#
+function populate_dir # num_files
+{
+	typeset -i num_files=$1
+
+	typeset -i filenum=0
+	while (( filenum < num_files )); do
+		log_must $FILE_WRITE -o create -c $WRITE_COUNT \
+		    -f $TESTDIR/$TESTFILE.$filenum -b $BLOCKSZ -d $DATA
+		(( filenum = filenum + 1 ))
+	done
+}
--- /dev/null	Fri Nov 22 15:22:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_001_pos.ksh	Fri Nov 22 15:22:25 2013
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the clri(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS directory with a number of files.
+# 2. Run clri against the raw device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the clri(1M) utility fails on a ZFS file system."
+
+populate_dir $NUM_FILES
+
+inode=`$LS -i $TESTDIR/$TESTFILE.0 | $AWK '{print $1}'`
+log_mustnot $CLRI /dev/rdsk/$DISK $inode
+log_mustnot $CLRI -F zfs /dev/rdsk/$DISK $inode
+
+log_pass "clri(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:25 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_002_pos.ksh	Fri Nov 22 15:22:25 2013
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the labelit(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS file system with some files.
+# 2. Run labelit(1M) against the device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	ismounted $TESTPOOL/$TESTFS
+	(( $? != 0 )) && \
+		log_must $ZFS mount $TESTPOOL/$TESTFS
+
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the labelit(1M) utility fails on a ZFS file system."
+
+populate_dir $NUM_FILES
+
+log_must $ZFS unmount $TESTDIR
+
+log_mustnot $LABELIT /dev/rdsk/${DISK}s0 mfiles ${DISK}s0
+
+log_pass "labelit(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_003_pos.ksh	Fri Nov 22 15:22:26 2013
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the fsdb(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS directory with a number of files.
+# 2. Run fsdb against the raw device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the fsdb(1M) utility fails on a ZFS file system."
+
+populate_dir $NUM_FILES
+inode_num=`$LS -li $TESTDIR/$TESTFILE.0 | $AWK '{print $1}'`
+[[ -z $inode_num ]] && \
+    log_fail "Failed to determine inode of file: $TESTDIR/$TESTFILE.0"
+
+log_mustnot $ECHO ":inode $inode_num" | $FSDB /dev/rdsk/${DISK}s0
+
+log_pass "fsdb(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_004_pos.ksh	Fri Nov 22 15:22:26 2013
@@ -0,0 +1,60 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the quotaon(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Enable a quota on a ZFS file system.
+# 2. Run quotaon against the device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the quotaon(1M) utility fails on a ZFS file system."
+
+log_must $ZFS set quota=1099511627776 $TESTPOOL/$TESTFS
+log_must $TOUCH $TESTDIR/quotas
+log_mustnot $QUOTAON /dev/dsk/${DISK}s0
+
+log_pass "quotaon(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:26 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_005_pos.ksh	Fri Nov 22 15:22:26 2013
@@ -0,0 +1,60 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the ff(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS file system with some files.
+# 2. Run ff(1M) against the device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the ff(1M) utility fails on a ZFS file system."
+
+populate_dir $NUM_FILES
+
+log_mustnot $FF -F zfs /dev/rdsk/${DISK}s0
+
+log_pass "ff(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_006_pos.ksh	Fri Nov 22 15:22:27 2013
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the fsirand(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS file system with some files.
+# 2. Run fsirand(1M) against the device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	ismounted $TESTPOOL/$TESTFS
+	(( $? != 0 )) && \
+		log_must $ZFS mount $TESTPOOL/$TESTFS
+
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the fsirand(1M) utility fails on a ZFS file system."
+
+populate_dir $NUM_FILES
+
+log_must $ZFS unmount $TESTDIR
+
+log_mustnot $FSIRAND /dev/rdsk/${DISK}s0
+
+log_pass "fsirand(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:27 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_007_pos.ksh	Fri Nov 22 15:22:27 2013
@@ -0,0 +1,72 @@
+#!/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the fstyp(1M) utility succeeds on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS file system with some files.
+# 2. Run fstyp(1M) against the device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	ismounted $TESTPOOL/$TESTFS
+	(( $? != 0 )) && \
+		log_must $ZFS mount $TESTPOOL/$TESTFS
+
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the fstyp(1M) utility succeeds on a ZFS file system."
+
+populate_dir $NUM_FILES
+
+log_must $ZFS unmount $TESTDIR
+
+if ! $(is_physical_device $DISK); then
+	log_must $FSTYP $DISK
+elif [[ $WRAPPER == "smi" ]]; then
+	log_must $FSTYP /dev/rdsk/${DISK}s2
+else
+	log_must $FSTYP /dev/rdsk/${DISK}s0
+fi
+
+log_pass "fstyp(1M) returned successfully."
--- /dev/null	Fri Nov 22 15:22:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_008_pos.ksh	Fri Nov 22 15:22:28 2013
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the ncheck(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS file system with some files.
+# 2. Run ncheck(1M) against the device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	ismounted $TESTPOOL/$TESTFS
+	(( $? != 0 )) && \
+		log_must $ZFS mount $TESTPOOL/$TESTFS
+
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the ncheck(1M) utility fails on a ZFS file system."
+
+populate_dir $NUM_FILES
+
+log_must $ZFS unmount $TESTDIR
+
+log_mustnot $NCHECK /dev/rdsk/${DISK}s0
+
+log_pass "ncheck(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/utils_test/utils_test_009_pos.ksh	Fri Nov 22 15:22:28 2013
@@ -0,0 +1,60 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/utils_test/utils_test.kshlib
+
+#
+# DESCRIPTION:
+# Ensure that the tunefs(1M) utility fails on a ZFS file system.
+#
+# STRATEGY:
+# 1. Populate a ZFS file system with some files.
+# 2. Run tunefs(1M) against the device.
+# 3. Ensure it fails.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/*
+}
+
+log_onexit cleanup
+
+log_assert "Ensure that the tunefs(1M) utility fails on a ZFS file system."
+
+populate_dir $NUM_FILES
+
+log_mustnot $TUNEFS -m 80 /dev/dsk/${DISK}s0
+
+log_pass "tunefs(1M) returned an error as expected."
--- /dev/null	Fri Nov 22 15:22:28 2013
+++ new/usr/src/test/zfs-tests/tests/functional/write_dirs/Makefile	Fri Nov 22 15:22:28 2013
@@ -0,0 +1,44 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/write_dirs
+
+PROGS = cleanup \
+	setup \
+	write_dirs_001_pos \
+	write_dirs_002_pos
+
+FILES = write_dirs.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:22:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/write_dirs/cleanup.ksh	Fri Nov 22 15:22:29 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:22:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/write_dirs/setup.ksh	Fri Nov 22 15:22:29 2013
@@ -0,0 +1,47 @@
+#!/usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+export SIZE="1gb"
+export SLICE=0
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+DISK=${DISKS%% *}
+
+log_must set_partition $SLICE "" $SIZE $DISK
+
+default_setup "$DISK"s"$SLICE"
--- /dev/null	Fri Nov 22 15:22:29 2013
+++ new/usr/src/test/zfs-tests/tests/functional/write_dirs/write_dirs_001_pos.ksh	Fri Nov 22 15:22:29 2013
@@ -0,0 +1,76 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Create as many directories with 50 big files each until the file system
+# is full. The zfs file system should be stable and works well.
+#
+# STRATEGY:
+# 1. Create a pool & dateset
+# 2. Make directories in the zfs file system
+# 3. Create 50 big files in each directories
+# 4. Test case exit when the disk is full.
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for file in `$FIND $TESTDIR -type f`; do
+		$CAT /dev/null > $file
+	done
+	log_must $SYNC
+	log_must $RM -rf $TESTDIR/*
+}
+
+typeset -i retval=0
+log_assert "Creating directories with 50 big files in each, until file system "\
+	"is full."
+
+log_onexit cleanup
+
+typeset -i bytes=8192
+typeset -i num_writes=300000
+typeset -i dirnum=50
+typeset -i filenum=50
+
+fill_fs "" $dirnum $filenum $bytes $num_writes
+retval=$?
+if (( retval == 28 )); then
+	log_note "No space left on device."
+elif (( retval != 0 )); then
+	log_fail "Unexpected exit: $retval"
+fi
+
+log_pass "Write big files in a directory succeeded."
--- /dev/null	Fri Nov 22 15:22:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/write_dirs/write_dirs_002_pos.ksh	Fri Nov 22 15:22:30 2013
@@ -0,0 +1,77 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Create as many directories with 5000 files each until the file system
+# is full. The zfs file system should be work well and stable.
+#
+# STRATEGY:
+# 1. Create a pool & dateset
+# 2. Make directories in the zfs file system
+# 3. Create 5000 files in each directories
+# 4. Test case exit when the disk is full
+#
+
+verify_runnable "both"
+
+function cleanup
+{
+	for file in `$FIND $TESTDIR -type f`; do
+		$CAT /dev/null > $file
+	done
+	log_must $SYNC
+	log_must $RM -rf $TESTDIR/*
+}
+
+typeset -i retval=0
+
+log_assert "Creating directories with 5000 files in each, until file system " \
+	"is full."
+
+log_onexit cleanup
+
+typeset -i bytes=8192
+typeset -i num_writes=20
+typeset -i dirnum=50
+typeset -i filenum=5000
+
+fill_fs "" $dirnum $filenum $bytes $num_writes
+retval=$?
+if (( retval == 28 )); then
+	log_note "No space left on device."
+elif (( retval != 0 )); then
+	log_fail "Unexpected exit: $retval"
+fi
+
+log_pass "Create many files in a directory succeeded."
--- /dev/null	Fri Nov 22 15:22:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/Makefile	Fri Nov 22 15:22:30 2013
@@ -0,0 +1,55 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/xattr
+
+PROGS = cleanup \
+	setup \
+	xattr_001_pos \
+	xattr_002_neg \
+	xattr_003_neg \
+	xattr_004_pos \
+	xattr_005_pos \
+	xattr_006_pos \
+	xattr_007_neg \
+	xattr_008_pos \
+	xattr_009_neg \
+	xattr_010_neg \
+	xattr_011_pos \
+	xattr_012_pos \
+	xattr_013_pos \
+
+FILES = xattr_common.kshlib
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	Fri Nov 22 15:22:30 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/cleanup.ksh	Fri Nov 22 15:22:30 2013
@@ -0,0 +1,45 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+ZFS_USER=$($CAT /tmp/zfs-xattr-test-user.txt)
+$RM /tmp/zfs-xattr-test-user.txt
+
+USES_NIS=$($CAT /tmp/zfs-xattr-test-nis.txt)
+$RM /tmp/zfs-xattr-test-nis.txt
+
+del_user $ZFS_USER
+
+if [ "${USES_NIS}" == "true" ]
+then
+    $SVCADM enable svc:/network/nis/client:default
+fi
+
+default_cleanup
--- /dev/null	Fri Nov 22 15:22:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/setup.ksh	Fri Nov 22 15:22:31 2013
@@ -0,0 +1,64 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+# if we're running NIS, turn it off until we clean up
+# (it can cause useradd to take a long time, hitting our TIMEOUT)
+USES_NIS=FALSE
+$SVCS svc:/network/nis/client:default | $GREP online > /dev/null
+if [ $? -eq 0 ]
+then
+	$SVCADM disable -t svc:/network/nis/client:default
+	USES_NIS=true
+fi
+
+# Make sure we use a brand new user for this
+ZFS_USER=zxtr
+ZFS_GROUP=staff
+while [ -z "${FOUND}" ]
+do
+	COUNT=0
+	USER_EXISTS=$( $GREP $ZFS_USER /etc/passwd )
+	if [ ! -z "${USER_EXISTS}" ]
+	then
+		ZFS_USER="${ZFS_USER}${COUNT}"
+		COUNT=$(( $COUNT + 1 ))
+	else
+		FOUND="true"
+	fi
+done
+
+log_must add_user $ZFS_GROUP $ZFS_USER
+
+$ECHO $ZFS_USER > /tmp/zfs-xattr-test-user.txt
+$ECHO $USES_NIS > /tmp/zfs-xattr-test-nis.txt
+
+DISK=${DISKS%% *}
+default_setup $DISK
--- /dev/null	Fri Nov 22 15:22:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_001_pos.ksh	Fri Nov 22 15:22:31 2013
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Creating, reading and writing xattrs on ZFS filesystems works as expected
+#
+# STRATEGY:
+#	1. Create an xattr on a ZFS-based file using runat
+#	2. Read an empty xattr directory
+#       3. Write the xattr using runat and cat
+#	3. Read the xattr using runat
+#	4. Delete the xattr
+#	5. List the xattr namespace successfully, checking for deletion
+#
+
+function cleanup {
+
+	if [ -f $TESTDIR/myfile.$$ ]
+	then
+		log_must $RM $TESTDIR/myfile.$$
+	fi
+}
+
+log_assert "Create/read/write/append of xattrs works"
+log_onexit cleanup
+
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+verify_write_xattr $TESTDIR/myfile.$$ passwd
+delete_xattr $TESTDIR/myfile.$$ passwd
+
+log_pass "Create/read/write of xattrs works"
--- /dev/null	Fri Nov 22 15:22:31 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_002_neg.ksh	Fri Nov 22 15:22:31 2013
@@ -0,0 +1,56 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Trying to read a non-existent xattr should fail.
+#
+# STRATEGY:
+#	1. Create a file
+#       2. Try to read a non-existent xattr, check that an error is returned.
+#
+
+function cleanup {
+
+	log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "A read of a non-existent xattr fails"
+log_onexit cleanup
+
+# create a file
+log_must $TOUCH $TESTDIR/myfile.$$
+log_mustnot eval "$CAT $TESTDIR/myfile.$$ not-here.txt > /dev/null 2>&1"
+
+log_pass "A read of a non-existent xattr fails"
--- /dev/null	Fri Nov 22 15:22:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_003_neg.ksh	Fri Nov 22 15:22:32 2013
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Attempting to read an xattr on a file for which we have no permissions
+# should fail.
+#
+# STRATEGY:
+#	1. Create a file, and set an with an xattr
+#       2. Set the octal file permissions to 000 on the file.
+#	3. Check that we're unable to read the xattr as a non-root user
+#	4. Check that we're unable to write an xattr as a non-root user
+#
+
+function cleanup {
+
+	log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "read/write xattr on a file with no permissions fails"
+log_onexit cleanup
+
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+log_must $CHMOD 000 $TESTDIR/myfile.$$
+log_mustnot $SU $ZFS_USER -c "$RUNAT $TESTDIR/myfile.$$ $CAT passwd"
+log_mustnot $SU $ZFS_USER -c "$RUNAT $TESTDIR/myfile.$$ $CP /etc/passwd ."
+
+log_pass "read/write xattr on a file with no permissions fails"
--- /dev/null	Fri Nov 22 15:22:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh	Fri Nov 22 15:22:32 2013
@@ -0,0 +1,86 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Creating files on ufs and tmpfs, and copying those files to ZFS with
+# appropriate cp flags, the xattrs will still be readable.
+#
+# STRATEGY:
+#	1. Create files in ufs and tmpfs with xattrs
+#       2. Copy those files to zfs
+#	3. Ensure the xattrs can be read and written
+#	4. Do the same in reverse.
+#
+
+# we need to be able to create zvols to hold our test
+# ufs filesystem.
+verify_runnable "global"
+
+# Make sure we clean up properly
+function cleanup {
+
+	if [ $( ismounted /tmp/ufs.$$ ufs ) ]
+	then
+		log_must $UMOUNT /tmp/ufs.$$
+		log_must $RM -rf /tmp/ufs.$$
+	fi
+}
+
+log_assert "Files from ufs,tmpfs with xattrs copied to zfs retain xattr info."
+log_onexit cleanup
+
+# Create a UFS file system that we can work in
+log_must $ZFS create -V128m $TESTPOOL/$TESTFS/zvol
+log_must eval "$ECHO y | $NEWFS /dev/zvol/dsk/$TESTPOOL/$TESTFS/zvol > /dev/null 2>&1"
+
+log_must $MKDIR /tmp/ufs.$$
+log_must $MOUNT /dev/zvol/dsk/$TESTPOOL/$TESTFS/zvol /tmp/ufs.$$
+
+# Create files in ufs and tmpfs, and set some xattrs on them.
+log_must $TOUCH /tmp/ufs.$$/ufs-file.$$
+log_must $TOUCH /tmp/tmpfs-file.$$
+
+log_must $RUNAT /tmp/ufs.$$/ufs-file.$$ $CP /etc/passwd .
+log_must $RUNAT /tmp/tmpfs-file.$$ $CP /etc/group .
+
+# copy those files to ZFS
+log_must $CP -@ /tmp/ufs.$$/ufs-file.$$ $TESTDIR
+log_must $CP -@ /tmp/tmpfs-file.$$ $TESTDIR
+
+# ensure the xattr information has been copied correctly
+log_must $RUNAT $TESTDIR/ufs-file.$$ $DIFF passwd /etc/passwd
+log_must $RUNAT $TESTDIR/tmpfs-file.$$ $DIFF group /etc/group
+
+log_must $UMOUNT /tmp/ufs.$$
+log_pass "Files from ufs,tmpfs with xattrs copied to zfs retain xattr info."
--- /dev/null	Fri Nov 22 15:22:32 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_005_pos.ksh	Fri Nov 22 15:22:32 2013
@@ -0,0 +1,78 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# read/write/create/delete xattr on a clone filesystem
+#
+#
+# STRATEGY:
+#	1. Create an xattr on a filesystem
+#	2. Snapshot the filesystem and clone it
+#       3. Verify the xattr can still be read, written, deleted
+#	4. Verify we can create new xattrs on new files created on the clone
+#
+
+function cleanup {
+
+	log_must $ZFS destroy $TESTPOOL/$TESTFS/clone
+	log_must $ZFS destroy $TESTPOOL/$TESTFS@snapshot1
+	log_must $RM $TESTDIR/myfile.$$
+}
+
+log_assert "read/write/create/delete xattr on a clone filesystem"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# snapshot & clone the filesystem
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot1
+log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot1 $TESTPOOL/$TESTFS/clone
+log_must $ZFS set mountpoint=$TESTDIR/clone $TESTPOOL/$TESTFS/clone
+
+# check for the xattrs on the clone
+verify_xattr $TESTDIR/clone/myfile.$$ passwd /etc/passwd
+
+# check we can create xattrs on the clone
+create_xattr $TESTDIR/clone/myfile.$$ foo /etc/passwd
+delete_xattr $TESTDIR/clone/myfile.$$ foo
+
+# delete the original dataset xattr
+delete_xattr $TESTDIR/myfile.$$ passwd
+
+# verify it's still there on the clone
+verify_xattr $TESTDIR/clone/myfile.$$ passwd /etc/passwd
+delete_xattr $TESTDIR/clone/myfile.$$ passwd
+
+log_pass "read/write/create/delete xattr on a clone filesystem"
--- /dev/null	Fri Nov 22 15:22:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_006_pos.ksh	Fri Nov 22 15:22:33 2013
@@ -0,0 +1,63 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# Xattrs present on a file in a snapshot should be visible.
+#
+# STRATEGY:
+#	1. Create a file and give it an xattr
+#       2. Take a snapshot of the filesystem
+#	3. Verify that we can take a snapshot of it.
+#
+
+function cleanup {
+
+	log_must $ZFS destroy $TESTPOOL/$TESTFS@snap
+	log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "read xattr on a snapshot"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# snapshot the filesystem
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+
+# check for the xattr on the snapshot
+verify_xattr $TESTDIR/.zfs/snapshot/snap/myfile.$$ passwd /etc/passwd
+
+log_pass "read xattr on a snapshot"
--- /dev/null	Fri Nov 22 15:22:33 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_007_neg.ksh	Fri Nov 22 15:22:33 2013
@@ -0,0 +1,81 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# Creating and writing xattrs on files in snapshot directories fails. Also,
+# we shouldn't be able to list the xattrs of files in snapshots who didn't have
+# xattrs when the snapshot was created (the xattr namespace wouldn't have been
+# created yet, and snapshots are read-only) See fsattr(5) for more details.
+#
+# STRATEGY:
+#	1. Create a file and add an xattr to it.
+#	2. Create another file, but don't add an xattr to it.
+#       3. Snapshot the filesystem
+#	4. Verify we're unable to alter the xattr on the first file
+#	5. Verify we're unable to list the xattrs on the second file
+#
+
+function cleanup {
+	log_must $ZFS destroy $TESTPOOL/$TESTFS@snap
+	log_must $RM $TESTDIR/myfile2.$$
+	log_must $RM $TESTDIR/myfile.$$
+	log_must $RM /tmp/output.$$
+	[[ -e /tmp/expected_output.$$ ]]  && log_must $RM  \
+	/tmp/expected_output.$$
+
+}
+
+log_assert "create/write xattr on a snapshot fails"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# create another file that doesn't have an xattr
+log_must $TOUCH $TESTDIR/myfile2.$$
+
+# snapshot the filesystem
+log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap
+
+# we shouldn't be able to alter the first file's xattr
+log_mustnot eval " $RUNAT $TESTDIR/.zfs/snapshot/snap/myfile.$$ \
+    $CP /etc/passwd .  >/tmp/output.$$  2>&1"
+log_must $GREP  -i  Read-only  /tmp/output.$$
+
+log_must eval "$RUNAT $TESTDIR/.zfs/snapshot/snap/myfile2.$$  \
+    $LS >/tmp/output.$$  2>&1"
+create_expected_output  /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw
+log_must $DIFF /tmp/output.$$ /tmp/expected_output.$$
+
+log_pass "create/write xattr on a snapshot fails"
--- /dev/null	Fri Nov 22 15:22:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_008_pos.ksh	Fri Nov 22 15:22:34 2013
@@ -0,0 +1,80 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# We verify that the special . and .. dirs work as expected for xattrs.
+#
+# STRATEGY:
+#	1. Create a file and an xattr on that file
+#	2. List the . directory, verifying the output
+#	3. Verify we're unable to list the ../ directory
+#
+
+function cleanup {
+	typeset file
+
+	for file in /tmp/output.$$ /tmp/expected-output.$$ \
+		$TESTDIR/myfile.$$ ; do
+		log_must $RM -f $file
+	done
+}
+
+log_assert "special . and .. dirs work as expected for xattrs"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# listing the directory .
+log_must eval "$RUNAT $TESTDIR/myfile.$$ $LS  . > /tmp/output.$$"
+create_expected_output  /tmp/expected-output.$$  \
+    SUNWattr_ro  SUNWattr_rw  passwd
+log_must $DIFF /tmp/output.$$ /tmp/expected-output.$$
+# list the directory . long form
+log_must eval "$RUNAT $TESTDIR/myfile.$$ $LS -a . > /tmp/output.$$"
+create_expected_output  /tmp/expected-output.$$ . ..  \
+    SUNWattr_ro  SUNWattr_rw  passwd
+log_must $DIFF /tmp/output.$$ /tmp/expected-output.$$
+
+# list the directory .. expecting one file
+OUTPUT=$($RUNAT $TESTDIR/myfile.$$ $LS ..)
+if [ "$OUTPUT" != ".." ]
+then
+	log_fail "Listing the .. directory doesn't show \"..\" as expected."
+fi
+
+# verify we can't list ../
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $LS ../ > /dev/null 2>&1"
+
+log_pass "special . and .. dirs work as expected for xattrs"
--- /dev/null	Fri Nov 22 15:22:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_009_neg.ksh	Fri Nov 22 15:22:34 2013
@@ -0,0 +1,62 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# links between xattr and normal file namespace fail
+#
+# STRATEGY:
+#	1. Create a file and add an xattr to it (to ensure the namespace exists)
+#       2. Verify we're unable to create a symbolic link
+#	3. Verify we're unable to create a hard link
+#
+
+function cleanup {
+
+	log_must $RM $TESTDIR/myfile.$$
+
+}
+
+log_assert "links between xattr and normal file namespace fail"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# Try to create a soft link from the xattr namespace to the default namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $LN -s /etc/passwd foo
+
+# Try to create a hard link from the xattr namespace to the default namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $LN /etc/passwd foo
+
+log_pass "links between xattr and normal file namespace fail"
--- /dev/null	Fri Nov 22 15:22:34 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_010_neg.ksh	Fri Nov 22 15:22:34 2013
@@ -0,0 +1,66 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# Verify that mkdir and various mknods fail inside the xattr namespace
+#
+# STRATEGY:
+#	1. Create a file and add an xattr to it (to ensure the namespace exists)
+#       2. Verify that mkdir fails inside the xattr namespace
+#	3. Verify that various mknods fails inside the xattr namespace
+#
+#
+
+function cleanup {
+
+	log_must $RM $TESTDIR/myfile.$$
+}
+
+log_assert "mkdir, mknod fail"
+log_onexit cleanup
+
+# create a file, and an xattr on it
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# Try to create directory in the xattr namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKDIR foo
+
+# Try to create a range of different filetypes in the xattr namespace
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKNOD block b 888 888
+
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKNOD char c
+
+log_mustnot $RUNAT $TESTDIR/myfile.$$ $MKNOD fifo p
+
+log_pass "mkdir, mknod fail"
--- /dev/null	Fri Nov 22 15:22:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh	Fri Nov 22 15:22:35 2013
@@ -0,0 +1,193 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+#
+# Basic applications work with xattrs: cpio cp find mv pax tar
+#
+# STRATEGY:
+#	1. For each application
+#       2. Create an xattr and archive/move/copy/find files with xattr support
+#	3. Also check that when appropriate flag is not used, the xattr
+#	   doesn't get copied
+#
+
+function cleanup {
+
+	log_must $RM $TESTDIR/myfile.$$
+}
+
+log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"
+log_onexit cleanup
+
+# Create a file, and set an xattr on it. This file is used in several of the
+# test scenarios below.
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+
+# For the archive applications below (tar, cpio, pax)
+# we create two archives, one with xattrs, one without
+# and try various cpio options extracting the archives
+# with and without xattr support, checking for correct behaviour
+
+
+log_note "Checking cpio"
+log_must $TOUCH $TESTDIR/cpio.$$
+create_xattr $TESTDIR/cpio.$$ passwd /etc/passwd
+$ECHO $TESTDIR/cpio.$$ | $CPIO -o@ > /tmp/xattr.$$.cpio
+$ECHO $TESTDIR/cpio.$$ | $CPIO -o > /tmp/noxattr.$$.cpio
+
+# we should have no xattr here
+log_must $CPIO -iu < /tmp/xattr.$$.cpio
+log_mustnot eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+
+# we should have an xattr here
+log_must $CPIO -iu@ < /tmp/xattr.$$.cpio
+log_must eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+
+# we should have no xattr here
+log_must $CPIO -iu < /tmp/noxattr.$$.cpio
+log_mustnot eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+
+# we should have no xattr here
+log_must $CPIO -iu@ < /tmp/noxattr.$$.cpio
+log_mustnot eval "$RUNAT $TESTDIR/cpio.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/cpio.$$ /tmp/xattr.$$.cpio /tmp/noxattr.$$.cpio
+
+
+
+log_note "Checking cp"
+# check that with the right flag, the xattr is preserved
+log_must $CP -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
+compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd
+log_must $RM $TESTDIR/myfile2.$$
+
+# without the right flag, there should be no xattr
+log_must $CP $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
+log_mustnot eval "$RUNAT $TESTDIR/myfile2.$$ $LS passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/myfile2.$$
+
+
+
+log_note "Checking find"
+# create a file without xattrs, and check that find -xattr only finds
+# our test file that has an xattr.
+log_must $MKDIR $TESTDIR/noxattrs
+log_must $TOUCH $TESTDIR/noxattrs/no-xattr
+
+$FIND $TESTDIR -xattr | $GREP myfile.$$
+[[ $? -ne 0 ]] && \
+	log_fail "find -xattr didn't find our file that had an xattr."
+$FIND $TESTDIR -xattr | $GREP no-xattr
+[[ $? -eq 0 ]] && \
+	log_fail "find -xattr found a file that didn't have an xattr."
+log_must $RM -rf $TESTDIR/noxattrs
+
+
+
+log_note "Checking mv"
+# mv doesn't have any flags to preserve/ommit xattrs - they're
+# always moved.
+log_must $TOUCH $TESTDIR/mvfile.$$
+create_xattr $TESTDIR/mvfile.$$ passwd /etc/passwd
+log_must $MV $TESTDIR/mvfile.$$ $TESTDIR/mvfile2.$$
+verify_xattr $TESTDIR/mvfile2.$$ passwd /etc/passwd
+log_must $RM $TESTDIR/mvfile2.$$
+
+
+log_note "Checking pax"
+log_must $TOUCH $TESTDIR/pax.$$
+create_xattr $TESTDIR/pax.$$ passwd /etc/passwd
+log_must $PAX -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$
+log_must $PAX -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$
+log_must $RM $TESTDIR/pax.$$
+
+# we should have no xattr here
+log_must $PAX -r -f $TESTDIR/noxattr.pax
+log_mustnot eval "$RUNAT $TESTDIR/pax.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/pax.$$
+
+# we should have no xattr here
+log_must $PAX -r@ -f $TESTDIR/noxattr.pax
+log_mustnot eval "$RUNAT $TESTDIR/pax.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/pax.$$
+
+
+# we should have an xattr here
+log_must $PAX -r@ -f $TESTDIR/xattr.pax
+verify_xattr $TESTDIR/pax.$$ passwd /etc/passwd
+log_must $RM $TESTDIR/pax.$$
+
+# we should have no xattr here
+log_must $PAX -r -f $TESTDIR/xattr.pax $TESTDIR
+log_mustnot eval "$RUNAT $TESTDIR/pax.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/pax.$$ $TESTDIR/noxattr.pax $TESTDIR/xattr.pax
+
+
+log_note "Checking tar"
+log_must $TOUCH $TESTDIR/tar.$$
+create_xattr $TESTDIR/tar.$$ passwd /etc/passwd
+
+log_must cd $TESTDIR
+
+log_must $TAR cf noxattr.tar tar.$$
+log_must $TAR c@f xattr.tar tar.$$
+log_must $RM $TESTDIR/tar.$$
+
+# we should have no xattr here
+log_must $TAR xf xattr.tar
+log_mustnot eval "$RUNAT $TESTDIR/tar.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/tar.$$
+
+# we should have an xattr here
+log_must $TAR x@f xattr.tar
+verify_xattr tar.$$ passwd /etc/passwd
+log_must $RM $TESTDIR/tar.$$
+
+# we should have no xattr here
+log_must $TAR xf $TESTDIR/noxattr.tar
+log_mustnot eval "$RUNAT $TESTDIR/tar.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/tar.$$
+
+# we should have no xattr here
+log_must $TAR x@f $TESTDIR/noxattr.tar
+log_mustnot eval "$RUNAT $TESTDIR/tar.$$ $CAT passwd > /dev/null 2>&1"
+log_must $RM $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar
+
+
+log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"
--- /dev/null	Fri Nov 22 15:22:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_012_pos.ksh	Fri Nov 22 15:22:35 2013
@@ -0,0 +1,103 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# xattr file sizes count towards normal disk usage
+#
+# STRATEGY:
+#	1. Create a file, and check pool and filesystem usage
+#       2. Create a 200mb xattr in that file
+#	3. Check pool and filesystem usage, to ensure it reflects the size
+#	   of the xattr
+#
+
+function cleanup {
+	log_must $RM $TESTDIR/myfile.$$
+}
+
+function get_pool_size {
+	poolname=$1
+	psize=$($ZPOOL list -H -o allocated $poolname)
+	if [[ $psize == *[mM] ]]
+	then
+		returnvalue=$($ECHO $psize | $SED -e 's/m//g' -e 's/M//g')
+		returnvalue=$((returnvalue * 1024))
+	else
+		returnvalue=$($ECHO $psize | $SED -e 's/k//g' -e 's/K//g')
+	fi
+	echo $returnvalue
+}
+
+log_assert "xattr file sizes count towards normal disk usage"
+log_onexit cleanup
+
+log_must $TOUCH $TESTDIR/myfile.$$
+
+POOL_SIZE=0
+NEW_POOL_SIZE=0
+
+if is_global_zone
+then
+	# get pool and filesystem sizes. Since we're starting with an empty
+	# pool, the usage should be small - a few k.
+	POOL_SIZE=$(get_pool_size $TESTPOOL)
+fi
+
+FS_SIZE=$($ZFS get -p -H -o value used $TESTPOOL/$TESTFS)
+
+log_must $RUNAT $TESTDIR/myfile.$$ $MKFILE 200m xattr
+
+#Make sure the newly created file is counted into zpool usage
+log_must $SYNC
+
+# now check to see if our pool disk usage has increased
+if is_global_zone
+then
+	NEW_POOL_SIZE=$(get_pool_size $TESTPOOL)
+	(($NEW_POOL_SIZE <= $POOL_SIZE)) && \
+	    log_fail "The new pool size $NEW_POOL_SIZE was less \
+            than or equal to the old pool size $POOL_SIZE."
+
+fi
+
+# also make sure our filesystem usage has increased
+NEW_FS_SIZE=$($ZFS get -p -H -o value used $TESTPOOL/$TESTFS)
+(($NEW_FS_SIZE <= $FS_SIZE)) && \
+    log_fail "The new filesystem size $NEW_FS_SIZE was less \
+    than or equal to the old filesystem size $FS_SIZE."
+
+log_pass "xattr file sizes count towards normal disk usage"
--- /dev/null	Fri Nov 22 15:22:35 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_013_pos.ksh	Fri Nov 22 15:22:35 2013
@@ -0,0 +1,88 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
+
+#
+# DESCRIPTION:
+# The noxattr mount option functions as expected
+#
+# STRATEGY:
+#	1. Create a file on a filesystem and add an xattr to it
+#	2. Unmount the filesystem, and mount it -o noxattr
+#	3. Verify that the xattr cannot be read and new files
+#	   cannot have xattrs set on them.
+#	4. Unmount and mount the filesystem normally
+#	5. Verify that xattrs can be set and accessed again
+#
+
+function cleanup {
+
+	log_must $RM $TESTDIR/myfile.$$
+}
+
+
+log_assert "The noxattr mount option functions as expected"
+log_onexit cleanup
+
+$ZFS set 2>&1 | $GREP xattr > /dev/null
+if [ $? -ne 0 ]
+then
+	log_unsupported "noxattr mount option not supported on this release."
+fi
+
+log_must $TOUCH $TESTDIR/myfile.$$
+create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+log_must $UMOUNT $TESTDIR
+log_must $ZFS mount -o noxattr $TESTPOOL/$TESTFS
+
+# check that we can't perform xattr operations
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $CAT passwd > /dev/null 2>&1"
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $RM passwd > /dev/null 2>&1"
+log_mustnot eval "$RUNAT $TESTDIR/myfile.$$ $CP /etc/passwd . > /dev/null 2>&1"
+
+log_must $TOUCH $TESTDIR/new.$$
+log_mustnot eval "$RUNAT $TESTDIR/new.$$ $CP /etc/passwd . > /dev/null 2>&1"
+log_mustnot eval "$RUNAT $TESTDIR/new.$$ $RM passwd > /dev/null 2>&1"
+
+# now mount the filesystem again as normal
+log_must $UMOUNT $TESTDIR
+log_must $ZFS mount $TESTPOOL/$TESTFS
+
+# we should still have an xattr on the first file
+verify_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
+
+# there should be no xattr on the file we created while the fs was mounted
+# -o noxattr
+log_mustnot eval "$RUNAT $TESTDIR/new.$$ $CAT passwd > /dev/null 2>&1"
+create_xattr $TESTDIR/new.$$ passwd /etc/passwd
+
+log_pass "The noxattr mount option functions as expected"
--- /dev/null	Fri Nov 22 15:22:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/xattr/xattr_common.kshlib	Fri Nov 22 15:22:36 2013
@@ -0,0 +1,107 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+# a function that takes a file, then creates and verifies
+# an xattr on that file. The xattr_contents is the file
+# that should appear in the xattr namespace.
+function create_xattr { # filename xattr_name xattr_contents
+	typeset FILE=$1
+	typeset XATTR_NAME=$2
+	typeset XATTR_CONTENTS=$3
+
+	# read any empty xattr on that file
+	log_must $RUNAT $FILE $LS
+	# create the xattr
+	log_must $RUNAT $FILE $CP $XATTR_CONTENTS $XATTR_NAME
+
+	verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS
+}
+
+# a function that compares the a single xattr between two files
+# and checks to see if their contents are identical
+function compare_xattrs { # filename1 filename2 xattr_name
+	typeset FILE1=$1
+	typeset FILE2=$2
+	typeset XATTR_NAME=$3
+
+	$RUNAT $FILE1 $CAT $XATTR_NAME > /tmp/file1.$$
+	$RUNAT $FILE2 $CAT $XATTR_NAME > /tmp/file2.$$
+
+	log_must $DIFF /tmp/file1.$$ /tmp/file2.$$
+	log_must $RM /tmp/file1.$$ /tmp/file2.$$
+}
+
+function verify_xattr { # filename xattr_name xattr_contents
+	typeset FILE=$1
+	typeset XATTR_NAME=$2
+	typeset XATTR_CONTENTS=$3
+
+	# read the xattr, writing it to a temp file
+	log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
+	log_must $DIFF $XATTR_CONTENTS /tmp/$XATTR_NAME.$$
+	$RM /tmp/$XATTR_NAME.$$
+}
+
+function delete_xattr { # filename xattr_name
+        typeset FILE=$1
+        typeset XATTR_NAME=$2
+
+        # delete the xattr
+        log_must $RUNAT $FILE $RM $XATTR_NAME
+        log_mustnot eval "$RUNAT $FILE $LS $XATTR_NAME > /dev/null 2>&1"
+}
+
+# not sure about this : really this should be testing write/append
+function verify_write_xattr { # filename xattr_name
+        typeset FILE=$1
+        typeset XATTR_NAME=$2
+
+        log_must eval "$RUNAT $FILE $DD if=/etc/passwd of=$XATTR_NAME"
+        log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
+        log_must $DD if=/etc/passwd of=/tmp/passwd_dd.$$
+        log_must $DIFF /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
+        log_must $RM /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
+}
+
+# this function is to create the expected output
+function create_expected_output  { # expected_output_file  contents_of_the_output
+   typeset FILE=$1
+   shift
+   if [[ -f $FILE ]]; then
+      log_must $RM $FILE
+   fi
+
+   for line in $@
+   do
+      log_must eval "$ECHO $line >> $FILE"
+   done
+ }
--- /dev/null	Fri Nov 22 15:22:36 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/Makefile	Fri Nov 22 15:22:36 2013
@@ -0,0 +1,46 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/zvol
+
+FILES = zvol.cfg \
+	zvol_common.shlib
+
+CMDS = $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+SUBDIRS = zvol_ENOSPC \
+	zvol_cli \
+	zvol_misc \
+	zvol_swap
+
+include $(SRC)/test/Makefile.com
--- /dev/null	Fri Nov 22 15:22:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol.cfg	Fri Nov 22 15:22:37 2013
@@ -0,0 +1,38 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+export DISK=${DISKS%% *}
+
+export TESTVOL=testvol
+export TESTFILE=testfile
+export TESTSNAP=testsnap
+export VOLSIZE=2g
+export DATA=0
+export ENOSPC=28
--- /dev/null	Fri Nov 22 15:22:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_ENOSPC/Makefile	Fri Nov 22 15:22:37 2013
@@ -0,0 +1,41 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/zvol/zvol_ENOSPC
+
+PROGS = cleanup \
+	setup \
+	zvol_ENOSPC_001_pos
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:22:37 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_ENOSPC/cleanup.ksh	Fri Nov 22 15:22:37 2013
@@ -0,0 +1,44 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+ismounted $TESTDIR ufs
+(( $? == 0 )) && log_must $UMOUNT -f $TESTDIR
+
+[[ -e $TESTDIR ]] && $RM -rf $TESTDIR
+
+default_zvol_cleanup
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_ENOSPC/setup.ksh	Fri Nov 22 15:22:38 2013
@@ -0,0 +1,45 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_setup $DISK $VOLSIZE
+
+$ECHO "y" | $NEWFS -v /dev/zvol/rdsk/$TESTPOOL/$TESTVOL >/dev/null 2>&1
+(( $? != 0 )) && log_fail "Unable to newfs(1M) $TESTPOOL/$TESTVOL"
+
+log_must $MKDIR $TESTDIR
+log_must $MOUNT /dev/zvol/dsk/$TESTPOOL/$TESTVOL $TESTDIR
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos.ksh	Fri Nov 22 15:22:38 2013
@@ -0,0 +1,80 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol.cfg
+
+#
+# DESCRIPTION:
+# A zvol volume will return ENOSPC when the underlying pool runs out of
+# space.
+#
+# STRATEGY:
+# 1. Create a pool
+# 2. Create a zvol volume
+# 3. Create a ufs file system ontop of the zvol
+# 4. Mount the ufs file system
+# 5. Fill volume until ENOSPC is returned
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -rf $TESTDIR/*
+}
+
+log_assert "A zvol volume will return ENOSPC when the underlying pool " \
+    "runs out of space."
+
+log_onexit cleanup
+
+typeset -i fn=0
+typeset -i retval=0
+
+BLOCKSZ=$(( 1024 * 1024 ))
+NUM_WRITES=40
+
+while (( 1 )); do
+        $FILE_WRITE -o create -f $TESTDIR/testfile$$.$fn \
+            -b $BLOCKSZ -c $NUM_WRITES
+        retval=$?
+        if (( $retval != 0 )); then
+                break
+        fi
+
+        (( fn = fn + 1 ))
+done
+
+(( $retval != $ENOSPC )) &&
+    log_fail "ENOSPC was not returned, $retval was received instead"
+
+log_pass "ENOSPC was returned as expected"
--- /dev/null	Fri Nov 22 15:22:38 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_cli/Makefile	Fri Nov 22 15:22:38 2013
@@ -0,0 +1,45 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/zvol/zvol_cli
+
+PROGS = cleanup \
+	setup \
+	zvol_cli_001_pos \
+	zvol_cli_002_pos \
+	zvol_cli_003_neg
+
+FILES = zvol_cli.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:22:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_cli/cleanup.ksh	Fri Nov 22 15:22:39 2013
@@ -0,0 +1,39 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_cleanup
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_cli/setup.ksh	Fri Nov 22 15:22:39 2013
@@ -0,0 +1,39 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_setup $DISK $VOLSIZE
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:39 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_001_pos.ksh	Fri Nov 22 15:22:39 2013
@@ -0,0 +1,63 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Executing well-formed 'zfs list' commands should return success
+#
+# STRATEGY:
+# 1. Create an array of valid options.
+# 2. Execute each element in the array.
+# 3. Verify success is returned.
+#
+
+verify_runnable "global"
+
+TESTVOL='testvol'
+
+set -A args  "list" "list -r" \
+    "list $TESTPOOL/$TESTVOL" "list -r $TESTPOOL/$TESTVOL"  \
+    "list -H $TESTPOOL/$TESTVOL" "list -Hr $TESTPOOL/$TESTVOL"  \
+    "list -rH $TESTPOOL/$TESTVOL" "list -o name $TESTPOOL/$TESTVOL" \
+    "list -r -o name $TESTPOOL/$TESTVOL" "list -H -o name $TESTPOOL/$TESTVOL" \
+    "list -rH -o name $TESTPOOL/$TESTVOL"
+
+log_assert "Executing well-formed 'zfs list' commands should return success"
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_must eval "$ZFS ${args[i]} > /dev/null"
+	((i = i + 1))
+done
+
+log_pass "Executing zfs list on volume works as expected"
--- /dev/null	Fri Nov 22 15:22:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh	Fri Nov 22 15:22:40 2013
@@ -0,0 +1,62 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Creating a volume with a 50 letter name should work.
+#
+# STRATEGY:
+# 1. Using a very long name, create a zvol
+# 2. Verify volume exists
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	datasetexists $TESTPOOL/$LONGVOLNAME && \
+		$ZFS destroy $TESTPOOL/$LONGVOLNAME
+}
+
+log_onexit cleanup
+
+log_assert "Creating a volume a 50 letter name should work."
+
+LONGVOLNAME="volumename50charslong_0123456789012345678901234567"
+
+log_must $ZFS create -V $VOLSIZE $TESTPOOL/$LONGVOLNAME
+
+datasetexists $TESTPOOL/$LONGVOLNAME || \
+	log_fail "Couldn't find long volume name"
+
+log_pass "Created a 50-letter zvol volume name"
--- /dev/null	Fri Nov 22 15:22:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_003_neg.ksh	Fri Nov 22 15:22:40 2013
@@ -0,0 +1,59 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Try each ZFS volume sub-command without parameters to make sure
+# it returns an error.
+#
+# STRATEGY:
+# 1. Create an array of parameters
+# 2. For each parameter in the array, execute the sub-command
+# 3. Verify an error is returned.
+#
+
+verify_runnable "global"
+
+set -A args "" "create -V" "create -V $TESTPOOL" \
+	"create -V $TESTPOOL/$TESTVOL@" "create -V blah" "destroy"
+
+log_assert "Try each ZFS volume sub-command without parameters to make sure" \
+    " it returns an error."
+
+typeset -i i=0
+while (( $i < ${#args[*]} )); do
+	log_mustnot $ZFS ${args[i]}
+	(( i = i + 1 ))
+done
+
+log_pass "Badly formed ZFS volume sub-commands fail as expected."
--- /dev/null	Fri Nov 22 15:22:40 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_common.shlib	Fri Nov 22 15:22:40 2013
@@ -0,0 +1,140 @@
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol.cfg
+
+#
+# Create a simple zvol volume
+#
+# Where disk_device: is the name of the disk to be used
+#       volume_size: is the size of the volume, e.g. 2G
+#
+function default_zvol_setup # disk_device volume_size
+{
+        typeset disk=$1
+        typeset size=$2
+	typeset savedumpdev
+	typeset -i output
+
+        create_pool $TESTPOOL "$disk"
+
+        log_must $ZFS create -V $size $TESTPOOL/$TESTVOL
+
+	set_dumpsize $TESTPOOL/$TESTVOL
+}
+
+#
+# Destroy the default zvol which was setup using
+# default_zvol_setup().
+#
+function default_zvol_cleanup
+{
+        if datasetexists $TESTPOOL/$TESTVOL ; then
+		log_must $ZFS destroy $TESTPOOL/$TESTVOL
+	fi
+
+        destroy_pool $TESTPOOL
+}
+
+function get_dumpdevice
+{
+	typeset ret=$($DUMPADM | $GREP "Dump device:" | $AWK '{print $3}')
+	echo $ret
+}
+
+function set_dumpsize
+{
+	typeset volume=$1
+
+	if [[ -z $volume ]] ; then
+		log_note "No volume specified."
+		return 1
+	fi
+
+	log_must $ZFS set volsize=64m $volume
+
+	output=$($DUMPADM -d /dev/zvol/dsk/$volume 2>&1 | \
+			$TAIL -1 | $AWK '{print $3}')
+
+	if [[ -n $output ]]; then
+		(( output = output / 1024 / 1024 ))
+		(( output = output + output / 5 ))
+		log_must $ZFS set volsize=${output}m $volume
+	fi
+	return 0
+}
+
+function safe_dumpadm
+{
+	typeset device=$1
+
+	if [[ -z $device || $device == "none" ]] ; then
+		log_note "No dump device volume specified."
+		return 1
+	fi
+	if [[ $device == "/dev/zvol/dsk/"* ]] ; then
+		typeset volume=${device#/dev/zvol/dsk/}
+		set_dumpsize $volume
+		log_must $DUMPADM -d $device
+	else
+		log_must $SWAPADD
+		if ! is_swap_inuse $device ; then
+			log_must $SWAP -a $device
+		fi
+		log_must $DUMPADM -d swap
+	fi
+}
+
+function is_zvol_dumpified
+{
+	typeset volume=$1
+
+	if [[ -z $volume ]] ; then
+		log_note "No volume specified."
+		return 1
+	fi
+
+	$ZDB -dddd $volume 2 | $GREP "dumpsize" > /dev/null 2>&1
+	return $?
+}
+
+function is_swap_inuse
+{
+	typeset device=$1
+
+	if [[ -z $device ]] ; then
+		log_note "No device specified."
+		return 1
+	fi
+
+	$SWAP -l | $GREP -w $device > /dev/null 2>&1
+	return $?
+}
--- /dev/null	Fri Nov 22 15:22:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/Makefile	Fri Nov 22 15:22:41 2013
@@ -0,0 +1,46 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/zvol/zvol_misc
+
+PROGS = cleanup \
+	setup \
+	zvol_misc_001_neg \
+	zvol_misc_002_pos \
+	zvol_misc_003_neg \
+	zvol_misc_004_pos \
+	zvol_misc_005_neg \
+	zvol_misc_006_pos
+
+CMDS = $(PROGS:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:22:41 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh	Fri Nov 22 15:22:41 2013
@@ -0,0 +1,39 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+default_zvol_cleanup
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh	Fri Nov 22 15:22:42 2013
@@ -0,0 +1,43 @@
+#! /usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+verify_runnable "global"
+
+if ! $(is_physical_device $DISKS) ; then
+	log_unsupported "This directory cannot be run on raw files."
+fi
+
+default_zvol_setup $DISK $VOLSIZE
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_001_neg.ksh	Fri Nov 22 15:22:42 2013
@@ -0,0 +1,64 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#	Verify that using a zvol as a dump device works.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Use dumpadm add the volume as dump device
+# 3. Verify the return code as expected.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dumpdev=$(get_dumpdevice)
+
+	if [[ $dumpdev != $savedumpdev ]] ; then
+		safe_dumpadm $savedumpdev
+	fi
+}
+
+log_assert "Verify that a ZFS volume can act as dump device."
+log_onexit cleanup
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+safe_dumpadm $voldev
+
+log_pass "Verify that a ZFS volume can act as dump device."
--- /dev/null	Fri Nov 22 15:22:42 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh	Fri Nov 22 15:22:42 2013
@@ -0,0 +1,91 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify that ZFS volume snapshot could be fscked
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Copy some files and create snapshot
+# 3. Verify fsck on the snapshot is OK
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	snapexists $TESTPOOL/$TESTVOL@snap && \
+		$ZFS destroy $TESTPOOL/$TESTVOL@snap
+
+	ismounted $TESTDIR ufs
+	(( $? == 0 )) && log_must $UMOUNT $TESTDIR
+
+	[[ -e $TESTDIR ]] && $RM -rf $TESTDIR
+}
+
+log_assert "Verify that ZFS volume snapshot could be fscked"
+log_onexit cleanup
+
+TESTVOL='testvol'
+BLOCKSZ=$(( 1024 * 1024 ))
+NUM_WRITES=40
+
+$ECHO "y" | $NEWFS -v /dev/zvol/rdsk/$TESTPOOL/$TESTVOL >/dev/null 2>&1
+(( $? != 0 )) && log_fail "Unable to newfs(1M) $TESTPOOL/$TESTVOL"
+
+log_must $MKDIR $TESTDIR
+log_must $MOUNT /dev/zvol/dsk/$TESTPOOL/$TESTVOL $TESTDIR
+
+typeset -i fn=0
+typeset -i retval=0
+
+while (( 1 )); do
+        $FILE_WRITE -o create -f $TESTDIR/testfile$$.$fn \
+            -b $BLOCKSZ -c $NUM_WRITES
+        retval=$?
+        if (( $retval != 0 )); then
+                break
+        fi
+
+        (( fn = fn + 1 ))
+done
+
+log_must $LOCKFS -f $TESTDIR
+log_must $ZFS snapshot $TESTPOOL/$TESTVOL@snap
+
+$FSCK -n /dev/zvol/rdsk/$TESTPOOL/$TESTVOL@snap >/dev/null 2>&1
+retval=$?
+(( $retval == 39 )) || log_fail "$FSCK exited with wrong value $retval "
+
+log_pass "Verify that ZFS volume snapshot could be fscked"
--- /dev/null	Fri Nov 22 15:22:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_003_neg.ksh	Fri Nov 22 15:22:43 2013
@@ -0,0 +1,75 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#	Verify creating a storage pool or running newfs on a zvol used as a
+#	dump device is denied.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Use dumpadm to set the volume as dump device
+# 3. Verify creating a pool & running newfs on the zvol returns an error.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dumpdev=$(get_dumpdevice)
+	if [[ $dumpdev != $savedumpdev ]] ; then
+		safe_dumpadm $savedumpdev
+	fi
+
+	if poolexists $TESTPOOL1 ; then
+		destroy_pool $TESTPOOL1
+	fi
+}
+
+log_assert "Verify zpool creation and newfs on dump zvol is denied."
+log_onexit cleanup
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+safe_dumpadm $voldev
+
+$ECHO "y" | $NEWFS -v $voldev > /dev/null 2>&1
+if (( $? == 0 )) ; then
+	log_fail "newfs on dump zvol succeeded unexpectedly"
+fi
+
+log_mustnot $ZPOOL create $TESTPOOL1 $voldev
+
+log_pass "Verify zpool creation and newfs on dump zvol is denied."
--- /dev/null	Fri Nov 22 15:22:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh	Fri Nov 22 15:22:43 2013
@@ -0,0 +1,109 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+# Verify the ability to take snapshots of zvols used as dump or swap.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Set the volume as dump or swap
+# 3. Verify creating a snapshot of the zvol succeeds.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dumpdev=$(get_dumpdevice)
+	if [[ $dumpdev != $savedumpdev ]] ; then
+		safe_dumpadm $savedumpdev
+	fi
+
+	$SWAP -l | $GREP -w $voldev > /dev/null 2>&1
+        if (( $? == 0 ));  then
+		log_must $SWAP -d $voldev
+	fi
+
+	typeset snap
+	for snap in snap0 snap1 ; do
+		if datasetexists $TESTPOOL/$TESTVOL@$snap ; then
+			log_must $ZFS destroy $TESTPOOL/$TESTVOL@$snap
+		fi
+	done
+}
+
+function verify_snapshot
+{
+	typeset volume=$1
+
+	log_must $ZFS snapshot $volume@snap0
+	log_must $ZFS snapshot $volume@snap1
+	log_must datasetexists $volume@snap0 $volume@snap1
+
+	log_must $ZFS destroy $volume@snap1
+	log_must $ZFS snapshot $volume@snap1
+
+	log_mustnot $ZFS rollback -r $volume@snap0
+	log_must datasetexists $volume@snap0
+
+	log_must $ZFS destroy -r $volume@snap0
+}
+
+log_assert "Verify the ability to take snapshots of zvols used as dump or swap."
+log_onexit cleanup
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+# create snapshot over dump zvol
+safe_dumpadm $voldev
+log_must is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+verify_snapshot $TESTPOOL/$TESTVOL
+
+safe_dumpadm $savedumpdev
+log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+# create snapshot over swap zvol
+
+log_must $SWAP -a $voldev
+log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+verify_snapshot $TESTPOOL/$TESTVOL
+
+log_must $SWAP -d $voldev
+log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL
+
+log_pass "Creating snapshots from dump/swap zvols succeeds."
--- /dev/null	Fri Nov 22 15:22:43 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_005_neg.ksh	Fri Nov 22 15:22:43 2013
@@ -0,0 +1,75 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+# 	Verify a device cannot be dump and swap at the same time.
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Set it as swap device.
+# 3. Verify dumpadm with this zvol will fail.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$SWAP -l | $GREP $voldev > /dev/null 2>&1
+	if (( $? == 0 )) ; then
+		log_must $SWAP -d $voldev
+	fi
+
+	typeset dumpdev=$(get_dumpdevice)
+	if [[ $dumpdev != $savedumpdev ]] ; then
+		safe_dumpadm $savedumpdev
+	fi
+}
+
+log_assert "Verify a device cannot be dump and swap at the same time."
+log_onexit cleanup
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+# If device in swap list, it cannot be dump device
+log_must $SWAP -a $voldev
+log_mustnot $DUMPADM -d $voldev
+log_must $SWAP -d $voldev
+
+# If device has dedicated as dump device, it cannot add into swap list
+safe_dumpadm $voldev
+log_mustnot $SWAP -a $voldev
+
+log_pass "A device cannot be dump and swap at the same time."
--- /dev/null	Fri Nov 22 15:22:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_006_pos.ksh	Fri Nov 22 15:22:44 2013
@@ -0,0 +1,72 @@
+#! /usr/bin/ksh -p
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+# ZFS volume as dump device, it should always have 128k volblocksize
+#
+# STRATEGY:
+# 1. Create a ZFS volume
+# 2. Use dumpadm set the volume as dump device
+# 3. Verify the volume's volblocksize=128k
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset dumpdev=$(get_dumpdevice)
+	if [[ $dumpdev != $savedumpdev ]] ; then
+		safe_dumpadm $savedumpdev
+	fi
+}
+
+log_assert "zfs volume as dumpdevice should have 128k volblocksize"
+log_onexit cleanup
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+savedumpdev=$(get_dumpdevice)
+
+typeset oblksize=$($ZFS get -H -o value volblocksize $TESTPOOL/$TESTVOL)
+log_note "original $TESTPOOL/$TESTVOL volblocksize=$oblksize"
+
+safe_dumpadm $voldev
+
+typeset blksize=$($ZFS get -H -o value volblocksize $TESTPOOL/$TESTVOL)
+
+if [[ $blksize != "128K" ]]; then
+	log_fail "ZFS volume $TESTPOOL/$TESTVOL volblocksize=$blksize"
+fi
+
+log_pass "zfs volume as dumpdevice should have 128k volblocksize"
--- /dev/null	Fri Nov 22 15:22:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/Makefile	Fri Nov 22 15:22:44 2013
@@ -0,0 +1,48 @@
+#
+# 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) 2013 by Delphix. All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+ROOTOPTPKG = $(ROOT)/opt/zfs-tests
+TESTDIR = $(ROOTOPTPKG)/tests/functional/zvol/zvol_swap
+
+PROGS = cleanup \
+	setup \
+	zvol_swap_001_pos \
+	zvol_swap_002_pos \
+	zvol_swap_003_pos \
+	zvol_swap_004_pos \
+	zvol_swap_005_pos \
+	zvol_swap_006_pos
+
+FILES = zvol_swap.cfg
+
+CMDS = $(PROGS:%=$(TESTDIR)/%) $(FILES:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(TESTDIR)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
+
+$(TESTDIR)/%: %.ksh
+	$(INS.rename)
--- /dev/null	Fri Nov 22 15:22:44 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/cleanup.ksh	Fri Nov 22 15:22:44 2013
@@ -0,0 +1,53 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+verify_runnable "global"
+
+log_must $SWAPADD
+for swapdev in $SAVESWAPDEVS
+do
+	if ! is_swap_inuse $swapdev ; then
+		log_must $SWAP -a $swapdev >/dev/null 2>&1
+	fi
+done
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+if is_swap_inuse $voldev ; then
+	log_must $SWAP -d $voldev
+fi
+
+default_zvol_cleanup
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/setup.ksh	Fri Nov 22 15:22:45 2013
@@ -0,0 +1,49 @@
+#! /usr/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+verify_runnable "global"
+
+for i in $SAVESWAPDEVS ; do
+	log_note "Executing: swap -d $i"
+	$SWAP -d $i >/dev/null 2>&1
+	if [[ $? != 0 ]]; then
+		log_untested "Unable to delete swap device $i because of" \
+				"insufficient RAM"
+	fi
+done
+
+default_zvol_setup $DISK $VOLSIZE
+
+log_pass
--- /dev/null	Fri Nov 22 15:22:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap.cfg	Fri Nov 22 15:22:45 2013
@@ -0,0 +1,40 @@
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/zvol/zvol.cfg
+
+#
+# Remember swap devices
+#
+SAVESWAPDEVS=$($SWAP -l | $NAWK '(NR != 1) {print $1}')
+
+export BLOCKSZ=$(( 1024 * 1024 ))
+export NUM_WRITES=40
+export SAVESWAPDEVS
--- /dev/null	Fri Nov 22 15:22:45 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_001_pos.ksh	Fri Nov 22 15:22:45 2013
@@ -0,0 +1,78 @@
+#! /usr/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+#
+# DESCRIPTION:
+# Verify that a zvol can be used as a swap device
+#
+# STRATEGY:
+# 1. Create a pool
+# 2. Create a zvol volume
+# 3. Use zvol as swap space
+# 4. Create a file under /tmp
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	$RM -rf /tmp/$TESTFILE
+
+	if is_swap_inuse $voldev ; then
+		log_must $SWAP -d $voldev
+	fi
+}
+
+log_assert "Verify that a zvol can be used as a swap device"
+
+log_onexit cleanup
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+log_note "Add zvol volume as swap space"
+log_must $SWAP -a $voldev
+
+log_note "Create a file under /tmp"
+log_must $FILE_WRITE -o create -f /tmp/$TESTFILE \
+    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+[[ ! -f /tmp/$TESTFILE ]] &&
+    log_fail "Unable to create file under /tmp"
+
+filesize=`$LS -l /tmp/$TESTFILE | $AWK '{print $5}'`
+tf_size=$(( BLOCKSZ * NUM_WRITES ))
+(( $tf_size != $filesize )) &&
+    log_fail "testfile is ($filesize bytes), expected ($tf_size bytes)"
+
+log_pass "Successfully added a zvol to swap area."
--- /dev/null	Fri Nov 22 15:22:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_002_pos.ksh	Fri Nov 22 15:22:46 2013
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# 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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#	Add a swap zvol, and consume most (not all) of the space. This test
+#	used to fill up swap, which can hang the system.
+#
+# STRATEGY:
+#	1. Create a new zvol and add it as swap
+#	2. Fill /tmp with 80% the size of the zvol
+#	5. Remove the new zvol, and restore original swap devices
+#
+
+verify_runnable "global"
+log_assert "Using a zvol as swap space, fill /tmp to 80%."
+
+vol=$TESTPOOL/$TESTVOL
+swapdev=/dev/zvol/dsk/$vol
+log_must $SWAP -a $swapdev
+
+# Get 80% of the number of 512 blocks in the zvol
+typeset -i count blks volsize=$(get_prop volsize $vol)
+((blks = (volsize / 512) * 80 / 100))
+# Use 'blks' to determine a count for dd based on a 1M block size.
+((count = blks / 2048))
+
+log_note "Fill 80% of swap"
+log_must $DD if=/dev/urandom of=/tmp/$TESTFILE bs=1048576 count=$count
+log_must $RM -f /tmp/$TESTFILE
+log_must $SWAP -d $swapdev
+
+log_pass "Using a zvol as swap space, fill /tmp to 80%."
--- /dev/null	Fri Nov 22 15:22:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_003_pos.ksh	Fri Nov 22 15:22:46 2013
@@ -0,0 +1,96 @@
+#! /bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_swap/zvol_swap.cfg
+
+#
+# DESCRIPTION:
+# Verify that a zvol device can be used as a swap device
+# through /etc/vfstab configuration.
+#
+# STRATEGY:
+# 1. Modify /etc/vfstab to add the test zvol as swap device.
+# 2. Use /sbin/swapadd to add zvol as swap device throuth /etc/vfstab
+# 3. Create a file under /tmp and verify the file
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	[[ -f /tmp/$TESTFILE ]] && log_must $RM -f /tmp/$TESTFILE
+	[[ -f $NEW_VFSTAB_FILE ]] && log_must $RM -f $NEW_VFSTAB_FILE
+	[[ -f $PREV_VFSTAB_FILE ]] && \
+	    log_must $MV $PREV_VFSTAB_FILE $VFSTAB_FILE
+	[[ -f $PREV_VFSTAB_FILE ]] && $RM -f $PREV_VFSTAB_FILE
+
+	log_must $SWAPADD $VFSTAB_FILE
+
+        if is_swap_inuse $voldev ; then
+		log_must $SWAP -d $voldev
+	fi
+
+}
+
+log_assert "Verify that a zvol device can be used as a swap device" \
+    "through /etc/vfstab configuration."
+
+log_onexit cleanup
+
+voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL
+VFSTAB_FILE=/etc/vfstab
+NEW_VFSTAB_FILE=/var/tmp/zvol_vfstab.$$
+PREV_VFSTAB_FILE=/var/tmp/zvol_vfstab.PREV.$$
+
+[[ -f $NEW_VFSTAB_FILE ]] && $CP /dev/null $NEW_VFSTAB_FILE
+
+$AWK '{if ($4 != "swap") print $1}' /etc/vfstab > $NEW_VFSTAB_FILE
+$ECHO "$voldev\t-\t-\tswap\t-\tno\t-"  >> $NEW_VFSTAB_FILE
+
+# Copy off the original vfstab, and run swapadd on the newly constructed one.
+log_must $CP $VFSTAB_FILE $PREV_VFSTAB_FILE
+log_must $CP $NEW_VFSTAB_FILE $VFSTAB_FILE
+log_must $SWAPADD $VFSTAB_FILE
+
+log_must $FILE_WRITE -o create -f /tmp/$TESTFILE \
+    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
+
+[[ ! -f /tmp/$TESTFILE ]] &&
+    log_fail "Unable to create file under /tmp"
+
+filesize=`$LS -l /tmp/$TESTFILE | $AWK '{print $5}'`
+tf_size=$((BLOCKSZ * NUM_WRITES))
+(($tf_size != $filesize)) && \
+    log_fail "testfile is ($filesize bytes), expected ($tf_size bytes)"
+
+log_pass "Successfully added a zvol to swap area through /etc/vfstab."
--- /dev/null	Fri Nov 22 15:22:46 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh	Fri Nov 22 15:22:46 2013
@@ -0,0 +1,83 @@
+#!/bin/bash
+#
+# 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 2007 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#	When a swap zvol is added it is resized to be equal to 1/4 c_max,
+#	capped between 2G and 16G.
+#
+# STRATEGY:
+#	1. Determine what 1/4 arc_c_max is.
+#	2. Create a zvols in a variety of sizes.
+#	3. Add them as swap, and verify the volsize is resized correctly.
+#
+
+verify_runnable "global"
+
+log_assert "For an added swap zvol, (2G <= volsize <= 16G)"
+
+typeset -i min max mem
+((mem = $($KSTAT -p ::arcstats:c_max | $AWK '{print $2}') / 4))
+((min = 2 * 1024 * 1024 * 1024))
+((max = 16 * 1024 * 1024 * 1024))
+
+for vbs in 512 1024 2048 4096 8192 16384 32768 65536 131072; do
+	for multiplier in 1 32 16384 131072; do
+		((volsize = vbs * multiplier))
+		vol="$TESTPOOL/vol_$volsize"
+		swapname="/dev/zvol/dsk/$vol"
+
+		# Create a sparse volume to test larger sizes
+		log_must $ZFS create -s -b $vbs -V $volsize $vol
+		log_must $SWAP -a $swapname
+
+		if ((mem <= min)); then		# volsize should be 2G
+			new_volsize=$(get_prop volsize $vol)
+			((new_volsize == min)) || log_fail \
+			    "Unexpected volsize: $new_volsize"
+		elif ((mem >= max)); then	# volsize should be 16G
+			new_volsize=$(get_prop volsize $vol)
+			((new_volsize == max)) || log_fail \
+			    "Unexpected volsize: $new_volsize"
+		else				# volsize should be 'mem'
+			new_volsize=$(get_prop volsize $vol)
+			((new_volsize == mem)) || log_fail \
+			    "Unexpected volsize: $new_volsize"
+		fi
+
+		log_must $SWAP -d $swapname
+		log_must $ZFS destroy $vol
+	done
+done
+
+log_pass "For an added swap zvol, (2G <= volsize <= 16G)"
--- /dev/null	Fri Nov 22 15:22:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh	Fri Nov 22 15:22:47 2013
@@ -0,0 +1,69 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#	swaplow + swaplen must be less than or equal to the volume size.
+#
+# STRATEGY:
+#	1. Get test system page size and test volume size.
+#	2. Random get swaplow and swaplen.
+#	3. Verify swap -a should succeed when swaplow + swaplen <= volume size.
+#
+
+verify_runnable "global"
+
+assertion="Verify the sum of swaplow and swaplen is less or equal to volsize"
+log_assert $assertion
+
+typeset vol=$TESTPOOL/$TESTVOL
+typeset swapname="/dev/zvol/dsk/$vol"
+typeset -i pageblocks volblocks max_swaplow
+#
+# Both swaplow and swaplen are the desired length of
+# the swap area in 512-byte blocks.
+#
+((pageblocks = $($PAGESIZE) / 512))
+((volblocks = $(get_prop volsize $vol) / 512))
+((max_swaplow = (volblocks - (pageblocks * 2))))
+
+for i in {0..10}; do
+	swaplow=$($SHUF -n 1 -i ${pageblocks}-${max_swaplow})
+	((maxlen = max_swaplow - swaplow))
+	swaplen=$($SHUF -n 1 -i ${pageblocks}-${maxlen})
+	log_must $SWAP -a $swapname $swaplow $swaplen
+	log_must $SWAP -d $swapname $swaplow
+done
+
+log_pass $assertion
--- /dev/null	Fri Nov 22 15:22:47 2013
+++ new/usr/src/test/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_006_pos.ksh	Fri Nov 22 15:22:47 2013
@@ -0,0 +1,108 @@
+#!/bin/ksh -p
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/zvol/zvol_common.shlib
+
+#
+# DESCRIPTION:
+#	A volume can be added as several segments, but overlapping segments
+#	are not allowed.
+#
+# STRATEGY:
+#	1. Figure out three groups swaplow and swaplen.
+#	2. Verify different volume segments can be added correctly.
+#	3. Verify overlapping swap volume are not allowed.
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+	typeset -i i=0
+
+	while ((count > 0)); do
+		log_must $SWAP -d $swapname ${swap_opt[$i]}
+
+		((i += 2))
+		((count -= 1))
+	done
+}
+
+log_assert "Verify volume can be add as several segments, but overlapping " \
+	"are not allowed."
+log_onexit cleanup
+
+# swap -a won't allow the use of multiple segments of the same volume unless
+# libdiskmgmt is disabled with the environment variable below.
+typeset -x NOINUSE_CHECK=1
+
+typeset vol=$TESTPOOL/$TESTVOL
+typeset -i pageblocks volblocks
+((pageblocks = $($PAGESIZE) / 512))
+((volblocks = $(get_prop volsize $vol) / 512))
+
+log_note "Verify volume can be add as several segments."
+
+#
+#		swaplow			swaplen
+set -A swap_opt	$((pageblocks))	    \
+		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
+		$((volblocks / 3))  \
+		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
+		$((volblocks / 2))  \
+		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \
+		$(((volblocks*2) / 3))  \
+		$((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) ))
+
+swapname=/dev/zvol/dsk/$vol
+typeset -i i=0 count=0
+
+if is_swap_inuse $swapname ; then
+	log_must $SWAP -d $swapname
+fi
+
+while ((i < ${#swap_opt[@]})); do
+	log_must $SWAP -a $swapname ${swap_opt[$i]} ${swap_opt[((i+1))]}
+
+	((i += 2))
+	((count += 1))
+done
+
+log_note "Verify overlapping swap volume are not allowed"
+i=0
+while ((i < ${#swap_opt[@]})); do
+	log_mustnot $SWAP -a $swapname ${swap_opt[$i]}
+
+	((i += 2))
+done
+
+log_pass "Verify volume can be added as several segments passed."
